blob: 6911eeea66bf5af5fbb34633676b0efe6089bad3 [file] [log] [blame]
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001/*
2 * PTRACE_GETREGSET was added to the kernel in v2.6.25,
3 * a PTRACE_GETREGS based fallback is provided for old kernels.
4 */
5static void
6getregs_old(pid_t pid)
7{
8 /* Use old method, with unreliable heuristical detection of 32-bitness. */
9 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &x86_64_regs);
10 if (get_regs_error)
11 return;
12
13 if (x86_64_regs.cs == 0x23) {
14 x86_io.iov_len = sizeof(i386_regs);
15 /*
16 * The order is important: i386_regs and x86_64_regs
17 * are overlaid in memory!
18 */
19 i386_regs.ebx = x86_64_regs.rbx;
20 i386_regs.ecx = x86_64_regs.rcx;
21 i386_regs.edx = x86_64_regs.rdx;
22 i386_regs.esi = x86_64_regs.rsi;
23 i386_regs.edi = x86_64_regs.rdi;
24 i386_regs.ebp = x86_64_regs.rbp;
25 i386_regs.eax = x86_64_regs.rax;
26 /* i386_regs.xds = x86_64_regs.ds; unused by strace */
27 /* i386_regs.xes = x86_64_regs.es; ditto... */
28 /* i386_regs.xfs = x86_64_regs.fs; */
29 /* i386_regs.xgs = x86_64_regs.gs; */
30 i386_regs.orig_eax = x86_64_regs.orig_rax;
31 i386_regs.eip = x86_64_regs.rip;
32 /* i386_regs.xcs = x86_64_regs.cs; */
33 /* i386_regs.eflags = x86_64_regs.eflags; */
34 i386_regs.esp = x86_64_regs.rsp;
35 /* i386_regs.xss = x86_64_regs.ss; */
36 } else {
37 x86_io.iov_len = sizeof(x86_64_regs);
38 }
39}