Debian Codegraph @

internal/efw/object.go

raw symbols SCIP
1 //go:build windows
2
3 package efw
4
5 import (
6 "syscall"
7 "unsafe"
8
9 "golang.org/x/sys/windows"
10 )
11
12 // https://github.com/microsoft/ebpf-for-windows/blob/9d9003c39c3fd75be5225ac0fce30077d6bf0604/include/ebpf_core_structs.h#L15
13 const _EBPF_MAX_PIN_PATH_LENGTH = 256
14
15 /*
16 Retrieve object info and type from a fd.
17
18 ebpf_result_t ebpf_object_get_info_by_fd(
19 fd_t bpf_fd,
20 _Inout_updates_bytes_to_opt_(*info_size, *info_size) void* info,
21 _Inout_opt_ uint32_t* info_size,
22 _Out_opt_ ebpf_object_type_t* type)
23 */
24 var ebpfObjectGetInfoByFdProc = newProc("ebpf_object_get_info_by_fd")
25
26 func EbpfObjectGetInfoByFd(fd int, info unsafe.Pointer, info_size *uint32) (ObjectType, error) {
27 addr, err := ebpfObjectGetInfoByFdProc.Find()
28 if err != nil {
29 return 0, err
30 }
31
32 var objectType ObjectType
33 err = errorResult(syscall.SyscallN(addr,
34 uintptr(fd),
35 uintptr(info),
36 uintptr(unsafe.Pointer(info_size)),
37 uintptr(unsafe.Pointer(&objectType)),
38 ))
39 return objectType, err
40 }
41
42 // ebpf_result_t ebpf_object_unpin(_In_z_ const char* path)
43 var ebpfObjectUnpinProc = newProc("ebpf_object_unpin")
44
45 func EbpfObjectUnpin(path string) error {
46 addr, err := ebpfObjectUnpinProc.Find()
47 if err != nil {
48 return err
49 }
50
51 pathBytes, err := windows.ByteSliceFromString(path)
52 if err != nil {
53 return err
54 }
55
56 return errorResult(syscall.SyscallN(addr, uintptr(unsafe.Pointer(&pathBytes[0]))))
57 }
58
59 /*
60 Retrieve the next pinned object path.
61
62 ebpf_result_t ebpf_get_next_pinned_object_path(
63 _In_opt_z_ const char* start_path,
64 _Out_writes_z_(next_path_len) char* next_path,
65 size_t next_path_len,
66 _Inout_opt_ ebpf_object_type_t* type)
67 */
68 var ebpfGetNextPinnedObjectPath = newProc("ebpf_get_next_pinned_object_path")
69
70 func EbpfGetNextPinnedObjectPath(startPath string, objectType ObjectType) (string, ObjectType, error) {
71 addr, err := ebpfGetNextPinnedObjectPath.Find()
72 if err != nil {
73 return "", 0, err
74 }
75
76 ptr, err := windows.BytePtrFromString(startPath)
77 if err != nil {
78 return "", 0, err
79 }
80
81 tmp := make([]byte, _EBPF_MAX_PIN_PATH_LENGTH)
82 err = errorResult(syscall.SyscallN(addr,
83 uintptr(unsafe.Pointer(ptr)),
84 uintptr(unsafe.Pointer(&tmp[0])),
85 uintptr(len(tmp)),
86 uintptr(unsafe.Pointer(&objectType)),
87 ))
88 return windows.ByteSliceToString(tmp), objectType, err
89 }
90
91 /*
92 Canonicalize a path using filesystem canonicalization rules.
93
94 _Must_inspect_result_ ebpf_result_t
95 ebpf_canonicalize_pin_path(_Out_writes_(output_size) char* output, size_t output_size, _In_z_ const char* input)
96 */
97 var ebpfCanonicalizePinPath = newProc("ebpf_canonicalize_pin_path")
98
99 func EbpfCanonicalizePinPath(input string) (string, error) {
100 addr, err := ebpfCanonicalizePinPath.Find()
101 if err != nil {
102 return "", err
103 }
104
105 inputBytes, err := windows.ByteSliceFromString(input)
106 if err != nil {
107 return "", err
108 }
109
110 output := make([]byte, _EBPF_MAX_PIN_PATH_LENGTH)
111 err = errorResult(syscall.SyscallN(addr,
112 uintptr(unsafe.Pointer(&output[0])),
113 uintptr(len(output)),
114 uintptr(unsafe.Pointer(&inputBytes[0])),
115 ))
116 return windows.ByteSliceToString(output), err
117 }