go/src/internal/syscall/unix
Kir Kolyshkin 2f6426834c os: make use of pidfd on linux
Use Process.handle field to store pidfd, and make use of it. Only use
pidfd functionality if all the needed syscalls are available.

1. Add/use pidfdWorks, which checks that all needed pidfd-related
   functionality works.

2. os.StartProcess: obtain the pidfd from the kernel, if possible, using
   the functionality added by CL 520266. Note we could not modify
   syscall.StartProcess to return pidfd directly because it is a public
   API and its callers do not expect it, so we have to use ensurePidfd
   and getPidfd.

3. (*Process).Kill: use pidfdSendSignal, if available and the pidfd is
   known. Otherwise, fall back to the old implementation.

4. (*Process).Wait: use pidfdWait, if available, otherwise fall back to
   using waitid/wait4. This is more complicated than expected due to
   struct siginfo_t idiosyncrasy.

NOTE pidfdSendSignal and pidfdWait are used without a race workaround
(blockUntilWaitable and sigMu, added by CL 23967) because with pidfd,
PID recycle issue doesn't exist (IOW, pidfd, unlike PID, is guaranteed
to refer to one particular process) and thus the race doesn't exist
either.

Rework of CL 528438 (reverted in CL 566477 because of #65857).

For #62654.
Updates #13987.

Change-Id: If5ef8920bd8619dc428b6282ffe4fb8c258ca224
Reviewed-on: https://go-review.googlesource.com/c/go/+/570036
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2024-05-17 01:23:00 +00:00
..
arc4random_darwin.go crypto/rand: use arc4random(3) on macOS and iOS 2024-03-19 20:02:21 +00:00
asm_aix_ppc64.s internal/syscall/unix, net: improve interface_aix.go 2018-10-23 02:38:52 +00:00
asm_darwin.s internal/syscall/unix: implement Eaccess on darwin 2024-04-19 15:02:38 +00:00
asm_openbsd.s internal/syscall/unix: implement Eaccess on openbsd 2024-04-11 16:36:52 +00:00
asm_solaris.s net: separate the Solaris fast/slow path of setting SOCK_* from others 2024-04-14 18:17:25 +00:00
at.go internal/syscall/unix: reuse existing {Fstat,Open,Unlink}at on freebsd 2022-09-19 15:51:18 +00:00
at_aix.go os: make Chtimes accept empty time values to skip file time modification 2023-05-11 18:19:17 +00:00
at_fstatat.go all: remove newline characters after return statements 2023-12-14 17:22:18 +00:00
at_fstatat2.go internal/syscall/unix: reuse existing {Fstat,Open,Unlink}at on freebsd 2022-09-19 15:51:18 +00:00
at_js.go os: make Chtimes accept empty time values to skip file time modification 2023-05-11 18:19:17 +00:00
at_libc.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
at_libc2.go internal/poll, internal/syscall/unix, net, runtime: convert openbsd (except mips64) to direct libc calls 2022-08-31 16:59:38 +00:00
at_solaris.go net: separate the Solaris fast/slow path of setting SOCK_* from others 2024-04-14 18:17:25 +00:00
at_sysnum_darwin.go internal/syscall/unix: implement Eaccess on darwin 2024-04-19 15:02:38 +00:00
at_sysnum_dragonfly.go internal/syscall/unix: implement Eaccess on dragonfly 2023-10-06 20:48:47 +00:00
at_sysnum_freebsd.go internal/syscall/unix: implement Eaccess on freebsd 2023-09-28 03:38:07 +00:00
at_sysnum_fstatat64_linux.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
at_sysnum_fstatat_linux.go syscall: update linux/loong64 kernel ABI, emulate fstatat with statx 2022-05-26 20:15:45 +00:00
at_sysnum_linux.go os: make Chtimes accept empty time values to skip file time modification 2023-05-11 18:19:17 +00:00
at_sysnum_netbsd.go internal/syscall/unix: implement Eaccess on netbsd 2023-10-03 14:13:33 +00:00
at_sysnum_newfstatat_linux.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
at_sysnum_openbsd.go internal/syscall/unix: implement Eaccess on openbsd 2024-04-11 16:36:52 +00:00
at_wasip1.go os: make Chtimes accept empty time values to skip file time modification 2023-05-11 18:19:17 +00:00
constants.go os/exec: LookPath: use eaccess for exec check on linux 2022-09-07 01:09:45 +00:00
copy_file_range_linux.go os, internal/poll, internal/syscall/unix: use copy_file_range on Linux 2020-04-28 00:59:36 +00:00
eaccess_bsd.go internal/syscall/unix: implement Eaccess on openbsd 2024-04-11 16:36:52 +00:00
eaccess_darwin.go internal/syscall/unix: implement Eaccess on darwin 2024-04-19 15:02:38 +00:00
eaccess_linux.go os/exec: LookPath: use eaccess for exec check on linux 2022-09-07 01:09:45 +00:00
eaccess_openbsd.go internal/syscall/unix: implement Eaccess on openbsd 2024-04-11 16:36:52 +00:00
eaccess_other.go internal/syscall/unix: implement Eaccess on darwin 2024-04-19 15:02:38 +00:00
fallocate_freebsd_64bit.go internal/syscall/unix: fix PosixFallocate error check on freebsd 2023-04-05 14:17:36 +00:00
fallocate_freebsd_386.go internal/syscall/unix: fix PosixFallocate error check on freebsd 2023-04-05 14:17:36 +00:00
fallocate_freebsd_arm.go internal/syscall/unix: fix PosixFallocate error check on freebsd 2023-04-05 14:17:36 +00:00
fcntl_js.go syscall: implement wasip1 Fcntl 2023-05-26 17:59:52 +00:00
fcntl_unix.go runtime: change fcntl to return two values 2023-05-20 20:32:54 +00:00
fcntl_wasip1.go syscall: implement wasip1 Fcntl 2023-05-26 17:59:52 +00:00
getentropy_netbsd.go internal/syscall/unix: fix gofmt 2023-08-15 19:42:54 +00:00
getentropy_openbsd.go internal/poll, internal/syscall/unix, net, runtime: convert openbsd (except mips64) to direct libc calls 2022-08-31 16:59:38 +00:00
getentropy_openbsd_mips64.go internal/poll, internal/syscall/unix, net, runtime: convert openbsd (except mips64) to direct libc calls 2022-08-31 16:59:38 +00:00
getrandom.go internal/syscall/unix: use atomic.Bool for getrandomUnsupported 2023-01-26 21:54:02 +00:00
getrandom_dragonfly.go internal/syscall/unix: unify GetRandom implementation 2021-03-11 08:19:31 +00:00
getrandom_freebsd.go internal/syscall/unix: unify GetRandom implementation 2021-03-11 08:19:31 +00:00
getrandom_linux.go internal/syscall/unix: unify GetRandom implementation 2021-03-11 08:19:31 +00:00
getrandom_solaris.go internal/syscall/unix: use atomic.Bool for getrandomUnsupported 2023-01-26 21:54:02 +00:00
ioctl_aix.go internal/syscall/unix: change Ioctl arg type to unsafe.Pointer on AIX 2021-08-16 16:58:24 +00:00
kernel_version_linux.go internal/syscall/unix: KernelVersion nitpicks 2022-09-05 21:39:28 +00:00
kernel_version_other.go net: separate the Solaris fast/slow path of setting SOCK_* from others 2024-04-14 18:17:25 +00:00
kernel_version_solaris.go net: implement TCP_KEEPIDLE, TCP_KEEPINTVL, and TCP_KEEPCNT on Solaris 11.4 2024-04-15 03:10:07 +00:00
kernel_version_solaris_test.go net: separate the Solaris fast/slow path of setting SOCK_* from others 2024-04-14 18:17:25 +00:00
net.go all: use new "unix" build tag where appropriate 2022-03-29 16:24:51 +00:00
net_darwin.go net: set IsNotFound for unknown services in LookupPort 2023-09-28 13:41:21 +00:00
net_js.go net: pass around pointers to SockaddrInetN 2021-11-04 21:52:36 +00:00
net_wasip1.go internal: add wasip1 support 2023-04-07 23:34:17 +00:00
nonblocking_js.go os: if descriptor is non-blocking, retain that in Fd method 2023-05-17 21:12:04 +00:00
nonblocking_unix.go internal/poll, internal/syscall/unix, net: move and export fcntl syscall wrapper 2023-05-18 09:15:25 +00:00
nonblocking_wasip1.go os: if descriptor is non-blocking, retain that in Fd method 2023-05-17 21:12:04 +00:00
pidfd_linux.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
pty_darwin.go os/signal/internal/pty: use libc (not cgo) on macOS 2022-11-10 19:24:46 +00:00
siginfo_linux.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
siginfo_linux_mipsx.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
siginfo_linux_other.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
siginfo_linux_test.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
sysnum_linux_386.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
sysnum_linux_amd64.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
sysnum_linux_arm.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
sysnum_linux_generic.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
sysnum_linux_mips64x.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
sysnum_linux_mipsx.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
sysnum_linux_ppc64x.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
sysnum_linux_s390x.go os: make use of pidfd on linux 2024-05-17 01:23:00 +00:00
tcsetpgrp_bsd.go os/signal: avoid calling ioctl via syscall.Syscall on BSDs 2024-03-20 10:09:15 +00:00
tcsetpgrp_linux.go os/signal: avoid calling ioctl via syscall.Syscall on BSDs 2024-03-20 10:09:15 +00:00
user_darwin.go os/user: fix buffer retry loop on macOS 2022-12-07 16:09:09 +00:00