From: Kir Kolyshkin Date: Wed, 13 Sep 2023 07:58:20 +0000 (-0700) Subject: internal/syscall/unix: add PidFDSendSignal for Linux X-Git-Tag: go1.22rc1~180 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ff05cdbd2bdc28ab545a5964f7f772e2ea4c5fd1;p=gostls13.git 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 --- diff --git a/src/internal/syscall/unix/pidfd_linux.go b/src/internal/syscall/unix/pidfd_linux.go new file mode 100644 index 0000000000..02cfaa062c --- /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 2bda08ccf1..9f750a1c03 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 ae5239ebfb..706898d41e 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 acaec05879..c00644b552 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 8c132c6bf5..bf25428e7e 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 bca526d2b9..6a9e238ce3 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 c86195e496..22d38f148e 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 a4dcf2bc9d..945ec28c2a 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 bf2c01e4e1..2c74343820 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 976275e1dc..68ec6fe3f8 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 a09db60753..3aa877cfe3 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 1ab6c5e148..a559f7e288 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 1083a507c7..ec52f8a4bd 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 2641cd2868..a6d92cea13 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 74d6e3a958..b87b51c0c0 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 eb275bc717..634cf30cf2 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 3bdee928ed..41106ed81f 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 7253c648e7..7d4f8f2264 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 9cfe2dc695..13c184c44f 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 61fb4c1668..00872a74fb 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 3a0afc404a..ea667ec1da 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)