Skip to content

Commit

Permalink
internal/linux: use unix.Auxv
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tklauser committed Feb 4, 2025
1 parent efec6c7 commit 29a58e4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/go-quicktest/qt v1.101.0
github.com/google/go-cmp v0.6.0
github.com/jsimonetti/rtnetlink/v2 v2.0.1
golang.org/x/sys v0.28.0
golang.org/x/sys v0.30.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
13 changes: 4 additions & 9 deletions internal/linux/auxv.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package linux

import (
"errors"
"fmt"
"io"
_ "unsafe"

"github.com/cilium/ebpf/internal"
"github.com/cilium/ebpf/unix"
)

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

//go:linkname runtime_getAuxv runtime.getAuxv
func runtime_getAuxv() []uintptr

type auxvRuntimeReader struct {
data []uintptr
index int
Expand Down Expand Up @@ -54,10 +50,9 @@ func newAuxvRuntimeReader() (auxvPairReader, error) {
return nil, fmt.Errorf("read auxv from runtime: %w", internal.ErrNotSupportedOnOS)
}

data := runtime_getAuxv()

if len(data)%2 != 0 {
return nil, errors.New("malformed auxv passed from runtime")
data, err := unix.Auxv()
if err != nil {
return nil, fmt.Errorf("read auxv from runtime: %w", err)
}

return &auxvRuntimeReader{
Expand Down
4 changes: 4 additions & 0 deletions internal/unix/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,7 @@ func SchedSetaffinity(pid int, set *CPUSet) error {
func SchedGetaffinity(pid int, set *CPUSet) error {
return linux.SchedGetaffinity(pid, set)
}

func Auxv() ([][2]uintptr, error) {
return linux.Auxv()
}
4 changes: 4 additions & 0 deletions internal/unix/types_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,7 @@ func SchedSetaffinity(pid int, set *CPUSet) error {
func SchedGetaffinity(pid int, set *CPUSet) error {
return errNonLinux()
}

func Auxv() ([][2]uintptr, error) {
return nil, errNonLinux()
}

0 comments on commit 29a58e4

Please sign in to comment.