diff options
author | dzwdz | 2022-07-09 15:24:58 +0200 |
---|---|---|
committer | dzwdz | 2022-07-09 15:24:58 +0200 |
commit | dad8b261ac7898f4d8cf537ad288ad6a1a74d124 (patch) | |
tree | 610712b313032529195c3e5319ab45b1a7482c65 /src/init/syscalls.c | |
parent | 2e8e2dc1fb1aaefbe82cc4261c615428aa6250d5 (diff) |
syscalls/pipe: turn into a POSIX-style api with separate rw ends
Without separate read/write ends you can't tell when there are no more writers left if you have multiple readers. Consider this piece of code:
int fd = pipe();
fork(); // execution continues in 2 processes
while (read(fd, &some_buf, sizeof somebuf) >= 0) {
...
}
Once both processes call `read()`, it's obvious that no writes are possible - all the processes that hold a reference to the pipe are currently stuck on a `read()` call, so the kernel could just make it return an error in both. But, what then? It's still possible to write to the pipe, and you can't know if the other process will do that. Thus, if you don't want to miss any output, you have to keep reading the pipe. Forever. Both processes end up stuck.
Having separate read/write ends prevents that.
Diffstat (limited to 'src/init/syscalls.c')
-rw-r--r-- | src/init/syscalls.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/init/syscalls.c b/src/init/syscalls.c index 14c0d52..25fa134 100644 --- a/src/init/syscalls.c +++ b/src/init/syscalls.c @@ -50,8 +50,8 @@ 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); +int _syscall_pipe(handle_t __user user_ends[2], int flags) { + return _syscall(_SYSCALL_PIPE, (int)user_ends, flags, 0, 0); } void _syscall_debug_klog(const void __user *buf, size_t len) { |