[CPU] Check for RawModule memory allocation success

This commit is contained in:
DrChat 2018-02-14 16:21:16 -06:00
parent 02b5a07bc9
commit 7818cdab60
1 changed files with 8 additions and 5 deletions

View File

@ -33,15 +33,18 @@ bool RawModule::LoadFile(uint32_t base_address, const std::wstring& path) {
// Allocate memory. // Allocate memory.
// Since we have no real heap just load it wherever. // Since we have no real heap just load it wherever.
base_address_ = base_address; base_address_ = base_address;
memory_->LookupHeap(base_address_) auto heap = memory_->LookupHeap(base_address_);
->AllocFixed(base_address_, file_length, 0, if (!heap ||
kMemoryAllocationReserve | kMemoryAllocationCommit, !heap->AllocFixed(base_address_, file_length, 0,
kMemoryProtectRead | kMemoryProtectWrite); kMemoryAllocationReserve | kMemoryAllocationCommit,
kMemoryProtectRead | kMemoryProtectWrite)) {
return false;
}
uint8_t* p = memory_->TranslateVirtual(base_address_); uint8_t* p = memory_->TranslateVirtual(base_address_);
// Read into memory. // Read into memory.
fread(p, file_length, 1, file); fread(p, file_length, 1, file);
fclose(file); fclose(file);
// Setup debug info. // Setup debug info.