[Lldb-commits] win32: Memory mapped have to be aligned on the right boundary
Carlo Kok
ck at remobjects.com
Thu Sep 26 09:27:59 PDT 2013
The current trunk implementation of win32 mapped files works fine if the
start address is 0, but if the start address is not 0, the memory
mapping fails. This is because mapviewoffile has to be aligned on the
system's dwAllocationGranularity. This patch fixes that. (This is used
when loading a Mach-O universal files, which have embedded files in them)
--
Carlo Kok
RemObjects Software
-------------- next part --------------
Index: C:/Projects/oxygene-nougat-llvm/lldb/source/Core/DataBufferMemoryMap.cpp
===================================================================
--- C:/Projects/oxygene-nougat-llvm/lldb/source/Core/DataBufferMemoryMap.cpp (revision 191382)
+++ C:/Projects/oxygene-nougat-llvm/lldb/source/Core/DataBufferMemoryMap.cpp (working copy)
@@ -147,8 +147,18 @@
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
// and the STAT structure is assumed to a valid pointer and already
@@ -206,13 +216,23 @@
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