summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/execve.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-27 21:01:45 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-27 21:14:42 +0100
commite67402c7027f13fcc03d61f88725470e4c66e820 (patch)
tree673d40ced3c4dec8da64200ee21c4c8398d6fcb6 /Kernel/Syscalls/execve.cpp
parent67bc5e0bbdcf313b20b32069a5e9b9806f8bd790 (diff)
downloadserenity-e67402c7027f13fcc03d61f88725470e4c66e820.zip
Kernel: Remove Range "valid" state and use Optional<Range> instead
It's easier to understand VM ranges if they are always valid. We can simply use an empty Optional<Range> to encode absence when needed.
Diffstat (limited to 'Kernel/Syscalls/execve.cpp')
-rw-r--r--Kernel/Syscalls/execve.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp
index 321017622c..83ee25b8e8 100644
--- a/Kernel/Syscalls/execve.cpp
+++ b/Kernel/Syscalls/execve.cpp
@@ -185,12 +185,12 @@ KResultOr<Process::LoadResult> Process::load_elf_object(FileDescription& object_
}
auto range = allocate_range({}, program_header.size_in_memory());
- if (!range.is_valid()) {
+ if (!range.has_value()) {
ph_load_result = ENOMEM;
return IterationDecision::Break;
}
- auto region_or_error = allocate_region(range, String::formatted("{} (master-tls)", elf_name), PROT_READ | PROT_WRITE, AllocationStrategy::Reserve);
+ auto region_or_error = allocate_region(range.value(), String::formatted("{} (master-tls)", elf_name), PROT_READ | PROT_WRITE, AllocationStrategy::Reserve);
if (region_or_error.is_error()) {
ph_load_result = region_or_error.error();
return IterationDecision::Break;
@@ -226,11 +226,11 @@ KResultOr<Process::LoadResult> Process::load_elf_object(FileDescription& object_
prot |= PROT_WRITE;
auto region_name = String::formatted("{} (data-{}{})", elf_name, program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "");
auto range = allocate_range(program_header.vaddr().offset(load_offset), program_header.size_in_memory());
- if (!range.is_valid()) {
+ if (!range.has_value()) {
ph_load_result = ENOMEM;
return IterationDecision::Break;
}
- auto region_or_error = allocate_region(range, region_name, prot, AllocationStrategy::Reserve);
+ auto region_or_error = allocate_region(range.value(), region_name, prot, AllocationStrategy::Reserve);
if (region_or_error.is_error()) {
ph_load_result = region_or_error.error();
return IterationDecision::Break;
@@ -263,11 +263,11 @@ KResultOr<Process::LoadResult> Process::load_elf_object(FileDescription& object_
if (program_header.is_executable())
prot |= PROT_EXEC;
auto range = allocate_range(program_header.vaddr().offset(load_offset), program_header.size_in_memory());
- if (!range.is_valid()) {
+ if (!range.has_value()) {
ph_load_result = ENOMEM;
return IterationDecision::Break;
}
- auto region_or_error = allocate_region_with_vmobject(range, *vmobject, program_header.offset(), elf_name, prot, true);
+ auto region_or_error = allocate_region_with_vmobject(range.value(), *vmobject, program_header.offset(), elf_name, prot, true);
if (region_or_error.is_error()) {
ph_load_result = region_or_error.error();
return IterationDecision::Break;
@@ -288,12 +288,12 @@ KResultOr<Process::LoadResult> Process::load_elf_object(FileDescription& object_
}
auto stack_range = allocate_range({}, Thread::default_userspace_stack_size);
- if (!stack_range.is_valid()) {
+ if (!stack_range.has_value()) {
dbgln("do_exec: Failed to allocate VM range for stack");
return ENOMEM;
}
- auto stack_region_or_error = allocate_region(stack_range, "Stack (Main thread)", PROT_READ | PROT_WRITE, AllocationStrategy::Reserve);
+ auto stack_region_or_error = allocate_region(stack_range.value(), "Stack (Main thread)", PROT_READ | PROT_WRITE, AllocationStrategy::Reserve);
if (stack_region_or_error.is_error())
return stack_region_or_error.error();
auto& stack_region = *stack_region_or_error.value();