diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-07 15:36:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-07 15:36:39 +0200 |
commit | b300f9aa2fd11796e63b5029008b33a1ae735928 (patch) | |
tree | 31d96f52a7733dc7de131eea9b096c58a411523f /Kernel/Syscalls/module.cpp | |
parent | 250b52d6e5ef4b57048ef7f52a02ebb2fb87780b (diff) | |
download | serenity-b300f9aa2fd11796e63b5029008b33a1ae735928.zip |
Kernel: Convert KBuffer::copy() => KBuffer::try_copy()
This was a weird KBuffer API that assumed failure was impossible.
This patch converts it to a modern KResultOr<NonnullOwnPtr<KBuffer>> API
and updates the two clients to the new style.
Diffstat (limited to 'Kernel/Syscalls/module.cpp')
-rw-r--r-- | Kernel/Syscalls/module.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Kernel/Syscalls/module.cpp b/Kernel/Syscalls/module.cpp index fe7066505b..b7a05b18e3 100644 --- a/Kernel/Syscalls/module.cpp +++ b/Kernel/Syscalls/module.cpp @@ -41,13 +41,21 @@ KResultOr<FlatPtr> Process::sys$module_load(Userspace<const char*> user_path, si if (!module) return ENOMEM; + KResult section_loading_result = KSuccess; elf_image->for_each_section_of_type(SHT_PROGBITS, [&](const ELF::Image::Section& section) { - if (!section.size()) + if (!section.size() || !section_loading_result.is_error()) + return; + auto section_storage_or_error = KBuffer::try_copy(section.raw_data(), section.size(), Memory::Region::Access::ReadWriteExecute); + if (section_storage_or_error.is_error()) { + section_loading_result = section_storage_or_error.error(); return; - auto section_storage = KBuffer::copy(section.raw_data(), section.size(), Memory::Region::Access::ReadWriteExecute); - section_storage_by_name.set(section.name(), section_storage.data()); + } + auto section_storage = section_storage_or_error.release_value(); + section_storage_by_name.set(section.name(), section_storage->data()); module->sections.append(move(section_storage)); }); + if (section_loading_result.is_error()) + return section_loading_result; bool missing_symbols = false; |