[commit: ghc] master, wip/deploy-docs, wip/packaging-fail, wip/run-nofib, wip/windows-32bit: Add missing levels to SegmentProt enum (cb745c8)

git at git.haskell.org git at git.haskell.org
Thu Mar 21 17:01:02 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branches: master,wip/deploy-docs,wip/packaging-fail,wip/run-nofib,wip/windows-32bit
Link       : http://ghc.haskell.org/trac/ghc/changeset/cb745c84a192c4a1f992649fbda584941f8ec3eb/ghc

>---------------------------------------------------------------

commit cb745c84a192c4a1f992649fbda584941f8ec3eb
Author: Artem Pyanykh <artempyanykh at gmail.com>
Date:   Mon Feb 25 18:46:42 2019 +0300

    Add missing levels to SegmentProt enum


>---------------------------------------------------------------

cb745c84a192c4a1f992649fbda584941f8ec3eb
 rts/LinkerInternals.h | 17 ++++++++++++++++-
 rts/linker/MachO.c    |  6 +++---
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
index a773b3e..75871a5 100644
--- a/rts/LinkerInternals.h
+++ b/rts/LinkerInternals.h
@@ -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;
 
 /*
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
index 7e1af76..b720077 100644
--- a/rts/linker/MachO.c
+++ b/rts/linker/MachO.c
@@ -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));



More information about the ghc-commits mailing list