mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-24 20:12:53 +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
Notes:
sideshowbarker
2024-07-17 22:23:32 +09:00
Author: https://github.com/BertalanD
Commit: ce1bf3724e
Pull-request: https://github.com/SerenityOS/serenity/pull/11318
Reviewed-by: https://github.com/IdanHo
Reviewed-by: https://github.com/bgianfo ✅
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