summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-02-07 20:15:15 -0500
committerBen Gamari <ben@smart-cactus.org>2022-02-09 14:44:42 -0500
commitbbdc9e4fa7aaa2401ad596304712babd5456444c (patch)
tree1b375a42cc5f2924303be68ca69722f81d894941
parentf5c9efa1486d17ebb0598b09ed75ad5af1f0bfc8 (diff)
downloadhaskell-bbdc9e4fa7aaa2401ad596304712babd5456444c.tar.gz
linker: Don't use MAP_FIXED
As noted in #21057, we really shouldn't be using MAP_FIXED. I would much rather have the process crash with a "failed to map" error than randomly overwrite existing mappings. Closes #21057.
-rw-r--r--rts/linker/MMap.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/rts/linker/MMap.c b/rts/linker/MMap.c
index 0fd12dcf5c..207e82ad2e 100644
--- a/rts/linker/MMap.c
+++ b/rts/linker/MMap.c
@@ -177,13 +177,10 @@ mmap_again:
if ((W_)result > 0x80000000) {
// oops, we were given memory over 2Gb
munmap(result,size);
-#if defined(freebsd_HOST_OS) || \
- defined(kfreebsdgnu_HOST_OS) || \
- defined(dragonfly_HOST_OS)
- // Some platforms require MAP_FIXED. This is normally
- // a bad idea, because MAP_FIXED will overwrite
- // existing mappings.
- fixed = MAP_FIXED;
+#if defined(MAP_TRYFIXED)
+ // Some platforms require MAP_FIXED. We use MAP_TRYFIXED since
+ // MAP_FIXED will overwrite existing mappings.
+ fixed = MAP_TRYFIXED;
goto mmap_again;
#else
reportMemoryMap();