mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
Kernel: sys$mmap() without MAP_FIXED should consider address a hint
If we can't use that specific address, it's still okay to put it anywhere else in VM.
This commit is contained in:
parent
e2f9e557d3
commit
5ab27e4bdc
1 changed files with 6 additions and 3 deletions
|
@ -134,14 +134,17 @@ void* Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> user_params)
|
||||||
|
|
||||||
Region* region = nullptr;
|
Region* region = nullptr;
|
||||||
auto range = allocate_range(VirtualAddress(addr), size, alignment);
|
auto range = allocate_range(VirtualAddress(addr), size, alignment);
|
||||||
if (!range.is_valid())
|
if (!range.is_valid()) {
|
||||||
|
if (addr && !map_fixed) {
|
||||||
|
// If there's an address but MAP_FIXED wasn't specified, the address is just a hint.
|
||||||
|
range = allocate_range({}, size, alignment);
|
||||||
|
}
|
||||||
return (void*)-ENOMEM;
|
return (void*)-ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
if (map_anonymous) {
|
if (map_anonymous) {
|
||||||
auto strategy = map_noreserve ? AllocationStrategy::None : AllocationStrategy::Reserve;
|
auto strategy = map_noreserve ? AllocationStrategy::None : AllocationStrategy::Reserve;
|
||||||
auto region_or_error = allocate_region(range, !name.is_null() ? name : "mmap", prot, strategy);
|
auto region_or_error = allocate_region(range, !name.is_null() ? name : "mmap", prot, strategy);
|
||||||
if (region_or_error.is_error() && (!map_fixed && addr != 0))
|
|
||||||
region_or_error = allocate_region(allocate_range({}, size), !name.is_null() ? name : "mmap", prot, strategy);
|
|
||||||
if (region_or_error.is_error())
|
if (region_or_error.is_error())
|
||||||
return (void*)region_or_error.error().error();
|
return (void*)region_or_error.error().error();
|
||||||
region = region_or_error.value();
|
region = region_or_error.value();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue