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 <kolyshkin@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
diff --git a/src/internal/syscall/unix/pidfd_linux.go b/src/internal/syscall/unix/pidfd_linux.go
new file mode 100644
index 0000000..02cfaa0
--- /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 2bda08c..9f750a1 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 ae5239e..706898d 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 acaec05..c00644b 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 8c132c6..bf25428 100644
--- a/src/internal/syscall/unix/sysnum_linux_generic.go
+++ b/src/internal/syscall/unix/sysnum_linux_generic.go
@@ -11,6 +11,7 @@
 // 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 bca526d..6a9e238 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 c86195e..22d38f1 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 a4dcf2b..945ec28 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 bf2c01e..2c74343 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 976275e..68ec6fe 100644
--- a/src/syscall/exec_linux_test.go
+++ b/src/syscall/exec_linux_test.go
@@ -12,6 +12,7 @@
 	"flag"
 	"fmt"
 	"internal/platform"
+	"internal/syscall/unix"
 	"internal/testenv"
 	"io"
 	"os"
@@ -560,11 +561,11 @@
 
 	// 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 a09db60..3aa877c 100644
--- a/src/syscall/export_linux_test.go
+++ b/src/syscall/export_linux_test.go
@@ -10,6 +10,5 @@
 )
 
 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 1ab6c5e..a559f7e 100644
--- a/src/syscall/syscall_linux_386.go
+++ b/src/syscall/syscall_linux_386.go
@@ -7,11 +7,10 @@
 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 1083a50..ec52f8a 100644
--- a/src/syscall/syscall_linux_amd64.go
+++ b/src/syscall/syscall_linux_amd64.go
@@ -9,11 +9,10 @@
 )
 
 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 2641cd2..a6d92ce 100644
--- a/src/syscall/syscall_linux_arm.go
+++ b/src/syscall/syscall_linux_arm.go
@@ -7,11 +7,10 @@
 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 74d6e3a..b87b51c 100644
--- a/src/syscall/syscall_linux_arm64.go
+++ b/src/syscall/syscall_linux_arm64.go
@@ -7,11 +7,10 @@
 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 eb275bc..634cf30 100644
--- a/src/syscall/syscall_linux_loong64.go
+++ b/src/syscall/syscall_linux_loong64.go
@@ -7,11 +7,10 @@
 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 3bdee92..41106ed 100644
--- a/src/syscall/syscall_linux_mips64x.go
+++ b/src/syscall/syscall_linux_mips64x.go
@@ -11,11 +11,10 @@
 )
 
 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 7253c64..7d4f8f2 100644
--- a/src/syscall/syscall_linux_mipsx.go
+++ b/src/syscall/syscall_linux_mipsx.go
@@ -9,11 +9,10 @@
 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 9cfe2dc..13c184c 100644
--- a/src/syscall/syscall_linux_ppc64x.go
+++ b/src/syscall/syscall_linux_ppc64x.go
@@ -11,11 +11,10 @@
 )
 
 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 61fb4c1..00872a7 100644
--- a/src/syscall/syscall_linux_riscv64.go
+++ b/src/syscall/syscall_linux_riscv64.go
@@ -7,11 +7,10 @@
 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 3a0afc4..ea667ec 100644
--- a/src/syscall/syscall_linux_s390x.go
+++ b/src/syscall/syscall_linux_s390x.go
@@ -7,11 +7,10 @@
 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)