Implement passing commandline strings
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 1m37s
Build documentation / build-and-deploy (push) Successful in 1m42s

This commit is contained in:
2026-04-28 19:48:34 +02:00
parent 347fe0a49d
commit 9fbe23024c
9 changed files with 51 additions and 7 deletions

View File

@@ -12,6 +12,8 @@
/* proc_map () base address */
#define PROC_MAP_BASE 0x0000700000000000
#define PROC_CMDLINE_BASE 0x0000100000000000
/* Platform-dependent process data */
struct proc_platformdata {
uint8_t fx_env[512] ALIGNED(16);

View File

@@ -3,6 +3,7 @@
#include <libk/rbtree.h>
#include <libk/std.h>
#include <libk/string.h>
#include <limine/requests.h>
#include <mm/malloc.h>
#include <mm/pmm.h>
#include <proc/env.h>
@@ -132,6 +133,8 @@ bool procgroup_unmap(struct procgroup* procgroup, uintptr_t start_vaddr, size_t
}
struct procgroup* procgroup_create(void) {
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
struct procgroup* procgroup = malloc(sizeof(*procgroup));
if (procgroup == NULL) {
return NULL;
@@ -156,6 +159,10 @@ struct procgroup* procgroup_create(void) {
procgroup->pd.cr3_paddr = mm_alloc_user_pd_phys();
procgroup->map_base = PROC_MAP_BASE;
procgroup->uvaddr_cmdline = procgroup_map(procgroup, PROC_CMDLINE_BASE, 1,
MM_PG_PRESENT | MM_PG_USER, &procgroup->paddr_cmdline);
memset((void*)((uintptr_t)hhdm->offset + procgroup->paddr_cmdline), 0, PROCGROUP_CMDLINE_MAX);
if (proc_create_resource_mail(procgroup) == NULL) {
id_alloc_fini(&procgroup->rid_alloc);
free(procgroup);
@@ -214,6 +221,8 @@ static void procgroup_delete(struct procgroup* procgroup, struct reschedule_ctx*
proc_env_cleanup(procgroup);
pmm_free(procgroup->paddr_cmdline, 1);
pmm_free(procgroup->pd.cr3_paddr, 1);
free(procgroup->tls.tls_tmpl);

View File

@@ -5,14 +5,15 @@
#include <libk/list.h>
#include <libk/rbtree.h>
#include <libk/std.h>
#include <page_size.h>
#include <proc/env.h>
#include <proc/resource.h>
#include <sync/spin_lock.h>
#include <sys/mm.h>
#include <sys/procgroup.h>
#define PROCGROUP_VFS_HANDLES_MAX 256
#define PROCGROUP_RESOURCES_MAX 256
#define PROCGROUP_RESOURCES_MAX 256
#define PROCGROUP_CMDLINE_MAX PAGE_SIZE
struct proc;
struct reschedule_ctx;
@@ -36,6 +37,8 @@ struct procgroup {
uintptr_t map_base;
struct procgroup_tls tls;
struct proc_env env;
uintptr_t uvaddr_cmdline;
uintptr_t paddr_cmdline;
};
struct procgroup* procgroup_create(void);

View File

@@ -289,10 +289,11 @@ DEFINE_SYSCALL(sys_device_do) {
return SYSRESULT(ret);
}
/* int exec (char* volume, char* path) */
/* int exec (char* volume, char* path, char* cmdline) */
DEFINE_SYSCALL(sys_exec) {
uintptr_t uvaddr_volume = a1;
uintptr_t uvaddr_path = a2;
uintptr_t uvaddr_cmdline = a3;
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
@@ -316,12 +317,21 @@ DEFINE_SYSCALL(sys_exec) {
const char* volume = (const char*)((uintptr_t)hhdm->offset + out_paddr);
out_paddr = mm_v2p(&procgroup->pd, uvaddr_cmdline);
char* cmdline = (out_paddr != 0) ? (char*)((uintptr_t)hhdm->offset + out_paddr) : NULL;
struct proc* new = proc_from_file(proc, volume, path, rctx);
if (new == NULL) {
return SYSRESULT(-ST_EXEC_ERROR);
}
if (cmdline != NULL) {
void* cmdline_dest = (void*)((uintptr_t)hhdm->offset + new->procgroup->paddr_cmdline);
strncpy(cmdline_dest, cmdline, PAGE_SIZE);
}
int pid = new->pid;
new->exec_pid = pid1;
@@ -931,7 +941,14 @@ DEFINE_SYSCALL(sys_date_time) {
date_time(dt);
return ST_OK;
return SYSRESULT(ST_OK);
}
/* const char* get_cmdline(void) */
DEFINE_SYSCALL(sys_get_cmdline) {
struct procgroup* procgroup = proc->procgroup;
return SYSRESULT(procgroup->uvaddr_cmdline);
}
static syscall_handler_func_t handler_table[] = {
@@ -976,6 +993,7 @@ static syscall_handler_func_t handler_table[] = {
[SYS_GET_VOLUME_INFO] = &sys_get_volume_info,
[SYS_VOLUME_DELETE] = &sys_volume_delete,
[SYS_DATE_TIME] = &sys_date_time,
[SYS_GET_CMDLINE] = &sys_get_cmdline,
};
syscall_handler_func_t syscall_find_handler(int syscall_num) {