summaryrefslogtreecommitdiff
path: root/Kernel/API
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2021-05-12 19:17:51 +0000
committerAndreas Kling <kling@serenityos.org>2021-05-12 22:38:20 +0200
commitfe5ca6ca276ad452a16215031fb395b4f5bef048 (patch)
tree100ae8dbf8d2b1cee4125cf335017a021c63093f /Kernel/API
parent2de11b0dc8bbaa0c264a7e6dbb32b5481a337fb8 (diff)
downloadserenity-fe5ca6ca276ad452a16215031fb395b4f5bef048.zip
Kernel: Implement multi-watch InodeWatcher :^)
This patch modifies InodeWatcher to switch to a one watcher, multiple watches architecture. The following changes have been made: - The watch_file syscall is removed, and in its place the create_iwatcher, iwatcher_add_watch and iwatcher_remove_watch calls have been added. - InodeWatcher now holds multiple WatchDescriptions for each file that is being watched. - The InodeWatcher file descriptor can be read from to receive events on all watched files. Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
Diffstat (limited to 'Kernel/API')
-rw-r--r--Kernel/API/InodeWatcherEvent.h28
-rw-r--r--Kernel/API/InodeWatcherFlags.h18
-rw-r--r--Kernel/API/Syscall.h304
3 files changed, 196 insertions, 154 deletions
diff --git a/Kernel/API/InodeWatcherEvent.h b/Kernel/API/InodeWatcherEvent.h
index db26588700..9a2ce68152 100644
--- a/Kernel/API/InodeWatcherEvent.h
+++ b/Kernel/API/InodeWatcherEvent.h
@@ -1,21 +1,37 @@
/*
- * Copyright (c) 2020, the SerenityOS developers.
+ * Copyright (c) 2020-2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
+#include <AK/EnumBits.h>
#include <AK/Types.h>
+#ifdef KERNEL
+# include <LibC/limits.h>
+#else
+# include <limits.h>
+#endif
+
struct [[gnu::packed]] InodeWatcherEvent {
- enum class Type {
+ enum class Type : u32 {
Invalid = 0,
- Modified,
- ChildAdded,
- ChildRemoved,
+ MetadataModified = 1 << 0,
+ ContentModified = 1 << 1,
+ Deleted = 1 << 2,
+ ChildCreated = 1 << 3,
+ ChildDeleted = 1 << 4,
};
+ int watch_descriptor { 0 };
Type type { Type::Invalid };
- unsigned inode_index { 0 };
+ size_t name_length { 0 };
+ // This is a VLA which is written during the read() from the descriptor.
+ const char name[];
};
+
+AK_ENUM_BITWISE_OPERATORS(InodeWatcherEvent::Type);
+
+constexpr unsigned MAXIMUM_EVENT_SIZE = sizeof(InodeWatcherEvent) + NAME_MAX + 1;
diff --git a/Kernel/API/InodeWatcherFlags.h b/Kernel/API/InodeWatcherFlags.h
new file mode 100644
index 0000000000..c9cdf42b1f
--- /dev/null
+++ b/Kernel/API/InodeWatcherFlags.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/EnumBits.h>
+#include <AK/Types.h>
+
+enum class InodeWatcherFlags : u32 {
+ None = 0,
+ Nonblock = 1 << 0,
+ CloseOnExec = 1 << 1,
+};
+
+AK_ENUM_BITWISE_OPERATORS(InodeWatcherFlags);
diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h
index e55d4fb739..57a36cd0e3 100644
--- a/Kernel/API/Syscall.h
+++ b/Kernel/API/Syscall.h
@@ -27,154 +27,156 @@ typedef u32 socklen_t;
namespace Kernel {
-#define ENUMERATE_SYSCALLS(S) \
- S(yield) \
- S(open) \
- S(close) \
- S(read) \
- S(lseek) \
- S(kill) \
- S(getuid) \
- S(exit) \
- S(geteuid) \
- S(getegid) \
- S(getgid) \
- S(getpid) \
- S(getppid) \
- S(getresuid) \
- S(getresgid) \
- S(waitid) \
- S(mmap) \
- S(munmap) \
- S(get_dir_entries) \
- S(getcwd) \
- S(gettimeofday) \
- S(gethostname) \
- S(sethostname) \
- S(chdir) \
- S(uname) \
- S(set_mmap_name) \
- S(readlink) \
- S(write) \
- S(ttyname) \
- S(stat) \
- S(getsid) \
- S(setsid) \
- S(getpgid) \
- S(setpgid) \
- S(getpgrp) \
- S(fork) \
- S(execve) \
- S(dup2) \
- S(sigaction) \
- S(umask) \
- S(getgroups) \
- S(setgroups) \
- S(sigreturn) \
- S(sigprocmask) \
- S(sigpending) \
- S(pipe) \
- S(killpg) \
- S(seteuid) \
- S(setegid) \
- S(setuid) \
- S(setgid) \
- S(setreuid) \
- S(setresuid) \
- S(setresgid) \
- S(alarm) \
- S(fstat) \
- S(access) \
- S(fcntl) \
- S(ioctl) \
- S(mkdir) \
- S(times) \
- S(utime) \
- S(sync) \
- S(ptsname) \
- S(select) \
- S(unlink) \
- S(poll) \
- S(rmdir) \
- S(chmod) \
- S(socket) \
- S(bind) \
- S(accept) \
- S(listen) \
- S(connect) \
- S(link) \
- S(chown) \
- S(fchmod) \
- S(symlink) \
- S(sendmsg) \
- S(recvmsg) \
- S(getsockopt) \
- S(setsockopt) \
- S(create_thread) \
- S(gettid) \
- S(donate) \
- S(rename) \
- S(ftruncate) \
- S(exit_thread) \
- S(mknod) \
- S(writev) \
- S(beep) \
- S(getsockname) \
- S(getpeername) \
- S(socketpair) \
- S(sched_setparam) \
- S(sched_getparam) \
- S(fchown) \
- S(halt) \
- S(reboot) \
- S(mount) \
- S(umount) \
- S(dump_backtrace) \
- S(dbgputch) \
- S(dbgputstr) \
- S(watch_file) \
- S(mprotect) \
- S(realpath) \
- S(get_process_name) \
- S(fchdir) \
- S(getrandom) \
- S(getkeymap) \
- S(setkeymap) \
- S(clock_gettime) \
- S(clock_settime) \
- S(clock_nanosleep) \
- S(join_thread) \
- S(module_load) \
- S(module_unload) \
- S(detach_thread) \
- S(set_thread_name) \
- S(get_thread_name) \
- S(madvise) \
- S(purge) \
- S(profiling_enable) \
- S(profiling_disable) \
- S(profiling_free_buffer) \
- S(futex) \
- S(chroot) \
- S(pledge) \
- S(unveil) \
- S(perf_event) \
- S(shutdown) \
- S(get_stack_bounds) \
- S(ptrace) \
- S(sendfd) \
- S(recvfd) \
- S(sysconf) \
- S(set_process_name) \
- S(disown) \
- S(adjtime) \
- S(allocate_tls) \
- S(prctl) \
- S(mremap) \
- S(set_coredump_metadata) \
- S(anon_create) \
- S(msyscall) \
- S(readv) \
+#define ENUMERATE_SYSCALLS(S) \
+ S(yield) \
+ S(open) \
+ S(close) \
+ S(read) \
+ S(lseek) \
+ S(kill) \
+ S(getuid) \
+ S(exit) \
+ S(geteuid) \
+ S(getegid) \
+ S(getgid) \
+ S(getpid) \
+ S(getppid) \
+ S(getresuid) \
+ S(getresgid) \
+ S(waitid) \
+ S(mmap) \
+ S(munmap) \
+ S(get_dir_entries) \
+ S(getcwd) \
+ S(gettimeofday) \
+ S(gethostname) \
+ S(sethostname) \
+ S(chdir) \
+ S(uname) \
+ S(set_mmap_name) \
+ S(readlink) \
+ S(write) \
+ S(ttyname) \
+ S(stat) \
+ S(getsid) \
+ S(setsid) \
+ S(getpgid) \
+ S(setpgid) \
+ S(getpgrp) \
+ S(fork) \
+ S(execve) \
+ S(dup2) \
+ S(sigaction) \
+ S(umask) \
+ S(getgroups) \
+ S(setgroups) \
+ S(sigreturn) \
+ S(sigprocmask) \
+ S(sigpending) \
+ S(pipe) \
+ S(killpg) \
+ S(seteuid) \
+ S(setegid) \
+ S(setuid) \
+ S(setgid) \
+ S(setreuid) \
+ S(setresuid) \
+ S(setresgid) \
+ S(alarm) \
+ S(fstat) \
+ S(access) \
+ S(fcntl) \
+ S(ioctl) \
+ S(mkdir) \
+ S(times) \
+ S(utime) \
+ S(sync) \
+ S(ptsname) \
+ S(select) \
+ S(unlink) \
+ S(poll) \
+ S(rmdir) \
+ S(chmod) \
+ S(socket) \
+ S(bind) \
+ S(accept) \
+ S(listen) \
+ S(connect) \
+ S(link) \
+ S(chown) \
+ S(fchmod) \
+ S(symlink) \
+ S(sendmsg) \
+ S(recvmsg) \
+ S(getsockopt) \
+ S(setsockopt) \
+ S(create_thread) \
+ S(gettid) \
+ S(donate) \
+ S(rename) \
+ S(ftruncate) \
+ S(exit_thread) \
+ S(mknod) \
+ S(writev) \
+ S(beep) \
+ S(getsockname) \
+ S(getpeername) \
+ S(socketpair) \
+ S(sched_setparam) \
+ S(sched_getparam) \
+ S(fchown) \
+ S(halt) \
+ S(reboot) \
+ S(mount) \
+ S(umount) \
+ S(dump_backtrace) \
+ S(dbgputch) \
+ S(dbgputstr) \
+ S(create_inode_watcher) \
+ S(inode_watcher_add_watch) \
+ S(inode_watcher_remove_watch) \
+ S(mprotect) \
+ S(realpath) \
+ S(get_process_name) \
+ S(fchdir) \
+ S(getrandom) \
+ S(getkeymap) \
+ S(setkeymap) \
+ S(clock_gettime) \
+ S(clock_settime) \
+ S(clock_nanosleep) \
+ S(join_thread) \
+ S(module_load) \
+ S(module_unload) \
+ S(detach_thread) \
+ S(set_thread_name) \
+ S(get_thread_name) \
+ S(madvise) \
+ S(purge) \
+ S(profiling_enable) \
+ S(profiling_disable) \
+ S(profiling_free_buffer) \
+ S(futex) \
+ S(chroot) \
+ S(pledge) \
+ S(unveil) \
+ S(perf_event) \
+ S(shutdown) \
+ S(get_stack_bounds) \
+ S(ptrace) \
+ S(sendfd) \
+ S(recvfd) \
+ S(sysconf) \
+ S(set_process_name) \
+ S(disown) \
+ S(adjtime) \
+ S(allocate_tls) \
+ S(prctl) \
+ S(mremap) \
+ S(set_coredump_metadata) \
+ S(anon_create) \
+ S(msyscall) \
+ S(readv) \
S(emuctl)
namespace Syscall {
@@ -442,6 +444,12 @@ struct SC_set_coredump_metadata_params {
StringArgument value;
};
+struct SC_inode_watcher_add_watch_params {
+ int fd;
+ StringArgument user_path;
+ u32 event_mask;
+};
+
void initialize();
int sync();