summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/app/testelf/main.c2
-rw-r--r--src/user/app/tests/kernel/miscsyscall.c13
-rw-r--r--src/user/lib/include/__errno.h1
-rw-r--r--src/user/lib/include/sys/wait.h4
-rw-r--r--src/user/lib/signal.c3
-rw-r--r--src/user/lib/syscall.c4
-rw-r--r--src/user/lib/syswait.c18
7 files changed, 38 insertions, 7 deletions
diff --git a/src/user/app/testelf/main.c b/src/user/app/testelf/main.c
index 5608cc7..a2e5932 100644
--- a/src/user/app/testelf/main.c
+++ b/src/user/app/testelf/main.c
@@ -10,7 +10,7 @@ int main(int argc, char **argv) {
printf("argc == %u\n", argc);
for (int i = 0; i < argc; i++)
printf("argv[%u] == %p == \"%s\"\n", i, argv[i], argv[i]);
- if (strcmp(argv[1], "stackexec") == 0) {
+ if (argv[1] && strcmp(argv[1], "stackexec") == 0) {
/* exec something with arguments on the stack */
const char s_d[] = "I am a pretty long string on the stack. Oh my. " \
"I hope I won't get corrupted.\0";
diff --git a/src/user/app/tests/kernel/miscsyscall.c b/src/user/app/tests/kernel/miscsyscall.c
index c90560e..459da2a 100644
--- a/src/user/app/tests/kernel/miscsyscall.c
+++ b/src/user/app/tests/kernel/miscsyscall.c
@@ -40,6 +40,18 @@ static void test_await2(void) {
_sys_filicide();
}
+static void test_wait2_basic(void) {
+ struct sys_wait2 data = {0};
+ int pid;
+ pid = fork();
+ if (pid == 0) {
+ exit(420);
+ }
+ test(_sys_wait2(-1, 0, &data) == pid);
+ test(data.status == 420);
+ test(_sys_wait2(-1, 0, NULL) == -ECHILD);
+}
+
static void test_pipe(void) {
const char *pipe_msgs[2] = {"hello", "world"};
hid_t ends[2];
@@ -293,6 +305,7 @@ static void test_badopen(void) {
void r_k_miscsyscall(void) {
run_test(test_await);
run_test(test_await2);
+ run_test(test_wait2_basic);
run_test(test_pipe);
run_test(test_memflag);
run_test(test_dup);
diff --git a/src/user/lib/include/__errno.h b/src/user/lib/include/__errno.h
index f72fcf6..0808ac6 100644
--- a/src/user/lib/include/__errno.h
+++ b/src/user/lib/include/__errno.h
@@ -13,6 +13,7 @@ E( 10, "EACCES")
E( 11, "EMFILE all file descriptors taken")
E( 12, "ECONNRESET")
E( 13, "EPIPE")
+E( 14, "ECHILD")
E(200, "EISDIR")
E(201, "ENAMETOOLONG")
E(202, "ENOTDIR")
diff --git a/src/user/lib/include/sys/wait.h b/src/user/lib/include/sys/wait.h
index c71418c..cff407e 100644
--- a/src/user/lib/include/sys/wait.h
+++ b/src/user/lib/include/sys/wait.h
@@ -2,8 +2,8 @@
#include <sys/types.h>
#define WIFSTOPPED(x) 0
-#define WEXITSTATUS(x) 0
-#define WIFEXITED(x) 0
+#define WEXITSTATUS(x) ((x)&0xFF)
+#define WIFEXITED(x) 1
#define WSTOPSIG(x) 0
#define WTERMSIG(x) 0
diff --git a/src/user/lib/signal.c b/src/user/lib/signal.c
index d8b673d..41340e7 100644
--- a/src/user/lib/signal.c
+++ b/src/user/lib/signal.c
@@ -76,8 +76,7 @@ int sigfillset(sigset_t *set) {
}
int sigprocmask(int how, const sigset_t *set, const sigset_t *oldset) {
- (void)how; (void)set; (void)oldset;
- __libc_panic("unimplemented");
+ return 0;
}
int sigsuspend(const sigset_t *mask) {
diff --git a/src/user/lib/syscall.c b/src/user/lib/syscall.c
index 3e8473c..5196683 100644
--- a/src/user/lib/syscall.c
+++ b/src/user/lib/syscall.c
@@ -90,6 +90,10 @@ uint32_t _sys_getppid(void) {
return (uint32_t)_syscall(_SYS_GETPPID, 0, 0, 0, 0, 0);
}
+int _sys_wait2(int pid, int flags, struct sys_wait2 __user *out) {
+ return (int)_syscall(_SYS_WAIT2, (long)pid, (long)flags, (long)out, 0, 0);
+}
+
long _sys_execbuf(void __user *buf, size_t len) {
return _syscall(_SYS_EXECBUF, (long)buf, (long)len, 0, 0, 0);
}
diff --git a/src/user/lib/syswait.c b/src/user/lib/syswait.c
index 6389cb2..ce80c7b 100644
--- a/src/user/lib/syswait.c
+++ b/src/user/lib/syswait.c
@@ -1,8 +1,22 @@
#include <bits/panic.h>
+#include <camellia.h>
+#include <camellia/syscalls.h>
+#include <errno.h>
#include <sys/resource.h>
#include <sys/wait.h>
pid_t wait3(int *wstatus, int opts, struct rusage *rusage) {
- (void)wstatus; (void)opts; (void)rusage;
- __libc_panic("unimplemented");
+ struct sys_wait2 res;
+ if (opts || rusage) {
+ __libc_panic("unimplemented");
+ }
+ pid_t ret = _sys_wait2(-1, 0, &res);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+ if (wstatus) {
+ *wstatus = res.status & 0xFF;
+ }
+ return ret;
}