]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: parse auxv for page size on dragonfly
authorTobias Klauser <tklauser@distanz.ch>
Thu, 29 Mar 2018 07:38:14 +0000 (07:38 +0000)
committerTobias Klauser <tobias.klauser@gmail.com>
Thu, 29 Mar 2018 14:19:13 +0000 (14:19 +0000)
Decode AT_PAGESZ to determine physPageSize on dragonfly.

Change-Id: I7236d7cbe43433f16dffddad19c1655bc0c7f31d
Reviewed-on: https://go-review.googlesource.com/103257
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/auxv_none.go
src/runtime/os_dragonfly.go

index 96fcbdc2feb45f25674e627078f5c431f0c735e8..9cb8da285b48e6fde14c3a7833852a6c4c68bac9 100644 (file)
@@ -4,6 +4,7 @@
 
 // +build !linux
 // +build !darwin
+// +build !dragonfly
 // +build !freebsd
 // +build !netbsd
 
index 681057f3d51d628f87531dc8f98ece8b85e2403f..85927b4026be4510f0d7552d67185c2bf05d9dff 100644 (file)
@@ -4,7 +4,10 @@
 
 package runtime
 
-import "unsafe"
+import (
+       "runtime/internal/sys"
+       "unsafe"
+)
 
 const (
        _NSIG        = 33
@@ -149,7 +152,9 @@ func newosproc(mp *m, stk unsafe.Pointer) {
 
 func osinit() {
        ncpu = getncpu()
-       physPageSize = getPageSize()
+       if physPageSize == 0 {
+               physPageSize = getPageSize()
+       }
 }
 
 var urandom_dev = []byte("/dev/urandom\x00")
@@ -242,3 +247,33 @@ func sigdelset(mask *sigset, i int) {
 
 func (c *sigctxt) fixsigcode(sig uint32) {
 }
+
+func sysargs(argc int32, argv **byte) {
+       n := argc + 1
+
+       // skip over argv, envp to get to auxv
+       for argv_index(argv, n) != nil {
+               n++
+       }
+
+       // skip NULL separator
+       n++
+
+       auxv := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*sys.PtrSize))
+       sysauxv(auxv[:])
+}
+
+const (
+       _AT_NULL   = 0
+       _AT_PAGESZ = 6
+)
+
+func sysauxv(auxv []uintptr) {
+       for i := 0; auxv[i] != _AT_NULL; i += 2 {
+               tag, val := auxv[i], auxv[i+1]
+               switch tag {
+               case _AT_PAGESZ:
+                       physPageSize = val
+               }
+       }
+}