]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix stackFromSystem returning memory
authorAustin Clements <austin@google.com>
Thu, 18 May 2017 17:59:00 +0000 (13:59 -0400)
committerAustin Clements <austin@google.com>
Tue, 23 May 2017 20:11:07 +0000 (20:11 +0000)
The stackFromSystem debug mode has two problems:

1) It rounds the stack allocation to _PageSize. If the physical page
size is >8K, this can cause unmapping the memory later to either
under-unmap or over-unmap.

2) It doesn't return the rounded-up allocation size to its caller, so
when we later unmap the memory, we may pass the wrong length.

Fix these problems by rounding the size up to the physical page size
and putting that rounded-up size in the returned stack bounds.

Fixes #17289.

Change-Id: I6b854af3b06bb16e3750798397bb5e2a722ec1cb
Reviewed-on: https://go-review.googlesource.com/43636
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/stack.go

index 562427a6a210788842ba2937884484b8ac5f90cc..7860cb183e31d65b7d7766755d055554684e4f44 100644 (file)
@@ -337,7 +337,8 @@ func stackalloc(n uint32) stack {
        }
 
        if debug.efence != 0 || stackFromSystem != 0 {
-               v := sysAlloc(round(uintptr(n), _PageSize), &memstats.stacks_sys)
+               n = uint32(round(uintptr(n), physPageSize))
+               v := sysAlloc(uintptr(n), &memstats.stacks_sys)
                if v == nil {
                        throw("out of memory (stackalloc)")
                }