Rewrite resource subsystem

This commit is contained in:
2026-01-18 20:50:45 +01:00
parent 4f7077d458
commit ddafc4eb19
20 changed files with 453 additions and 225 deletions

View File

@@ -3,32 +3,36 @@
#include <alloc/liballoc.h>
#include <m/proc.h>
#include <m/resource_buffer.h>
static int liballoc_mutex;
static uintptr_t liballoc_map_base = PROC_MAP_BASE;
static int mem_rid_base = 1000000;
void liballoc_init (void) { liballoc_mutex = proc_create_resource_mutex (100, RV_PRIVATE); }
void liballoc_init (void) {
liballoc_mutex = proc_create_resource (100, PR_MUTEX, RV_PRIVATE, NULL);
}
int liballoc_lock (void) {
proc_mutex_lock (liballoc_mutex);
proc_mutex_lock (liballoc_mutex, RV_PRIVATE);
return 0;
}
int liballoc_unlock (void) {
proc_mutex_unlock (liballoc_mutex);
proc_mutex_unlock (liballoc_mutex, RV_PRIVATE);
return 0;
}
void* liballoc_alloc (int pages) {
uintptr_t current_base = liballoc_map_base;
uintptr_t out_paddr;
int mem_rid = proc_create_resource_mem (mem_rid_base++, pages, RV_PRIVATE, &out_paddr);
struct resource_buffer mem_init = {.type = PR_MEM, .u = {.mem = {.pages = (size_t)pages}}};
int mem_rid = proc_create_resource (mem_rid_base++, PR_MEM, RV_PRIVATE, &mem_init);
if (mem_rid < 0)
return NULL;
proc_map (out_paddr, current_base, pages, PM_PRESENT | PM_RW | PM_USER);
proc_map (mem_init.u.mem.paddr, current_base, (size_t)pages, PM_PRESENT | PM_RW | PM_USER);
uintptr_t old_base = current_base;
current_base += pages * PAGE_SIZE;
@@ -36,20 +40,7 @@ void* liballoc_alloc (int pages) {
return (void*)old_base;
}
int liballoc_free (void* ptr, int pages) {
int res;
uintptr_t out_paddr;
res = proc_translate_v2p ((uintptr_t)ptr, &out_paddr);
if (res < 0)
return res;
res = proc_unmap ((uintptr_t)ptr, pages);
if (res < 0)
return res;
return proc_mem_unref (out_paddr, pages);
}
int liballoc_free (void* ptr, int pages) { return 0; }
/** Durand's Ridiculously Amazing Super Duper Memory functions. */