diff options
| author | Austin Clements <austin@google.com> | 2018-06-29 14:56:48 -0400 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2018-06-29 21:27:23 +0000 |
| commit | 955cc07dde70415489fb2096eb575654181e21fe (patch) | |
| tree | 9f4380ee615b06c0bf48aa5b893301a80b1e3c9e /src/runtime/stack.go | |
| parent | a94a390e5cf802e54c95afb973c2f51be76f669e (diff) | |
| download | go-955cc07dde70415489fb2096eb575654181e21fe.tar.xz | |
runtime: remap stack spans with MAP_STACK on OpenBSD
OpenBSD 6.4 is going to start requiring that the SP points to memory
that was mapped with MAP_STACK on system call entry, traps, and when
switching to the alternate signal stack [1]. Currently, Go doesn't map
any memory MAP_STACK, so the kernel quickly kills Go processes.
Fix this by remapping the memory that backs stack spans with
MAP_STACK, and re-remapping it without MAP_STACK when it's returned to
the heap.
[1] http://openbsd-archive.7691.n7.nabble.com/stack-register-checking-td338238.html
Fixes #26142.
Change-Id: I656eb84385a22833445d49328bb304f8cdd0e225
Reviewed-on: https://go-review.googlesource.com/121657
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/runtime/stack.go')
| -rw-r--r-- | src/runtime/stack.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/runtime/stack.go b/src/runtime/stack.go index 648603db35..c7bfc0434b 100644 --- a/src/runtime/stack.go +++ b/src/runtime/stack.go @@ -186,6 +186,7 @@ func stackpoolalloc(order uint8) gclinkptr { if s.manualFreeList.ptr() != nil { throw("bad manualFreeList") } + osStackAlloc(s) s.elemsize = _FixedStack << order for i := uintptr(0); i < _StackCacheSize; i += s.elemsize { x := gclinkptr(s.base() + i) @@ -238,6 +239,7 @@ func stackpoolfree(x gclinkptr, order uint8) { // By not freeing, we prevent step #4 until GC is done. stackpool[order].remove(s) s.manualFreeList = 0 + osStackFree(s) mheap_.freeManual(s, &memstats.stacks_inuse) } } @@ -385,6 +387,7 @@ func stackalloc(n uint32) stack { if s == nil { throw("out of memory") } + osStackAlloc(s) s.elemsize = uintptr(n) } v = unsafe.Pointer(s.base()) @@ -463,6 +466,7 @@ func stackfree(stk stack) { if gcphase == _GCoff { // Free the stack immediately if we're // sweeping. + osStackFree(s) mheap_.freeManual(s, &memstats.stacks_inuse) } else { // If the GC is running, we can't return a @@ -1112,6 +1116,7 @@ func freeStackSpans() { if s.allocCount == 0 { list.remove(s) s.manualFreeList = 0 + osStackFree(s) mheap_.freeManual(s, &memstats.stacks_inuse) } s = next @@ -1126,6 +1131,7 @@ func freeStackSpans() { for s := stackLarge.free[i].first; s != nil; { next := s.next stackLarge.free[i].remove(s) + osStackFree(s) mheap_.freeManual(s, &memstats.stacks_inuse) s = next } |
