diff --git a/changelog/2502.added.md b/changelog/2502.added.md new file mode 100644 index 0000000000..f1966a7eba --- /dev/null +++ b/changelog/2502.added.md @@ -0,0 +1 @@ +Add `getregs()`/`getregset()`/`setregset()` for Linux/musl/aarch64 diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 8abaf4d71b..762b337687 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -14,11 +14,10 @@ pub type AddressType = *mut ::libc::c_void; target_os = "linux", any( all( - target_arch = "x86_64", + any(target_arch = "x86_64", target_arch = "aarch64"), any(target_env = "gnu", target_env = "musl") ), all(target_arch = "x86", target_env = "gnu"), - all(target_arch = "aarch64", target_env = "gnu"), all(target_arch = "riscv64", target_env = "gnu"), ), ))] @@ -334,8 +333,13 @@ pub fn getregs(pid: Pid) -> Result { /// [ptrace(2)]: https://www.man7.org/linux/man-pages/man2/ptrace.2.html #[cfg(all( target_os = "linux", - target_env = "gnu", - any(target_arch = "aarch64", target_arch = "riscv64") + any( + all( + target_arch = "aarch64", + any(target_env = "gnu", target_env = "musl") + ), + all(target_arch = "riscv64", target_env = "gnu") + ) ))] pub fn getregs(pid: Pid) -> Result { getregset::(pid) @@ -344,12 +348,17 @@ pub fn getregs(pid: Pid) -> Result { /// Get a particular set of user registers, as with `ptrace(PTRACE_GETREGSET, ...)` #[cfg(all( target_os = "linux", - target_env = "gnu", any( - target_arch = "x86_64", - target_arch = "x86", - target_arch = "aarch64", - target_arch = "riscv64", + all( + target_env = "gnu", + any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "aarch64", + target_arch = "riscv64" + ) + ), + all(target_env = "musl", target_arch = "aarch64") ) ))] pub fn getregset(pid: Pid) -> Result { @@ -408,8 +417,13 @@ pub fn setregs(pid: Pid, regs: user_regs_struct) -> Result<()> { /// [ptrace(2)]: https://www.man7.org/linux/man-pages/man2/ptrace.2.html #[cfg(all( target_os = "linux", - target_env = "gnu", - any(target_arch = "aarch64", target_arch = "riscv64") + any( + all( + target_env = "gnu", + any(target_arch = "aarch64", target_arch = "riscv64") + ), + all(target_env = "musl", target_arch = "aarch64") + ) ))] pub fn setregs(pid: Pid, regs: user_regs_struct) -> Result<()> { setregset::(pid, regs) @@ -418,12 +432,17 @@ pub fn setregs(pid: Pid, regs: user_regs_struct) -> Result<()> { /// Set a particular set of user registers, as with `ptrace(PTRACE_SETREGSET, ...)` #[cfg(all( target_os = "linux", - target_env = "gnu", any( - target_arch = "x86_64", - target_arch = "x86", - target_arch = "aarch64", - target_arch = "riscv64", + all( + target_env = "gnu", + any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "aarch64", + target_arch = "riscv64" + ) + ), + all(target_env = "musl", target_arch = "aarch64") ) ))] pub fn setregset(pid: Pid, mut regs: S::Regs) -> Result<()> { diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index c99c6762c3..2e3e809ee8 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -292,12 +292,17 @@ fn test_ptrace_syscall() { #[cfg(all( target_os = "linux", - target_env = "gnu", any( - target_arch = "x86_64", - target_arch = "x86", - target_arch = "aarch64", - target_arch = "riscv64", + all( + target_env = "gnu", + any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "aarch64", + target_arch = "riscv64" + ) + ), + all(target_env = "musl", target_arch = "aarch64") ) ))] #[test]