aboutsummaryrefslogtreecommitdiffstats
path: root/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/alloc.c b/alloc.c
index 39a2585..dce15d3 100644
--- a/alloc.c
+++ b/alloc.c
@@ -19,8 +19,9 @@
* This code uses a modified buddy system allocator for large allocations
* and a SLAB allocator for small allocations.
*
- * This generally assumes 8-bit bytes and 2's-complement arithmetric.
- * These days, that's oh-such-a-strech...
+ * This generally assumes 8-bit bytes and 2's-complement arithmetric,
+ * and that an all-zero bit pattern is a valid NULL. These days, that's
+ * oh-such-a-strech...
*/
#include <assert.h>
@@ -78,7 +79,6 @@ struct arena_header {
uint16_t arena_bytesize;
uint16_t arena_ptrsize;
void *arena_base; /* Base of allocation */
- void *root_data_ptr; /* Root data pointer - for the user */
void *free_bitmap; /* The free bitmap */
void *alloc_bitmap; /* The allocated (buddy) bitmap */
void *data_start; /* Beginning of data area */
@@ -86,6 +86,7 @@ struct arena_header {
int arena_size_lg2; /* Current arena allocation size */
int header_size; /* Size of this header+padding */
struct slab_info slab[SLAB_INFO_COUNT];
+ void *root_data_ptrs[ROOT_DATA_POINTERS]; /* Root data pointers - for the user */
};
/* This is the minimal order before going to SLAB allocation. */
@@ -235,10 +236,17 @@ static struct ObjStore *os;
static struct arena_header *ah;
/*
- * Initalize the object store arena allocator.
+ * Initalize the object store arena allocator. This returns NULL
+ * on failure, or a pointer to the "root data pointer" array if
+ * successful.
*/
-void *objstore_arena_init(void)
+void **objstore_arena_init(const char *main_file, const char *log_file)
{
+ size_t arena_len = sizeof(struct arena_header); /* Minimum initial size */
+
+ if ( !objstore_init(main_file, log_file, &arena_len) )
+ return NULL; /* Failed to initialize arena */
+
os = objstore_os_struct;
ah = (struct arena_header *)os->arena;
@@ -247,6 +255,8 @@ void *objstore_arena_init(void)
size_t total_size, bitmap_size;
int i, header_pad;
+ memset(ah, 0, sizeof(*ah)); /* Just in case */
+
/* Uninitialized arena */
memcpy(ah->arena_magic, objstore_arena_magic, 16);
ah->arena_byteorder = 0x12345678;
@@ -309,7 +319,7 @@ void *objstore_arena_init(void)
return NULL; /* Incompatible or corrupt arena */
}
- return ah->data_start;
+ return ah->root_data_ptrs;
}
/*