mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 11:34:59 +00:00
Kernel: Use TRY() in sys$execve()
There are more opportunities to use TRY() here, but it will require improvements to error propagation first.
This commit is contained in:
parent
982991d92d
commit
6bf901b414
1 changed files with 6 additions and 17 deletions
|
@ -435,11 +435,8 @@ static KResultOr<LoadResult> load_elf_object(NonnullOwnPtr<Memory::AddressSpace>
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stack_region_or_error = new_space->allocate_region(stack_range.value(), "Stack (Main thread)", PROT_READ | PROT_WRITE, AllocationStrategy::Reserve);
|
auto* stack_region = TRY(new_space->allocate_region(stack_range.value(), "Stack (Main thread)", PROT_READ | PROT_WRITE, AllocationStrategy::Reserve));
|
||||||
if (stack_region_or_error.is_error())
|
stack_region->set_stack(true);
|
||||||
return stack_region_or_error.error();
|
|
||||||
auto& stack_region = *stack_region_or_error.value();
|
|
||||||
stack_region.set_stack(true);
|
|
||||||
|
|
||||||
return LoadResult {
|
return LoadResult {
|
||||||
move(new_space),
|
move(new_space),
|
||||||
|
@ -449,7 +446,7 @@ static KResultOr<LoadResult> load_elf_object(NonnullOwnPtr<Memory::AddressSpace>
|
||||||
AK::try_make_weak_ptr(master_tls_region),
|
AK::try_make_weak_ptr(master_tls_region),
|
||||||
master_tls_size,
|
master_tls_size,
|
||||||
master_tls_alignment,
|
master_tls_alignment,
|
||||||
stack_region.make_weak_ptr()
|
stack_region->make_weak_ptr()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,13 +510,9 @@ KResult Process::do_exec(NonnullRefPtr<FileDescription> main_program_description
|
||||||
|
|
||||||
auto main_program_metadata = main_program_description->metadata();
|
auto main_program_metadata = main_program_description->metadata();
|
||||||
|
|
||||||
auto load_result_or_error = load(main_program_description, interpreter_description, main_program_header);
|
auto load_result = TRY(load(main_program_description, interpreter_description, main_program_header));
|
||||||
if (load_result_or_error.is_error()) {
|
|
||||||
dbgln("do_exec: Failed to load main program or interpreter for {}", path);
|
|
||||||
return load_result_or_error.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto signal_trampoline_range = load_result_or_error.value().space->allocate_range({}, PAGE_SIZE);
|
auto signal_trampoline_range = load_result.space->allocate_range({}, PAGE_SIZE);
|
||||||
if (!signal_trampoline_range.has_value()) {
|
if (!signal_trampoline_range.has_value()) {
|
||||||
dbgln("do_exec: Failed to allocate VM for signal trampoline");
|
dbgln("do_exec: Failed to allocate VM for signal trampoline");
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
@ -536,7 +529,6 @@ KResult Process::do_exec(NonnullRefPtr<FileDescription> main_program_description
|
||||||
|
|
||||||
kill_threads_except_self();
|
kill_threads_except_self();
|
||||||
|
|
||||||
auto& load_result = load_result_or_error.value();
|
|
||||||
bool executable_is_setid = false;
|
bool executable_is_setid = false;
|
||||||
|
|
||||||
if (!(main_program_description->custody()->mount_flags() & MS_NOSUID)) {
|
if (!(main_program_description->custody()->mount_flags() & MS_NOSUID)) {
|
||||||
|
@ -858,10 +850,7 @@ KResult Process::exec(String path, Vector<String> arguments, Vector<String> envi
|
||||||
// * ET_EXEC binary that just gets loaded
|
// * ET_EXEC binary that just gets loaded
|
||||||
// * ET_DYN binary that requires a program interpreter
|
// * ET_DYN binary that requires a program interpreter
|
||||||
//
|
//
|
||||||
auto file_or_error = VirtualFileSystem::the().open(path, O_EXEC, 0, current_directory());
|
auto description = TRY(VirtualFileSystem::the().open(path, O_EXEC, 0, current_directory()));
|
||||||
if (file_or_error.is_error())
|
|
||||||
return file_or_error.error();
|
|
||||||
auto description = file_or_error.release_value();
|
|
||||||
auto metadata = description->metadata();
|
auto metadata = description->metadata();
|
||||||
|
|
||||||
if (!metadata.is_regular_file())
|
if (!metadata.is_regular_file())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue