]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: parse auxv for page size and executable name on Solaris
authorTobias Klauser <tklauser@distanz.ch>
Tue, 3 Apr 2018 09:06:59 +0000 (09:06 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 3 Apr 2018 15:49:45 +0000 (15:49 +0000)
Decode AT_PAGESZ to determine physPageSize and AT_SUN_EXECNAME for
os.Executable.

Change-Id: I6ff774ad9d76c68fc61eb307df58217c17fd578d
Reviewed-on: https://go-review.googlesource.com/104375
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/os/executable_solaris.go
src/runtime/auxv_none.go
src/runtime/os3_solaris.go

index 80f937201ac89e7533baa818083d13ee06b3ed72..b145980c5656b625cd47388eaa4ff0e32d5dedf0 100644 (file)
@@ -6,12 +6,17 @@ package os
 
 import "syscall"
 
+var executablePath string // set by sysauxv in ../runtime/os3_solaris.go
+
 var initCwd, initCwdErr = Getwd()
 
 func executable() (string, error) {
-       path, err := syscall.Getexecname()
-       if err != nil {
-               return path, err
+       path := executablePath
+       if len(path) == 0 {
+               path, err := syscall.Getexecname()
+               if err != nil {
+                       return path, err
+               }
        }
        if len(path) > 0 && path[0] != '/' {
                if initCwdErr != nil {
index 9cb8da285b48e6fde14c3a7833852a6c4c68bac9..3ca617b21eb00dfc0b701f8d993186c7035b67b3 100644 (file)
@@ -7,6 +7,7 @@
 // +build !dragonfly
 // +build !freebsd
 // +build !netbsd
+// +build !solaris
 
 package runtime
 
index 8378be3edb8d1785d7d3b2e3c24b9b335f2f7723..ef9ffc02aea1f67f72e429c12856bdb23f551c77 100644 (file)
@@ -4,7 +4,10 @@
 
 package runtime
 
-import "unsafe"
+import (
+       "runtime/internal/sys"
+       "unsafe"
+)
 
 //go:cgo_export_dynamic runtime.end _end
 //go:cgo_export_dynamic runtime.etext _etext
@@ -128,7 +131,9 @@ func getPageSize() uintptr {
 
 func osinit() {
        ncpu = getncpu()
-       physPageSize = getPageSize()
+       if physPageSize == 0 {
+               physPageSize = getPageSize()
+       }
 }
 
 func tstart_sysvicall(newm *m) uint32
@@ -509,3 +514,40 @@ func osyield() {
        }
        osyield1()
 }
+
+//go:linkname executablePath os.executablePath
+var executablePath string
+
+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++
+
+       // now argv+n is auxv
+       auxv := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*sys.PtrSize))
+       sysauxv(auxv[:])
+}
+
+const (
+       _AT_NULL         = 0    // Terminates the vector
+       _AT_PAGESZ       = 6    // Page size in bytes
+       _AT_SUN_EXECNAME = 2014 // exec() path name
+)
+
+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
+               case _AT_SUN_EXECNAME:
+                       executablePath = gostringnocopy((*byte)(unsafe.Pointer(val)))
+               }
+       }
+}