summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/module.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-07 15:36:39 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-07 15:36:39 +0200
commitb300f9aa2fd11796e63b5029008b33a1ae735928 (patch)
tree31d96f52a7733dc7de131eea9b096c58a411523f /Kernel/Syscalls/module.cpp
parent250b52d6e5ef4b57048ef7f52a02ebb2fb87780b (diff)
downloadserenity-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.cpp14
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;