diff --git a/bootparam.cfg b/bootparam.cfg index f2e6719..e37c40e 100644 --- a/bootparam.cfg +++ b/bootparam.cfg @@ -3,3 +3,5 @@ ps2.enable_logging=false ram.enable_logging=false tlsf.mem_min=131072 tlsf.mem_percentage=20 +tlsf.allocation_asserted=true +slab.allocation_asserted=true diff --git a/src/slab.c b/src/slab.c index a0211f1..db984a5 100644 --- a/src/slab.c +++ b/src/slab.c @@ -2,6 +2,7 @@ #include "address.h" #include "ram.h" #include "std.h" +#include "bootparam.h" #define EFF_SPACE_IN_SLAB (PAGE_SIZE - sizeof(struct slab)) #define SLOT_SIZE(obj_size) ((obj_size) + sizeof(struct free_stack)) @@ -85,6 +86,10 @@ static void *slab_obj_alloc(struct slab *slab) { return (char*)free - slab->cache->obj_size; } +bool slab_allocation_asserted; +BOOTPARAM_BOOL("slab.allocation_asserted", slab_allocation_asserted); +#define ALLOCATION_CHECK(ret) do { if (slab_allocation_asserted) ASSERT(ret); } while (0) + void *slab_cache_alloc(struct slab_cache *cache) { ASSERT(cache != NULL); if (cache->partial_slabs != NULL) { @@ -100,11 +105,13 @@ void *slab_cache_alloc(struct slab_cache *cache) { cache->full_slabs = slab; } + ALLOCATION_CHECK(obj); return obj; } if (cache->empty_slabs == NULL) { if (!slab_cache_new_slab(cache)) { + ALLOCATION_CHECK(NULL); return NULL; } } @@ -122,7 +129,9 @@ void *slab_cache_alloc(struct slab_cache *cache) { cache->full_slabs = slab; } - return slab_obj_alloc(slab); + void *ret = slab_obj_alloc(slab); + ALLOCATION_CHECK(ret); + return ret; } static void slab_cache_remove_slab_from_list( diff --git a/src/tlsf.c b/src/tlsf.c index 8fd92ed..6ea58bb 100644 --- a/src/tlsf.c +++ b/src/tlsf.c @@ -1,5 +1,6 @@ #include #include +#include "bootparam.h" #include "std.h" #include "tlsf.h" #include "sync.h" @@ -579,11 +580,16 @@ void kern_alloc_init(void *addr, size_t pool_size, size_t sli_shift) { global_pool = tlsf_init(addr, pool_size, sli_shift); } +bool tlsf_allocation_asserted; +BOOTPARAM_BOOL("tlsf.allocation_asserted", tlsf_allocation_asserted); +#define ALLOCATION_CHECK(ret) do { if (tlsf_allocation_asserted) ASSERT(ret); } while (0) + void *kern_alloc(size_t size) { ASSERT(global_pool != NULL); spin_lock(&global_pool_lock); void *ret = tlsf_alloc(global_pool, size); spin_unlock(&global_pool_lock); + ALLOCATION_CHECK(ret); return ret; } @@ -592,6 +598,7 @@ void *kern_zalloc(size_t size) { spin_lock(&global_pool_lock); void *ret = tlsf_zalloc(global_pool, size); spin_unlock(&global_pool_lock); + ALLOCATION_CHECK(ret); return ret; } @@ -600,6 +607,7 @@ void *kern_realloc(void *ptr, size_t new_size) { spin_lock(&global_pool_lock); void *ret = tlsf_realloc(global_pool, ptr, new_size); spin_unlock(&global_pool_lock); + ALLOCATION_CHECK(ret); return ret; }