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

@@ -103,6 +103,10 @@ void app_main(void) {
char printcmdsbuf[4];
char line[1024];
const char* cmdline = get_cmdline();
debug_printf("cmdline=\"%s\"\n", cmdline);
if (env_get(process_get_pgid(), "printcmds", (void*)printcmdsbuf, sizeof(printcmdsbuf)) ==
ST_OK &&
strcmp(printcmdsbuf, "yes") == 0) {

View File

@@ -42,5 +42,6 @@
#define SYS_GET_VOLUME_INFO 39
#define SYS_VOLUME_DELETE 40
#define SYS_DATE_TIME 41
#define SYS_GET_CMDLINE 42
#endif // _M_SYSCALL_DEFS_H

View File

@@ -28,7 +28,7 @@ static void receiver(void* arg) {
}
static void run_ce_interactive(void) {
int ce_pid = exec("sys", "/ce");
int ce_pid = exec("sys", "/ce", "-i");
ce_pgid = get_procgroup(ce_pid);
process_spawn(&receiver, NULL);

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) {

View File

@@ -39,7 +39,9 @@ int device_do(const char* device_key, int cmd, void* a1, void* a2, void* a3, voi
return (int)do_syscall(SYS_DEVICE_DO, device_key, cmd, a1, a2, a3, a4);
}
int exec(const char* volume, const char* path) { return (int)do_syscall(SYS_EXEC, volume, path); }
int exec(const char* volume, const char* path, const char* cmdline) {
return (int)do_syscall(SYS_EXEC, volume, path, cmdline);
}
int volume_open(const char* volume) { return (int)do_syscall(SYS_VOLUME_OPEN, volume); }
@@ -126,3 +128,5 @@ int get_volume_info(struct volume_info* infos, size_t count) {
int volume_delete(const char* key) { return (int)do_syscall(SYS_VOLUME_DELETE, key); }
int date_time(struct date_time* dt) { return (int)do_syscall(SYS_DATE_TIME, dt); }
const char* get_cmdline(void) { return (const char*)do_syscall(SYS_GET_CMDLINE, 0); }

View File

@@ -47,7 +47,7 @@ void* argument_ptr(void);
int device_do(const char* device_key, int cmd, void* a1, void* a2, void* a3, void* a4);
/* Run external ELF program */
int exec(const char* volume, const char* path);
int exec(const char* volume, const char* path, const char* cmdline);
/* Open a file */
int volume_open(const char* volume);
@@ -133,4 +133,7 @@ int volume_delete(const char* key);
/* Get date-time */
int date_time(struct date_time* dt);
/* Get commandline string */
const char* get_cmdline(void);
#endif // _LIBMSL_M_SYSTEM_H