Add missing levels to SegmentProt enum
authorArtem Pyanykh <artempyanykh@gmail.com>
Mon, 25 Feb 2019 15:46:42 +0000 (18:46 +0300)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Wed, 20 Mar 2019 23:52:39 +0000 (19:52 -0400)
rts/LinkerInternals.h
rts/linker/MachO.c

index a773b3e..75871a5 100644 (file)
@@ -62,9 +62,24 @@ typedef
         }
    SectionAlloc;
 
+/* Indicates a desired memory protection for pages within a segment. Defined as
+ * enum since it's more explicit and look nicer in a debugger.
+ *
+ * Can be used directly as a substitution for a combination of PROT_X flags on
+ * POSIX systems.
+ */
 typedef enum {
+#if RTS_LINKER_USE_MMAP
+    SEGMENT_PROT_RO  = PROT_READ,
+    SEGMENT_PROT_RX  = PROT_READ | PROT_EXEC,
+    SEGMENT_PROT_RWO = PROT_READ | PROT_WRITE,
+    SEGMENT_PROT_RWX = PROT_READ | PROT_WRITE | PROT_EXEC
+#else
+    SEGMENT_PROT_RO,
     SEGMENT_PROT_RX,
-    SEGMENT_PROT_RW
+    SEGMENT_PROT_RWO,
+    SEGMENT_PROT_RWX
+#endif
 } SegmentProt;
 
 /*
index 7e1af76..b720077 100644 (file)
@@ -1141,9 +1141,9 @@ ocBuildSegments_MachO(ObjectCode *oc)
         initSegment(rwSegment,
                     curMem,
                     roundUpToPage(size_rwSegment),
-                    SEGMENT_PROT_RW,
+                    SEGMENT_PROT_RWO,
                     n_rwSections);
-        IF_DEBUG(linker, debugBelch("ocBuildSegments_MachO: init segment %d (RW) at %p size %zu\n",
+        IF_DEBUG(linker, debugBelch("ocBuildSegments_MachO: init segment %d (RWO) at %p size %zu\n",
                                     curSegment, rwSegment->start, rwSegment->size));
         curMem = (char *)curMem + rwSegment->size;
         curSegment++;
@@ -1155,7 +1155,7 @@ ocBuildSegments_MachO(ObjectCode *oc)
         initSegment(gbZerofillSegment,
                     curMem,
                     roundUpToPage(size_gbZerofillSegment),
-                    SEGMENT_PROT_RW,
+                    SEGMENT_PROT_RWO,
                     n_gbZerofills);
         IF_DEBUG(linker, debugBelch("ocBuildSegments_MachO: init segment %d (GB_ZEROFILL) at %p size %zu\n",
                                     curSegment, gbZerofillSegment->start, gbZerofillSegment->size));