Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ jobs:
workflow_id: 'cicd.yml',
event: 'schedule',
branch: 'main',
status: 'success', // or 'completed' if upstream is buggy again
status: 'completed',
per_page: 1
});

Expand Down
28 changes: 28 additions & 0 deletions internal/efw/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,31 @@ func EbpfGetNextPinnedObjectPath(startPath string, objectType ObjectType) (strin
))
return windows.ByteSliceToString(tmp), objectType, err
}

/*
Canonicalize a path using filesystem canonicalization rules.

_Must_inspect_result_ ebpf_result_t
ebpf_canonicalize_pin_path(_Out_writes_(output_size) char* output, size_t output_size, _In_z_ const char* input)
*/
var ebpfCanonicalizePinPath = newProc("ebpf_canonicalize_pin_path")

func EbpfCanonicalizePinPath(input string) (string, error) {
addr, err := ebpfCanonicalizePinPath.Find()
if err != nil {
return "", err
}

inputBytes, err := windows.ByteSliceFromString(input)
if err != nil {
return "", err
}

output := make([]byte, _EBPF_MAX_PIN_PATH_LENGTH)
err = errorResult(syscall.SyscallN(addr,
uintptr(unsafe.Pointer(&output[0])),
uintptr(len(output)),
uintptr(unsafe.Pointer(&inputBytes[0])),
))
return windows.ByteSliceToString(output), err
}
6 changes: 5 additions & 1 deletion internal/testutils/bpffs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import (
"strings"
"testing"

"github.com/cilium/ebpf/internal/efw"
"github.com/go-quicktest/qt"

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

// TempBPFFS creates a random prefix to use when pinning on Windows.
func TempBPFFS(tb testing.TB) string {
tb.Helper()

path := filepath.Join("ebpf-go-test", strconv.Itoa(rand.Int()))
path, err := efw.EbpfCanonicalizePinPath(path)
qt.Assert(tb, qt.IsNil(err))

tb.Cleanup(func() {
tb.Helper()

Expand Down
7 changes: 7 additions & 0 deletions pin/walk_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pin

import (
"errors"
"fmt"
"iter"
"strings"

Expand All @@ -15,6 +16,12 @@ import (
// Callers must invoke [Pin.Take] if they wish to hold on to the object.
func WalkDir(root string, opts *ebpf.LoadPinOptions) iter.Seq2[*Pin, error] {
return func(yield func(*Pin, error) bool) {
root, err := efw.EbpfCanonicalizePinPath(root)
if err != nil {
yield(nil, fmt.Errorf("failed to canonicalize pin path %q: %w", root, err))
return
}

cursor := root
for {
next, _, err := efw.EbpfGetNextPinnedObjectPath(cursor, efw.EBPF_OBJECT_UNKNOWN)
Expand Down
Loading