File tree 3 files changed +72
-0
lines changed
3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2025 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
+ //go:build go1.21 && (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos)
6
+
7
+ package unix
8
+
9
+ import (
10
+ "syscall"
11
+ "unsafe"
12
+ )
13
+
14
+ //go:linkname runtime_getAuxv runtime.getAuxv
15
+ func runtime_getAuxv () []uintptr
16
+
17
+ // Auxv returns the ELF auxiliary vector as a sequence of key/value pairs.
18
+ // The returned slice is always a fresh copy, owned by the caller.
19
+ // It returns an error on non-ELF platforms, or if the auxiliary vector cannot be accessed,
20
+ // which happens in some locked-down environments and build modes.
21
+ func Auxv () ([][2 ]uintptr , error ) {
22
+ vec := runtime_getAuxv ()
23
+ vecLen := len (vec )
24
+
25
+ if vecLen == 0 {
26
+ return nil , syscall .ENOENT
27
+ }
28
+
29
+ if vecLen % 2 != 0 {
30
+ return nil , syscall .EINVAL
31
+ }
32
+
33
+ result := make ([]uintptr , vecLen )
34
+ copy (result , vec )
35
+ return unsafe .Slice ((* [2 ]uintptr )(unsafe .Pointer (& result [0 ])), vecLen / 2 ), nil
36
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2025 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
+ //go:build go1.21 && linux
6
+
7
+ package unix_test
8
+
9
+ import (
10
+ "testing"
11
+
12
+ "golang.org/x/sys/unix"
13
+ )
14
+
15
+ func TestAuxv (t * testing.T ) {
16
+ vec , err := unix .Auxv ()
17
+ if err != nil {
18
+ t .Fatalf ("unexpected error: %v" , err )
19
+ }
20
+ if len (vec ) == 0 {
21
+ t .Errorf ("got zero auxv entries on linux, expected > 0" )
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2025 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
+ //go:build !go1.21 && (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos)
6
+
7
+ package unix
8
+
9
+ import "syscall"
10
+
11
+ func Auxv () ([][2 ]uintptr , error ) {
12
+ return nil , syscall .ENOTSUP
13
+ }
You can’t perform that action at this time.
0 commit comments