linux/context: Add updated context files
This commit is contained in:
parent
65ca1382d8
commit
03914309e3
|
@ -1,15 +1,20 @@
|
|||
#include "context.h"
|
||||
|
||||
#if defined(_ANDROID)
|
||||
#include <asm/sigcontext.h>
|
||||
#include <asm/sigcontext.h>
|
||||
#else
|
||||
#include <ucontext.h>
|
||||
#if HOST_OS == OS_DARWIN
|
||||
#define _XOPEN_SOURCE 1
|
||||
#define __USE_GNU 1
|
||||
#endif
|
||||
|
||||
#include <ucontext.h>
|
||||
#endif
|
||||
|
||||
|
||||
//////
|
||||
|
||||
#define MCTX(p) (((ucontext_t *)(segfault_ctx))->uc_mcontext.p)
|
||||
#define MCTX(p) (((ucontext_t *)(segfault_ctx))->uc_mcontext p)
|
||||
template <typename Ta, typename Tb>
|
||||
void swap(Ta& a, Tb& b, bool reverse) {
|
||||
if (reverse) {
|
||||
|
@ -23,16 +28,39 @@ void swap(Ta& a, Tb& b, bool reverse) {
|
|||
void context_segfault(rei_host_context_t* reictx, void* segfault_ctx, bool to_segfault) {
|
||||
|
||||
#if HOST_CPU == CPU_ARM
|
||||
swap(reictx->pc, MCTX(arm_pc), to_segfault);
|
||||
#if HOST_OS == OS_LINUX
|
||||
swap(reictx->pc, MCTX(.arm_pc), to_segfault);
|
||||
u32* r =(u32*) &MCTX(.arm_r0);
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
swap(reictx->r[i], r[i], to_segfault);
|
||||
|
||||
#elif HOST_OS == OS_DARWIN
|
||||
swap(reictx->pc, MCTX(->__ss.__pc), to_segfault);
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
swap(reictx->r[i], MCTX(->__ss.__r[i]), to_segfault);
|
||||
#else
|
||||
#error HOST_OS
|
||||
#endif
|
||||
#elif HOST_CPU == CPU_X86
|
||||
swap(reictx->pc, MCTX(gregs[REG_EIP]), to_segfault);
|
||||
swap(reictx->esp, MCTX(gregs[REG_ESP]), to_segfault);
|
||||
swap(reictx->eax, MCTX(gregs[REG_EAX]), to_segfault);
|
||||
swap(reictx->ecx, MCTX(gregs[REG_ECX]), to_segfault);
|
||||
#if HOST_OS == OS_LINUX
|
||||
swap(reictx->pc, MCTX(.gregs[REG_EIP]), to_segfault);
|
||||
swap(reictx->esp, MCTX(.gregs[REG_ESP]), to_segfault);
|
||||
swap(reictx->eax, MCTX(.gregs[REG_EAX]), to_segfault);
|
||||
swap(reictx->ecx, MCTX(.gregs[REG_ECX]), to_segfault);
|
||||
#elif HOST_OS == OS_DARWIN
|
||||
swap(reictx->pc, MCTX(->__ss.__eip), to_segfault);
|
||||
swap(reictx->esp, MCTX(->__ss.__esp), to_segfault);
|
||||
swap(reictx->eax, MCTX(->__ss.__eax), to_segfault);
|
||||
swap(reictx->ecx, MCTX(->__ss.__ecx), to_segfault);
|
||||
#else
|
||||
#error HOST_OS
|
||||
#endif
|
||||
#elif HOST_CPU == CPU_MIPS
|
||||
swap(reictx->pc, MCTX(pc), to_segfault);
|
||||
swap(reictx->pc, MCTX(.pc), to_segfault);
|
||||
#else
|
||||
#error Unsupported HOST_CPU
|
||||
#error Unsupported HOST_CPU
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ struct rei_host_context_t {
|
|||
u32 ecx;
|
||||
u32 esp;
|
||||
#elif HOST_CPU == CPU_ARM
|
||||
u32 r0;
|
||||
u32 r[15];
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue