#include <linux/errno.h>
#include <linux/preempt.h>
#include <linux/sched.h>
-
+#include <linux/slab.h>
+
+#include "palacios.h"
#include "util-hashtable.h"
return (hash_value % table_length);
};
-#define freekey(X) kfree(X)
+#define freekey(X) palacios_free(X)
static void * tmp_realloc(void * old_ptr, uint_t old_size, uint_t new_size) {
- void * new_buf = kmalloc(new_size, GFP_KERNEL);
+ void * new_buf = palacios_alloc(new_size);
if (new_buf == NULL) {
return NULL;
}
memcpy(new_buf, old_ptr, old_size);
- kfree(old_ptr);
+ palacios_free(old_ptr);
return new_buf;
}
}
}
- htable = (struct hashtable *)kmalloc(sizeof(struct hashtable), GFP_KERNEL);
+ if (prime_index==prime_table_len) {
+ // cannot build large enough hash table
+ return NULL;
+ }
+
+ htable = (struct hashtable *)palacios_alloc(sizeof(struct hashtable));
if (htable == NULL) {
return NULL; /*oom*/
}
- htable->table = (struct hash_entry **)kmalloc(sizeof(struct hash_entry*) * size, GFP_KERNEL);
+ htable->table = (struct hash_entry **)palacios_alloc(sizeof(struct hash_entry*) * size);
if (htable->table == NULL) {
- kfree(htable);
+ palacios_free(htable);
return NULL; /*oom*/
}
new_size = primes[++(htable->prime_index)];
- new_table = (struct hash_entry **)kmalloc(sizeof(struct hash_entry*) * new_size, GFP_KERNEL);
+ new_table = (struct hash_entry **)palacios_alloc(sizeof(struct hash_entry*) * new_size);
if (new_table != NULL) {
memset(new_table, 0, new_size * sizeof(struct hash_entry *));
}
}
- kfree(htable->table);
+ palacios_free(htable->table);
htable->table = new_table;
} else {
hashtable_expand(htable);
}
- new_entry = (struct hash_entry *)kmalloc(sizeof(struct hash_entry), GFP_KERNEL);
+ new_entry = (struct hash_entry *)palacios_alloc(sizeof(struct hash_entry));
if (new_entry == NULL) {
(htable->entry_count)--;
if ((hash_value == tmp_entry->hash) && (htable->eq_fn(key, tmp_entry->key))) {
if (free_value) {
- kfree((void *)(tmp_entry->value));
+ palacios_free((void *)(tmp_entry->value));
}
tmp_entry->value = value;
if (free_key) {
freekey((void *)(cursor->key));
}
- kfree(cursor);
+ palacios_free(cursor);
return value;
}
if (free_keys) {
freekey((void *)(tmp->key));
}
- kfree((void *)(tmp->value));
- kfree(tmp);
+ palacios_free((void *)(tmp->value));
+ palacios_free(tmp);
}
}
} else {
if (free_keys) {
freekey((void *)(tmp->key));
}
- kfree(tmp);
+ palacios_free(tmp);
}
}
}
- kfree(htable->table);
- kfree(htable);
+ palacios_free(htable->table);
+ palacios_free(htable);
}