diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-02-24 20:08:48 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-27 20:37:57 +0100 |
commit | feb00b7105bbb55ba28b3fe8b6c526695f77bc84 (patch) | |
tree | 4be5bcdf63171729618deff8194db8fbcdb5bc3f /Kernel/Coredump.cpp | |
parent | 6682afb5d4d6b7455f85fa3a8f07dd14cae4211e (diff) | |
download | serenity-feb00b7105bbb55ba28b3fe8b6c526695f77bc84.zip |
Everywhere: Make JSON serialization fallible
This allows us to eliminate a major source of infallible allocation in
the Kernel, as well as lay down the groundwork for OOM fallibility in
userland.
Diffstat (limited to 'Kernel/Coredump.cpp')
-rw-r--r-- | Kernel/Coredump.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/Kernel/Coredump.cpp b/Kernel/Coredump.cpp index fe4629d53a..47958440f1 100644 --- a/Kernel/Coredump.cpp +++ b/Kernel/Coredump.cpp @@ -220,22 +220,26 @@ ErrorOr<void> Coredump::create_notes_process_data(auto& builder) const TRY(builder.append_bytes(ReadonlyBytes { (void*)&info, sizeof(info) })); { - JsonObjectSerializer process_obj { builder }; - process_obj.add("pid"sv, m_process->pid().value()); - process_obj.add("termination_signal"sv, m_process->termination_signal()); - process_obj.add("executable_path"sv, m_process->executable() ? TRY(m_process->executable()->try_serialize_absolute_path())->view() : ""sv); + auto process_obj = TRY(JsonObjectSerializer<>::try_create(builder)); + TRY(process_obj.add("pid"sv, m_process->pid().value())); + TRY(process_obj.add("termination_signal"sv, m_process->termination_signal())); + TRY(process_obj.add("executable_path"sv, m_process->executable() ? TRY(m_process->executable()->try_serialize_absolute_path())->view() : ""sv)); { - auto arguments_array = process_obj.add_array("arguments"sv); + auto arguments_array = TRY(process_obj.add_array("arguments"sv)); for (auto const& argument : m_process->arguments()) - arguments_array.add(argument.view()); + TRY(arguments_array.add(argument.view())); + TRY(arguments_array.finish()); } { - auto environment_array = process_obj.add_array("environment"sv); + auto environment_array = TRY(process_obj.add_array("environment"sv)); for (auto const& variable : m_process->environment()) - environment_array.add(variable.view()); + TRY(environment_array.add(variable.view())); + TRY(environment_array.finish()); } + + TRY(process_obj.finish()); } TRY(builder.append('\0')); @@ -296,10 +300,12 @@ ErrorOr<void> Coredump::create_notes_metadata_data(auto& builder) const TRY(builder.append_bytes(ReadonlyBytes { (void*)&metadata, sizeof(metadata) })); { - JsonObjectSerializer metadata_obj { builder }; - m_process->for_each_coredump_property([&](auto& key, auto& value) { - metadata_obj.add(key.view(), value.view()); - }); + auto metadata_obj = TRY(JsonObjectSerializer<>::try_create(builder)); + TRY(m_process->for_each_coredump_property([&](auto& key, auto& value) -> ErrorOr<void> { + TRY(metadata_obj.add(key.view(), value.view())); + return {}; + })); + TRY(metadata_obj.finish()); } TRY(builder.append('\0')); return {}; |