Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
microcai committed Jan 8, 2025
1 parent 69cba2b commit d6e98fb
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/asm/x86_64_ms_pe_gas.S
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
.align 16
trampoline_callback_entry:
# 获取本代码的起始位置,存入 r10 寄存器
lea trampoline_callback_entry@GOTPCREL(%rip),%r10
jmpq * jump_address@GOTPCREL(%rip) // 6byte + 8byte
lea trampoline_callback_entry(%rip),%r10
jmpq * jump_address(%rip) // 6byte + 8byte
jump_address: // 保留 8 个字节的空间,generate_trampoline 会在此处填入跳转地址
.space 16, 0xcc

4 changes: 2 additions & 2 deletions src/asm/x86_64_sysv_elf_gas.S
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
.align 16
trampoline_callback_entry:
# 获取本代码的起始位置,存入 r10 寄存器
mov trampoline_callback_entry@GOTPCREL(%rip),%r10
lea trampoline_callback_entry(%rip),%r10
jmpq * jump_address(%rip) // 6byte + 8byte

.align 16
jump_address: // 保留 8 个字节的空间,generate_trampoline 会在此处填入跳转地址
.space 8, 0xcc

12 changes: 6 additions & 6 deletions src/executable_allocator.cpp
Original file line number Diff line number Diff line change
@@ -37,14 +37,15 @@ void ExecutableAllocator::unprotect(void* raw_ptr, std::size_t size)

#else

void * ExecutableAllocator::allocate(std::size_t size)
{
// return malloc(size);
#ifdef MAP_JIT
auto out = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT, -1, 0);
#define MMAP_FLAG (MAP_PRIVATE | MAP_ANONYMOUS|MAP_JIT)
#else
auto out = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#define MMAP_FLAG (MAP_PRIVATE | MAP_ANONYMOUS)
#endif

void * ExecutableAllocator::allocate(std::size_t size)
{
auto out = mmap(0, size, PROT_READ | PROT_WRITE, MMAP_FLAG, -1, 0);
if (out == nullptr)
{
throw std::bad_alloc{};
@@ -54,7 +55,6 @@ void * ExecutableAllocator::allocate(std::size_t size)

void ExecutableAllocator::deallocate(void* raw_ptr, std::size_t size)
{
// free(raw_ptr);
munmap(raw_ptr, size);
}

0 comments on commit d6e98fb

Please sign in to comment.