|
17 | 17 |
|
18 | 18 | #include <linux/ptrace.h>
|
19 | 19 |
|
| 20 | +static inline |
| 21 | +int ptrace_wrapper(int op, pid_t pid, void *addr, void *data) { |
| 22 | + int retries = 3; |
| 23 | + int result; |
| 24 | + do { |
| 25 | + result = ptrace(op, pid, addr, data); |
| 26 | + } while (result < 0 && (errno == EAGAIN || errno == EBUSY) && retries-- > 0); |
| 27 | + return result; |
| 28 | +} |
| 29 | + |
20 | 30 | static inline
|
21 | 31 | int ptrace_attach(pid_t pid) {
|
22 |
| - return ptrace(PTRACE_ATTACH, pid, 0, 0); |
| 32 | + return ptrace_wrapper(PTRACE_ATTACH, pid, 0, 0); |
23 | 33 | }
|
24 | 34 |
|
25 | 35 | static inline
|
26 | 36 | int ptrace_detach(pid_t pid) {
|
27 |
| - return ptrace(PTRACE_DETACH, pid, 0, 0); |
| 37 | + return ptrace_wrapper(PTRACE_DETACH, pid, 0, 0); |
28 | 38 | }
|
29 | 39 |
|
30 | 40 | static inline
|
31 | 41 | int ptrace_continue(pid_t pid) {
|
32 |
| - return ptrace(PTRACE_CONT, pid, 0, 0); |
| 42 | + return ptrace_wrapper(PTRACE_CONT, pid, 0, 0); |
33 | 43 | }
|
34 | 44 |
|
35 | 45 | static inline
|
36 | 46 | int ptrace_getsiginfo(pid_t pid, siginfo_t *siginfo) {
|
37 |
| - return ptrace(PTRACE_GETSIGINFO, pid, 0, siginfo); |
| 47 | + return ptrace_wrapper(PTRACE_GETSIGINFO, pid, 0, siginfo); |
38 | 48 | }
|
39 | 49 |
|
40 | 50 | static inline
|
41 | 51 | int ptrace_pokedata(pid_t pid, unsigned long addr, unsigned long value) {
|
42 |
| - return ptrace(PTRACE_POKEDATA, pid, addr, value); |
| 52 | + return ptrace_wrapper(PTRACE_POKEDATA, pid, (void*)(uintptr_t)addr, (void*)(uintptr_t)value); |
43 | 53 | }
|
44 | 54 |
|
45 | 55 | static inline
|
46 | 56 | int ptrace_getregset(pid_t pid, int type, struct iovec *regs) {
|
47 |
| - return ptrace(PTRACE_GETREGSET, pid, type, regs); |
| 57 | + return ptrace_wrapper(PTRACE_GETREGSET, pid, (void*)(uintptr_t)type, regs); |
48 | 58 | }
|
49 | 59 |
|
50 | 60 | static inline
|
51 | 61 | int ptrace_setregset(pid_t pid, int type, struct iovec *regs) {
|
52 |
| - return ptrace(PTRACE_SETREGSET, pid, type, regs); |
| 62 | + return ptrace_wrapper(PTRACE_SETREGSET, pid, (void*)(uintptr_t)type, regs); |
53 | 63 | }
|
0 commit comments