Debian Codegraph @

internal/linux/auxv.go

raw symbols SCIP
1 package linux
2
3 import (
4 "fmt"
5 "io"
6
7 "github.com/cilium/ebpf/internal"
8 "github.com/cilium/ebpf/internal/platform"
9 "github.com/cilium/ebpf/internal/unix"
10 )
11
12 type auxvPairReader interface {
13 Close() error
14 ReadAuxvPair() (uint64, uint64, error)
15 }
16
17 // See https://elixir.bootlin.com/linux/v6.5.5/source/include/uapi/linux/auxvec.h
18 const (
19 _AT_NULL = 0 // End of vector
20 _AT_SYSINFO_EHDR = 33 // Offset to vDSO blob in process image
21 )
22
23 type auxvRuntimeReader struct {
24 data [][2]uintptr
25 index int
26 }
27
28 func (r *auxvRuntimeReader) Close() error {
29 return nil
30 }
31
32 func (r *auxvRuntimeReader) ReadAuxvPair() (uint64, uint64, error) {
33 if r.index >= len(r.data)+2 {
34 return 0, 0, io.EOF
35 }
36
37 // we manually add the (_AT_NULL, _AT_NULL) pair at the end
38 // that is not provided by the go runtime
39 var tag, value uintptr
40 if r.index < len(r.data) {
41 tag, value = r.data[r.index][0], r.data[r.index][1]
42 } else {
43 tag, value = _AT_NULL, _AT_NULL
44 }
45 r.index += 1
46 return uint64(tag), uint64(value), nil
47 }
48
49 func newAuxvRuntimeReader() (auxvPairReader, error) {
50 if !platform.IsLinux {
51 return nil, fmt.Errorf("read auxv from runtime: %w", internal.ErrNotSupportedOnOS)
52 }
53
54 data, err := unix.Auxv()
55 if err != nil {
56 return nil, fmt.Errorf("read auxv from runtime: %w", err)
57 }
58
59 return &auxvRuntimeReader{
60 data: data,
61 index: 0,
62 }, nil
63 }