From 5059a07aa46a89cb45ca6eabd13f2173baa73bb3 Mon Sep 17 00:00:00 2001 From: Guoqi Chen Date: Wed, 7 Jun 2023 07:25:11 +0800 Subject: [PATCH] unix: implement Ptrace{Set,Get}Regs using PTRACE_{GET,SET}REGSET for Linux The same change was already done in CL 501756. Fixes #60679. Change-Id: I5d1f4ad89cabb0ac120b3d72876944fb3283ec6f Reviewed-on: https://go-review.googlesource.com/c/sys/+/501795 Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: David Chase Reviewed-by: Ian Lance Taylor --- unix/syscall_linux.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index aa0c55151..ec24faea5 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -12,6 +12,7 @@ package unix import ( + "debug/elf" "encoding/binary" "strconv" "syscall" @@ -1700,11 +1701,17 @@ func PtracePokeUser(pid int, addr uintptr, data []byte) (count int, err error) { } 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(elf.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(elf.NT_PRSTATUS), unsafe.Pointer(&iov)) } func PtraceSetOptions(pid int, options int) (err error) {