1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 22:18:11 +00:00

Kernel+LibC: Add minherit() and MAP_INHERIT_ZERO

This patch adds the minherit() syscall originally invented by OpenBSD.
Only the MAP_INHERIT_ZERO mode is supported for now. If set on an mmap
region, that region will be zeroed out on fork().
This commit is contained in:
Andreas Kling 2020-04-12 20:22:26 +02:00
parent dd00175ae2
commit c19b56dc99
8 changed files with 58 additions and 1 deletions

View file

@ -632,6 +632,32 @@ int Process::sys$madvise(void* address, size_t size, int advice)
return -EINVAL;
}
int Process::sys$minherit(void* address, size_t size, int inherit)
{
REQUIRE_PROMISE(stdio);
auto* region = region_from_range({ VirtualAddress(address), size });
if (!region)
return -EINVAL;
if (!region->is_mmap())
return -EINVAL;
if (region->is_shared())
return -EINVAL;
if (!region->vmobject().is_anonymous())
return -EINVAL;
switch (inherit) {
case MAP_INHERIT_ZERO:
region->set_inherit_mode(Region::InheritMode::ZeroedOnFork);
return 0;
}
return -EINVAL;
}
int Process::sys$purge(int mode)
{
REQUIRE_NO_PROMISES;