[llvm] r295880 - [Support] Re-add the special OSX flags on mmap.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 13:24:06 PST 2017


Author: zturner
Date: Wed Feb 22 15:24:06 2017
New Revision: 295880

URL: http://llvm.org/viewvc/llvm-project?rev=295880&view=rev
Log:
[Support] Re-add the special OSX flags on mmap.

The problem appears to be that these flags can only be used
when mapping a file for read-only, not for readwrite.  So
we do that here.

Modified:
    llvm/trunk/lib/Support/Unix/Path.inc

Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=295880&r1=295879&r2=295880&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Wed Feb 22 15:24:06 2017
@@ -551,6 +551,25 @@ std::error_code mapped_file_region::init
 
   int flags = (Mode == readwrite) ? MAP_SHARED : MAP_PRIVATE;
   int prot = (Mode == readonly) ? PROT_READ : (PROT_READ | PROT_WRITE);
+#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.  These flags are only usable when mapping
+  // with PROT_READ, so take care not to specify them otherwise.
+  //----------------------------------------------------------------------
+  if (Mode == readonly) {
+#if defined(MAP_RESILIENT_CODESIGN)
+    flags |= MAP_RESILIENT_CODESIGN;
+#endif
+#if defined(MAP_RESILIENT_MEDIA)
+    flags |= MAP_RESILIENT_MEDIA;
+#endif
+  }
+#endif // #if defined (__APPLE__)
 
   Mapping = ::mmap(nullptr, Size, prot, flags, FD, Offset);
   if (Mapping == MAP_FAILED)




More information about the llvm-commits mailing list