[Lldb-commits] [lldb] r191447 - On Windows MapViewOfFile requires the offset to be aligned on the system dwAllocationGranularity
Carlo Kok
ck at remobjects.com
Thu Sep 26 11:52:08 PDT 2013
Author: carlokok
Date: Thu Sep 26 13:52:08 2013
New Revision: 191447
URL: http://llvm.org/viewvc/llvm-project?rev=191447&view=rev
Log:
On Windows MapViewOfFile requires the offset to be aligned on the system dwAllocationGranularity
Modified:
lldb/trunk/source/Core/DataBufferMemoryMap.cpp
Modified: lldb/trunk/source/Core/DataBufferMemoryMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataBufferMemoryMap.cpp?rev=191447&r1=191446&r2=191447&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataBufferMemoryMap.cpp (original)
+++ lldb/trunk/source/Core/DataBufferMemoryMap.cpp Thu Sep 26 13:52:08 2013
@@ -147,7 +147,17 @@ DataBufferMemoryMap::MemoryMapFromFileSp
Clear();
return 0;
}
-
+
+
+#ifdef _WIN32
+static size_t win32memmapalignment = 0;
+void LoadWin32MemMapAlignment ()
+{
+ SYSTEM_INFO data;
+ GetSystemInfo(&data);
+ win32memmapalignment = data.dwAllocationGranularity;
+}
+#endif
//----------------------------------------------------------------------
// The file descriptor FD is assumed to already be opened as read only
@@ -206,13 +216,23 @@ DataBufferMemoryMap::MemoryMapFromFileDe
HANDLE fileMapping = CreateFileMapping(handle, NULL, writeable ? PAGE_READWRITE : PAGE_READONLY, file_size_high, file_size_low, NULL);
if (fileMapping != NULL)
{
- m_mmap_addr = (uint8_t*)MapViewOfFile(fileMapping, writeable ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ, (DWORD)(offset >> 32), (DWORD)(offset), length);
- if (m_mmap_addr != NULL)
- {
- m_mmap_size = length;
- m_data = m_mmap_addr;
- m_size = length;
- }
+ if (win32memmapalignment == 0) LoadWin32MemMapAlignment();
+ lldb::offset_t realoffset = offset;
+ lldb::offset_t delta = 0;
+ if (realoffset % win32memmapalignment != 0) {
+ realoffset = realoffset / win32memmapalignment * win32memmapalignment;
+ delta = offset - realoffset;
+ }
+
+ LPVOID data = MapViewOfFile(fileMapping, writeable ? FILE_MAP_WRITE : FILE_MAP_READ, 0, realoffset, length + delta);
+ m_mmap_addr = (uint8_t *)data;
+ if (!data) {
+ Error error;
+ error.SetErrorToErrno ();
+ } else {
+ m_data = m_mmap_addr + delta;
+ m_size = length;
+ }
CloseHandle(fileMapping);
}
}
More information about the lldb-commits
mailing list