this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove libkqueue and use in-kernel kqueues

This commit pretty much just implements the bridge between userspace and kernel code for kqueues; for the real details of the change, check out the commit in the LKM.

+55 -60
-3
.gitmodules
··· 7 7 [submodule "src/external/libcxxabi"] 8 8 path = src/external/libcxxabi 9 9 url = ../darling-libcxxabi.git 10 - [submodule "src/external/libkqueue"] 11 - path = src/external/libkqueue 12 - url = ../darling-libkqueue.git 13 10 [submodule "src/external/zlib"] 14 11 path = src/external/zlib 15 12 url = ../darling-zlib.git
-2
src/CMakeLists.txt
··· 102 102 ${CMAKE_BINARY_DIR}/${DARLING_SDK_RELATIVE_PATH}/usr/include/libxml2 103 103 ) 104 104 105 - add_subdirectory(external/libkqueue) 106 - 107 105 # needs to come before libplatform because it generates mig headers that libplatform needs 108 106 add_subdirectory(kernel) 109 107
+11 -6
src/kernel/emulation/linux/kqueue/kevent.c
··· 4 4 #include <linux-syscalls/linux.h> 5 5 #include <stddef.h> 6 6 #include <sys/errno.h> 7 - 8 - int __attribute__((weak)) __attribute__((visibility("default"))) kevent_impl(int kq, ...) { return -ENOSYS; } 7 + #include "../mach/lkm.h" 8 + #include <lkm/api.h> 9 9 10 10 long sys_kevent(int kq, const struct kevent *changelist, int nchanges, 11 11 struct kevent *eventlist, int nevents, 12 12 const struct timespec *timeout) 13 13 { 14 - int ret = kevent_impl(kq, changelist, nchanges, eventlist, nevents, timeout); 15 - if (ret < 0) 16 - ret = -errno; 17 - return ret; 14 + struct kevent_args args = { 15 + .fd = kq, 16 + .changelist = changelist, 17 + .nchanges = nchanges, 18 + .eventlist = eventlist, 19 + .nevents = nevents, 20 + .timeout = timeout, 21 + }; 22 + return lkm_call(NR_kevent, &args); 18 23 } 19 24
+12 -6
src/kernel/emulation/linux/kqueue/kevent64.c
··· 4 4 #include <linux-syscalls/linux.h> 5 5 #include <stddef.h> 6 6 #include <sys/errno.h> 7 - 8 - int __attribute__((weak)) __attribute__((visibility("default"))) kevent64_impl(int kq, ...) { return -ENOSYS; } 7 + #include "../mach/lkm.h" 8 + #include <lkm/api.h> 9 9 10 10 long sys_kevent64(int kq, const struct kevent64_s *changelist, int nchanges, 11 11 struct kevent64_s *eventlist, int nevents, unsigned int flags, 12 12 const struct timespec *timeout) 13 13 { 14 - int ret = kevent64_impl(kq, changelist, nchanges, eventlist, nevents, flags, timeout); 15 - if (ret < 0) 16 - ret = -errno; 17 - return ret; 14 + struct kevent64_args args = { 15 + .fd = kq, 16 + .changelist = changelist, 17 + .nchanges = nchanges, 18 + .eventlist = eventlist, 19 + .nevents = nevents, 20 + .flags = flags, 21 + .timeout = timeout, 22 + }; 23 + return lkm_call(NR_kevent64, &args); 18 24 } 19 25
+8 -2
src/kernel/emulation/linux/kqueue/kevent_qos.c
··· 10 10 #include "kqueue.h" 11 11 #include "../bsdthread/workq_kernreturn.h" 12 12 13 - static int default_kq = -1; 13 + // not static because `mach_init.c` needs to reset it on fork 14 + // (but since we're using symbol visibility, no one else will be able to see it, so it's ok) 15 + // we can remove this once our LKM supports kqueue workqs and workloops (at that point, this syscall will turn into a simple trap into the LKM) 16 + int default_kq = -1; 14 17 15 18 extern void* memmove(void* dst, const void* src, __SIZE_TYPE__ n); 19 + 20 + // we have an LKM trap for kevent_qos, but due to our LKM not supporting workqs and workloops yet, 21 + // it's easier to keep our old behavior and translate this into a kevent64 call and handle workq stuff ourselves. 22 + // TODO: support workqs and workloops in the LKM (requires in-kernel pthread operations) 16 23 17 24 static void kevent_qos_to_64(const struct kevent_qos_s *ev, struct kevent64_s* ev64); 18 25 static void kevent_64_to_qos(const struct kevent64_s* ev64, struct kevent_qos_s *ev); ··· 33 40 if (default_kq == -1) 34 41 { 35 42 default_kq = sys_kqueue(); 36 - sys_fcntl(default_kq, F_SETFD, FD_CLOEXEC); 37 43 } 38 44 39 45 if (changelist != NULL && nchanges > 0)
+3 -10
src/kernel/emulation/linux/kqueue/kqueue.c
··· 5 5 #include <stddef.h> 6 6 #include <sys/errno.h> 7 7 #include "../simple.h" 8 - 9 - int __attribute__((weak)) __attribute__((visibility("default"))) kqueue_impl(void) 10 - { 11 - __simple_printf("No kqueue implementation?!\n"); 12 - return -ENOSYS; 13 - } 8 + #include "../mach/lkm.h" 9 + #include <lkm/api.h> 14 10 15 11 long sys_kqueue(void) 16 12 { 17 - int ret = kqueue_impl(); 18 - if (ret < 0) 19 - ret = -errno; 20 - return ret; 13 + return lkm_call(NR_kqueue_create, NULL); 21 14 } 22 15
+2 -2
src/kernel/emulation/linux/misc/ptrace.c
··· 116 116 } 117 117 case PT_SIGEXC: 118 118 { 119 - lkm_call(0x1028, "sigexc: self via ptrace\n"); 119 + __simple_kprintf("sigexc: self via ptrace\n"); 120 120 121 121 struct ptrace_sigexc_args args; 122 122 args.pid = getpid(); ··· 169 169 __simple_sprintf(buf, "ptrace() req=%s, ret=%d\n", cmd, ret); 170 170 else 171 171 __simple_sprintf(buf, "ptrace() req=%d\n", request); 172 - lkm_call(0x1028, buf); 172 + __simple_kprintf(buf); 173 173 174 174 return ret; 175 175 }
+2 -2
src/kernel/emulation/linux/signal/sigexc.c
··· 48 48 49 49 #define DEBUG_SIGEXC 50 50 #ifdef DEBUG_SIGEXC 51 - #define kern_printf(...) { char buf[128]; __simple_sprintf(buf, __VA_ARGS__); lkm_call(0x1028, buf); } 51 + #define kern_printf(...) __simple_kprintf(__VA_ARGS__) 52 52 #else 53 53 #define kern_printf(...) 54 54 #endif ··· 147 147 { 148 148 am_i_ptraced = true; 149 149 150 - lkm_call(0x1028, "darling_sigexc_self()\n"); 150 + __simple_kprintf("darling_sigexc_self()\n"); 151 151 // Make sigexc_handler the handler for all signals in the process 152 152 for (int i = 1; i <= 31; i++) 153 153 {
+8 -14
src/kernel/emulation/linux/unistd/close.c
··· 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 5 #include "../bsdthread/cancelable.h" 6 - 7 - __attribute__((weak)) 8 - __attribute__((visibility("default"))) 9 - int kqueue_close(int kq) { return -1; } 6 + #include "../mach/lkm.h" 7 + #include <lkm/api.h> 10 8 11 9 long sys_close(int fd) 12 10 { ··· 21 19 ret = LINUX_SYSCALL1(__NR_close, fd); 22 20 if (ret < 0) 23 21 ret = errno_linux_to_bsd(ret); 24 - else 25 - kqueue_close(fd); 22 + else { 23 + struct closing_descriptor_args args = { 24 + .fd = fd, 25 + }; 26 + lkm_call(NR_closing_descriptor, &args); 27 + } 26 28 27 29 return ret; 28 30 } ··· 37 39 38 40 return ret; 39 41 } 40 - 41 - // Special variant for libkqueue to avoid recursion into kqueue_close() 42 - __attribute__((visibility("default"))) 43 - long __close_for_kqueue(int fd) 44 - { 45 - return close_internal(fd); 46 - } 47 -
-6
src/kernel/emulation/linux/unistd/dup.c
··· 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 5 6 - __attribute__((weak)) 7 - __attribute__((visibility("default"))) 8 - void kqueue_dup(int oldfd, int newfd) { } 9 - 10 6 long sys_dup(int fd) 11 7 { 12 8 int ret; ··· 14 10 ret = LINUX_SYSCALL1(__NR_dup, fd); 15 11 if (ret < 0) 16 12 ret = errno_linux_to_bsd(ret); 17 - else 18 - kqueue_dup(fd, ret); 19 13 20 14 return ret; 21 15 }
-4
src/kernel/emulation/linux/unistd/dup2.c
··· 4 4 #include <linux-syscalls/linux.h> 5 5 #include "../duct_errno.h" 6 6 7 - extern void kqueue_dup(int oldfd, int newfd); 8 - 9 7 long sys_dup2(int fd_from, int fd_to) 10 8 { 11 9 int ret; ··· 22 20 #endif 23 21 if (ret < 0) 24 22 ret = errno_linux_to_bsd(ret); 25 - else 26 - kqueue_dup(fd_from, fd_to); 27 23 28 24 return ret; 29 25 }
+4
src/kernel/libsyscall/mach/mach_init.c
··· 64 64 65 65 #ifdef DARLING 66 66 #include <darling/lkm/api.h> 67 + 68 + extern int default_kq; 67 69 #endif 68 70 69 71 mach_port_t bootstrap_port = MACH_PORT_NULL; ··· 139 141 _mach_fork_child(void) 140 142 { 141 143 #ifdef DARLING 144 + // we only have to reset to `-1`; the LKM takes care of closing it for us 145 + default_kq = -1; 142 146 mach_init_doit(NULL); 143 147 #else 144 148 mach_init_doit();
-1
src/libc/CMakeLists.txt
··· 183 183 $<TARGET_OBJECTS:libc-locale> 184 184 $<TARGET_OBJECTS:libc-i386> 185 185 $<TARGET_OBJECTS:libc-x86_64> 186 - $<TARGET_OBJECTS:kqueue> 187 186 $<TARGET_OBJECTS:libc-darwin> 188 187 $<TARGET_OBJECTS:libc-stdio_legacy> 189 188 $<TARGET_OBJECTS:libc-compat_legacy>
+5
src/libnotify/notifyd/CMakeLists.txt
··· 1 1 project(notifyd) 2 2 3 + add_compile_definitions( 4 + SINGLE_THREADED_NOTIFY_STATE=1 5 + MACH_NOTIFY_SEND_POSSIBLE_EXPECTED=1 6 + ) 7 + 3 8 mig(notify_ipc.defs) 4 9 mig(notify.defs) 5 10
-2
src/libsystem/CMakeLists.txt
··· 33 33 add_circular(system FAT 34 34 SOURCES 35 35 ${libsystem_sources} 36 - OBJECTS 37 - $<TARGET_OBJECTS:kqueue> 38 36 39 37 SIBLINGS 40 38