Skip to content

Commit

Permalink
Add getregs()/setregs()/getregset()/setregset() for Linux/mus…
Browse files Browse the repository at this point in the history
…l/aarch64 (#2502)

* Support getregs() for aarch64-unknown-linux-musl

* Expand the scope of Linux/musl/aarch64 implementation

* Enable tests

* Simplifiy arch condition
  • Loading branch information
orhun authored Sep 15, 2024
1 parent 6cfbf2d commit 062211b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
1 change: 1 addition & 0 deletions changelog/2502.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `getregs()`/`getregset()`/`setregset()` for Linux/musl/aarch64
51 changes: 35 additions & 16 deletions src/sys/ptrace/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
))]
Expand Down Expand Up @@ -334,8 +333,13 @@ pub fn getregs(pid: Pid) -> Result<user_regs_struct> {
/// [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<user_regs_struct> {
getregset::<regset::NT_PRSTATUS>(pid)
Expand All @@ -344,12 +348,17 @@ pub fn getregs(pid: Pid) -> Result<user_regs_struct> {
/// 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<S: RegisterSet>(pid: Pid) -> Result<S::Regs> {
Expand Down Expand Up @@ -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::<regset::NT_PRSTATUS>(pid, regs)
Expand All @@ -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<S: RegisterSet>(pid: Pid, mut regs: S::Regs) -> Result<()> {
Expand Down
15 changes: 10 additions & 5 deletions test/sys/test_ptrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 062211b

Please sign in to comment.