From eb6acf02ad2cba4c0603c2a9d87508f942709945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 14 Sep 2024 11:05:22 +0300 Subject: [PATCH 1/4] Support getregs() for aarch64-unknown-linux-musl --- changelog/2502.added.md | 1 + src/sys/ptrace/linux.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelog/2502.added.md diff --git a/changelog/2502.added.md b/changelog/2502.added.md new file mode 100644 index 0000000000..ec639752ee --- /dev/null +++ b/changelog/2502.added.md @@ -0,0 +1 @@ +Add `getregset()` for Linux/musl/aarch64 diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 8abaf4d71b..ea842d4ea0 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) From 3ae812d2ffe94322a9937ddcf4bf1cda54b9e8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 14 Sep 2024 18:33:14 +0300 Subject: [PATCH 2/4] Expand the scope of Linux/musl/aarch64 implementation --- changelog/2502.added.md | 2 +- src/sys/ptrace/linux.rs | 39 +++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/changelog/2502.added.md b/changelog/2502.added.md index ec639752ee..f1966a7eba 100644 --- a/changelog/2502.added.md +++ b/changelog/2502.added.md @@ -1 +1 @@ -Add `getregset()` for Linux/musl/aarch64 +Add `getregs()`/`getregset()`/`setregset()` for Linux/musl/aarch64 diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index ea842d4ea0..4966d6cefa 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -348,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", any(target_arch = "aarch64")) ) ))] pub fn getregset(pid: Pid) -> Result { @@ -412,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) @@ -422,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<()> { From f803e832211188e2b75cf824a606962287890239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 14 Sep 2024 18:33:26 +0300 Subject: [PATCH 3/4] Enable tests --- test/sys/test_ptrace.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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] From cd2ff4ab7953bc11e40510672e103ce9419197c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 14 Sep 2024 18:36:23 +0300 Subject: [PATCH 4/4] Simplifiy arch condition --- src/sys/ptrace/linux.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 4966d6cefa..762b337687 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -358,7 +358,7 @@ pub fn getregs(pid: Pid) -> Result { target_arch = "riscv64" ) ), - all(target_env = "musl", any(target_arch = "aarch64")) + all(target_env = "musl", target_arch = "aarch64") ) ))] pub fn getregset(pid: Pid) -> Result {