Debian Codegraph @

internal/efw/proc.go

raw symbols SCIP
1 //go:build windows
2
3 package efw
4
5 import (
6 "errors"
7 "fmt"
8 "syscall"
9
10 "golang.org/x/sys/windows"
11 )
12
13 /*
14 The BPF syscall wrapper which is ABI compatible with Linux.
15
16 int bpf(int cmd, union bpf_attr* attr, unsigned int size)
17 */
18 var BPF = newProc("bpf")
19
20 type proc struct {
21 proc *windows.LazyProc
22 }
23
24 func newProc(name string) proc {
25 return proc{module.NewProc(name)}
26 }
27
28 func (p proc) Find() (uintptr, error) {
29 if err := p.proc.Find(); err != nil {
30 if errors.Is(err, windows.ERROR_MOD_NOT_FOUND) {
31 return 0, fmt.Errorf("load %s: not found", module.Name)
32 }
33 return 0, err
34 }
35 return p.proc.Addr(), nil
36 }
37
38 // uint32Result wraps a function which returns a uint32_t.
39 func uint32Result(r1, _ uintptr, _ syscall.Errno) uint32 {
40 return uint32(r1)
41 }
42
43 // errorResult wraps a function which returns ebpf_result_t.
44 func errorResult(r1, _ uintptr, errNo syscall.Errno) error {
45 err := resultToError(Result(r1))
46 if err != nil && errNo != 0 {
47 return fmt.Errorf("%w (errno: %v)", err, errNo)
48 }
49 return err
50 }