From ff05cdbd2bdc28ab545a5964f7f772e2ea4c5fd1 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 13 Sep 2023 00:58:20 -0700 Subject: [PATCH] internal/syscall/unix: add PidFDSendSignal for Linux CL 520266 added pidfd_send_signal linux syscall numbers to the syscall package for the sake of a unit test. As pidfd_send_signal will be used from the os package, let's revert the changes to syscall package, add the pidfd_send_signal syscall numbers and the implementation to internal/syscall/unix, and change the above test to use it. Updates #51246. For #62654. Change-Id: I862174c3c1a64baf1080792bdb3a1c1d1b417bb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/528436 Run-TryBot: Kirill Kolyshkin Reviewed-by: Cherry Mui Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt --- src/internal/syscall/unix/pidfd_linux.go | 15 +++++++++++++++ src/internal/syscall/unix/sysnum_linux_386.go | 5 +++-- src/internal/syscall/unix/sysnum_linux_amd64.go | 5 +++-- src/internal/syscall/unix/sysnum_linux_arm.go | 5 +++-- src/internal/syscall/unix/sysnum_linux_generic.go | 5 +++-- src/internal/syscall/unix/sysnum_linux_mips64x.go | 5 +++-- src/internal/syscall/unix/sysnum_linux_mipsx.go | 5 +++-- src/internal/syscall/unix/sysnum_linux_ppc64x.go | 5 +++-- src/internal/syscall/unix/sysnum_linux_s390x.go | 5 +++-- src/syscall/exec_linux_test.go | 9 +++++---- src/syscall/export_linux_test.go | 3 +-- src/syscall/syscall_linux_386.go | 9 ++++----- src/syscall/syscall_linux_amd64.go | 9 ++++----- src/syscall/syscall_linux_arm.go | 9 ++++----- src/syscall/syscall_linux_arm64.go | 9 ++++----- src/syscall/syscall_linux_loong64.go | 9 ++++----- src/syscall/syscall_linux_mips64x.go | 9 ++++----- src/syscall/syscall_linux_mipsx.go | 9 ++++----- src/syscall/syscall_linux_ppc64x.go | 9 ++++----- src/syscall/syscall_linux_riscv64.go | 9 ++++----- src/syscall/syscall_linux_s390x.go | 9 ++++----- 21 files changed, 85 insertions(+), 72 deletions(-) create mode 100644 src/internal/syscall/unix/pidfd_linux.go diff --git a/src/internal/syscall/unix/pidfd_linux.go b/src/internal/syscall/unix/pidfd_linux.go new file mode 100644 index 00000000000..02cfaa062ca --- /dev/null +++ b/src/internal/syscall/unix/pidfd_linux.go @@ -0,0 +1,15 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package unix + +import "syscall" + +func PidFDSendSignal(pidfd uintptr, s syscall.Signal) error { + _, _, errno := syscall.Syscall(pidfdSendSignalTrap, pidfd, uintptr(s), 0) + if errno != 0 { + return errno + } + return nil +} diff --git a/src/internal/syscall/unix/sysnum_linux_386.go b/src/internal/syscall/unix/sysnum_linux_386.go index 2bda08ccf1a..9f750a1c03e 100644 --- a/src/internal/syscall/unix/sysnum_linux_386.go +++ b/src/internal/syscall/unix/sysnum_linux_386.go @@ -5,6 +5,7 @@ package unix const ( - getrandomTrap uintptr = 355 - copyFileRangeTrap uintptr = 377 + getrandomTrap uintptr = 355 + copyFileRangeTrap uintptr = 377 + pidfdSendSignalTrap uintptr = 424 ) diff --git a/src/internal/syscall/unix/sysnum_linux_amd64.go b/src/internal/syscall/unix/sysnum_linux_amd64.go index ae5239ebfb5..706898d41e5 100644 --- a/src/internal/syscall/unix/sysnum_linux_amd64.go +++ b/src/internal/syscall/unix/sysnum_linux_amd64.go @@ -5,6 +5,7 @@ package unix const ( - getrandomTrap uintptr = 318 - copyFileRangeTrap uintptr = 326 + getrandomTrap uintptr = 318 + copyFileRangeTrap uintptr = 326 + pidfdSendSignalTrap uintptr = 424 ) diff --git a/src/internal/syscall/unix/sysnum_linux_arm.go b/src/internal/syscall/unix/sysnum_linux_arm.go index acaec058790..c00644b5528 100644 --- a/src/internal/syscall/unix/sysnum_linux_arm.go +++ b/src/internal/syscall/unix/sysnum_linux_arm.go @@ -5,6 +5,7 @@ package unix const ( - getrandomTrap uintptr = 384 - copyFileRangeTrap uintptr = 391 + getrandomTrap uintptr = 384 + copyFileRangeTrap uintptr = 391 + pidfdSendSignalTrap uintptr = 424 ) diff --git a/src/internal/syscall/unix/sysnum_linux_generic.go b/src/internal/syscall/unix/sysnum_linux_generic.go index 8c132c6bf50..bf25428e7ec 100644 --- a/src/internal/syscall/unix/sysnum_linux_generic.go +++ b/src/internal/syscall/unix/sysnum_linux_generic.go @@ -11,6 +11,7 @@ package unix // means only arm64 loong64 and riscv64 use the standard numbers. const ( - getrandomTrap uintptr = 278 - copyFileRangeTrap uintptr = 285 + getrandomTrap uintptr = 278 + copyFileRangeTrap uintptr = 285 + pidfdSendSignalTrap uintptr = 424 ) diff --git a/src/internal/syscall/unix/sysnum_linux_mips64x.go b/src/internal/syscall/unix/sysnum_linux_mips64x.go index bca526d2b90..6a9e238ce3d 100644 --- a/src/internal/syscall/unix/sysnum_linux_mips64x.go +++ b/src/internal/syscall/unix/sysnum_linux_mips64x.go @@ -7,6 +7,7 @@ package unix const ( - getrandomTrap uintptr = 5313 - copyFileRangeTrap uintptr = 5320 + getrandomTrap uintptr = 5313 + copyFileRangeTrap uintptr = 5320 + pidfdSendSignalTrap uintptr = 5424 ) diff --git a/src/internal/syscall/unix/sysnum_linux_mipsx.go b/src/internal/syscall/unix/sysnum_linux_mipsx.go index c86195e4969..22d38f148ed 100644 --- a/src/internal/syscall/unix/sysnum_linux_mipsx.go +++ b/src/internal/syscall/unix/sysnum_linux_mipsx.go @@ -7,6 +7,7 @@ package unix const ( - getrandomTrap uintptr = 4353 - copyFileRangeTrap uintptr = 4360 + getrandomTrap uintptr = 4353 + copyFileRangeTrap uintptr = 4360 + pidfdSendSignalTrap uintptr = 4424 ) diff --git a/src/internal/syscall/unix/sysnum_linux_ppc64x.go b/src/internal/syscall/unix/sysnum_linux_ppc64x.go index a4dcf2bc9d7..945ec28c2a0 100644 --- a/src/internal/syscall/unix/sysnum_linux_ppc64x.go +++ b/src/internal/syscall/unix/sysnum_linux_ppc64x.go @@ -7,6 +7,7 @@ package unix const ( - getrandomTrap uintptr = 359 - copyFileRangeTrap uintptr = 379 + getrandomTrap uintptr = 359 + copyFileRangeTrap uintptr = 379 + pidfdSendSignalTrap uintptr = 424 ) diff --git a/src/internal/syscall/unix/sysnum_linux_s390x.go b/src/internal/syscall/unix/sysnum_linux_s390x.go index bf2c01e4e16..2c743438201 100644 --- a/src/internal/syscall/unix/sysnum_linux_s390x.go +++ b/src/internal/syscall/unix/sysnum_linux_s390x.go @@ -5,6 +5,7 @@ package unix const ( - getrandomTrap uintptr = 349 - copyFileRangeTrap uintptr = 375 + getrandomTrap uintptr = 349 + copyFileRangeTrap uintptr = 375 + pidfdSendSignalTrap uintptr = 424 ) diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go index 976275e1dcf..68ec6fe3f8e 100644 --- a/src/syscall/exec_linux_test.go +++ b/src/syscall/exec_linux_test.go @@ -12,6 +12,7 @@ import ( "flag" "fmt" "internal/platform" + "internal/syscall/unix" "internal/testenv" "io" "os" @@ -560,11 +561,11 @@ func testPidFD(t *testing.T, userns bool) error { // Use pidfd to send a signal to the child. sig := syscall.SIGINT - if _, _, e := syscall.Syscall(syscall.Sys_pidfd_send_signal, uintptr(pidfd), uintptr(sig), 0); e != 0 { - if e != syscall.EINVAL && testenv.SyscallIsNotSupported(e) { - t.Skip("pidfd_send_signal syscall not supported:", e) + if err := unix.PidFDSendSignal(uintptr(pidfd), sig); err != nil { + if err != syscall.EINVAL && testenv.SyscallIsNotSupported(err) { + t.Skip("pidfd_send_signal syscall not supported:", err) } - t.Fatal("pidfd_send_signal syscall failed:", e) + t.Fatal("pidfd_send_signal syscall failed:", err) } // Check if the child received our signal. err = cmd.Wait() diff --git a/src/syscall/export_linux_test.go b/src/syscall/export_linux_test.go index a09db607530..3aa877cfe3c 100644 --- a/src/syscall/export_linux_test.go +++ b/src/syscall/export_linux_test.go @@ -10,6 +10,5 @@ var ( ) const ( - Sys_GETEUID = sys_GETEUID - Sys_pidfd_send_signal = _SYS_pidfd_send_signal + Sys_GETEUID = sys_GETEUID ) diff --git a/src/syscall/syscall_linux_386.go b/src/syscall/syscall_linux_386.go index 1ab6c5e1485..a559f7e288a 100644 --- a/src/syscall/syscall_linux_386.go +++ b/src/syscall/syscall_linux_386.go @@ -7,11 +7,10 @@ package syscall import "unsafe" const ( - _SYS_setgroups = SYS_SETGROUPS32 - _SYS_clone3 = 435 - _SYS_faccessat2 = 439 - _SYS_pidfd_send_signal = 424 - _SYS_fchmodat2 = 452 + _SYS_setgroups = SYS_SETGROUPS32 + _SYS_clone3 = 435 + _SYS_faccessat2 = 439 + _SYS_fchmodat2 = 452 ) func setTimespec(sec, nsec int64) Timespec { diff --git a/src/syscall/syscall_linux_amd64.go b/src/syscall/syscall_linux_amd64.go index 1083a507c70..ec52f8a4bd9 100644 --- a/src/syscall/syscall_linux_amd64.go +++ b/src/syscall/syscall_linux_amd64.go @@ -9,11 +9,10 @@ import ( ) const ( - _SYS_setgroups = SYS_SETGROUPS - _SYS_clone3 = 435 - _SYS_faccessat2 = 439 - _SYS_pidfd_send_signal = 424 - _SYS_fchmodat2 = 452 + _SYS_setgroups = SYS_SETGROUPS + _SYS_clone3 = 435 + _SYS_faccessat2 = 439 + _SYS_fchmodat2 = 452 ) //sys Dup2(oldfd int, newfd int) (err error) diff --git a/src/syscall/syscall_linux_arm.go b/src/syscall/syscall_linux_arm.go index 2641cd28686..a6d92cea131 100644 --- a/src/syscall/syscall_linux_arm.go +++ b/src/syscall/syscall_linux_arm.go @@ -7,11 +7,10 @@ package syscall import "unsafe" const ( - _SYS_setgroups = SYS_SETGROUPS32 - _SYS_clone3 = 435 - _SYS_faccessat2 = 439 - _SYS_pidfd_send_signal = 424 - _SYS_fchmodat2 = 452 + _SYS_setgroups = SYS_SETGROUPS32 + _SYS_clone3 = 435 + _SYS_faccessat2 = 439 + _SYS_fchmodat2 = 452 ) func setTimespec(sec, nsec int64) Timespec { diff --git a/src/syscall/syscall_linux_arm64.go b/src/syscall/syscall_linux_arm64.go index 74d6e3a9586..b87b51c0c04 100644 --- a/src/syscall/syscall_linux_arm64.go +++ b/src/syscall/syscall_linux_arm64.go @@ -7,11 +7,10 @@ package syscall import "unsafe" const ( - _SYS_setgroups = SYS_SETGROUPS - _SYS_clone3 = 435 - _SYS_faccessat2 = 439 - _SYS_pidfd_send_signal = 424 - _SYS_fchmodat2 = 452 + _SYS_setgroups = SYS_SETGROUPS + _SYS_clone3 = 435 + _SYS_faccessat2 = 439 + _SYS_fchmodat2 = 452 ) //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT diff --git a/src/syscall/syscall_linux_loong64.go b/src/syscall/syscall_linux_loong64.go index eb275bc7173..634cf30cf26 100644 --- a/src/syscall/syscall_linux_loong64.go +++ b/src/syscall/syscall_linux_loong64.go @@ -7,11 +7,10 @@ package syscall import "unsafe" const ( - _SYS_setgroups = SYS_SETGROUPS - _SYS_clone3 = 435 - _SYS_faccessat2 = 439 - _SYS_pidfd_send_signal = 424 - _SYS_fchmodat2 = 452 + _SYS_setgroups = SYS_SETGROUPS + _SYS_clone3 = 435 + _SYS_faccessat2 = 439 + _SYS_fchmodat2 = 452 ) //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT diff --git a/src/syscall/syscall_linux_mips64x.go b/src/syscall/syscall_linux_mips64x.go index 3bdee928ed6..41106ed81ff 100644 --- a/src/syscall/syscall_linux_mips64x.go +++ b/src/syscall/syscall_linux_mips64x.go @@ -11,11 +11,10 @@ import ( ) const ( - _SYS_setgroups = SYS_SETGROUPS - _SYS_clone3 = 5435 - _SYS_faccessat2 = 5439 - _SYS_pidfd_send_signal = 5424 - _SYS_fchmodat2 = 5452 + _SYS_setgroups = SYS_SETGROUPS + _SYS_clone3 = 5435 + _SYS_faccessat2 = 5439 + _SYS_fchmodat2 = 5452 ) //sys Dup2(oldfd int, newfd int) (err error) diff --git a/src/syscall/syscall_linux_mipsx.go b/src/syscall/syscall_linux_mipsx.go index 7253c648e71..7d4f8f2264d 100644 --- a/src/syscall/syscall_linux_mipsx.go +++ b/src/syscall/syscall_linux_mipsx.go @@ -9,11 +9,10 @@ package syscall import "unsafe" const ( - _SYS_setgroups = SYS_SETGROUPS - _SYS_clone3 = 4435 - _SYS_faccessat2 = 4439 - _SYS_pidfd_send_signal = 4424 - _SYS_fchmodat2 = 4452 + _SYS_setgroups = SYS_SETGROUPS + _SYS_clone3 = 4435 + _SYS_faccessat2 = 4439 + _SYS_fchmodat2 = 4452 ) func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) diff --git a/src/syscall/syscall_linux_ppc64x.go b/src/syscall/syscall_linux_ppc64x.go index 9cfe2dc6959..13c184c44fe 100644 --- a/src/syscall/syscall_linux_ppc64x.go +++ b/src/syscall/syscall_linux_ppc64x.go @@ -11,11 +11,10 @@ import ( ) const ( - _SYS_setgroups = SYS_SETGROUPS - _SYS_clone3 = 435 - _SYS_faccessat2 = 439 - _SYS_pidfd_send_signal = 424 - _SYS_fchmodat2 = 452 + _SYS_setgroups = SYS_SETGROUPS + _SYS_clone3 = 435 + _SYS_faccessat2 = 439 + _SYS_fchmodat2 = 452 ) //sys Dup2(oldfd int, newfd int) (err error) diff --git a/src/syscall/syscall_linux_riscv64.go b/src/syscall/syscall_linux_riscv64.go index 61fb4c16685..00872a74fba 100644 --- a/src/syscall/syscall_linux_riscv64.go +++ b/src/syscall/syscall_linux_riscv64.go @@ -7,11 +7,10 @@ package syscall import "unsafe" const ( - _SYS_setgroups = SYS_SETGROUPS - _SYS_clone3 = 435 - _SYS_faccessat2 = 439 - _SYS_pidfd_send_signal = 424 - _SYS_fchmodat2 = 452 + _SYS_setgroups = SYS_SETGROUPS + _SYS_clone3 = 435 + _SYS_faccessat2 = 439 + _SYS_fchmodat2 = 452 ) //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT diff --git a/src/syscall/syscall_linux_s390x.go b/src/syscall/syscall_linux_s390x.go index 3a0afc404a0..ea667ec1da5 100644 --- a/src/syscall/syscall_linux_s390x.go +++ b/src/syscall/syscall_linux_s390x.go @@ -7,11 +7,10 @@ package syscall import "unsafe" const ( - _SYS_setgroups = SYS_SETGROUPS - _SYS_clone3 = 435 - _SYS_faccessat2 = 439 - _SYS_pidfd_send_signal = 424 - _SYS_fchmodat2 = 452 + _SYS_setgroups = SYS_SETGROUPS + _SYS_clone3 = 435 + _SYS_faccessat2 = 439 + _SYS_fchmodat2 = 452 ) //sys Dup2(oldfd int, newfd int) (err error)