|
@@ -3,9 +3,13 @@
|
|
|
#ifdef HAVE_LOCKS
|
|
|
#include <pthread.h>
|
|
|
#endif /* HAVE_LOCKS */
|
|
|
-#include "dmm_init.h"
|
|
|
+#include "initialize_allocator.h"
|
|
|
|
|
|
-void dmm_init(allocator_t *allocator) {
|
|
|
+#ifdef WITH_MEMORY_SPACE_AWARENESS
|
|
|
+void initialize_allocator(allocator_t *allocator, void *starting_address, size_t size) {
|
|
|
+#else
|
|
|
+void initialize_allocator(allocator_t *allocator) {
|
|
|
+#endif /* WITH_MEMORY_SPACE_AWARENESS */
|
|
|
int i;
|
|
|
heap_t *current_heap;
|
|
|
maptable_node_t *maptablenode;
|
|
@@ -39,7 +43,18 @@ void dmm_init(allocator_t *allocator) {
|
|
|
// 2 last ones with 64 and 256 (2 fixed lists per heap)
|
|
|
// 2 * 4 + 2 * 2 = 12 maptable nodes
|
|
|
current_heap = &allocator->heaps[0];
|
|
|
+
|
|
|
+#ifndef WITH_MEMORY_SPACE_AWARENESS
|
|
|
maptablenode = (maptable_node_t *) sbrk((int)(12*(sizeof(maptable_node_t))));
|
|
|
+#else
|
|
|
+ if(12*(sizeof(maptable_node_t)) < size) {
|
|
|
+ maptablenode = (maptable_node_t *) sbrk((int)(12*(sizeof(maptable_node_t))));
|
|
|
+ allocator->border_ptr = starting_address + 12*(sizeof(maptable_node_t));
|
|
|
+ allocator->remaining_size = size - 12*(sizeof(maptable_node_t));
|
|
|
+ } else {
|
|
|
+ // Houston, we have a problem
|
|
|
+ }
|
|
|
+#endif /* WITH_MEMORY_SPACE_AWARENESS */
|
|
|
|
|
|
maptablenode->size = 32;
|
|
|
maptablenode->fixed_list_head = NULL;
|
|
@@ -87,5 +102,7 @@ void dmm_init(allocator_t *allocator) {
|
|
|
(maptablenode+1)->size = 256;
|
|
|
(maptablenode+1)->fixed_list_head = NULL;
|
|
|
(maptablenode+1)->next = NULL;
|
|
|
+
|
|
|
+ allocator->initialized = true;
|
|
|
}
|
|
|
|