1
0
mirror of https://github.com/golang/go synced 2024-09-30 06:14:31 -06:00
go/misc/cgo/testsanitizers/testdata/tsan_shared.go
Bryan C. Mills 8f1e2d4ef7 misc/cgo/testsanitizers: move test source files into testdata directory
If we run 'go test ./...' in the misc module, we don't want to see
errors for these standalone files.

We could instead add +ignore tags to each file individually, but this
is exactly what a testdata directory is for.

Updates #30228

Change-Id: I7047ad888dd6aff701f5982d58b6a79f6a487c58
Reviewed-on: https://go-review.googlesource.com/c/163417
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-22 21:58:00 +00:00

64 lines
1.5 KiB
Go

// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// This program failed with SIGSEGV when run under the C/C++ ThreadSanitizer.
// The Go runtime had re-registered the C handler with the wrong flags due to a
// typo, resulting in null pointers being passed for the info and context
// parameters to the handler.
/*
#cgo CFLAGS: -fsanitize=thread
#cgo LDFLAGS: -fsanitize=thread
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ucontext.h>
void check_params(int signo, siginfo_t *info, void *context) {
ucontext_t* uc = (ucontext_t*)(context);
if (info->si_signo != signo) {
fprintf(stderr, "info->si_signo does not match signo.\n");
abort();
}
if (uc->uc_stack.ss_size == 0) {
fprintf(stderr, "uc_stack has size 0.\n");
abort();
}
}
// Set up the signal handler in a high priority constructor, so
// that it is installed before the Go code starts.
static void register_handler(void) __attribute__ ((constructor (200)));
static void register_handler() {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = check_params;
if (sigaction(SIGUSR1, &sa, NULL) != 0) {
perror("failed to register SIGUSR1 handler");
exit(EXIT_FAILURE);
}
}
*/
import "C"
import "syscall"
func init() {
C.raise(C.int(syscall.SIGUSR1))
}
func main() {}