From be10c515003c22b8b4f0d98d1085687efbcf6955 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 24 Mar 2016 08:39:54 +0100 Subject: [PATCH] runtime/cgo: block signals to the iOS mach exception handler For darwin/arm{,64} a non-Go thread is created to convert EXC_BAD_ACCESS to panics. However, the Go signal handler refuse to handle signals that would otherwise be ignored if they arrive at non-Go threads. Block all (posix) signals to that thread, making sure that no unexpected signals arrive to it. At least one test, TestStop in os/signal, depends on signals not arriving on any non-Go threads. For #14318 Change-Id: I901467fb53bdadb0d03b0f1a537116c7f4754423 Reviewed-on: https://go-review.googlesource.com/21047 Reviewed-by: David Crawshaw --- src/runtime/cgo/gcc_signal_darwin_armx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/runtime/cgo/gcc_signal_darwin_armx.c b/src/runtime/cgo/gcc_signal_darwin_armx.c index e77c507e93..02c54d80a2 100644 --- a/src/runtime/cgo/gcc_signal_darwin_armx.c +++ b/src/runtime/cgo/gcc_signal_darwin_armx.c @@ -182,6 +182,7 @@ darwin_arm_init_mach_exception_handler() int ret; pthread_t thr = NULL; pthread_attr_t attr; + sigset_t ign, oset; ret = mach_port_allocate( mach_task_self(), @@ -192,11 +193,18 @@ darwin_arm_init_mach_exception_handler() abort(); } + // Block all signals to the exception handler thread + sigfillset(&ign); + pthread_sigmask(SIG_SETMASK, &ign, &oset); + // Start a thread to handle exceptions. uintptr_t port_set = (uintptr_t)mach_exception_handler_port_set; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); ret = pthread_create(&thr, &attr, mach_exception_handler, (void*)port_set); + + pthread_sigmask(SIG_SETMASK, &oset, nil); + if (ret) { fprintf(stderr, "runtime/cgo: pthread_create failed: %d\n", ret); abort(); -- 2.48.1