Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mcontext.c
Go to the documentation of this file.
1 #include <sys/ucontext.h>
2 #define __FRAME_OFFSETS
3 #include <asm/ptrace.h>
4 #include <sysdep/ptrace.h>
5 
7 {
8 #ifdef __i386__
9 #define COPY2(X,Y) regs->gp[X] = mc->gregs[REG_##Y]
10 #define COPY(X) regs->gp[X] = mc->gregs[REG_##X]
11 #define COPY_SEG(X) regs->gp[X] = mc->gregs[REG_##X] & 0xffff;
12 #define COPY_SEG_CPL3(X) regs->gp[X] = (mc->gregs[REG_##X] & 0xffff) | 3;
14  COPY(EDI); COPY(ESI); COPY(EBP);
15  COPY2(UESP, ESP); /* sic */
16  COPY(EBX); COPY(EDX); COPY(ECX); COPY(EAX);
17  COPY(EIP); COPY_SEG_CPL3(CS); COPY(EFL); COPY_SEG_CPL3(SS);
18 #else
19 #define COPY2(X,Y) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##Y]
20 #define COPY(X) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##X]
21  COPY(R8); COPY(R9); COPY(R10); COPY(R11);
22  COPY(R12); COPY(R13); COPY(R14); COPY(R15);
23  COPY(RDI); COPY(RSI); COPY(RBP); COPY(RBX);
24  COPY(RDX); COPY(RAX); COPY(RCX); COPY(RSP);
25  COPY(RIP);
26  COPY2(EFLAGS, EFL);
27  COPY2(CS, CSGSFS);
28  regs->gp[CS / sizeof(unsigned long)] &= 0xffff;
29  regs->gp[CS / sizeof(unsigned long)] |= 3;
30 #endif
31 }