File tree 3 files changed +61
-4
lines changed 3 files changed +61
-4
lines changed Original file line number Diff line number Diff line change 4
4
5
5
package os
6
6
7
- import "syscall"
7
+ import (
8
+ "syscall"
9
+ _ "unsafe" // for go:linkname
10
+ )
8
11
9
- var executablePath string // set by sysauxv in ../runtime/os3_solaris.go
12
+ // solarisExecutablePath is defined in the runtime package.
13
+ func solarisExecutablePath () string
10
14
11
15
var initCwd , initCwdErr = Getwd ()
12
16
13
17
func executable () (string , error ) {
14
- path := executablePath
18
+ path := solarisExecutablePath ()
15
19
if len (path ) == 0 {
16
20
path , err := syscall .Getexecname ()
17
21
if err != nil {
Original file line number Diff line number Diff line change
1
+ // Copyright 2011 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package runtime
6
+
7
+ import (
8
+ "runtime/internal/sys"
9
+ "unsafe"
10
+ )
11
+
12
+ var executablePath string
13
+
14
+ func sysargs (argc int32 , argv * * byte ) {
15
+ n := argc + 1
16
+
17
+ // skip over argv, envp to get to auxv
18
+ for argv_index (argv , n ) != nil {
19
+ n ++
20
+ }
21
+
22
+ // skip NULL separator
23
+ n ++
24
+
25
+ // now argv+n is auxv
26
+ auxv := (* [1 << 28 ]uintptr )(add (unsafe .Pointer (argv ), uintptr (n )* sys .PtrSize ))
27
+ sysauxv (auxv [:])
28
+ }
29
+
30
+ const (
31
+ _AT_NULL = 0 // Terminates the vector
32
+ _AT_PAGESZ = 6 // Page size in bytes
33
+ _AT_SUN_EXECNAME = 2014 // exec() path name
34
+ )
35
+
36
+ func sysauxv (auxv []uintptr ) {
37
+ for i := 0 ; auxv [i ] != _AT_NULL ; i += 2 {
38
+ tag , val := auxv [i ], auxv [i + 1 ]
39
+ switch tag {
40
+ case _AT_PAGESZ :
41
+ physPageSize = val
42
+ case _AT_SUN_EXECNAME :
43
+ executablePath = gostringnocopy ((* byte )(unsafe .Pointer (val )))
44
+ }
45
+ }
46
+ }
47
+
48
+ //go:linkname solarisExecutablePath os.solarisExecutablePath
49
+
50
+ // solarisExecutablePath is called from the os package to fetch the
51
+ // saved executable path.
52
+ func solarisExecutablePath () string {
53
+ return executablePath
54
+ }
Original file line number Diff line number Diff line change 3
3
// license that can be found in the LICENSE file.
4
4
5
5
// +build !plan9
6
- // +build !solaris
7
6
// +build !windows
8
7
// +build !nacl
9
8
// +build !freebsd
You can’t perform that action at this time.
0 commit comments