MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / CodeBuffer

Method CodeBuffer

FEXCore/Source/Interface/Core/CPUBackend.cpp:348–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346 }
347
348 CodeBuffer::CodeBuffer(size_t Size)
349 : Size(Size) {
350 Ptr = static_cast<uint8_t*>(FEXCore::Allocator::VirtualAlloc(Size, true));
351 LOGMAN_THROW_A_FMT(!!Ptr, "Couldn't allocate code buffer");
352
353 // Protect the last page of the allocated buffer to trigger SIGSEGV on write access
354 uintptr_t LastPageAddr = AlignDown(reinterpret_cast<uintptr_t>(Ptr) + Size - 1, FEXCore::Utils::FEX_PAGE_SIZE);
355 if (!FEXCore::Allocator::VirtualProtect(reinterpret_cast<void*>(LastPageAddr), FEXCore::Utils::FEX_PAGE_SIZE,
356 FEXCore::Allocator::ProtectOptions::None)) {
357 LogMan::Msg::EFmt("Failed to mprotect last page of code buffer.");
358 }
359
360 LookupCache = fextl::make_unique<GuestToHostMap>();
361 }
362
363 CodeBuffer::~CodeBuffer() {
364 FEXCore::Allocator::VirtualFree(Ptr, Size);

Callers

nothing calls this directly

Calls 4

VirtualAllocFunction · 0.85
AlignDownFunction · 0.85
VirtualProtectFunction · 0.85
EFmtFunction · 0.85

Tested by

no test coverage detected