Skip to content

Commit

Permalink
less ifdeff
Browse files Browse the repository at this point in the history
  • Loading branch information
microcai committed Nov 5, 2024
1 parent cc68ff2 commit 4aa3fa8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 3 additions & 6 deletions include/trampoline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace trampoline
static constexpr long _jit_code_size = 64;

unsigned char _jit_code[_jit_code_size];
void generate_trampoline(const void* wrap_func_ptr);
void generate_trampoline(const void* wrap_func_ptr, int select_asm_model = 0);

void* operator new(std::size_t size)
{
Expand Down Expand Up @@ -101,7 +101,6 @@ namespace trampoline

void attach_trampoline()
{
#ifdef _M_IX86
if constexpr (callabi == x86_stdcall)
{
/*
Expand All @@ -118,11 +117,9 @@ namespace trampoline
void* raw;
static_assert(sizeof(call_op_func) == sizeof(raw), "member function pointer size assumption failed");
memcpy(&raw, &call_op_func, sizeof(raw));
generate_trampoline2(raw);
generate_trampoline(raw, 1);
}
else
#endif
if constexpr (callabi == x86_cdecl)
else if constexpr (callabi == x86_cdecl)
{
generate_trampoline(reinterpret_cast<void*>(&dynamic_function::_callback_trunk_cdecl_x86));
}
Expand Down
4 changes: 4 additions & 0 deletions src/asm/x86_ms_pe_masm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ _trampoline2_code_end:

ALIGN 4
generate_trampoline proc public
mov eax, DWORD PTR [ebp + 14];
test eax, eax;
jnz generate_trampoline2;
push ebp
mov ebp, esp
push edi
push esi
mov edi, DWORD PTR [ebp + 8] ; <-- edi is now _jit_code
lea esi, trampoline_code ; < -- esi is now &trampoline_code
mov ecx, (_callback_trunk_cdecl_x86_address - trampoline_code)
Expand Down
6 changes: 3 additions & 3 deletions src/trampoline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

extern "C" // from assembly code
{
extern std::size_t generate_trampoline(void* jit_code_address, const void* call_target);
extern std::size_t generate_trampoline(void* jit_code_address, const void* call_target, int select_asm_model);
}

void trampoline::dynamic_function_base::generate_trampoline(const void* wrap_func_ptr)
void trampoline::dynamic_function_base::generate_trampoline(const void* wrap_func_ptr, int select_asm_model)
{
auto code_size = ::generate_trampoline(_jit_code, wrap_func_ptr);
auto code_size = ::generate_trampoline(_jit_code, wrap_func_ptr, select_asm_model);
assert(code_size <= _jit_code_size);
ExecutableAllocator{}.protect(this, sizeof (*this));
}

0 comments on commit 4aa3fa8

Please sign in to comment.