Properly implement liballoc_free ()

This commit is contained in:
2026-01-16 22:09:16 +01:00
parent ab8093cc6c
commit 9a7dbf0594
12 changed files with 142 additions and 24 deletions

View File

@@ -6,7 +6,7 @@
static int liballoc_mutex;
static uintptr_t liballoc_map_base = PROC_MAP_BASE;
static int mem_rid_base = 10000;
static int mem_rid_base = 1000000;
void liballoc_init (void) { liballoc_mutex = proc_create_resource_mutex (100, RV_PRIVATE); }
@@ -36,7 +36,20 @@ void* liballoc_alloc (int pages) {
return (void*)old_base;
}
int liballoc_free (void* ptr, int pages) { return 0; }
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);
}
/** Durand's Ridiculously Amazing Super Duper Memory functions. */

View File

@@ -41,4 +41,12 @@ int proc_spawn_thread (uintptr_t vstack_top, size_t stack_size, void* entry) {
0);
}
int proc_translate_v2p (uintptr_t vaddr, uintptr_t* out_paddr) {
return syscall (SYS_PROC_TRANSLATE_V2P, vaddr, (uintptr_t)out_paddr, 0, 0, 0, 0);
}
int proc_mem_unref (uintptr_t paddr, size_t pages) {
return syscall (SYS_PROC_MEM_UNREF, paddr, (uintptr_t)pages, 0, 0, 0, 0);
}
int proc_sched (void) { return syscall (SYS_PROC_SCHED, 0, 0, 0, 0, 0, 0); }

View File

@@ -27,6 +27,7 @@ int proc_mutex_lock (int mutex_rid);
int proc_mutex_unlock (int mutex_rid);
int proc_spawn_thread (uintptr_t vstack_top, size_t stack_size, void* entry);
int proc_sched (void);
int proc_translate_resource_mem (uintptr_t vaddr);
int proc_translate_v2p (uintptr_t vaddr, uintptr_t* out_paddr);
int proc_mem_unref (uintptr_t paddr, size_t pages);
#endif // _LIBMSL_M_PROC_H