mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 09:05:07 +00:00
Kernel: Replace intersecting ranges in mmap when MAP_FIXED is specified
This behavior is mandated by POSIX and is used by software like Wine after reserving large chunks of the address range.
This commit is contained in:
parent
fd3be7ffcc
commit
ce1bf3724e
1 changed files with 5 additions and 0 deletions
|
@ -189,11 +189,16 @@ ErrorOr<FlatPtr> Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> use
|
||||||
if (map_randomized) {
|
if (map_randomized) {
|
||||||
return address_space().page_directory().range_allocator().try_allocate_randomized(Memory::page_round_up(size), alignment);
|
return address_space().page_directory().range_allocator().try_allocate_randomized(Memory::page_round_up(size), alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto range = address_space().try_allocate_range(VirtualAddress(addr), size, alignment);
|
auto range = address_space().try_allocate_range(VirtualAddress(addr), size, alignment);
|
||||||
if (range.is_error()) {
|
if (range.is_error()) {
|
||||||
if (addr && !map_fixed) {
|
if (addr && !map_fixed) {
|
||||||
// If there's an address but MAP_FIXED wasn't specified, the address is just a hint.
|
// If there's an address but MAP_FIXED wasn't specified, the address is just a hint.
|
||||||
range = address_space().try_allocate_range({}, size, alignment);
|
range = address_space().try_allocate_range({}, size, alignment);
|
||||||
|
} else if (map_fixed) {
|
||||||
|
// If MAP_FIXED is specified, existing mappings that intersect the requested range are removed.
|
||||||
|
TRY(address_space().unmap_mmap_range(VirtualAddress(addr), size));
|
||||||
|
range = address_space().try_allocate_range(VirtualAddress(addr), size, alignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return range;
|
return range;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue