fixes issue 5507

This commit is contained in:
sktsqrl 2012-07-11 20:54:50 -07:00
parent 1d44de53b5
commit 8dd11bd1c0
2 changed files with 21 additions and 18 deletions

View File

@ -58,22 +58,26 @@ void MemArena::ReleaseSpace()
}
void* MemArena::CreateView(s64 offset, size_t size)
{
#ifdef _WIN32
return MapViewOfFile(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size);
#else
return mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
#endif
}
void* MemArena::CreateViewAt(s64 offset, size_t size, void* base)
void *MemArena::CreateView(s64 offset, size_t size, void *base)
{
#ifdef _WIN32
return MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base);
#else
return mmap(base, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, offset);
void *retval = mmap(
base, size,
PROT_READ | PROT_WRITE,
MAP_SHARED | ((base == nullptr) ? 0 : MAP_FIXED),
fd, offset);
if (retval == MAP_FAILED)
{
NOTICE_LOG(MEMMAP, "mmap on %s failed", ram_temp_file);
return nullptr;
}
else
{
return retval;
}
#endif
}
@ -160,14 +164,14 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32
goto bail;
}
#ifdef _M_X64
*views[i].out_ptr = (u8*)arena->CreateViewAt(
*views[i].out_ptr = (u8*)arena->CreateView(
position, views[i].size, base + views[i].virtual_address);
#else
if (views[i].flags & MV_MIRROR_PREVIOUS) {
// No need to create multiple identical views.
*views[i].out_ptr = *views[i - 1].out_ptr;
} else {
*views[i].out_ptr = (u8*)arena->CreateViewAt(
*views[i].out_ptr = (u8*)arena->CreateView(
position, views[i].size, base + (views[i].virtual_address & 0x3FFFFFFF));
if (!*views[i].out_ptr)
goto bail;

View File

@ -33,12 +33,11 @@ class MemArena
public:
void GrabLowMemSpace(size_t size);
void ReleaseSpace();
void* CreateView(s64 offset, size_t size);
void* CreateViewAt(s64 offset, size_t size, void* base);
void ReleaseView(void* view, size_t size);
void *CreateView(s64 offset, size_t size, void *base = nullptr);
void ReleaseView(void *view, size_t size);
// This only finds 1 GB in 32-bit
static u8* Find4GBBase();
static u8 *Find4GBBase();
private:
#ifdef _WIN32