1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // This program failed with SIGSEGV when run under the C/C++ ThreadSanitizer.
8 // The Go runtime had re-registered the C handler with the wrong flags due to a
9 // typo, resulting in null pointers being passed for the info and context
10 // parameters to the handler.
13 #cgo CFLAGS: -fsanitize=thread
14 #cgo LDFLAGS: -fsanitize=thread
22 void check_params(int signo, siginfo_t *info, void *context) {
23 ucontext_t* uc = (ucontext_t*)(context);
25 if (info->si_signo != signo) {
26 fprintf(stderr, "info->si_signo does not match signo.\n");
30 if (uc->uc_stack.ss_size == 0) {
31 fprintf(stderr, "uc_stack has size 0.\n");
37 // Set up the signal handler in a high priority constructor, so
38 // that it is installed before the Go code starts.
40 static void register_handler(void) __attribute__ ((constructor (200)));
42 static void register_handler() {
44 memset(&sa, 0, sizeof(sa));
45 sigemptyset(&sa.sa_mask);
46 sa.sa_flags = SA_SIGINFO;
47 sa.sa_sigaction = check_params;
49 if (sigaction(SIGUSR1, &sa, NULL) != 0) {
50 perror("failed to register SIGUSR1 handler");
60 C
.raise(C
.int(syscall
.SIGUSR1
))