[Lldb-commits] [lldb] r270254 - Adopt mmap flags that allow mmap'ed memory to be less crash prone.

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri May 20 12:18:22 PDT 2016


Author: gclayton
Date: Fri May 20 14:18:20 2016
New Revision: 270254

URL: http://llvm.org/viewvc/llvm-project?rev=270254&view=rev
Log:
Adopt mmap flags that allow mmap'ed memory to be less crash prone.

On Darwin if a mmap file is code signed and the code signature is invalid, it used to crash. If we specify the MAP_RESILIENT_CODESIGN mmap flag when mapping a file for reading, we can avoid crashing.

Another mmap flag named MAP_RESILIENT_MEDIA allows us to survive if we mmap files that are on removable media like network servers or removable hard drives. If a file was mapped and later the media that had the file became unavailable, we would crash when we would touch the next page that wasn't paged in. Now it will return zeroes and stop of from us from crashing.

<rdar://problem/25918698>


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=270254&r1=270253&r2=270254&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataBufferMemoryMap.cpp (original)
+++ lldb/trunk/source/Core/DataBufferMemoryMap.cpp Fri May 20 14:18:20 2016
@@ -14,8 +14,29 @@
 #include "lldb/Host/windows/windows.h"
 #else
 #include <sys/mman.h>
-#endif
 
+#define MAP_EXTRA_HOST_READ_FLAGS 0
+
+#if defined (__APPLE__)
+//----------------------------------------------------------------------
+// Newer versions of MacOSX have a flag that will allow us to read from
+// binaries whose code signature is invalid without crashing by using
+// the MAP_RESILIENT_CODESIGN flag. Also if a file from removable media
+// is mapped we can avoid crashing and return zeroes to any pages we try
+// to read if the media becomes unavailable by using the
+// MAP_RESILIENT_MEDIA flag.
+//----------------------------------------------------------------------
+#if defined(MAP_RESILIENT_CODESIGN)
+    #undef MAP_EXTRA_HOST_READ_FLAGS
+    #if defined(MAP_RESILIENT_MEDIA)
+        #define MAP_EXTRA_HOST_READ_FLAGS MAP_RESILIENT_CODESIGN | MAP_RESILIENT_MEDIA
+    #else
+        #define MAP_EXTRA_HOST_READ_FLAGS MAP_RESILIENT_CODESIGN
+    #endif
+#endif // #if defined(MAP_RESILIENT_CODESIGN)
+#endif // #if defined (__APPLE__)
+
+#endif // #else #ifdef _WIN32
 // C++ Includes
 #include <cerrno>
 #include <climits>
@@ -255,10 +276,12 @@ DataBufferMemoryMap::MemoryMapFromFileDe
                 if (length > 0)
                 {
                     int prot = PROT_READ;
+                    int flags = MAP_PRIVATE;
                     if (writeable)
                         prot |= PROT_WRITE;
+                    else
+                        flags |= MAP_EXTRA_HOST_READ_FLAGS;
 
-                    int flags = MAP_PRIVATE;
                     if (fd_is_file)
                         flags |= MAP_FILE;
 




More information about the lldb-commits mailing list