bootparams for panic on mem exhaustion

This commit is contained in:
uosfz 2026-05-21 17:49:38 +02:00
parent 77dc72e76c
commit b3d51307fd
Signed by: uosfz
SSH key fingerprint: SHA256:FlktuluyhTQg3jHZNLKwxOOC5hbfrUXM0tz3IA3lGJo
3 changed files with 20 additions and 1 deletions

View file

@ -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

View file

@ -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(

View file

@ -1,5 +1,6 @@
#include <stddef.h>
#include <stdint.h>
#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;
}