|
11 | 11 | #endif |
12 | 12 | #include <longjmp.h> |
13 | 13 | #include <sysdep/ptrace_user.h> |
| 14 | +#include <sys/uio.h> |
| 15 | +#include <asm/sigcontext.h> |
| 16 | +#include <linux/elf.h> |
14 | 17 |
|
15 | | -int save_fp_registers(int pid, unsigned long *fp_regs) |
| 18 | +int have_xstate_support; |
| 19 | + |
| 20 | +int save_i387_registers(int pid, unsigned long *fp_regs) |
16 | 21 | { |
17 | 22 | if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0) |
18 | 23 | return -errno; |
19 | 24 | return 0; |
20 | 25 | } |
21 | 26 |
|
22 | | -int restore_fp_registers(int pid, unsigned long *fp_regs) |
| 27 | +int save_fp_registers(int pid, unsigned long *fp_regs) |
| 28 | +{ |
| 29 | + struct iovec iov; |
| 30 | + |
| 31 | + if (have_xstate_support) { |
| 32 | + iov.iov_base = fp_regs; |
| 33 | + iov.iov_len = sizeof(struct _xstate); |
| 34 | + if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0) |
| 35 | + return -errno; |
| 36 | + return 0; |
| 37 | + } else { |
| 38 | + return save_i387_registers(pid, fp_regs); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +int restore_i387_registers(int pid, unsigned long *fp_regs) |
23 | 43 | { |
24 | 44 | if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0) |
25 | 45 | return -errno; |
26 | 46 | return 0; |
27 | 47 | } |
28 | 48 |
|
| 49 | +int restore_fp_registers(int pid, unsigned long *fp_regs) |
| 50 | +{ |
| 51 | + struct iovec iov; |
| 52 | + |
| 53 | + if (have_xstate_support) { |
| 54 | + iov.iov_base = fp_regs; |
| 55 | + iov.iov_len = sizeof(struct _xstate); |
| 56 | + if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0) |
| 57 | + return -errno; |
| 58 | + return 0; |
| 59 | + } else { |
| 60 | + return restore_i387_registers(pid, fp_regs); |
| 61 | + } |
| 62 | +} |
| 63 | + |
29 | 64 | #ifdef __i386__ |
30 | 65 | int have_fpx_regs = 1; |
31 | 66 | int save_fpx_registers(int pid, unsigned long *fp_regs) |
@@ -85,6 +120,16 @@ int put_fp_registers(int pid, unsigned long *regs) |
85 | 120 | return restore_fp_registers(pid, regs); |
86 | 121 | } |
87 | 122 |
|
| 123 | +void arch_init_registers(int pid) |
| 124 | +{ |
| 125 | + struct _xstate fp_regs; |
| 126 | + struct iovec iov; |
| 127 | + |
| 128 | + iov.iov_base = &fp_regs; |
| 129 | + iov.iov_len = sizeof(struct _xstate); |
| 130 | + if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0) |
| 131 | + have_xstate_support = 1; |
| 132 | +} |
88 | 133 | #endif |
89 | 134 |
|
90 | 135 | unsigned long get_thread_reg(int reg, jmp_buf *buf) |
|
0 commit comments