| 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); |
nothing calls this directly
no test coverage detected