]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use 4K as the boundary of legal pointers
authorAustin Clements <austin@google.com>
Fri, 6 Jan 2017 14:44:41 +0000 (09:44 -0500)
committerAustin Clements <austin@google.com>
Fri, 6 Jan 2017 16:19:14 +0000 (16:19 +0000)
Currently, the check for legal pointers in stack copying uses
_PageSize (8K) as the minimum legal pointer. By default, Linux won't
let you map under 64K, but

1) it's less clear what other OSes allow or will allow in the future;

2) while mapping the first page is a terrible idea, mapping anywhere
above that is arguably more justifiable;

3) the compiler only assumes the first physical page (4K) is never
mapped.

Make the runtime consistent with the compiler and more robust by
changing the bad pointer check to use 4K as the minimum legal pointer.

This came out of discussions on CLs 34663 and 34719.

Change-Id: Idf721a788bd9699fb348f47bdd083cf8fa8bd3e5
Reviewed-on: https://go-review.googlesource.com/34890
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/compile/internal/ssa/nilcheck.go
src/runtime/malloc.go
src/runtime/stack.go

index eb2d297f802609ec94939f403dab304410a8914a..9f58db664b144499911a8924071b8b45b450e9b7 100644 (file)
@@ -132,6 +132,8 @@ func nilcheckelim(f *Func) {
 }
 
 // All platforms are guaranteed to fault if we load/store to anything smaller than this address.
+//
+// This should agree with minLegalPointer in the runtime.
 const minZeroPage = 4096
 
 // nilcheckelim2 eliminates unnecessary nil checks.
index 1c9efc3432e422fcbc4b3ae3e5e27f1a46c42988..da39dac5102923da939df0b637238aa42c7793d0 100644 (file)
@@ -157,6 +157,13 @@ const (
        _MaxGcproc = 32
 
        _MaxArena32 = 1<<32 - 1
+
+       // minLegalPointer is the smallest possible legal pointer.
+       // This is the smallest possible architectural page size,
+       // since we assume that the first page is never mapped.
+       //
+       // This should agree with minZeroPage in the compiler.
+       minLegalPointer uintptr = 4096
 )
 
 // physPageSize is the size in bytes of the OS's physical pages.
index b77a3119c3e488e51f8ffd8c37af699ad36ee8aa..0f1a5c1c55e12d5326f8c7040985ee5f85dc2dc5 100644 (file)
@@ -601,7 +601,7 @@ func adjustpointers(scanp unsafe.Pointer, cbv *bitvector, adjinfo *adjustinfo, f
                        pp := (*uintptr)(add(scanp, i*sys.PtrSize))
                retry:
                        p := *pp
-                       if f != nil && 0 < p && p < _PageSize && debug.invalidptr != 0 {
+                       if f != nil && 0 < p && p < minLegalPointer && debug.invalidptr != 0 {
                                // Looks like a junk value in a pointer slot.
                                // Live analysis wrong?
                                getg().m.traceback = 2