summaryrefslogtreecommitdiff
path: root/src/sys/os
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-10 19:44:32 -0400
committerIan Moffett <ian@osmora.org>2025-10-10 19:44:32 -0400
commit7c46a8f234d618d7471e6b09d480688270a33fe3 (patch)
treeb35ab6e1d9e21ab871ecc92f853e51f47aff46bf /src/sys/os
parent2c5df0dfeaf878f0f09485b7a80c79aea36d194e (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/sys/os')
-rw-r--r--src/sys/os/os_proc.c25
1 files changed, 25 insertions, 0 deletions
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);
+}