Skip to content

Commit

Permalink
Fix mapping of files from bundle to only map the necessary part (dotn…
Browse files Browse the repository at this point in the history
…et#42402)

Mapping the whole bundle every time leads to VM space starvation. Which mostly matters on 32bit.
  • Loading branch information
vitek-karas authored Sep 21, 2020
1 parent 42965a1 commit ca0ca12
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/coreclr/src/vm/peimagelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,22 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner)
if (m_FileMap == NULL)
ThrowLastError();

//DWORD lowPart = (DWORD)offset;
//DWORD highPart = (DWORD)(offset >> 32);
char *addr = (char*)CLRMapViewOfFile(m_FileMap, FILE_MAP_READ, 0, 0, 0);
addr += offset;
m_FileView.Assign((LPVOID)addr);

if (m_FileView == NULL)
// - Windows - MapViewOfFileEx requires offset to be allocation granularity aligned (typically 64KB)
// - Linux/OSX - mmap requires offset to be page aligned (PAL sets allocation granularity to page size)
UINT32 alignment = g_SystemInfo.dwAllocationGranularity;
UINT64 mapBegin = AlignDown((UINT64)offset, alignment);
UINT64 mapSize = ((UINT64)(offset + size)) - mapBegin;

_ASSERTE((offset - mapBegin) < alignment);
_ASSERTE((offset - mapBegin) < mapSize);
_ASSERTE(mapSize >= (UINT64)size);

char *addr = (char*)CLRMapViewOfFile(m_FileMap, FILE_MAP_READ, mapBegin >> 32, (DWORD)mapBegin, (DWORD)mapSize);
if (addr == NULL)
ThrowLastError();

addr += (offset - mapBegin);
m_FileView.Assign((LPVOID)addr);
}
Init(m_FileView, (COUNT_T)size);
}
Expand Down

0 comments on commit ca0ca12

Please sign in to comment.