Add sys_exec () and libprocess wrapper, fix ramdisk tar parsing
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m26s

This commit is contained in:
2026-02-14 21:50:09 +01:00
parent 690e09339e
commit b0b69f3e9e
27 changed files with 112 additions and 39 deletions

View File

@@ -1,7 +1,10 @@
#include <aux/compiler.h>
#include <device/device.h>
#include <fs/path.h>
#include <fs/vfs.h>
#include <libk/assert.h>
#include <libk/fieldlengthof.h>
#include <libk/fieldsizeof.h>
#include <libk/std.h>
#include <limine/requests.h>
#include <m/status.h>
@@ -181,7 +184,7 @@ DEFINE_SYSCALL (sys_device_do) {
uintptr_t out_paddr;
if (!(cmd >= 0 && cmd < (int)fieldlengthof (struct device, ops)))
return -ST_BAD_DEVICE_OP;
return SYSRESULT (-ST_BAD_DEVICE_OP);
spin_lock (&proc->procgroup->lock);
@@ -206,7 +209,7 @@ DEFINE_SYSCALL (sys_device_do) {
struct device* device = device_find (device_id);
if (device == NULL)
return -ST_NOT_FOUND;
return SYSRESULT (-ST_NOT_FOUND);
spin_lock (&device->lock);
@@ -214,7 +217,43 @@ DEFINE_SYSCALL (sys_device_do) {
spin_unlock (&device->lock);
return ret;
return SYSRESULT (ret);
}
/* int exec (char* path) */
DEFINE_SYSCALL (sys_exec) {
uintptr_t uvaddr_path = a1;
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
uintptr_t out_paddr;
spin_lock (&proc->procgroup->lock);
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_path);
spin_unlock (&proc->procgroup->lock);
if (out_paddr == 0)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
char mountpoint[fieldsizeof (struct vfs_mountpoint, key)];
const char* subpath = NULL;
if (!path_parse (path, mountpoint, &subpath))
return SYSRESULT (-ST_BAD_PATH);
struct proc* new = proc_from_file (mountpoint, subpath);
if (new == NULL)
return SYSRESULT (-ST_EXEC_ERROR);
int pid = new->pid;
if (proc_register (new, reschedule_cpu) == PROC_NEED_RESCHEDULE)
*reschedule = true;
return SYSRESULT (pid);
}
static syscall_handler_func_t handler_table[] = {
@@ -230,6 +269,7 @@ static syscall_handler_func_t handler_table[] = {
[SYS_MUTEX_LOCK] = &sys_mutex_lock,
[SYS_MUTEX_UNLOCK] = &sys_mutex_unlock,
[SYS_DEVICE_DO] = &sys_device_do,
[SYS_EXEC] = &sys_exec,
};
syscall_handler_func_t syscall_find_handler (int syscall_num) {