Skip to content

Commit 29a58e4

Browse files
committed
internal/linux: use unix.Auxv
Use the newly added Auxv wrapper added in golang.org/x/sys/unix v0.30.0 instead of manually go:linknaming runtime.getAuxv. This also allows to get rid of the check for malformed auxv data as it is already performed by unix.Auxv. Signed-off-by: Tobias Klauser <[email protected]>
1 parent efec6c7 commit 29a58e4

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/go-quicktest/qt v1.101.0
77
github.com/google/go-cmp v0.6.0
88
github.com/jsimonetti/rtnetlink/v2 v2.0.1
9-
golang.org/x/sys v0.28.0
9+
golang.org/x/sys v0.30.0
1010
)
1111

1212
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
2323
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
2424
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
2525
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
26-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
27-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
26+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
27+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

internal/linux/auxv.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package linux
22

33
import (
4-
"errors"
54
"fmt"
65
"io"
7-
_ "unsafe"
86

97
"github.com/cilium/ebpf/internal"
8+
"github.com/cilium/ebpf/unix"
109
)
1110

1211
type auxvPairReader interface {
@@ -20,9 +19,6 @@ const (
2019
_AT_SYSINFO_EHDR = 33 // Offset to vDSO blob in process image
2120
)
2221

23-
//go:linkname runtime_getAuxv runtime.getAuxv
24-
func runtime_getAuxv() []uintptr
25-
2622
type auxvRuntimeReader struct {
2723
data []uintptr
2824
index int
@@ -54,10 +50,9 @@ func newAuxvRuntimeReader() (auxvPairReader, error) {
5450
return nil, fmt.Errorf("read auxv from runtime: %w", internal.ErrNotSupportedOnOS)
5551
}
5652

57-
data := runtime_getAuxv()
58-
59-
if len(data)%2 != 0 {
60-
return nil, errors.New("malformed auxv passed from runtime")
53+
data, err := unix.Auxv()
54+
if err != nil {
55+
return nil, fmt.Errorf("read auxv from runtime: %w", err)
6156
}
6257

6358
return &auxvRuntimeReader{

internal/unix/types_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,7 @@ func SchedSetaffinity(pid int, set *CPUSet) error {
195195
func SchedGetaffinity(pid int, set *CPUSet) error {
196196
return linux.SchedGetaffinity(pid, set)
197197
}
198+
199+
func Auxv() ([][2]uintptr, error) {
200+
return linux.Auxv()
201+
}

internal/unix/types_other.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,7 @@ func SchedSetaffinity(pid int, set *CPUSet) error {
278278
func SchedGetaffinity(pid int, set *CPUSet) error {
279279
return errNonLinux()
280280
}
281+
282+
func Auxv() ([][2]uintptr, error) {
283+
return nil, errNonLinux()
284+
}

0 commit comments

Comments
 (0)