diff --git a/rts/linker/MMap.c b/rts/linker/MMap.c index 22b96936f429d1d961c56cd9f2ec8e6d861a977a..8c797ac679d3e66a4b90c913cdf4ba959217fc9b 100644 --- a/rts/linker/MMap.c +++ b/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; } }