Skip to content

Commit

Permalink
runtime: mark OpenBSD raise function nosplit
Browse files Browse the repository at this point in the history
It is called by the signal handler before switching to gsignal
(sigtrampgo -> sigfwdgo -> dieFromSignal -> raise)
which means that it must not split the stack.

All other instances of raise are already marked nosplit.

Fixes golang#40076

Change-Id: I4794491331af48c46d0d8ebc82d34c6483f0e6cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/241121
Run-TryBot: Ian Lance Taylor <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: David Chase <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
  • Loading branch information
ianlancetaylor committed Jul 8, 2020
1 parent 0844ff8 commit 9699086
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/os/pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ func TestStdPipe(t *testing.T) {
}
}
}

// Test redirecting stdout but not stderr. Issue 40076.
cmd := osexec.Command(os.Args[0], "-test.run", "TestStdPipeHelper")
cmd.Stdout = w
var stderr bytes.Buffer
cmd.Stderr = &stderr
cmd.Env = append(os.Environ(), "GO_TEST_STD_PIPE_HELPER=1")
if err := cmd.Run(); err == nil {
t.Errorf("unexpected success of write to closed stdout")
} else if ee, ok := err.(*osexec.ExitError); !ok {
t.Errorf("unexpected exec error type %T: %v", err, err)
} else if ws, ok := ee.Sys().(syscall.WaitStatus); !ok {
t.Errorf("unexpected wait status type %T: %v", ee.Sys(), ee.Sys())
} else if !ws.Signaled() || ws.Signal() != syscall.SIGPIPE {
t.Errorf("unexpected exit status %v for write to closed stdout", err)
}
if output := stderr.Bytes(); len(output) > 0 {
t.Errorf("unexpected output on stderr: %s", output)
}
}

// This is a helper for TestStdPipe. It's not a test in itself.
Expand Down
1 change: 1 addition & 0 deletions src/runtime/os_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ func osStackRemap(s *mspan, flags int32) {
}
}

//go:nosplit
func raise(sig uint32) {
thrkill(getthrid(), int(sig))
}
Expand Down

0 comments on commit 9699086

Please sign in to comment.