]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: block signals to the iOS mach exception handler
authorElias Naur <elias.naur@gmail.com>
Thu, 24 Mar 2016 07:39:54 +0000 (08:39 +0100)
committerElias Naur <elias.naur@gmail.com>
Thu, 24 Mar 2016 14:12:12 +0000 (14:12 +0000)
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 <crawshaw@golang.org>
src/runtime/cgo/gcc_signal_darwin_armx.c

index e77c507e9359aad44c7faa5d6e61a7c6edc97d78..02c54d80a232c618b11f389823d812e4153931a1 100644 (file)
@@ -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();