[Git][ghc/ghc][master] 2 commits: rts/linker: Fix out-of-bounds mapping logic
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Tue Dec 3 22:12:00 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
292ed74e by Ben Gamari at 2024-12-03T17:10:52-05:00
rts/linker: Fix out-of-bounds mapping logic
Previously the structure of `mmapInRegion` concealed a subtle bug
concerning handling of `mmap` returning mappings below the beginning of
the desired region. Specifically, we would reset `p = result + bytes`
and then again reset `p = region->start` before looping around for
another iteration. This resulted in an infinite loop on FreeBSD.
Fixes #25492.
- - - - -
20912f5b by Ben Gamari at 2024-12-03T17:10:52-05:00
rts/linker: Clarify debug output
- - - - -
2 changed files:
- rts/Linker.c
- rts/linker/MMap.c
Changes:
=====================================
rts/Linker.c
=====================================
@@ -1118,7 +1118,7 @@ freePreloadObjectFile (ObjectCode *oc)
*/
void freeObjectCode (ObjectCode *oc)
{
- IF_DEBUG(linker, ocDebugBelch(oc, "start\n"));
+ IF_DEBUG(linker, ocDebugBelch(oc, "freeObjectCode: start\n"));
// Run finalizers
if (oc->type == STATIC_OBJECT &&
=====================================
rts/linker/MMap.c
=====================================
@@ -351,12 +351,7 @@ mmapInRegion (
if (result == NULL) {
// The mapping failed
return NULL;
- } else if (result < region->start) {
- // Uh oh, we assume that mmap() will only give us a
- // an address at or after the requested address.
- // Try again.
- p = (uint8_t *) result + bytes;
- } else if (result < region->end) {
+ } else if (result >= region->start && result < region->end) {
// Success!
region->last = (uint8_t *) result + bytes;
return result;
@@ -364,17 +359,23 @@ mmapInRegion (
// We failed to find a suitable mapping
munmap(result, bytes);
reportMemoryMap();
- errorBelch("mmapForLinker: failed to mmap() memory below 2Gb; "
+ errorBelch("mmapForLinker: failed to mmap() memory between %p and %p; "
"asked for %zu bytes at %p. "
"Try specifying an address with +RTS -xm<addr> -RTS",
- bytes, p);
+ region->start, region->end, bytes, p);
return NULL;
- }
+ } else if (result < region->start) {
+ // Uh oh, we assume that mmap() will only give us a
+ // an address at or after the requested address.
+ // Try bump forward by a bit and try again.
+ p = (uint8_t *) p + bytes;
+ } else if (result >= region->end) {
+ // mmap() gave us too high an address; wrap around and try again
+ wrapped = true;
+ p = region->start;
+ }
- // mmap() gave us too high an address; wrap around and try again
munmap(result, bytes);
- wrapped = true;
- p = region->start;
}
}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f813c8d70e41f0d4663d894db2fee593c71a9772...20912f5bac6fe4146172accc1849d9b762eb45e3
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f813c8d70e41f0d4663d894db2fee593c71a9772...20912f5bac6fe4146172accc1849d9b762eb45e3
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241203/204956f4/attachment-0001.html>
More information about the ghc-commits
mailing list