Debian Codegraph @

pin/walk_windows.go

raw symbols SCIP
1 package pin
2
3 import (
4 "errors"
5 "fmt"
6 "iter"
7 "strings"
8
9 "github.com/cilium/ebpf"
10 "github.com/cilium/ebpf/internal/efw"
11 )
12
13 // WalkDir walks the file tree rooted at path and yields a [Pin] for each
14 // BPF object below the path.
15 //
16 // Callers must invoke [Pin.Take] if they wish to hold on to the object.
17 func WalkDir(root string, opts *ebpf.LoadPinOptions) iter.Seq2[*Pin, error] {
18 return func(yield func(*Pin, error) bool) {
19 root, err := efw.EbpfCanonicalizePinPath(root)
20 if err != nil {
21 yield(nil, fmt.Errorf("failed to canonicalize pin path %q: %w", root, err))
22 return
23 }
24
25 cursor := root
26 for {
27 next, _, err := efw.EbpfGetNextPinnedObjectPath(cursor, efw.EBPF_OBJECT_UNKNOWN)
28 if errors.Is(err, efw.EBPF_NO_MORE_KEYS) {
29 break
30 } else if err != nil {
31 yield(nil, err)
32 return
33 }
34
35 if !strings.HasPrefix(next, root) {
36 break
37 }
38
39 obj, err := Load(next, opts)
40 if err != nil {
41 yield(nil, err)
42 return
43 }
44
45 pin := &Pin{next, obj}
46 ok := yield(pin, nil)
47 pin.close()
48 if !ok {
49 return
50 }
51
52 cursor = next
53 }
54 }
55 }