Skip to content
Snippets Groups Projects
Commit 81861b88 authored by Ben Gamari's avatar Ben Gamari
Browse files

rts: Allow ExecPage to allocate anywhere in address space

Currently the ExecPage facility has two users:

 * GHCi, for constructing info tables, and
 * the adjustor allocation path

Despite neither of these have any spatial locality constraints ExecPage
was using the linker's `mmapAnonForLinker`, which tries hard to ensure
that mappings end up nearby the executable image. This makes adjustor
allocation needlessly subject to fragmentation concerns.

We now instead return less constrained mappings, improving the
robustness of the mechanism.

Addresses #25503.
parent 39bb6e58
No related branches found
No related tags found
1 merge request!13622rts: Allow ExecPage to allocate anywhere in address space
Pipeline #103415 passed
......@@ -10,7 +10,7 @@
#include "linker/MMap.h"
ExecPage *allocateExecPage(void) {
ExecPage *page = (ExecPage *) mmapAnonForLinker(getPageSize());
ExecPage *page = (ExecPage *) mmapAnon(getPageSize());
return page;
}
......
......@@ -207,6 +207,12 @@ memoryAccessToProt(MemoryAccess access)
}
}
void *
mmapAnon (size_t bytes)
{
return VirtualAlloc(NULL, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
}
//
// Returns NULL on failure.
//
......@@ -410,6 +416,15 @@ mmapForLinker (size_t bytes, MemoryAccess access, uint32_t flags, int fd, int of
return result;
}
/*
* Map read/write pages anywhere in memory. Returns NULL on failure.
*/
void *
mmapAnon (size_t bytes)
{
return mmapAnywhere(bytes, MEM_READ_WRITE_THEN_READ_EXECUTE, MAP_ANONYMOUS, -1, 0);
}
/*
* Map read/write pages in low memory. Returns NULL on failure.
*/
......
......@@ -64,7 +64,11 @@ typedef enum {
extern void *mmap_32bit_base;
// Map read/write anonymous memory.
// Map read/write anonymous memory anywhere in memory.
void *mmapAnon(size_t bytes);
// Map read/write anonymous memory, enforcing the constraint of
// placing the mapping within 4GB of the executable image.
void *mmapAnonForLinker (size_t bytes);
// Change protection of previous mapping memory.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment