tsan12.go 929 B

1234567891011121314151617181920212223242526272829303132333435
  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.
  4. package main
  5. // This program hung when run under the C/C++ ThreadSanitizer. TSAN installs a
  6. // libc interceptor that writes signal handlers to a global variable within the
  7. // TSAN runtime instead of making a sigaction system call. A bug in
  8. // syscall.runtime_AfterForkInChild corrupted TSAN's signal forwarding table
  9. // during calls to (*os/exec.Cmd).Run, causing the parent process to fail to
  10. // invoke signal handlers.
  11. import (
  12. "fmt"
  13. "os"
  14. "os/exec"
  15. "os/signal"
  16. "syscall"
  17. )
  18. import "C"
  19. func main() {
  20. ch := make(chan os.Signal, 1)
  21. signal.Notify(ch, syscall.SIGUSR1)
  22. if err := exec.Command("true").Run(); err != nil {
  23. fmt.Fprintf(os.Stderr, "Unexpected error from `true`: %v", err)
  24. os.Exit(1)
  25. }
  26. syscall.Kill(syscall.Getpid(), syscall.SIGUSR1)
  27. <-ch
  28. }