slab: rewrite slab allocator

This commit is contained in:
Matheus
2025-09-04 22:40:10 -03:00
parent 8cba07f65c
commit 2fa040096c
11 changed files with 500 additions and 261 deletions
+5 -2
View File
@@ -821,17 +821,18 @@ void vmm_unmap(void *addr, size_t size, int flags) {
static scache_t *ctxcache;
static void ctxctor(scache_t *cache, void *obj) {
static bool ctxctor(scache_t *cache, void *obj) {
vmmcontext_t *ctx = obj;
ctx->space.start = USERSPACE_START;
ctx->space.end = USERSPACE_END;
MUTEX_INIT(&ctx->space.lock);
ctx->space.ranges = NULL;
return true;
}
vmmcontext_t *vmm_newcontext() {
if (ctxcache == NULL) {
ctxcache = slab_newcache(sizeof(vmmcontext_t), 0, ctxctor, ctxctor);
ctxcache = slab_newcache(sizeof(vmmcontext_t), 0, ctxctor, NULL);
__assert(ctxcache);
}
@@ -854,6 +855,8 @@ void vmm_destroycontext(vmmcontext_t *context) {
vmm_unmap(context->space.start, context->space.end - context->space.start, 0);
vmm_switchcontext(oldctx);
arch_mmu_destroytable(context->pagetable);
context->space.ranges = NULL;
slab_free(ctxcache, context);
}