diff options
-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); +} |