Skip to content

Commit dfbf809

Browse files
committed
runtime: unskip TestG0StackOverflow
The stack bounds from pthread are not always accurate, and could cause seg fault if we run out of the actual stack space before reaching the bounds. Here we use an artificially small stack bounds to check overflow without actually running out of the system stack. Change-Id: I8067c5e1297307103b315d9d0c60120293b57aab Reviewed-on: https://go-review.googlesource.com/c/go/+/523695 Reviewed-by: Michael Pratt <[email protected]> Run-TryBot: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 5d9e0be commit dfbf809

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/runtime/crash_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,6 @@ func TestRuntimePanic(t *testing.T) {
792792
func TestG0StackOverflow(t *testing.T) {
793793
testenv.MustHaveExec(t)
794794

795-
switch runtime.GOOS {
796-
case "android", "darwin", "dragonfly", "freebsd", "ios", "linux", "netbsd", "openbsd":
797-
t.Skipf("g0 stack is wrong on pthread platforms (see golang.org/issue/26061)")
798-
}
799-
800795
if os.Getenv("TEST_G0_STACK_OVERFLOW") != "1" {
801796
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestG0StackOverflow$", "-test.v"))
802797
cmd.Env = append(cmd.Env, "TEST_G0_STACK_OVERFLOW=1")

src/runtime/export_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,15 @@ func unexportedPanicForTesting(b []byte, i int) byte {
682682

683683
func G0StackOverflow() {
684684
systemstack(func() {
685+
g0 := getg()
686+
sp := getcallersp()
687+
// The stack bounds for g0 stack is not always precise.
688+
// Use an artificially small stack, to trigger a stack overflow
689+
// without actually run out of the system stack (which may seg fault).
690+
g0.stack.lo = sp - 4096
691+
g0.stackguard0 = g0.stack.lo + stackGuard
692+
g0.stackguard1 = g0.stackguard0
693+
685694
stackOverflow(nil)
686695
})
687696
}

0 commit comments

Comments
 (0)