diff options
author | dzwdz | 2022-07-05 22:51:21 +0200 |
---|---|---|
committer | dzwdz | 2022-07-05 22:51:21 +0200 |
commit | a89984d7200381d7b8035c48124d93105d59cf24 (patch) | |
tree | 01e788518dca3c5cdb269e82b6a272612ab51970 /src/init | |
parent | b16ab3edc8d3f3d5bcbe0afc8dec3e9ed822a224 (diff) |
kernel: initial partial pipe support
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/syscalls.c | 4 | ||||
-rw-r--r-- | src/init/tests/main.c | 23 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/init/syscalls.c b/src/init/syscalls.c index 6e4c2dc..54ea715 100644 --- a/src/init/syscalls.c +++ b/src/init/syscalls.c @@ -50,6 +50,10 @@ void __user *_syscall_memflag(void __user *addr, size_t len, int flags) { return (void __user *)_syscall(_SYSCALL_MEMFLAG, (int)addr, (int)len, flags, 0); } +handle_t _syscall_pipe(int flags) { + return (handle_t)_syscall(_SYSCALL_PIPE, flags, 0, 0, 0); +} + void _syscall_debug_klog(const void __user *buf, size_t len) { return (void)_syscall(_SYSCALL_DEBUG_KLOG, (int)buf, (int)len, 0, 0); } diff --git a/src/init/tests/main.c b/src/init/tests/main.c index 1260a35..e5e3941 100644 --- a/src/init/tests/main.c +++ b/src/init/tests/main.c @@ -141,6 +141,28 @@ static void test_malloc(void) { free(p1); } +static void test_pipe(void) { + const char *msgs[2] = {"hello", "world"}; + char buf[16]; + int ret; + handle_t pipe = _syscall_pipe(0); + assert(pipe > 0); + + if (!_syscall_fork(0, NULL)) { + ret = _syscall_write(pipe, msgs[0], 5, -1); + assert(ret == 5); + _syscall_exit(0); + } else { + ret = _syscall_read(pipe, buf, 16, 0); + assert(ret == 5); + assert(!memcmp(buf, msgs[0], 5)); + } + + // TODO vice versa + // TODO partial reads, writes + // TODO kill process that's waiting on a pipe +} + static void stress_fork(void) { /* run a lot of processes */ for (size_t i = 0; i < 2048; i++) { @@ -157,5 +179,6 @@ void test_all(void) { run_forked(test_orphaned_fs); run_forked(test_memflag); run_forked(test_malloc); + run_forked(test_pipe); run_forked(stress_fork); } |