]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: correct new thread stack for openbsd MAP_STACK
authorJoel Sing <joel@sing.id.au>
Mon, 9 Jul 2018 18:54:37 +0000 (04:54 +1000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 11 Jul 2018 17:58:23 +0000 (17:58 +0000)
OpenBSD 6.4 will require the stack pointer to be pointing at an area that is
marked as MAP_STACK when entering and exiting syscalls. Adjust the stack pointer
used for a new thread such that it points within the stack, not at the top of
it (i.e. outside).

Fixes #26142

Change-Id: I905bd8e5be3dfc325392e7ac490fb56a7c71b3aa
Reviewed-on: https://go-review.googlesource.com/122735
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/os_openbsd.go

index 1660511616965021dafc94d6ab90c48a633ca10d..96112cb25b778ed7ae7f7730182048b296496623 100644 (file)
@@ -6,6 +6,7 @@ package runtime
 
 import (
        "runtime/internal/atomic"
+       "runtime/internal/sys"
        "unsafe"
 )
 
@@ -182,10 +183,12 @@ func newosproc(mp *m) {
                print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n")
        }
 
+       // Stack pointer must point inside stack area (as marked with MAP_STACK),
+       // rather than at the top of it.
        param := tforkt{
                tf_tcb:   unsafe.Pointer(&mp.tls[0]),
                tf_tid:   (*int32)(unsafe.Pointer(&mp.procid)),
-               tf_stack: uintptr(stk),
+               tf_stack: uintptr(stk) - sys.PtrSize,
        }
 
        var oset sigset