diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-10 19:44:32 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-10 19:44:32 -0400 |
commit | 7c46a8f234d618d7471e6b09d480688270a33fe3 (patch) | |
tree | b35ab6e1d9e21ab871ecc92f853e51f47aff46bf /src | |
parent | 2c5df0dfeaf878f0f09485b7a80c79aea36d194e (diff) |
kern: proc: Add getargv system call
Introduce a getargv system call that allows one to fetch an argument
string using an index into the argument vector.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/include/compat/unix/syscall.h | 3 | ||||
-rw-r--r-- | src/sys/include/sys/proc.h | 5 | ||||
-rw-r--r-- | src/sys/include/sys/syscall.h | 3 | ||||
-rw-r--r-- | src/sys/os/os_proc.c | 25 |
4 files changed, 34 insertions, 2 deletions
diff --git a/src/sys/include/compat/unix/syscall.h b/src/sys/include/compat/unix/syscall.h index 743e50c..2cca0bc 100644 --- a/src/sys/include/compat/unix/syscall.h +++ b/src/sys/include/compat/unix/syscall.h @@ -71,7 +71,8 @@ scret_t(*g_unix_sctab[])(struct syscall_args *) = { [SYS_spawn] = sys_spawn, [SYS_mount] = sys_mount, [SYS_open] = sys_open, - [SYS_muxtap] = sys_muxtap + [SYS_muxtap] = sys_muxtap, + [SYS_getargv] = sys_getargv }; #endif /* !_NEED_UNIX_SCTAB */ diff --git a/src/sys/include/sys/proc.h b/src/sys/include/sys/proc.h index 5bffc3e..dcf6108 100644 --- a/src/sys/include/sys/proc.h +++ b/src/sys/include/sys/proc.h @@ -218,5 +218,10 @@ __dead void md_proc_kick(struct proc *procp); */ scret_t sys_spawn(struct syscall_args *scargs); +/* + * Get argument number n + */ +scret_t sys_getargv(struct syscall_args *scargs); + #endif /* !_KERNEL */ #endif /* !_SYS_PROC_H_ */ diff --git a/src/sys/include/sys/syscall.h b/src/sys/include/sys/syscall.h index 09996ae..8353eda 100644 --- a/src/sys/include/sys/syscall.h +++ b/src/sys/include/sys/syscall.h @@ -51,7 +51,8 @@ #define SYS_spawn 0x06 /* spawn a process */ #define SYS_mount 0x07 /* mount a filesystem */ #define SYS_open 0x08 /* open a file */ -#define SYS_muxtap 0x09 /* mux an I/O tap */ +#define SYS_muxtap 0x09 /* mux an I/O tap */ +#define SYS_getargv 0x0A /* get process argv */ typedef __ssize_t scret_t; typedef __ssize_t scarg_t; diff --git a/src/sys/os/os_proc.c b/src/sys/os/os_proc.c index 27ffac8..4af45a0 100644 --- a/src/sys/os/os_proc.c +++ b/src/sys/os/os_proc.c @@ -320,3 +320,28 @@ sys_spawn(struct syscall_args *scargs) envblk = penv_blk_cpy(proc_self(), u_blk); return proc_spawn(buf, envblk); } + +/* + * Get argument number number + * + * ARG0: Argument number + * ARG1: Buffer result + * ARG2: Max length + */ +scret_t +sys_getargv(struct syscall_args *scargs) +{ + uint16_t argno = SCARG(scargs, uint16_t, 0); + char *u_buf = SCARG(scargs, char *, 1); + size_t maxlen = SCARG(scargs, size_t, 2); + struct proc *self = proc_self(); + struct penv_blk *envblk = self->envblk; + char *arg; + + if (argno >= envblk->argc) { + return -EINVAL; + } + + arg = envblk->argv[argno]; + return copyoutstr(arg, u_buf, maxlen); +} |