Skip to content

Commit 062211b

Browse files
authored
Add getregs()/setregs()/getregset()/setregset() for Linux/musl/aarch64 (#2502)
* Support getregs() for aarch64-unknown-linux-musl * Expand the scope of Linux/musl/aarch64 implementation * Enable tests * Simplifiy arch condition
1 parent 6cfbf2d commit 062211b

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

changelog/2502.added.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `getregs()`/`getregset()`/`setregset()` for Linux/musl/aarch64

src/sys/ptrace/linux.rs

+35-16
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ pub type AddressType = *mut ::libc::c_void;
1414
target_os = "linux",
1515
any(
1616
all(
17-
target_arch = "x86_64",
17+
any(target_arch = "x86_64", target_arch = "aarch64"),
1818
any(target_env = "gnu", target_env = "musl")
1919
),
2020
all(target_arch = "x86", target_env = "gnu"),
21-
all(target_arch = "aarch64", target_env = "gnu"),
2221
all(target_arch = "riscv64", target_env = "gnu"),
2322
),
2423
))]
@@ -334,8 +333,13 @@ pub fn getregs(pid: Pid) -> Result<user_regs_struct> {
334333
/// [ptrace(2)]: https://www.man7.org/linux/man-pages/man2/ptrace.2.html
335334
#[cfg(all(
336335
target_os = "linux",
337-
target_env = "gnu",
338-
any(target_arch = "aarch64", target_arch = "riscv64")
336+
any(
337+
all(
338+
target_arch = "aarch64",
339+
any(target_env = "gnu", target_env = "musl")
340+
),
341+
all(target_arch = "riscv64", target_env = "gnu")
342+
)
339343
))]
340344
pub fn getregs(pid: Pid) -> Result<user_regs_struct> {
341345
getregset::<regset::NT_PRSTATUS>(pid)
@@ -344,12 +348,17 @@ pub fn getregs(pid: Pid) -> Result<user_regs_struct> {
344348
/// Get a particular set of user registers, as with `ptrace(PTRACE_GETREGSET, ...)`
345349
#[cfg(all(
346350
target_os = "linux",
347-
target_env = "gnu",
348351
any(
349-
target_arch = "x86_64",
350-
target_arch = "x86",
351-
target_arch = "aarch64",
352-
target_arch = "riscv64",
352+
all(
353+
target_env = "gnu",
354+
any(
355+
target_arch = "x86_64",
356+
target_arch = "x86",
357+
target_arch = "aarch64",
358+
target_arch = "riscv64"
359+
)
360+
),
361+
all(target_env = "musl", target_arch = "aarch64")
353362
)
354363
))]
355364
pub fn getregset<S: RegisterSet>(pid: Pid) -> Result<S::Regs> {
@@ -408,8 +417,13 @@ pub fn setregs(pid: Pid, regs: user_regs_struct) -> Result<()> {
408417
/// [ptrace(2)]: https://www.man7.org/linux/man-pages/man2/ptrace.2.html
409418
#[cfg(all(
410419
target_os = "linux",
411-
target_env = "gnu",
412-
any(target_arch = "aarch64", target_arch = "riscv64")
420+
any(
421+
all(
422+
target_env = "gnu",
423+
any(target_arch = "aarch64", target_arch = "riscv64")
424+
),
425+
all(target_env = "musl", target_arch = "aarch64")
426+
)
413427
))]
414428
pub fn setregs(pid: Pid, regs: user_regs_struct) -> Result<()> {
415429
setregset::<regset::NT_PRSTATUS>(pid, regs)
@@ -418,12 +432,17 @@ pub fn setregs(pid: Pid, regs: user_regs_struct) -> Result<()> {
418432
/// Set a particular set of user registers, as with `ptrace(PTRACE_SETREGSET, ...)`
419433
#[cfg(all(
420434
target_os = "linux",
421-
target_env = "gnu",
422435
any(
423-
target_arch = "x86_64",
424-
target_arch = "x86",
425-
target_arch = "aarch64",
426-
target_arch = "riscv64",
436+
all(
437+
target_env = "gnu",
438+
any(
439+
target_arch = "x86_64",
440+
target_arch = "x86",
441+
target_arch = "aarch64",
442+
target_arch = "riscv64"
443+
)
444+
),
445+
all(target_env = "musl", target_arch = "aarch64")
427446
)
428447
))]
429448
pub fn setregset<S: RegisterSet>(pid: Pid, mut regs: S::Regs) -> Result<()> {

test/sys/test_ptrace.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,17 @@ fn test_ptrace_syscall() {
292292

293293
#[cfg(all(
294294
target_os = "linux",
295-
target_env = "gnu",
296295
any(
297-
target_arch = "x86_64",
298-
target_arch = "x86",
299-
target_arch = "aarch64",
300-
target_arch = "riscv64",
296+
all(
297+
target_env = "gnu",
298+
any(
299+
target_arch = "x86_64",
300+
target_arch = "x86",
301+
target_arch = "aarch64",
302+
target_arch = "riscv64"
303+
)
304+
),
305+
all(target_env = "musl", target_arch = "aarch64")
301306
)
302307
))]
303308
#[test]

0 commit comments

Comments
 (0)