From 5f2cda2a48993e3e5cbb2b1025c17cb4188cee5b Mon Sep 17 00:00:00 2001 From: Lubos Dolezel Date: Sat, 22 Feb 2020 20:53:36 +0100 Subject: [PATCH] Fixes for LLDB and Node.js --- src/external/cocotron | 2 +- src/external/foundation | 2 +- src/external/lkm | 2 +- src/kernel/emulation/linux/mman/madvise.c | 9 ++++- src/kernel/emulation/linux/process/execve.c | 3 +- src/kernel/emulation/linux/signal/sigexc.c | 37 +++++++++++++++------ 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/external/cocotron b/src/external/cocotron index e6398f012..2b2fe77e3 160000 --- a/src/external/cocotron +++ b/src/external/cocotron @@ -1 +1 @@ -Subproject commit e6398f0123e3ae32bca211128639af2fc8c7cd42 +Subproject commit 2b2fe77e33fb58b0edfbae8ed696f34eee035cf0 diff --git a/src/external/foundation b/src/external/foundation index 575903a40..26f962406 160000 --- a/src/external/foundation +++ b/src/external/foundation @@ -1 +1 @@ -Subproject commit 575903a40126463475492855351d26e37688e761 +Subproject commit 26f962406f5c5c8124c20d5d7a54050cec0b821c diff --git a/src/external/lkm b/src/external/lkm index f41e784cb..779233b42 160000 --- a/src/external/lkm +++ b/src/external/lkm @@ -1 +1 @@ -Subproject commit f41e784cb6b76f5bb60738db8644aa3de56c20c1 +Subproject commit 779233b426949e330f72634dbb269f6cb092fc48 diff --git a/src/kernel/emulation/linux/mman/madvise.c b/src/kernel/emulation/linux/mman/madvise.c index d480dc8bc..562108c85 100644 --- a/src/kernel/emulation/linux/mman/madvise.c +++ b/src/kernel/emulation/linux/mman/madvise.c @@ -4,14 +4,21 @@ #include "../../../../../platform-include/sys/errno.h" #include +#define MADV_FREE 5 +#define MADV_FREE_REUSABLE 7 +#define MADV_FREE_REUSE 8 + long sys_madvise(void* addr, unsigned long len, int advice) { int ret; + if (advice == MADV_FREE_REUSABLE || advice == MADV_FREE_REUSE) + advice = MADV_FREE; + // advice < 0 are identical between OS X and Linux // advice >= 5 are specific to OS X/BSD if (advice >= 5) - return -ENOTSUP; + return 0; ret = LINUX_SYSCALL(__NR_madvise, addr, len, advice); diff --git a/src/kernel/emulation/linux/process/execve.c b/src/kernel/emulation/linux/process/execve.c index 99d1d507c..f61711cdc 100644 --- a/src/kernel/emulation/linux/process/execve.c +++ b/src/kernel/emulation/linux/process/execve.c @@ -87,7 +87,8 @@ long sys_execve(char* fname, char** argvp, char** envp) if (arg != NULL) { *arg = '\0'; // terminate interp - while (isspace(*arg)) + arg++; + while (isspace(*arg) && *arg) arg++; if (*arg == '\0') arg = NULL; // no argument, just whitespace diff --git a/src/kernel/emulation/linux/signal/sigexc.c b/src/kernel/emulation/linux/signal/sigexc.c index 8d101b8dd..56ce73044 100644 --- a/src/kernel/emulation/linux/signal/sigexc.c +++ b/src/kernel/emulation/linux/signal/sigexc.c @@ -318,13 +318,14 @@ void sigexc_handler(int linux_signum, struct linux_siginfo* info, struct linux_u // SIGILL -> EXC_BAD_INSTRUCTION // SIGFPE -> EXC_ARITHMETIC // * -> EXC_SOFTWARE with EXC_SOFT_SIGNAL (e.g. SIGSTOP) + kern_printf("sigexc_handler #2\n"); - switch (bsd_signum) + // Only real exceptions produced by the CPU get translated to these + // Mach exceptions. The rest comes as EXC_SOFTWARE. + if (info != NULL && info->si_code != 0) { - // Only real exceptions produced by the CPU get translated to these - // Mach exceptions. The rest comes as EXC_SOFTWARE. - if (info != NULL && info->si_code != 0) - { + switch (bsd_signum) + { case SIGSEGV: mach_exception = EXC_BAD_ACCESS; codes[0] = EXC_I386_GPFLT; @@ -356,11 +357,17 @@ void sigexc_handler(int linux_signum, struct linux_siginfo* info, struct linux_u } } break; + default: + mach_exception = EXC_SOFTWARE; + codes[0] = EXC_SOFT_SIGNAL; + codes[1] = bsd_signum; } - default: - mach_exception = EXC_SOFTWARE; - codes[0] = EXC_SOFT_SIGNAL; - codes[1] = bsd_signum; + } + else + { + mach_exception = EXC_SOFTWARE; + codes[0] = EXC_SOFT_SIGNAL; + codes[1] = bsd_signum; } port = get_exc_port(mach_exception, &behavior); @@ -417,14 +424,22 @@ void sigexc_handler(int linux_signum, struct linux_siginfo* info, struct linux_u { _pthread_setspecific_direct(SIGEXC_TSD_KEY, bsd_signum); + kern_return_t ret; + if (behavior & MACH_EXCEPTION_CODES) { - mach_exception_raise(port, thread, mach_task_self(), mach_exception, codes, sizeof(codes) / sizeof(codes[0])); + ret = mach_exception_raise(port, thread, mach_task_self(), mach_exception, codes, sizeof(codes) / sizeof(codes[0])); } else { exception_data_type_t small_codes[2] = { (exception_data_type_t) codes[0], (exception_data_type_t) codes[1] }; - exception_raise(port, thread, mach_task_self(), mach_exception, small_codes, sizeof(small_codes) / sizeof(small_codes[0])); + ret = exception_raise(port, thread, mach_task_self(), mach_exception, small_codes, sizeof(small_codes) / sizeof(small_codes[0])); + } + + if (ret == MACH_RCV_PORT_DIED || ret == MACH_SEND_INVALID_DEST) + { + kern_printf("Exception handler death? ret is 0x%x\n", ret); + darling_sigexc_uninstall(); } bsd_signum = _pthread_getspecific_direct(SIGEXC_TSD_KEY); -- 2.51.2