this repo has no description
1
fork

Configure Feed

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

Support thread cancelability

+130 -29
+2 -1
src/kernel/emulation/linux/CMakeLists.txt
··· 253 253 bsdthread/workq_kernreturn.c 254 254 bsdthread/workq_open.c 255 255 bsdthread/pthread_kill.c 256 - bsdthread/__pthread_canceled.c 257 256 bsdthread/pthread_chdir.c 258 257 bsdthread/pthread_fchdir.c 258 + bsdthread/pthread_markcancel.c 259 + bsdthread/pthread_canceled.c 259 260 psynch/psynch_errno.c 260 261 psynch/psynch_rw_rdlock.c 261 262 psynch/psynch_rw_wrlock.c
-22
src/kernel/emulation/linux/bsdthread/__pthread_canceled.c
··· 1 - #include "__pthread_canceled.h" 2 - #include "../base.h" 3 - #include "../errno.h" 4 - #include "../signal/duct_signals.h" 5 - #include "../../../../../platform-include/sys/errno.h" 6 - #include <stddef.h> 7 - #include "../simple.h" 8 - 9 - long sys_pthread_canceled(int action) 10 - { 11 - switch (action) 12 - { 13 - case 0: // has the thread been canceled with __pthread_markcancel? 14 - // return 0 if yes 15 - return -EAGAIN; 16 - case 1: // enable cancellation 17 - break; 18 - case 2: // disable cancellation 19 - break; 20 - } 21 - } 22 -
src/kernel/emulation/linux/bsdthread/__pthread_canceled.h src/kernel/emulation/linux/bsdthread/pthread_canceled.h
+11
src/kernel/emulation/linux/bsdthread/cancelable.h
··· 1 + #ifndef _BSDTHREAD_CANCELLABLE_H 2 + #define _BSDTHREAD_CANCELLABLE_H 3 + #include <sys/errno.h> 4 + #include "pthread_canceled.h" 5 + 6 + #define CANCELATION_POINT() \ 7 + if (sys_pthread_canceled(0) == 0) \ 8 + return -EINTR; 9 + 10 + #endif 11 +
+4
src/kernel/emulation/linux/bsdthread/disable_threadsignal.c
··· 6 6 #include "../../../../../platform-include/sys/errno.h" 7 7 #include <linux-syscalls/linux.h> 8 8 #include <stddef.h> 9 + #include "pthread_canceled.h" 9 10 10 11 #ifndef SIG_BLOCK 11 12 # define SIG_BLOCK 1 ··· 18 19 19 20 sigset_t set = ~0; 20 21 22 + // Disable cancelation 23 + sys_pthread_canceled(2); 24 + 21 25 // Signal config is per-thread on Linux 22 26 return sys_sigprocmask(SIG_BLOCK, &set, NULL); 23 27 }
+17
src/kernel/emulation/linux/bsdthread/pthread_canceled.c
··· 1 + #include "pthread_canceled.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <linux-syscalls/linux.h> 5 + #include <stddef.h> 6 + #include "../mach/lkm.h" 7 + #include "../../../../lkm/api.h" 8 + 9 + long sys_pthread_canceled(int action) 10 + { 11 + int ret = lkm_call(NR_pthread_canceled, (void*)(long) action); 12 + if (ret < 0) 13 + ret = errno_linux_to_bsd(ret); 14 + 15 + return ret; 16 + } 17 +
+4 -1
src/kernel/emulation/linux/bsdthread/pthread_kill.c
··· 15 15 args.thread_port = thread_port; 16 16 args.sig = signum_bsd_to_linux(sig); 17 17 18 - return lkm_call(NR_pthread_kill_trap, &args); 18 + int ret = lkm_call(NR_pthread_kill_trap, &args); 19 + if (ret < 0) 20 + ret = errno_linux_to_bsd(ret); 19 21 22 + return ret; 20 23 } 21 24
+17
src/kernel/emulation/linux/bsdthread/pthread_markcancel.c
··· 1 + #include "pthread_markcancel.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <linux-syscalls/linux.h> 5 + #include <stddef.h> 6 + #include "../mach/lkm.h" 7 + #include "../../../../lkm/api.h" 8 + 9 + long sys_pthread_markcancel(int thread_port) 10 + { 11 + int ret = lkm_call(NR_pthread_markcancel, (void*)(long) thread_port); 12 + if (ret < 0) 13 + ret = errno_linux_to_bsd(ret); 14 + 15 + return ret; 16 + } 17 +
+7
src/kernel/emulation/linux/bsdthread/pthread_markcancel.h
··· 1 + #ifndef PTHREAD_MARKCANCEL_H 2 + #define PTHREAD_MARKCANCEL_H 3 + 4 + long sys_pthread_markcancel(int thread_port); 5 + 6 + #endif 7 +
+2
src/kernel/emulation/linux/fcntl/fcntl.c
··· 5 5 #include "../errno.h" 6 6 #include <linux-syscalls/linux.h> 7 7 #include "../../../../../platform-include/sys/errno.h" 8 + #include "../bsdthread/cancelable.h" 8 9 9 10 #ifndef O_NOFOLLOW 10 11 # define O_NOFOLLOW 0x0100 ··· 24 25 25 26 long sys_fcntl(int fd, int cmd, long arg) 26 27 { 28 + CANCELATION_POINT(); 27 29 return sys_fcntl_nocancel(fd, cmd, arg); 28 30 } 29 31
+3 -1
src/kernel/emulation/linux/fcntl/open.c
··· 6 6 //#include "../../../../platform-include/sys/fcntl.h" 7 7 #include "../../../../libc/include/fcntl.h" 8 8 #include "../bsdthread/per_thread_wd.h" 9 + #include "../bsdthread/cancelable.h" 9 10 10 11 #ifndef O_NOFOLLOW 11 12 # define O_NOFOLLOW 0x0100 ··· 23 24 24 25 long sys_open(const char* filename, int flags, unsigned int mode) 25 26 { 26 - return sys_openat(get_perthread_wd(), filename, flags, mode); 27 + CANCELATION_POINT(); 28 + return sys_openat_nocancel(get_perthread_wd(), filename, flags, mode); 27 29 } 28 30 29 31 long sys_open_nocancel(const char* filename, int flags, unsigned int mode)
+2
src/kernel/emulation/linux/fcntl/openat.c
··· 5 5 #include <linux-syscalls/linux.h> 6 6 #include "../../../../libc/include/fcntl.h" 7 7 #include "../common_at.h" 8 + #include "../bsdthread/cancelable.h" 8 9 9 10 #ifndef O_NOFOLLOW 10 11 # define O_NOFOLLOW 0x0100 ··· 20 21 21 22 long sys_openat(int fd, const char* filename, int flags, unsigned int mode) 22 23 { 24 + CANCELATION_POINT(); 23 25 return sys_openat_nocancel(fd, filename, flags, mode); 24 26 } 25 27
+2
src/kernel/emulation/linux/mman/msync.c
··· 3 3 #include "../errno.h" 4 4 #include "../base.h" 5 5 #include <linux-syscalls/linux.h> 6 + #include "../bsdthread/cancelable.h" 6 7 7 8 int msync_flags_bsd_to_linux(int flags) 8 9 { ··· 20 21 21 22 long sys_msync(void* addr, unsigned long len, int flags) 22 23 { 24 + CANCELATION_POINT(); 23 25 return sys_msync_nocancel(addr, len, flags); 24 26 } 25 27
+2
src/kernel/emulation/linux/network/accept.c
··· 4 4 #include <linux-syscalls/linux.h> 5 5 #include "socket.h" 6 6 #include "duct.h" 7 + #include "../bsdthread/cancelable.h" 7 8 8 9 long sys_accept(int fd, void* from, int* socklen) 9 10 { 11 + CANCELATION_POINT(); 10 12 return sys_accept_nocancel(fd, from, socklen); 11 13 } 12 14
+2
src/kernel/emulation/linux/network/connect.c
··· 5 5 #include "../../../../../platform-include/sys/socket.h" 6 6 #include "../../../../../platform-include/sys/errno.h" 7 7 #include "duct.h" 8 + #include "../bsdthread/cancelable.h" 8 9 9 10 extern void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n); 10 11 11 12 long sys_connect(int fd, const void* name, int socklen) 12 13 { 14 + CANCELATION_POINT(); 13 15 return sys_connect_nocancel(fd, name, socklen); 14 16 } 15 17
+2
src/kernel/emulation/linux/network/recvfrom.c
··· 5 5 #include <stddef.h> 6 6 #include "socket.h" 7 7 #include "duct.h" 8 + #include "../bsdthread/cancelable.h" 8 9 9 10 extern void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n); 10 11 11 12 long sys_recvfrom(int fd, void* buf, unsigned long len, 12 13 int flags, const void* from, int* socklen) 13 14 { 15 + CANCELATION_POINT(); 14 16 return sys_recvfrom_nocancel(fd, buf, len, flags, from, socklen); 15 17 } 16 18
+2
src/kernel/emulation/linux/network/recvmsg.c
··· 5 5 #include <stddef.h> 6 6 #include "duct.h" 7 7 #include "getsockopt.h" 8 + #include "../bsdthread/cancelable.h" 8 9 9 10 extern void *malloc(__SIZE_TYPE__ size); 10 11 extern void free(void* ptr); ··· 14 15 15 16 long sys_recvmsg(int socket, struct bsd_msghdr* msg, int flags) 16 17 { 18 + CANCELATION_POINT(); 17 19 return sys_recvmsg_nocancel(socket, msg, flags); 18 20 } 19 21
+2
src/kernel/emulation/linux/network/sendmsg.c
··· 4 4 #include <linux-syscalls/linux.h> 5 5 #include <stddef.h> 6 6 #include "duct.h" 7 + #include "../bsdthread/cancelable.h" 7 8 8 9 extern void *malloc(__SIZE_TYPE__ size); 9 10 extern void free(void* ptr); ··· 11 12 12 13 long sys_sendmsg(int socket, const struct bsd_msghdr* msg, int flags) 13 14 { 15 + CANCELATION_POINT(); 14 16 return sys_sendmsg_nocancel(socket, msg, flags); 15 17 } 16 18
+2
src/kernel/emulation/linux/network/sendto.c
··· 5 5 // #include "../../../../../platform-include/sys/socket.h" 6 6 #include "../../../../../platform-include/sys/errno.h" 7 7 #include "duct.h" 8 + #include "../bsdthread/cancelable.h" 8 9 9 10 extern void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n); 10 11 11 12 long sys_sendto(int fd, const void* buffer, unsigned long length, 12 13 int flags, const void* sockaddr, int socklen) 13 14 { 15 + CANCELATION_POINT(); 14 16 return sys_sendto_nocancel(fd, buffer, length, flags, sockaddr, socklen); 15 17 } 16 18
+7
src/kernel/emulation/linux/process/wait4.c
··· 9 9 #include <sys/signal.h> 10 10 #include <stddef.h> 11 11 #include <linux-syscalls/linux.h> 12 + #include "../bsdthread/cancelable.h" 12 13 13 14 extern int getpid(void); 14 15 15 16 long sys_wait4(int pid, int* status, int options, void* rusage) 17 + { 18 + CANCELATION_POINT(); 19 + return sys_wait4_nocancel(pid, status, options, rusage); 20 + } 21 + 22 + long sys_wait4_nocancel(int pid, int* status, int options, void* rusage) 16 23 { 17 24 int ret, linux_options; 18 25 int mystatus;
+1
src/kernel/emulation/linux/process/wait4.h
··· 2 2 #define LINUX_WAIT4_H 3 3 4 4 long sys_wait4(int pid, int* status, int options, void* rusage); 5 + long sys_wait4_nocancel(int pid, int* status, int options, void* rusage); 5 6 6 7 int waitopts_bsd_to_linux(int options); 7 8
+1 -1
src/kernel/emulation/linux/psynch/ulock_wait.c
··· 22 22 23 23 24 24 char dbg[100]; 25 - __simple_sprintf(dbg, "ulock_wait on %p for %d ns", addr, timeout / 1000); 25 + // __simple_sprintf(dbg, "ulock_wait on %p for %d ns", addr, timeout / 1000); 26 26 lkm_call(0x1028, dbg); 27 27 28 28 if (timeout > 0)
+1 -1
src/kernel/emulation/linux/psynch/ulock_wake.c
··· 13 13 bool no_errno = operation & ULF_NO_ERRNO; 14 14 15 15 char buf[100]; 16 - __simple_sprintf(buf, "ulock_wake on %p", addr); 16 + // __simple_sprintf(buf, "ulock_wake on %p", addr); 17 17 lkm_call(0x1024, buf); 18 18 19 19 op = operation & UL_OPCODE_MASK;
+2
src/kernel/emulation/linux/select/poll.c
··· 3 3 #include "../errno.h" 4 4 #include <stddef.h> 5 5 #include <linux-syscalls/linux.h> 6 + #include "../bsdthread/cancelable.h" 6 7 7 8 long sys_poll(struct pollfd* fds, unsigned int nfds, int timeout) 8 9 { 10 + CANCELATION_POINT(); 9 11 return sys_poll_nocancel(fds, nfds, timeout); 10 12 } 11 13
+2
src/kernel/emulation/linux/select/pselect.c
··· 3 3 #include "../errno.h" 4 4 #include <stddef.h> 5 5 #include <linux-syscalls/linux.h> 6 + #include "../bsdthread/cancelable.h" 6 7 7 8 long sys_pselect(int nfds, void* rfds, void* wfds, void* efds, struct bsd_timeval* timeout, const sigset_t* mask) 8 9 { 10 + CANCELATION_POINT(); 9 11 return sys_pselect_nocancel(nfds, rfds, wfds, efds, timeout, mask); 10 12 } 11 13
+2
src/kernel/emulation/linux/select/select.c
··· 3 3 #include "../errno.h" 4 4 #include <stddef.h> 5 5 #include <linux-syscalls/linux.h> 6 + #include "../bsdthread/cancelable.h" 6 7 7 8 long sys_select(int nfds, void* rfds, void* wfds, void* efds, struct bsd_timeval* timeout) 8 9 { 10 + CANCELATION_POINT(); 9 11 return sys_select_nocancel(nfds, rfds, wfds, efds, timeout); 10 12 } 11 13
+2
src/kernel/emulation/linux/signal/sigsuspend.c
··· 4 4 #include "duct_signals.h" 5 5 #include <stddef.h> 6 6 #include <linux-syscalls/linux.h> 7 + #include "../bsdthread/cancelable.h" 7 8 8 9 long sys_sigsuspend(sigset_t set) 9 10 { 11 + CANCELATION_POINT(); 10 12 return sys_sigsuspend_nocancel(set); 11 13 } 12 14
+2
src/kernel/emulation/linux/synch/semwait_signal.c
··· 4 4 #include "../time/gettimeofday.h" 5 5 #include <linux-syscalls/linux.h> 6 6 #include <stddef.h> 7 + #include "../bsdthread/cancelable.h" 7 8 8 9 typedef int kern_return_t; 9 10 extern kern_return_t semaphore_timedwait_signal_trap(int cond_sem, int mutex_sem, unsigned int tv_sec, unsigned int tv_nsec); ··· 16 17 17 18 long sys_semwait_signal(int cond_sem, int mutex_sem, int timeout, int relative, int64_t tv_sec, int32_t tv_nsec) 18 19 { 20 + CANCELATION_POINT(); 19 21 return sys_semwait_signal_nocancel(cond_sem, mutex_sem, timeout, relative, tv_sec, tv_nsec); 20 22 } 21 23
+5 -2
src/kernel/emulation/linux/syscalls.c
··· 162 162 #include "bsdthread/bsdthread_create.h" 163 163 #include "bsdthread/bsdthread_terminate.h" 164 164 #include "bsdthread/disable_threadsignal.h" 165 - #include "bsdthread/__pthread_canceled.h" 166 165 #include "bsdthread/pthread_chdir.h" 167 166 #include "bsdthread/pthread_fchdir.h" 167 + #include "bsdthread/pthread_markcancel.h" 168 + #include "bsdthread/pthread_canceled.h" 168 169 #include "hfs/stub.h" 169 170 #include "xattr/getattrlistbulk.h" 170 171 #include "xattr/getattrlistat.h" ··· 368 369 [328] = sys_pthread_kill, 369 370 [329] = sys_sigprocmask, // __pthread_sigmask 370 371 [331] = sys_disable_threadsignal, 372 + [332] = sys_pthread_markcancel, 371 373 [333] = sys_pthread_canceled, 372 374 [334] = sys_semwait_signal, 373 375 [336] = sys_proc_info, ··· 400 402 [397] = sys_write_nocancel, 401 403 [398] = sys_open_nocancel, 402 404 [399] = sys_close_nocancel, 403 - [400] = sys_wait4, 405 + [400] = sys_wait4_nocancel, 404 406 [401] = sys_recvmsg_nocancel, 405 407 [402] = sys_sendmsg_nocancel, 406 408 [403] = sys_recvfrom_nocancel, ··· 417 419 [414] = sys_pread_nocancel, 418 420 [415] = sys_pwrite_nocancel, 419 421 [417] = sys_poll_nocancel, 422 + [420] = sys_sem_wait_nocancel, 420 423 [423] = sys_semwait_signal_nocancel, 421 424 [441] = sys_guarded_open_np, 422 425 [442] = sys_guarded_close_np,
+2
src/kernel/emulation/linux/unistd/close.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 + #include "../bsdthread/cancelable.h" 5 6 6 7 __attribute__((weak)) 7 8 __attribute__((visibility("default"))) ··· 9 10 10 11 long sys_close(int fd) 11 12 { 13 + CANCELATION_POINT(); 12 14 return sys_close_nocancel(fd); 13 15 } 14 16
+2
src/kernel/emulation/linux/unistd/pread.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 + #include "../bsdthread/cancelable.h" 5 6 6 7 long sys_pread(int fd, void* mem, int len, long long ofs) 7 8 { 9 + CANCELATION_POINT(); 8 10 return sys_pread_nocancel(fd, mem, len, ofs); 9 11 } 10 12
+2
src/kernel/emulation/linux/unistd/pwrite.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 + #include "../bsdthread/cancelable.h" 5 6 6 7 long sys_pwrite(int fd, const void* mem, int len, long long ofs) 7 8 { 9 + CANCELATION_POINT(); 8 10 return sys_pwrite_nocancel(fd, mem, len, ofs); 9 11 } 10 12
+2
src/kernel/emulation/linux/unistd/read.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 + #include "../bsdthread/cancelable.h" 5 6 6 7 long sys_read(int fd, void* mem, int len) 7 8 { 9 + CANCELATION_POINT(); 8 10 return sys_read_nocancel(fd, mem, len); 9 11 } 10 12
+2
src/kernel/emulation/linux/unistd/readv.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 + #include "../bsdthread/cancelable.h" 5 6 6 7 long sys_readv(int fd, struct iovec* iovp, unsigned int len) 7 8 { 9 + CANCELATION_POINT(); 8 10 return sys_readv_nocancel(fd, iovp, len); 9 11 } 10 12
+2
src/kernel/emulation/linux/unistd/write.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 + #include "../bsdthread/cancelable.h" 5 6 6 7 long sys_write(int fd, const void* mem, int len) 7 8 { 9 + CANCELATION_POINT(); 8 10 return sys_write_nocancel(fd, mem, len); 9 11 } 10 12
+2
src/kernel/emulation/linux/unistd/writev.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 + #include "../bsdthread/cancelable.h" 5 6 6 7 long sys_writev(int fd, struct iovec* iovp, unsigned int len) 7 8 { 9 + CANCELATION_POINT(); 8 10 return sys_writev_nocancel(fd, iovp, len); 9 11 } 10 12
+7
src/kernel/emulation/linux/wrapped/sem_wait.c
··· 4 4 #include <sys/errno.h> 5 5 #include <linux-syscalls/linux.h> 6 6 #include <elfcalls.h> 7 + #include "../bsdthread/cancelable.h" 7 8 8 9 extern struct elf_calls* _elfcalls; 9 10 10 11 long sys_sem_wait(int* sem) 12 + { 13 + CANCELATION_POINT(); 14 + return sys_sem_wait_nocancel(sem); 15 + } 16 + 17 + long sys_sem_wait_nocancel(int* sem) 11 18 { 12 19 #ifndef VARIANT_DYLD 13 20 int ret;
+1
src/kernel/emulation/linux/wrapped/sem_wait.h
··· 2 2 #define LINUX_SEM_WAIT_H 3 3 4 4 long sys_sem_wait(int* sem); 5 + long sys_sem_wait_nocancel(int* sem); 5 6 6 7 #endif 7 8