Properly implement liballoc_free ()
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <m/status.h>
|
||||
#include <m/syscall_defs.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <proc/mem.h>
|
||||
#include <proc/mutex.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/resource.h>
|
||||
@@ -130,6 +131,7 @@ DEFINE_SYSCALL (sys_proc_mutex_lock) {
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
/* int proc_mutex_unlock (int mutex_rid) */
|
||||
DEFINE_SYSCALL (sys_proc_mutex_unlock) {
|
||||
spin_lock_ctx_t ctxpr;
|
||||
int rid = (int)a1;
|
||||
@@ -200,6 +202,58 @@ DEFINE_SYSCALL (sys_proc_sched) {
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
DEFINE_SYSCALL (sys_proc_translate_v2p) {
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
spin_lock_ctx_t ctxprpd;
|
||||
int result = ST_OK;
|
||||
|
||||
uintptr_t vaddr = a1;
|
||||
uintptr_t* out_paddr_buf = (uintptr_t*)a2;
|
||||
|
||||
spin_lock (&proc->pd->lock, &ctxprpd);
|
||||
|
||||
uintptr_t out_paddr_buf_paddr = mm_v2p (proc->pd, (uintptr_t)out_paddr_buf, 0);
|
||||
|
||||
if (!mm_validate_buffer (proc->pd, (uintptr_t)out_paddr_buf, sizeof (uintptr_t), 0)) {
|
||||
spin_unlock (&proc->pd->lock, &ctxprpd);
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
}
|
||||
|
||||
uintptr_t* out_paddr_buf_vaddr = (uintptr_t*)((uintptr_t)hhdm->offset + out_paddr_buf_paddr);
|
||||
|
||||
uintptr_t translated_addr = mm_v2p (proc->pd, vaddr, 0);
|
||||
if (translated_addr == 0) {
|
||||
result = -ST_BAD_ADDRESS_SPACE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
*out_paddr_buf_vaddr = translated_addr;
|
||||
|
||||
done:
|
||||
spin_unlock (&proc->pd->lock, &ctxprpd);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* int proc_resource_mem_unref (int mem_rid, size_t pages) */
|
||||
DEFINE_SYSCALL (sys_proc_mem_unref) {
|
||||
spin_lock_ctx_t ctxpr;
|
||||
int rid = (int)a1;
|
||||
size_t pages = (size_t)a2;
|
||||
|
||||
struct proc_resource* resource;
|
||||
spin_lock (&proc->lock, &ctxpr);
|
||||
rbtree_find (struct proc_resource, &proc->resource_tree, rid, resource, proc_resource_tree_link,
|
||||
rid);
|
||||
spin_unlock (&proc->lock, &ctxpr);
|
||||
|
||||
if (resource == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
proc_mem_unref (proc, &resource->u.mem, pages);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_PROC_QUIT] = &sys_proc_quit,
|
||||
[SYS_PROC_TEST] = &sys_proc_test,
|
||||
@@ -212,6 +266,8 @@ static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_PROC_MUTEX_UNLOCK] = &sys_proc_mutex_unlock,
|
||||
[SYS_PROC_SPAWN_THREAD] = &sys_proc_spawn_thread,
|
||||
[SYS_PROC_SCHED] = &sys_proc_sched,
|
||||
[SYS_PROC_TRANSLATE_V2P] = &sys_proc_translate_v2p,
|
||||
[SYS_PROC_MEM_UNREF] = &sys_proc_mem_unref,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||
|
||||
Reference in New Issue
Block a user