1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:27:45 +00:00

Kernel+UE: Add MAP_FIXED_NOREPLACE mmap() flag

This feature was introduced in version 4.17 of the Linux kernel, and
while it's not specified by POSIX, I think it will be a nice addition to
our system.

MAP_FIXED_NOREPLACE provides a less error-prone alternative to
MAP_FIXED: while regular fixed mappings would cause any intersecting
ranges to be unmapped, MAP_FIXED_NOREPLACE returns EEXIST instead. This
ensures that we don't corrupt our process's address space if something
is already at the requested address.

Note that the more portable way to do this is to use regular
MAP_ANONYMOUS, and check afterwards whether the returned address matches
what we wanted. This, however, has a large performance impact on
programs like Wine which try to reserve large portions of the address
space at once, as the non-matching addresses have to be unmapped
separately.
This commit is contained in:
Daniel Bertalan 2021-12-22 12:23:06 +01:00 committed by Andreas Kling
parent 4195a7ef4b
commit 77f9272aaf
6 changed files with 18 additions and 15 deletions

View file

@ -23,6 +23,7 @@ extern "C" {
#define MAP_NORESERVE 0x80
#define MAP_RANDOMIZED 0x100
#define MAP_PURGEABLE 0x200
#define MAP_FIXED_NOREPLACE 0x400
#define PROT_READ 0x1
#define PROT_WRITE 0x2