mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
Kernel: Add MAP_NORESERVE support to mmap
Rather than lazily committing regions by default, we now commit the entire region unless MAP_NORESERVE is specified. This solves random crashes in low-memory situations where e.g. the malloc heap allocated memory, but using pages that haven't been used before triggers a crash when no more physical memory is available. Use this flag to create large regions without actually committing the backing memory. madvise() can be used to commit arbitrary areas of such regions after creating them.
This commit is contained in:
parent
bc5d6992a4
commit
c3451899bc
7 changed files with 30 additions and 15 deletions
|
@ -120,6 +120,7 @@ void* Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> user_params)
|
|||
bool map_private = flags & MAP_PRIVATE;
|
||||
bool map_stack = flags & MAP_STACK;
|
||||
bool map_fixed = flags & MAP_FIXED;
|
||||
bool map_noreserve = flags & MAP_NORESERVE;
|
||||
|
||||
if (map_shared && map_private)
|
||||
return (void*)-EINVAL;
|
||||
|
@ -148,10 +149,9 @@ void* Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> user_params)
|
|||
if (!region && (!map_fixed && addr != 0))
|
||||
region = allocate_region_with_vmobject({}, size, vmobject, 0, !name.is_null() ? name : "mmap (purgeable)", prot);
|
||||
} else if (map_anonymous) {
|
||||
|
||||
region = allocate_region(range.value(), !name.is_null() ? name : "mmap", prot, false);
|
||||
region = allocate_region(range.value(), !name.is_null() ? name : "mmap", prot, !map_noreserve);
|
||||
if (!region && (!map_fixed && addr != 0))
|
||||
region = allocate_region(allocate_range({}, size), !name.is_null() ? name : "mmap", prot, false);
|
||||
region = allocate_region(allocate_range({}, size), !name.is_null() ? name : "mmap", prot, !map_noreserve);
|
||||
} else {
|
||||
if (offset < 0)
|
||||
return (void*)-EINVAL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue