diff --git a/src/backend_x64/block_of_code.cpp b/src/backend_x64/block_of_code.cpp index 6f128263..3ffc3003 100644 --- a/src/backend_x64/block_of_code.cpp +++ b/src/backend_x64/block_of_code.cpp @@ -141,7 +141,7 @@ void BlockOfCode::GenMemoryAccessors() { CallFunction(cb.MemoryRead32); ABI_PopCallerSaveRegistersAndAdjustStack(this); ret(); - + align(); read_memory_64 = getCurr(); ABI_PushCallerSaveRegistersAndAdjustStack(this); @@ -227,7 +227,7 @@ void BlockOfCode::nop(size_t size) { } } -void* BlockOfCode::alloc(size_t alloc_size) { +void* BlockOfCode::AllocateFromCodeSpace(size_t alloc_size) { if (size_ + alloc_size >= maxSize_) { throw Xbyak::Error(Xbyak::ERR_CODE_IS_TOO_BIG); } diff --git a/src/backend_x64/block_of_code.h b/src/backend_x64/block_of_code.h index 12ccc9f3..4824e6b6 100644 --- a/src/backend_x64/block_of_code.h +++ b/src/backend_x64/block_of_code.h @@ -129,7 +129,11 @@ public: void int3() { db(0xCC); } void nop(size_t size = 1); - void* alloc(size_t size); + /// Allocate memory of `size` bytes from the same block of memory the code is in. + /// This is useful for objects that need to be placed close to or within code. + /// The lifetime of this memory is the same as the code around it. + void* AllocateFromCodeSpace(size_t size); + void SetCodePtr(CodePtr code_ptr); void EnsurePatchLocationSize(CodePtr begin, size_t size); diff --git a/src/backend_x64/unwind_windows.cpp b/src/backend_x64/unwind_windows.cpp index 8b975ea9..58e47893 100644 --- a/src/backend_x64/unwind_windows.cpp +++ b/src/backend_x64/unwind_windows.cpp @@ -177,7 +177,7 @@ void BlockOfCode::UnwindHandler::Register(BlockOfCode* code) { const auto prolog_info = GetPrologueInformation(); code->align(16); - UNWIND_INFO* unwind_info = static_cast(code->alloc(sizeof(UNWIND_INFO))); + UNWIND_INFO* unwind_info = static_cast(code->AllocateFromCodeSpace(sizeof(UNWIND_INFO))); unwind_info->Version = 1; unwind_info->Flags = 0; // No special exception handling required. unwind_info->SizeOfProlog = prolog_info.prolog_size; @@ -186,11 +186,11 @@ void BlockOfCode::UnwindHandler::Register(BlockOfCode* code) { unwind_info->FrameOffset = 0; // Unused because FrameRegister == 0 // UNWIND_INFO::UnwindCode field: const size_t size_of_unwind_code = sizeof(UNWIND_CODE) * prolog_info.unwind_code.size(); - UNWIND_CODE* unwind_code = static_cast(code->alloc(size_of_unwind_code)); + UNWIND_CODE* unwind_code = static_cast(code->AllocateFromCodeSpace(size_of_unwind_code)); memcpy(unwind_code, prolog_info.unwind_code.data(), size_of_unwind_code); code->align(16); - RUNTIME_FUNCTION* rfuncs = static_cast(code->alloc(sizeof(RUNTIME_FUNCTION))); + RUNTIME_FUNCTION* rfuncs = static_cast(code->AllocateFromCodeSpace(sizeof(RUNTIME_FUNCTION))); rfuncs->BeginAddress = static_cast(reinterpret_cast(code->run_code) - code->getCode()); rfuncs->EndAddress = static_cast(code->maxSize_); rfuncs->UnwindData = static_cast(reinterpret_cast(unwind_info) - code->getCode());