Debian Codegraph @

internal/sys/fd_windows.go

raw symbols SCIP
1 package sys
2
3 import (
4 "fmt"
5 "os"
6 "runtime"
7
8 "github.com/cilium/ebpf/internal"
9 "github.com/cilium/ebpf/internal/efw"
10 )
11
12 // FD wraps a handle which is managed by the eBPF for Windows runtime.
13 //
14 // It is not equivalent to a real file descriptor or handle.
15 type FD struct {
16 raw int
17 cleanup runtime.Cleanup
18 }
19
20 // NewFD wraps a raw fd with a finalizer.
21 //
22 // You must not use the raw fd after calling this function.
23 func NewFD(value int) (*FD, error) {
24 if value == invalidFd {
25 return nil, fmt.Errorf("invalid fd %d", value)
26 }
27
28 if value == 0 {
29 // The efW runtime never uses zero fd it seems. No need to dup it.
30 return nil, fmt.Errorf("invalid zero fd")
31 }
32
33 return newFD(value), nil
34 }
35
36 func (fd *FD) Close() error {
37 if fd.raw == invalidFd {
38 return nil
39 }
40
41 return efw.EbpfCloseFd(fd.Disown())
42 }
43
44 func (fd *FD) Dup() (*FD, error) {
45 if fd.raw == invalidFd {
46 return nil, ErrClosedFd
47 }
48
49 dup, err := efw.EbpfDuplicateFd(fd.raw)
50 if err != nil {
51 return nil, err
52 }
53
54 return NewFD(int(dup))
55 }
56
57 // File is not implemented.
58 func (fd *FD) File(name string) (*os.File, error) {
59 return nil, fmt.Errorf("file from fd: %w", internal.ErrNotSupportedOnOS)
60 }