Commit be10c515 authored by Elias Naur's avatar Elias Naur

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/21047Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
parent b9feb91f
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment