mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
Kernel: Use TRY() in sys$module_load() and sys$module_unload()
This commit is contained in:
parent
56a2594de7
commit
274d535d0e
1 changed files with 6 additions and 17 deletions
|
@ -23,22 +23,13 @@ KResultOr<FlatPtr> Process::sys$module_load(Userspace<const char*> user_path, si
|
||||||
|
|
||||||
REQUIRE_NO_PROMISES;
|
REQUIRE_NO_PROMISES;
|
||||||
|
|
||||||
auto path = get_syscall_path_argument(user_path, path_length);
|
auto path = TRY(get_syscall_path_argument(user_path, path_length));
|
||||||
if (path.is_error())
|
auto description = TRY(VirtualFileSystem::the().open(path->view(), O_RDONLY, 0, current_directory()));
|
||||||
return path.error();
|
auto payload = TRY(description->read_entire_file());
|
||||||
auto description_or_error = VirtualFileSystem::the().open(path.value()->view(), O_RDONLY, 0, current_directory());
|
|
||||||
if (description_or_error.is_error())
|
|
||||||
return description_or_error.error();
|
|
||||||
auto& description = description_or_error.value();
|
|
||||||
auto payload_or_error = description->read_entire_file();
|
|
||||||
if (payload_or_error.is_error())
|
|
||||||
return payload_or_error.error();
|
|
||||||
|
|
||||||
auto& payload = *payload_or_error.value();
|
auto storage = KBuffer::try_create_with_bytes(ReadonlyBytes { payload->data(), payload->size() });
|
||||||
auto storage = KBuffer::try_create_with_size(payload.size());
|
|
||||||
if (!storage)
|
if (!storage)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
memcpy(storage->data(), payload.data(), payload.size());
|
|
||||||
|
|
||||||
auto elf_image = try_make<ELF::Image>(storage->data(), storage->size());
|
auto elf_image = try_make<ELF::Image>(storage->data(), storage->size());
|
||||||
if (!elf_image)
|
if (!elf_image)
|
||||||
|
@ -155,11 +146,9 @@ KResultOr<FlatPtr> Process::sys$module_unload(Userspace<const char*> user_name,
|
||||||
|
|
||||||
REQUIRE_NO_PROMISES;
|
REQUIRE_NO_PROMISES;
|
||||||
|
|
||||||
auto module_name_or_error = try_copy_kstring_from_user(user_name, name_length);
|
auto module_name = TRY(try_copy_kstring_from_user(user_name, name_length));
|
||||||
if (module_name_or_error.is_error())
|
|
||||||
return module_name_or_error.error();
|
|
||||||
|
|
||||||
auto it = g_modules->find(module_name_or_error.value()->view());
|
auto it = g_modules->find(module_name->view());
|
||||||
if (it == g_modules->end())
|
if (it == g_modules->end())
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue