diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-10 07:42:04 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-10 07:42:04 +0200 |
| commit | 34f286d38d1329e8f904bbb63c4cfea2f7fe7642 (patch) | |
| tree | 178389382b1a90f9f738a67ce3efd8e70a324c8a /integrationtests/cmd/ioworkload/scenario_pidfd.go | |
| parent | 590b3acdae8f4adb34d96889fad483fafa880e93 (diff) | |
integrationtests: return errors for pidfd syscall lookup (task 377)
Diffstat (limited to 'integrationtests/cmd/ioworkload/scenario_pidfd.go')
| -rw-r--r-- | integrationtests/cmd/ioworkload/scenario_pidfd.go | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/integrationtests/cmd/ioworkload/scenario_pidfd.go b/integrationtests/cmd/ioworkload/scenario_pidfd.go index 1ac7c4d..2aafced 100644 --- a/integrationtests/cmd/ioworkload/scenario_pidfd.go +++ b/integrationtests/cmd/ioworkload/scenario_pidfd.go @@ -76,7 +76,11 @@ func pidfdGetfdFailure() error { } func pidfdOpen(pid int, flags uintptr) (int, error) { - fd, _, errno := syscall.Syscall(pidfdOpenSyscallNr(), uintptr(pid), flags, 0) + syscallNr, err := pidfdOpenSyscallNr() + if err != nil { + return 0, err + } + fd, _, errno := syscall.Syscall(syscallNr, uintptr(pid), flags, 0) if errno != 0 { return 0, errno } @@ -84,8 +88,12 @@ func pidfdOpen(pid int, flags uintptr) (int, error) { } func pidfdGetfd(pidfd int, targetFd int, flags uintptr) (int, error) { + syscallNr, err := pidfdGetfdSyscallNr() + if err != nil { + return 0, err + } fd, _, errno := syscall.Syscall( - pidfdGetfdSyscallNr(), + syscallNr, uintptr(pidfd), uintptr(targetFd), flags, @@ -96,24 +104,30 @@ func pidfdGetfd(pidfd int, targetFd int, flags uintptr) (int, error) { return int(fd), nil } -func pidfdOpenSyscallNr() uintptr { +func pidfdOpenSyscallNr() (uintptr, error) { + return pidfdOpenSyscallNrForArch(runtime.GOARCH) +} + +func pidfdGetfdSyscallNr() (uintptr, error) { + return pidfdGetfdSyscallNrForArch(runtime.GOARCH) +} + +func pidfdOpenSyscallNrForArch(arch string) (uintptr, error) { // Go's syscall package does not expose pidfd constants on all toolchains. - if runtime.GOARCH == "amd64" { - return 434 + switch arch { + case "amd64", "arm64": + return 434, nil + default: + return 0, fmt.Errorf("pidfd_open syscall number not defined for GOARCH=%s", arch) } - if runtime.GOARCH == "arm64" { - return 434 - } - panic("pidfd_open syscall number not defined for GOARCH=" + runtime.GOARCH) } -func pidfdGetfdSyscallNr() uintptr { +func pidfdGetfdSyscallNrForArch(arch string) (uintptr, error) { // Go's syscall package does not expose pidfd constants on all toolchains. - if runtime.GOARCH == "amd64" { - return 438 - } - if runtime.GOARCH == "arm64" { - return 438 + switch arch { + case "amd64", "arm64": + return 438, nil + default: + return 0, fmt.Errorf("pidfd_getfd syscall number not defined for GOARCH=%s", arch) } - panic("pidfd_getfd syscall number not defined for GOARCH=" + runtime.GOARCH) } |
