tsan8.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2016 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.
  4. package main
  5. // This program failed when run under the C/C++ ThreadSanitizer. The TSAN
  6. // sigaction function interceptor returned SIG_DFL instead of the Go runtime's
  7. // handler in registerSegvForwarder.
  8. /*
  9. #cgo CFLAGS: -fsanitize=thread
  10. #cgo LDFLAGS: -fsanitize=thread
  11. #include <signal.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. struct sigaction prev_sa;
  16. void forwardSignal(int signo, siginfo_t *info, void *context) {
  17. // One of sa_sigaction and/or sa_handler
  18. if ((prev_sa.sa_flags&SA_SIGINFO) != 0) {
  19. prev_sa.sa_sigaction(signo, info, context);
  20. return;
  21. }
  22. if (prev_sa.sa_handler != SIG_IGN && prev_sa.sa_handler != SIG_DFL) {
  23. prev_sa.sa_handler(signo);
  24. return;
  25. }
  26. fprintf(stderr, "No Go handler to forward to!\n");
  27. abort();
  28. }
  29. void registerSegvFowarder() {
  30. struct sigaction sa;
  31. memset(&sa, 0, sizeof(sa));
  32. sigemptyset(&sa.sa_mask);
  33. sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
  34. sa.sa_sigaction = forwardSignal;
  35. if (sigaction(SIGSEGV, &sa, &prev_sa) != 0) {
  36. perror("failed to register SEGV forwarder");
  37. exit(EXIT_FAILURE);
  38. }
  39. }
  40. */
  41. import "C"
  42. func main() {
  43. C.registerSegvFowarder()
  44. defer func() {
  45. recover()
  46. }()
  47. var nilp *int
  48. *nilp = 42
  49. }