summaryrefslogtreecommitdiff
path: root/rts/Linker.c
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-11-23 14:58:15 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-12-01 19:58:17 -0500
commit97d71646ddf3814de62573100ed0b224d1588cbc (patch)
treeef0db7a064554e585528ed9f76d799a77157c9bb /rts/Linker.c
parentadd0aeaefd4d823d31315564e924ce8c018fb69e (diff)
downloadhaskell-97d71646ddf3814de62573100ed0b224d1588cbc.tar.gz
rts/linker: Introduce munmapForLinker
Consolidates munmap calls to ensure consistent error handling.
Diffstat (limited to 'rts/Linker.c')
-rw-r--r--rts/Linker.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index 6873b1a9b7..eebde2a799 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -1149,6 +1149,14 @@ mmapAnonForLinker (size_t bytes)
return mmapForLinker (bytes, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, -1, 0);
}
+void munmapForLinker (void *addr, size_t bytes, const char *caller)
+{
+ int r = munmap(addr, bytes);
+ if (r == -1) {
+ // Should we abort here?
+ sysErrorBelch("munmap: %s", caller);
+ }
+}
/* Note [Memory protection in the linker]
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1235,7 +1243,7 @@ freePreloadObjectFile (ObjectCode *oc)
#else
if (RTS_LINKER_USE_MMAP && oc->imageMapped) {
- munmap(oc->image, oc->fileSize);
+ munmapForLinker(oc->image, oc->fileSize, "freePreloadObjectFile");
}
else {
stgFree(oc->image);
@@ -1283,8 +1291,10 @@ void freeObjectCode (ObjectCode *oc)
switch(oc->sections[i].alloc){
#if RTS_LINKER_USE_MMAP
case SECTION_MMAP:
- munmap(oc->sections[i].mapped_start,
- oc->sections[i].mapped_size);
+ munmapForLinker(
+ oc->sections[i].mapped_start,
+ oc->sections[i].mapped_size,
+ "freeObjectCode");
break;
case SECTION_M32:
// Freed by m32_allocator_free
@@ -2053,7 +2063,7 @@ void freeSegments (ObjectCode *oc)
continue;
} else {
#if RTS_LINKER_USE_MMAP
- CHECKM(0 == munmap(s->start, s->size), "freeSegments: failed to unmap memory");
+ munmapForLinker(s->start, s->size, "freeSegments");
#else
stgFree(s->start);
#endif