]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: unskip TestG0StackOverflow
authorCherry Mui <cherryyz@google.com>
Mon, 28 Aug 2023 18:59:13 +0000 (14:59 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 8 Sep 2023 19:14:29 +0000 (19:14 +0000)
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 <mpratt@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/crash_test.go
src/runtime/export_test.go

index 2c990c199ccaff8ec32bb2e13607bdd21ff23d8a..38ff6020965a1fb57620a882a1572ac4c8ba888b 100644 (file)
@@ -792,11 +792,6 @@ func TestRuntimePanic(t *testing.T) {
 func TestG0StackOverflow(t *testing.T) {
        testenv.MustHaveExec(t)
 
-       switch runtime.GOOS {
-       case "android", "darwin", "dragonfly", "freebsd", "ios", "linux", "netbsd", "openbsd":
-               t.Skipf("g0 stack is wrong on pthread platforms (see golang.org/issue/26061)")
-       }
-
        if os.Getenv("TEST_G0_STACK_OVERFLOW") != "1" {
                cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestG0StackOverflow$", "-test.v"))
                cmd.Env = append(cmd.Env, "TEST_G0_STACK_OVERFLOW=1")
index c43c5d05516b900b08272138b4b3c8a096c62387..008d2042cd4f98339d60b0b331795b017b0d6919 100644 (file)
@@ -682,6 +682,15 @@ func unexportedPanicForTesting(b []byte, i int) byte {
 
 func G0StackOverflow() {
        systemstack(func() {
+               g0 := getg()
+               sp := getcallersp()
+               // The stack bounds for g0 stack is not always precise.
+               // Use an artificially small stack, to trigger a stack overflow
+               // without actually run out of the system stack (which may seg fault).
+               g0.stack.lo = sp - 4096
+               g0.stackguard0 = g0.stack.lo + stackGuard
+               g0.stackguard1 = g0.stackguard0
+
                stackOverflow(nil)
        })
 }