1 // SPDX-License-Identifier: GPL-2.0 2 #include <sys/ucontext.h> 3 #define __FRAME_OFFSETS 4 #include <asm/ptrace.h> 5 #include <sysdep/ptrace.h> 6 #include <sysdep/mcontext.h> 7 #include <arch.h> 8 get_regs_from_mc(struct uml_pt_regs * regs,mcontext_t * mc)9void get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc) 10 { 11 #ifdef __i386__ 12 #define COPY2(X,Y) regs->gp[X] = mc->gregs[REG_##Y] 13 #define COPY(X) regs->gp[X] = mc->gregs[REG_##X] 14 #define COPY_SEG(X) regs->gp[X] = mc->gregs[REG_##X] & 0xffff; 15 #define COPY_SEG_CPL3(X) regs->gp[X] = (mc->gregs[REG_##X] & 0xffff) | 3; 16 COPY_SEG(GS); COPY_SEG(FS); COPY_SEG(ES); COPY_SEG(DS); 17 COPY(EDI); COPY(ESI); COPY(EBP); 18 COPY2(UESP, ESP); /* sic */ 19 COPY(EBX); COPY(EDX); COPY(ECX); COPY(EAX); 20 COPY(EIP); COPY_SEG_CPL3(CS); COPY(EFL); COPY_SEG_CPL3(SS); 21 #else 22 #define COPY2(X,Y) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##Y] 23 #define COPY(X) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##X] 24 COPY(R8); COPY(R9); COPY(R10); COPY(R11); 25 COPY(R12); COPY(R13); COPY(R14); COPY(R15); 26 COPY(RDI); COPY(RSI); COPY(RBP); COPY(RBX); 27 COPY(RDX); COPY(RAX); COPY(RCX); COPY(RSP); 28 COPY(RIP); 29 COPY2(EFLAGS, EFL); 30 COPY2(CS, CSGSFS); 31 regs->gp[SS / sizeof(unsigned long)] = mc->gregs[REG_CSGSFS] >> 48; 32 #endif 33 } 34 mc_set_rip(void * _mc,void * target)35void mc_set_rip(void *_mc, void *target) 36 { 37 mcontext_t *mc = _mc; 38 39 #ifdef __i386__ 40 mc->gregs[REG_EIP] = (unsigned long)target; 41 #else 42 mc->gregs[REG_RIP] = (unsigned long)target; 43 #endif 44 } 45