this repo has no description
1
fork

Configure Feed

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

sys_sigaction() and sys_sigreturn() implemented

+220 -3
+3 -1
src/kernel/emulation/linux/CMakeLists.txt
··· 4 4 5 5 enable_language(C ASM) 6 6 7 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fvisibility=hidden -fPIC -ggdb") 7 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fvisibility=hidden -fPIC -ggdb -Wno-int-conversion") 8 8 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") 9 9 10 10 set(emulation_sources ··· 44 44 signal/duct_signals.c 45 45 signal/kill.c 46 46 signal/sigaltstack.c 47 + signal/sigaction.c 48 + signal/sigreturn.c 47 49 misc/ioctl.c 48 50 misc/thread_selfid.c 49 51 misc/sysctl.c
+2 -1
src/kernel/emulation/linux/signal/duct_signals.c
··· 1 + #define __sigset_t_defined 2 + #include "../../../../../platform-include/sys/signal.h" 1 3 #include "duct_signals.h" 2 - #include "../../../../../platform-include/sys/signal.h" 3 4 4 5 int signum_linux_to_bsd(int signum) 5 6 {
+4 -1
src/kernel/emulation/linux/signal/duct_signals.h
··· 1 1 #ifndef LINUX_DUCT_SIGNALS_H 2 2 #define LINUX_DUCT_SIGNALS_H 3 - #include <signal.h> 4 3 5 4 #define LINUX_NSIG 32 6 5 #define LINUX_SIGHUP 1 ··· 50 49 #define LINUX_SIGSTKSZ 8192 51 50 52 51 typedef unsigned long long linux_sigset_t; 52 + 53 + #ifndef __sigset_t_defined 54 + typedef unsigned int sigset_t; 55 + #endif 53 56 54 57 int signum_linux_to_bsd(int signum); 55 58 int signum_bsd_to_linux(int signum);
+107
src/kernel/emulation/linux/signal/sigaction.c
··· 1 + #include "sigaction.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <asm/unistd.h> 5 + #include <stddef.h> 6 + #include "../../../../../platform-include/sys/errno.h" 7 + 8 + static void handler_linux_to_bsd(int linux_signum, struct linux_siginfo* info, void* ctxt); 9 + static int sigflags_bsd_to_linux(int flags); 10 + static int sigflags_linux_to_bsd(int flags); 11 + 12 + extern void* memcpy(void* dest, const void* src, unsigned long len); 13 + 14 + // Libc uses only one trampoline 15 + void (*sa_tramp)(void*, int, int, struct bsd_siginfo*, void*) = 0; 16 + static bsd_sig_handler* sig_handlers[32]; 17 + 18 + long sys_sigaction(int signum, const struct bsd___sigaction* nsa, struct bsd_sigaction* osa) 19 + { 20 + int ret, linux_signum; 21 + struct linux_sigaction sa, olsa; 22 + 23 + linux_signum = signum_bsd_to_linux(signum); 24 + if (linux_signum == 0) 25 + return -EINVAL; 26 + 27 + if (nsa != NULL) 28 + { 29 + sa_tramp = nsa->sa_tramp; 30 + sa.sa_sigaction = &handler_linux_to_bsd; 31 + sigset_bsd_to_linux(&nsa->sa_mask, &sa.sa_mask); 32 + sa.sa_flags = sigflags_bsd_to_linux(nsa->sa_flags); 33 + sa.sa_restorer = NULL; 34 + } 35 + 36 + ret = LINUX_SYSCALL(__NR_rt_sigaction, linux_signum, 37 + (nsa != NULL) ? &sa : NULL, &olsa, 38 + sizeof(sa.sa_mask)); 39 + if (ret < 0) 40 + return errno_linux_to_bsd(ret); 41 + 42 + if (nsa != NULL) 43 + sig_handlers[linux_signum] = nsa->sa_sigaction; 44 + 45 + if (osa != NULL) 46 + { 47 + osa->sa_sigaction = sig_handlers[linux_signum]; 48 + sigset_linux_to_bsd(&olsa.sa_mask, &osa->sa_mask); 49 + osa->sa_flags = sigflags_linux_to_bsd(olsa.sa_flags); 50 + } 51 + 52 + return 0; 53 + } 54 + 55 + static void handler_linux_to_bsd(int linux_signum, struct linux_siginfo* info, void* ctxt) 56 + { 57 + int bsd_signum; 58 + struct bsd_siginfo binfo; 59 + 60 + bsd_signum = signum_linux_to_bsd(linux_signum); 61 + 62 + memcpy(&binfo, info, sizeof(binfo)); 63 + binfo.si_signo = signum_linux_to_bsd(binfo.si_signo); 64 + 65 + sig_handlers[linux_signum](bsd_signum, &binfo, ctxt); 66 + } 67 + 68 + static int sigflags_bsd_to_linux(int flags) 69 + { 70 + int linux_flags = LINUX_SA_SIGINFO; 71 + 72 + if (flags & BSD_SA_NOCLDSTOP) 73 + linux_flags |= LINUX_SA_NOCLDSTOP; 74 + if (flags & BSD_SA_NOCLDWAIT) 75 + linux_flags |= LINUX_SA_NOCLDWAIT; 76 + if (flags & BSD_SA_ONSTACK) 77 + linux_flags |= LINUX_SA_ONSTACK; 78 + if (flags & BSD_SA_NODEFER) 79 + linux_flags |= LINUX_SA_NODEFER; 80 + if (flags & BSD_SA_RESETHAND) 81 + linux_flags |= LINUX_SA_RESETHAND; 82 + if (flags & BSD_SA_RESTART) 83 + linux_flags |= LINUX_SA_RESTART; 84 + 85 + return linux_flags; 86 + } 87 + 88 + static int sigflags_linux_to_bsd(int flags) 89 + { 90 + int bsd_flags = 0; 91 + 92 + if (flags & LINUX_SA_NOCLDSTOP) 93 + bsd_flags |= BSD_SA_NOCLDSTOP; 94 + if (flags & LINUX_SA_NOCLDWAIT) 95 + bsd_flags |= BSD_SA_NOCLDWAIT; 96 + if (flags & LINUX_SA_ONSTACK) 97 + bsd_flags |= BSD_SA_ONSTACK; 98 + if (flags & LINUX_SA_NODEFER) 99 + bsd_flags |= BSD_SA_NODEFER; 100 + if (flags & LINUX_SA_RESETHAND) 101 + bsd_flags |= BSD_SA_RESETHAND; 102 + if (flags & LINUX_SA_RESTART) 103 + bsd_flags |= BSD_SA_RESTART; 104 + 105 + return bsd_flags; 106 + } 107 +
+81
src/kernel/emulation/linux/signal/sigaction.h
··· 1 + #ifndef LINUX_SIGACTION_H 2 + #define LINUX_SIGACTION_H 3 + #include "duct_signals.h" 4 + 5 + #define BSD_SA_ONSTACK 0x0001 6 + #define BSD_SA_RESTART 0x0002 7 + #define BSD_SA_RESETHAND 0x0004 8 + #define BSD_SA_NOCLDSTOP 0x0008 9 + #define BSD_SA_NODEFER 0x0010 10 + #define BSD_SA_NOCLDWAIT 0x0020 11 + #define BSD_SA_SIGINFO 0x0040 12 + 13 + #define LINUX_SA_NOCLDSTOP 0x00000001u 14 + #define LINUX_SA_NOCLDWAIT 0x00000002u 15 + #define LINUX_SA_SIGINFO 0x00000004u 16 + #define LINUX_SA_ONSTACK 0x08000000u 17 + #define LINUX_SA_RESTART 0x10000000u 18 + #define LINUX_SA_NODEFER 0x40000000u 19 + #define LINUX_SA_RESETHAND 0x80000000u 20 + 21 + struct bsd_siginfo 22 + { 23 + int si_signo; 24 + int si_errno; 25 + int si_code; 26 + unsigned int si_pid; 27 + unsigned int si_uid; 28 + int si_status; 29 + void* si_addr; 30 + void* si_val_ptr; 31 + long si_band; 32 + unsigned long __pad[7]; 33 + }; 34 + 35 + # define __SI_MAX_SIZE 128 36 + # if defined (__x86_64__) 37 + # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4) 38 + # else 39 + # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3) 40 + # endif 41 + 42 + struct linux_siginfo 43 + { 44 + int si_signo; 45 + int si_errno; 46 + int si_code; 47 + 48 + union 49 + { 50 + int _pad[__SI_PAD_SIZE]; 51 + }; 52 + }; 53 + 54 + typedef void (bsd_sig_handler)(int, struct bsd_siginfo*, void*); 55 + struct bsd_sigaction 56 + { 57 + bsd_sig_handler* sa_sigaction; 58 + unsigned int sa_mask; 59 + int sa_flags; 60 + }; 61 + 62 + struct bsd___sigaction 63 + { 64 + bsd_sig_handler* sa_sigaction; 65 + void (*sa_tramp)(void*, int, int, struct bsd_siginfo*, void*); 66 + unsigned int sa_mask; 67 + int sa_flags; 68 + }; 69 + 70 + struct linux_sigaction 71 + { 72 + void (*sa_sigaction)(int, struct linux_siginfo*, void*); 73 + int sa_flags; 74 + void (*sa_restorer)(void); 75 + linux_sigset_t sa_mask; 76 + }; 77 + 78 + long sys_sigaction(int signum, const struct bsd___sigaction* nsa, struct bsd_sigaction* osa); 79 + 80 + #endif 81 +
+12
src/kernel/emulation/linux/signal/sigreturn.c
··· 1 + #include "sigreturn.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + 5 + long sys_sigreturn() 6 + { 7 + // Apple's libc invokes sigreturn directly, 8 + // but Linux injects a rt_sigreturn() syscall on its own. 9 + // Hance we must ignore this call. 10 + return 0; 11 + } 12 +
+7
src/kernel/emulation/linux/signal/sigreturn.h
··· 1 + #ifndef LINUX_SIGRETURN_H 2 + #define LINUX_SIGRETURN_H 3 + 4 + long sys_sigreturn(); 5 + 6 + #endif 7 +
+4
src/kernel/emulation/linux/syscalls.c
··· 30 30 #include "unistd/readlink.h" 31 31 #include "signal/kill.h" 32 32 #include "signal/sigaltstack.h" 33 + #include "signal/sigaction.h" 34 + #include "signal/sigreturn.h" 33 35 #include "misc/ioctl.h" 34 36 #include "misc/getrlimit.h" 35 37 #include "misc/thread_selfid.h" ··· 59 61 [36] = sys_sync, 60 62 [37] = sys_kill, 61 63 [41] = sys_dup, 64 + [46] = sys_sigaction, 62 65 [53] = sys_sigaltstack, 63 66 [54] = sys_ioctl, 64 67 [58] = sys_readlink, ··· 79 82 [181] = sys_setgid, 80 83 [182] = sys_setegid, 81 84 [183] = sys_seteuid, 85 + [184] = sys_sigreturn, 82 86 [187] = sys_fdatasync, 83 87 [188] = sys_stat, 84 88 [189] = sys_fstat,