this repo has no description
1
fork

Configure Feed

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

Bring back libkqueue

This partially reverts commit 63f9a0e16542a764a3dc79291a0097df1fe1ec46.

+66 -45
+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 10 13 [submodule "src/external/zlib"] 11 14 path = src/external/zlib 12 15 url = ../darling-zlib.git
+2
src/CMakeLists.txt
··· 109 109 ${CMAKE_BINARY_DIR}/${DARLING_SDK_RELATIVE_PATH}/usr/include/libxml2 110 110 ) 111 111 112 + add_subdirectory(external/libkqueue) 113 + 112 114 # needs to come before libplatform because it generates mig headers that libplatform needs 113 115 add_subdirectory(kernel) 114 116
+6 -11
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 - #include "../mach/lkm.h" 8 - #include <lkm/api.h> 7 + 8 + int __attribute__((weak)) __attribute__((visibility("default"))) kevent_impl(int kq, ...) { return -ENOSYS; } 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 - 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); 14 + int ret = kevent_impl(kq, changelist, nchanges, eventlist, nevents, timeout); 15 + if (ret < 0) 16 + ret = -errno; 17 + return ret; 23 18 } 24 19
+6 -12
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 - #include "../mach/lkm.h" 8 - #include <lkm/api.h> 7 + 8 + int __attribute__((weak)) __attribute__((visibility("default"))) kevent64_impl(int kq, ...) { return -ENOSYS; } 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 - 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); 14 + int ret = kevent64_impl(kq, changelist, nchanges, eventlist, nevents, flags, timeout); 15 + if (ret < 0) 16 + ret = -errno; 17 + return ret; 24 18 } 25 19
+5 -13
src/kernel/emulation/linux/kqueue/kevent_qos.c
··· 11 11 #include "../bsdthread/workq_kernreturn.h" 12 12 #include "kevent64.h" 13 13 14 - // not static because `mach_init.c` needs to reset it on fork 15 - // (but since we're using symbol visibility, no one else will be able to see it, so it's ok) 16 - // 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) 17 - int default_kq = -1; 14 + static int default_kq = -1; 18 15 19 16 extern void* memmove(void* dst, const void* src, __SIZE_TYPE__ n); 20 - 21 - // we have an LKM trap for kevent_qos, but due to our LKM not supporting workqs and workloops yet, 22 - // it's easier to keep our old behavior and translate this into a kevent64 call and handle workq stuff ourselves. 23 - // TODO: support workqs and workloops in the LKM (requires in-kernel pthread operations) 24 17 25 18 static void kevent_qos_to_64(const struct kevent_qos_s *ev, struct kevent64_s* ev64); 26 19 static void kevent_64_to_qos(const struct kevent64_s* ev64, struct kevent_qos_s *ev); ··· 38 31 if ((kq == -1) != !!(flags & KEVENT_FLAG_WORKQ)) 39 32 return -EINVAL; 40 33 41 - if (kq < 0) { 42 - if (default_kq == -1) { 43 - default_kq = sys_kqueue(); 44 - } 45 - kq = default_kq; 34 + if (default_kq == -1) 35 + { 36 + default_kq = sys_kqueue(); 37 + sys_fcntl(default_kq, F_SETFD, FD_CLOEXEC); 46 38 } 47 39 48 40 if (changelist != NULL && nchanges > 0)
+10 -3
src/kernel/emulation/linux/kqueue/kqueue.c
··· 5 5 #include <stddef.h> 6 6 #include <sys/errno.h> 7 7 #include "../simple.h" 8 - #include "../mach/lkm.h" 9 - #include <lkm/api.h> 8 + 9 + int __attribute__((weak)) __attribute__((visibility("default"))) kqueue_impl(void) 10 + { 11 + __simple_printf("No kqueue implementation?!\n"); 12 + return -ENOSYS; 13 + } 10 14 11 15 long sys_kqueue(void) 12 16 { 13 - return lkm_call(NR_kqueue_create, NULL); 17 + int ret = kqueue_impl(); 18 + if (ret < 0) 19 + ret = -errno; 20 + return ret; 14 21 } 15 22
+14
src/kernel/emulation/linux/unistd/close.c
··· 7 7 #include <lkm/api.h> 8 8 #include "../simple.h" 9 9 10 + __attribute__((weak)) 11 + __attribute__((visibility("default"))) 12 + int kqueue_close(int kq) { return -1; } 13 + 10 14 long sys_close(int fd) 11 15 { 12 16 CANCELATION_POINT(); ··· 25 29 ret = LINUX_SYSCALL1(__NR_close, fd); 26 30 if (ret < 0) 27 31 ret = errno_linux_to_bsd(ret); 32 + else 33 + kqueue_close(fd); 28 34 29 35 return ret; 30 36 } ··· 39 45 40 46 return ret; 41 47 } 48 + 49 + // Special variant for libkqueue to avoid recursion into kqueue_close() 50 + __attribute__((visibility("default"))) 51 + long __close_for_kqueue(int fd) 52 + { 53 + return close_internal(fd); 54 + } 55 +
+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 + 6 10 long sys_dup(int fd) 7 11 { 8 12 int ret; ··· 10 14 ret = LINUX_SYSCALL1(__NR_dup, fd); 11 15 if (ret < 0) 12 16 ret = errno_linux_to_bsd(ret); 17 + else 18 + kqueue_dup(fd, ret); 13 19 14 20 return ret; 15 21 }
+4
src/kernel/emulation/linux/unistd/dup2.c
··· 6 6 #include "../mach/lkm.h" 7 7 #include <lkm/api.h> 8 8 9 + extern void kqueue_dup(int oldfd, int newfd); 10 + 9 11 long sys_dup2(int fd_from, int fd_to) 10 12 { 11 13 int ret; ··· 22 24 #endif 23 25 if (ret < 0) 24 26 ret = errno_linux_to_bsd(ret); 27 + else 28 + kqueue_dup(fd_from, fd_to); 25 29 26 30 return ret; 27 31 }
-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; 69 67 #endif 70 68 71 69 mach_port_t bootstrap_port = MACH_PORT_NULL; ··· 141 139 _mach_fork_child(void) 142 140 { 143 141 #ifdef DARLING 144 - // we only have to reset to `-1`; the LKM takes care of closing it for us 145 - default_kq = -1; 146 142 mach_init_doit(NULL); 147 143 #else 148 144 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> 186 187 $<TARGET_OBJECTS:libc-darwin> 187 188 $<TARGET_OBJECTS:libc-stdio_legacy> 188 189 $<TARGET_OBJECTS:libc-compat_legacy>
+9 -2
src/libsystem/CMakeLists.txt
··· 30 30 31 31 set(DYLIB_INSTALL_NAME "/usr/lib/libSystem.B.dylib") 32 32 set(DYLIB_CURRENT_VERSION "1281.0.0") 33 - add_darling_library(system 34 - ${libsystem_sources} 33 + add_circular(system FAT 34 + SOURCES 35 + ${libsystem_sources} 36 + OBJECTS 37 + $<TARGET_OBJECTS:kqueue> 38 + 39 + SIBLINGS 40 + 41 + system_malloc 35 42 ) 36 43 37 44 function(libsystem_reexport)