summaryrefslogtreecommitdiff
path: root/vendor/github.com/cilium/ebpf/internal/sys/fd.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2025-02-03 10:12:35 +0000
committerLibravatar GitHub <noreply@github.com>2025-02-03 10:12:35 +0000
commitc086d4048c2a26a0bf70c1ced24c78680a786710 (patch)
treecf7606e8452e9047d7f0e0d9b6de10edf7ebdc89 /vendor/github.com/cilium/ebpf/internal/sys/fd.go
parent[chore]: Bump golang.org/x/oauth2 from 0.24.0 to 0.25.0 (#3725) (diff)
downloadgotosocial-c086d4048c2a26a0bf70c1ced24c78680a786710.tar.xz
[chore]: Bump github.com/KimMachineGun/automemlimit from 0.6.1 to 0.7.0 (#3726)
Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.6.1 to 0.7.0. - [Release notes](https://github.com/KimMachineGun/automemlimit/releases) - [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.6.1...v0.7.0) --- updated-dependencies: - dependency-name: github.com/KimMachineGun/automemlimit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/cilium/ebpf/internal/sys/fd.go')
-rw-r--r--vendor/github.com/cilium/ebpf/internal/sys/fd.go96
1 files changed, 0 insertions, 96 deletions
diff --git a/vendor/github.com/cilium/ebpf/internal/sys/fd.go b/vendor/github.com/cilium/ebpf/internal/sys/fd.go
deleted file mode 100644
index 65517d45e..000000000
--- a/vendor/github.com/cilium/ebpf/internal/sys/fd.go
+++ /dev/null
@@ -1,96 +0,0 @@
-package sys
-
-import (
- "fmt"
- "math"
- "os"
- "runtime"
- "strconv"
-
- "github.com/cilium/ebpf/internal/unix"
-)
-
-var ErrClosedFd = unix.EBADF
-
-type FD struct {
- raw int
-}
-
-func newFD(value int) *FD {
- fd := &FD{value}
- runtime.SetFinalizer(fd, (*FD).Close)
- return fd
-}
-
-// NewFD wraps a raw fd with a finalizer.
-//
-// You must not use the raw fd after calling this function, since the underlying
-// file descriptor number may change. This is because the BPF UAPI assumes that
-// zero is not a valid fd value.
-func NewFD(value int) (*FD, error) {
- if value < 0 {
- return nil, fmt.Errorf("invalid fd %d", value)
- }
-
- fd := newFD(value)
- if value != 0 {
- return fd, nil
- }
-
- dup, err := fd.Dup()
- _ = fd.Close()
- return dup, err
-}
-
-func (fd *FD) String() string {
- return strconv.FormatInt(int64(fd.raw), 10)
-}
-
-func (fd *FD) Int() int {
- return fd.raw
-}
-
-func (fd *FD) Uint() uint32 {
- if fd.raw < 0 || int64(fd.raw) > math.MaxUint32 {
- // Best effort: this is the number most likely to be an invalid file
- // descriptor. It is equal to -1 (on two's complement arches).
- return math.MaxUint32
- }
- return uint32(fd.raw)
-}
-
-func (fd *FD) Close() error {
- if fd.raw < 0 {
- return nil
- }
-
- value := int(fd.raw)
- fd.raw = -1
-
- fd.Forget()
- return unix.Close(value)
-}
-
-func (fd *FD) Forget() {
- runtime.SetFinalizer(fd, nil)
-}
-
-func (fd *FD) Dup() (*FD, error) {
- if fd.raw < 0 {
- return nil, ErrClosedFd
- }
-
- // Always require the fd to be larger than zero: the BPF API treats the value
- // as "no argument provided".
- dup, err := unix.FcntlInt(uintptr(fd.raw), unix.F_DUPFD_CLOEXEC, 1)
- if err != nil {
- return nil, fmt.Errorf("can't dup fd: %v", err)
- }
-
- return newFD(dup), nil
-}
-
-func (fd *FD) File(name string) *os.File {
- fd.Forget()
- return os.NewFile(uintptr(fd.raw), name)
-}