Optimized Exit bridge managment

This commit is contained in:
ptitSeb 2023-05-10 17:27:31 +02:00
parent ea7eb6f866
commit 157d368939
7 changed files with 13 additions and 15 deletions

View File

@ -224,9 +224,12 @@ box86context_t *NewBox86Context(int argc)
context->system = NewBridge();
context->globaldefver = NewDefaultVersion();
context->weakdefver = NewDefaultVersion();
// Cannot use Bridge name as the map is not initialized yet
// create vsyscall
context->vsyscall = AddBridge(context->system, iFEv, x86Syscall, 0, NULL);
addAlternate((void*)0xffffe400, (void*)context->vsyscall);
// create exit bridge
context->exit_bridge = AddBridge(context->system, NULL, NULL, 0, NULL);
#ifdef BUILD_LIB
context->box86lib = RTLD_DEFAULT; // not ideal
#else

View File

@ -54,17 +54,6 @@ uint32_t* GetParityTab()
return x86emu_parity_tab;
}
void PushExit(x86emu_t* emu)
{
uintptr_t endMarker = AddCheckBridge(my_context->system, NULL, NULL, 0, "(ExitEmulation)");
Push(emu, endMarker);
}
void* GetExit()
{
return (void*)AddCheckBridge(my_context->system, NULL, NULL, 0, "(ExitEmulation)");
}
static void internalX86Setup(x86emu_t* emu, box86context_t *context, uintptr_t start, uintptr_t stack, int stacksize, int ownstack)
{
emu->context = context;

View File

@ -4,6 +4,7 @@
#include <stdint.h>
#include "regs.h"
#include "x86emu_private.h"
#include "box86context.h"
typedef struct x86emu_s x86emu_t;
static inline uint8_t Fetch8(x86emu_t *emu) {return *(uint8_t*)(R_EIP++);}
@ -52,6 +53,12 @@ static inline void Push(x86emu_t *emu, uint32_t v)
}
#endif
static inline void PushExit(x86emu_t* emu)
{
R_ESP -= 4;
*((uint32_t*)R_ESP) = my_context->exit_bridge;
}
#if 0
// the op code definition can be found here: http://ref.x86asm.net/geek32.html
static inline reg32_t* GetECommon(x86emu_t* emu, uint32_t m)

View File

@ -113,6 +113,7 @@ typedef struct box86context_s {
kh_threadstack_t *stacksizes; // stack sizes attributes for thread (temporary)
bridge_t *system; // other bridges
uintptr_t exit_bridge; // exit bridge value
uintptr_t vsyscall; // vsyscall bridge value
dlprivate_t *dlprivate; // dlopen library map
kh_symbolmap_t *alwrappers; // the map of wrapper for alGetProcAddress

View File

@ -35,8 +35,6 @@ void ResetSegmentsCache(x86emu_t *emu);
const char* DumpCPURegs(x86emu_t* emu, uintptr_t ip);
void StopEmu(x86emu_t* emu, const char* reason);
void PushExit(x86emu_t* emu);
void* GetExit();
void EmuCall(x86emu_t* emu, uintptr_t addr);
void AddCleanup(x86emu_t *emu, void *p);
void AddCleanup1Arg(x86emu_t *emu, void *p, void* a);

View File

@ -1337,7 +1337,7 @@ EXPORT int my_makecontext(x86emu_t* emu, void* ucp, void* fnc, int32_t argc, int
}
// push the return value
--esp;
*esp = (uintptr_t)GetExit();
*esp = my_context->exit_bridge;
u->uc_mcontext.gregs[REG_ESP] = (uintptr_t)esp;
return 0;

View File

@ -1659,7 +1659,7 @@ int main(int argc, const char **argv, char **env)
// Stack is ready, with stacked: NULL env NULL argv argc
SetEIP(emu, my_context->ep);
ResetFlags(emu);
PushExit(emu); // push to pop it just after
Push32(emu, my_context->exit_bridge); // push to pop it just after
SetEDX(emu, Pop32(emu)); // EDX is exit function
DynaRun(emu);
// Get EAX