From: chenguoqi Date: Thu, 8 Jun 2023 06:04:26 +0000 (+0800) Subject: syscall: implement Ptrace{Set,Get}Regs using PTRACE_{GET,SET}REGSET on all linux... X-Git-Tag: go1.21rc1~42 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fafa4091abb4ed6de6ff4daef67ef1cf9db40923;p=gostls13.git syscall: implement Ptrace{Set,Get}Regs using PTRACE_{GET,SET}REGSET on all linux platforms In the ptrace system call, most of the newer architectures (e.g. arm64,riscv64,loong64) do not provide support for the command PTRACE_{GET, SET}REGS. The Linux kernel 2.6.33-rc7[1] introduces support for the command PTRACE_{GET,SET}REGSET, which exports different types of register sets depending on the NT_* types, completely overriding the functionality provided by PTRACE_{GET,SET}REGS. [1] https://lore.kernel.org/all/20100211195614.886724710@sbs-t61.sc.intel.com/ Fixes #60679. Change-Id: I8c2671d64a7ecd654834740f4f1e1e50c00edcae Reviewed-on: https://go-review.googlesource.com/c/go/+/501756 TryBot-Result: Gopher Robot Reviewed-by: David Chase Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go index 618b2e6d42..a2768e1845 100644 --- a/src/syscall/syscall_linux.go +++ b/src/syscall/syscall_linux.go @@ -936,12 +936,22 @@ func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error) { return ptracePoke(PTRACE_POKEDATA, PTRACE_PEEKDATA, pid, addr, data) } +const ( + _NT_PRSTATUS = 1 +) + func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) { - return ptracePtr(PTRACE_GETREGS, pid, 0, unsafe.Pointer(regsout)) + var iov Iovec + iov.Base = (*byte)(unsafe.Pointer(regsout)) + iov.SetLen(int(unsafe.Sizeof(*regsout))) + return ptracePtr(PTRACE_GETREGSET, pid, uintptr(_NT_PRSTATUS), unsafe.Pointer(&iov)) } func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) { - return ptracePtr(PTRACE_SETREGS, pid, 0, unsafe.Pointer(regs)) + var iov Iovec + iov.Base = (*byte)(unsafe.Pointer(regs)) + iov.SetLen(int(unsafe.Sizeof(*regs))) + return ptracePtr(PTRACE_SETREGSET, pid, uintptr(_NT_PRSTATUS), unsafe.Pointer(&iov)) } func PtraceSetOptions(pid int, options int) (err error) {