From 528a39cd75f3f6ddc851539b94a54b4da8de49f8 Mon Sep 17 00:00:00 2001 From: Lorenz Bauer Date: Wed, 8 Sep 2021 10:09:57 +0100 Subject: [PATCH] unix: add PidfdOpen and PidfdGetfd Add wrappers for the pidfd_open and pidfd_getfd sycalls, available since 5.3. PIDFD_NONBLOCK is defined manually since mkerrors.sh doesn't handle including linux/pidfd.h well. See https://man7.org/linux/man-pages/man2/pidfd_open.2.html Change-Id: I68dfb52f6a7a44b7f3324a8379860a1bb765e71b Reviewed-on: https://go-review.googlesource.com/c/sys/+/347332 Reviewed-by: Tobias Klauser Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser TryBot-Result: Go Bot --- unix/linux/types.go | 6 ++++++ unix/syscall_linux.go | 3 +++ unix/zsyscall_linux.go | 22 ++++++++++++++++++++++ unix/ztypes_linux_386.go | 4 ++++ unix/ztypes_linux_amd64.go | 4 ++++ unix/ztypes_linux_arm.go | 4 ++++ unix/ztypes_linux_arm64.go | 4 ++++ unix/ztypes_linux_mips.go | 4 ++++ unix/ztypes_linux_mips64.go | 4 ++++ unix/ztypes_linux_mips64le.go | 4 ++++ unix/ztypes_linux_mipsle.go | 4 ++++ unix/ztypes_linux_ppc.go | 4 ++++ unix/ztypes_linux_ppc64.go | 4 ++++ unix/ztypes_linux_ppc64le.go | 4 ++++ unix/ztypes_linux_riscv64.go | 4 ++++ unix/ztypes_linux_s390x.go | 4 ++++ unix/ztypes_linux_sparc64.go | 4 ++++ 17 files changed, 87 insertions(+) diff --git a/unix/linux/types.go b/unix/linux/types.go index 7d76e5cc..515e3b66 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -3829,3 +3829,9 @@ type LandlockPathBeneathAttr C.struct_landlock_path_beneath_attr const ( LANDLOCK_RULE_PATH_BENEATH = C.LANDLOCK_RULE_PATH_BENEATH ) + +// pidfd flags. + +const ( + PIDFD_NONBLOCK = C.O_NONBLOCK +) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index df8628e5..b90214d3 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2288,6 +2288,9 @@ type RemoteIovec struct { //sys ProcessVMReadv(pid int, localIov []Iovec, remoteIov []RemoteIovec, flags uint) (n int, err error) = SYS_PROCESS_VM_READV //sys ProcessVMWritev(pid int, localIov []Iovec, remoteIov []RemoteIovec, flags uint) (n int, err error) = SYS_PROCESS_VM_WRITEV +//sys PidfdOpen(pid int, flags int) (fd int, err error) = SYS_PIDFD_OPEN +//sys PidfdGetfd(pidfd int, targetfd int, flags int) (fd int, err error) = SYS_PIDFD_GETFD + /* * Unimplemented */ diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 2dbe3da7..f98d2e36 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -1945,6 +1945,28 @@ func ProcessVMWritev(pid int, localIov []Iovec, remoteIov []RemoteIovec, flags u // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func PidfdOpen(pid int, flags int) (fd int, err error) { + r0, _, e1 := Syscall(SYS_PIDFD_OPEN, uintptr(pid), uintptr(flags), 0) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func PidfdGetfd(pidfd int, targetfd int, flags int) (fd int, err error) { + r0, _, e1 := Syscall(SYS_PIDFD_GETFD, uintptr(pidfd), uintptr(targetfd), uintptr(flags)) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func pipe2(p *[2]_C_int, flags int) (err error) { _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0) if e1 != 0 { diff --git a/unix/ztypes_linux_386.go b/unix/ztypes_linux_386.go index 72f2e96f..3219aded 100644 --- a/unix/ztypes_linux_386.go +++ b/unix/ztypes_linux_386.go @@ -635,3 +635,7 @@ const ( PPS_GETCAP = 0x800470a3 PPS_FETCH = 0xc00470a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_amd64.go b/unix/ztypes_linux_amd64.go index d5f018d1..16acd3bc 100644 --- a/unix/ztypes_linux_amd64.go +++ b/unix/ztypes_linux_amd64.go @@ -653,3 +653,7 @@ const ( PPS_GETCAP = 0x800870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_arm.go b/unix/ztypes_linux_arm.go index 675446d9..c4982a22 100644 --- a/unix/ztypes_linux_arm.go +++ b/unix/ztypes_linux_arm.go @@ -630,3 +630,7 @@ const ( PPS_GETCAP = 0x800470a3 PPS_FETCH = 0xc00470a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_arm64.go b/unix/ztypes_linux_arm64.go index 711d0711..98bb8a41 100644 --- a/unix/ztypes_linux_arm64.go +++ b/unix/ztypes_linux_arm64.go @@ -632,3 +632,7 @@ const ( PPS_GETCAP = 0x800870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_mips.go b/unix/ztypes_linux_mips.go index c1131c74..d5bfc356 100644 --- a/unix/ztypes_linux_mips.go +++ b/unix/ztypes_linux_mips.go @@ -636,3 +636,7 @@ const ( PPS_GETCAP = 0x400470a3 PPS_FETCH = 0xc00470a4 ) + +const ( + PIDFD_NONBLOCK = 0x80 +) diff --git a/unix/ztypes_linux_mips64.go b/unix/ztypes_linux_mips64.go index 91d5574f..b52c568d 100644 --- a/unix/ztypes_linux_mips64.go +++ b/unix/ztypes_linux_mips64.go @@ -635,3 +635,7 @@ const ( PPS_GETCAP = 0x400870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x80 +) diff --git a/unix/ztypes_linux_mips64le.go b/unix/ztypes_linux_mips64le.go index 5d721497..a340b84b 100644 --- a/unix/ztypes_linux_mips64le.go +++ b/unix/ztypes_linux_mips64le.go @@ -635,3 +635,7 @@ const ( PPS_GETCAP = 0x400870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x80 +) diff --git a/unix/ztypes_linux_mipsle.go b/unix/ztypes_linux_mipsle.go index a5addd06..b43d8e2c 100644 --- a/unix/ztypes_linux_mipsle.go +++ b/unix/ztypes_linux_mipsle.go @@ -636,3 +636,7 @@ const ( PPS_GETCAP = 0x400470a3 PPS_FETCH = 0xc00470a4 ) + +const ( + PIDFD_NONBLOCK = 0x80 +) diff --git a/unix/ztypes_linux_ppc.go b/unix/ztypes_linux_ppc.go index bb6b03df..efd7313a 100644 --- a/unix/ztypes_linux_ppc.go +++ b/unix/ztypes_linux_ppc.go @@ -642,3 +642,7 @@ const ( PPS_GETCAP = 0x400470a3 PPS_FETCH = 0xc00470a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_ppc64.go b/unix/ztypes_linux_ppc64.go index 7637243b..22cedda5 100644 --- a/unix/ztypes_linux_ppc64.go +++ b/unix/ztypes_linux_ppc64.go @@ -642,3 +642,7 @@ const ( PPS_GETCAP = 0x400870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_ppc64le.go b/unix/ztypes_linux_ppc64le.go index a1a28e52..452a76df 100644 --- a/unix/ztypes_linux_ppc64le.go +++ b/unix/ztypes_linux_ppc64le.go @@ -642,3 +642,7 @@ const ( PPS_GETCAP = 0x400870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_riscv64.go b/unix/ztypes_linux_riscv64.go index e0a8a136..96c667df 100644 --- a/unix/ztypes_linux_riscv64.go +++ b/unix/ztypes_linux_riscv64.go @@ -660,3 +660,7 @@ const ( PPS_GETCAP = 0x800870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_s390x.go b/unix/ztypes_linux_s390x.go index 21d6e56c..af04ee17 100644 --- a/unix/ztypes_linux_s390x.go +++ b/unix/ztypes_linux_s390x.go @@ -656,3 +656,7 @@ const ( PPS_GETCAP = 0x800870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x800 +) diff --git a/unix/ztypes_linux_sparc64.go b/unix/ztypes_linux_sparc64.go index 0531e98f..6f385cf6 100644 --- a/unix/ztypes_linux_sparc64.go +++ b/unix/ztypes_linux_sparc64.go @@ -637,3 +637,7 @@ const ( PPS_GETCAP = 0x400870a3 PPS_FETCH = 0xc00870a4 ) + +const ( + PIDFD_NONBLOCK = 0x4000 +)