mirror of
https://github.com/golang/go
synced 2024-11-26 02:57:57 -07:00
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>
This commit is contained in:
parent
5a6f1b35d4
commit
ff05cdbd2b
15
src/internal/syscall/unix/pidfd_linux.go
Normal file
15
src/internal/syscall/unix/pidfd_linux.go
Normal file
@ -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
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
package unix
|
||||
|
||||
const (
|
||||
getrandomTrap uintptr = 355
|
||||
copyFileRangeTrap uintptr = 377
|
||||
getrandomTrap uintptr = 355
|
||||
copyFileRangeTrap uintptr = 377
|
||||
pidfdSendSignalTrap uintptr = 424
|
||||
)
|
||||
|
@ -5,6 +5,7 @@
|
||||
package unix
|
||||
|
||||
const (
|
||||
getrandomTrap uintptr = 318
|
||||
copyFileRangeTrap uintptr = 326
|
||||
getrandomTrap uintptr = 318
|
||||
copyFileRangeTrap uintptr = 326
|
||||
pidfdSendSignalTrap uintptr = 424
|
||||
)
|
||||
|
@ -5,6 +5,7 @@
|
||||
package unix
|
||||
|
||||
const (
|
||||
getrandomTrap uintptr = 384
|
||||
copyFileRangeTrap uintptr = 391
|
||||
getrandomTrap uintptr = 384
|
||||
copyFileRangeTrap uintptr = 391
|
||||
pidfdSendSignalTrap uintptr = 424
|
||||
)
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -7,6 +7,7 @@
|
||||
package unix
|
||||
|
||||
const (
|
||||
getrandomTrap uintptr = 5313
|
||||
copyFileRangeTrap uintptr = 5320
|
||||
getrandomTrap uintptr = 5313
|
||||
copyFileRangeTrap uintptr = 5320
|
||||
pidfdSendSignalTrap uintptr = 5424
|
||||
)
|
||||
|
@ -7,6 +7,7 @@
|
||||
package unix
|
||||
|
||||
const (
|
||||
getrandomTrap uintptr = 4353
|
||||
copyFileRangeTrap uintptr = 4360
|
||||
getrandomTrap uintptr = 4353
|
||||
copyFileRangeTrap uintptr = 4360
|
||||
pidfdSendSignalTrap uintptr = 4424
|
||||
)
|
||||
|
@ -7,6 +7,7 @@
|
||||
package unix
|
||||
|
||||
const (
|
||||
getrandomTrap uintptr = 359
|
||||
copyFileRangeTrap uintptr = 379
|
||||
getrandomTrap uintptr = 359
|
||||
copyFileRangeTrap uintptr = 379
|
||||
pidfdSendSignalTrap uintptr = 424
|
||||
)
|
||||
|
@ -5,6 +5,7 @@
|
||||
package unix
|
||||
|
||||
const (
|
||||
getrandomTrap uintptr = 349
|
||||
copyFileRangeTrap uintptr = 375
|
||||
getrandomTrap uintptr = 349
|
||||
copyFileRangeTrap uintptr = 375
|
||||
pidfdSendSignalTrap uintptr = 424
|
||||
)
|
||||
|
@ -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()
|
||||
|
@ -10,6 +10,5 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
Sys_GETEUID = sys_GETEUID
|
||||
Sys_pidfd_send_signal = _SYS_pidfd_send_signal
|
||||
Sys_GETEUID = sys_GETEUID
|
||||
)
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user