diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-11 21:50:12 +0200 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-12 16:09:09 +0200 |
commit | 8a4654a9243deb3db759ca071debdacc64e1e2db (patch) | |
tree | 7d9920a2d5cf90c7a7802deee201d8747325c504 /Kernel | |
parent | d2ffcfb762a579d3803e1bd05fac37cc5b9dfa00 (diff) | |
download | serenity-8a4654a9243deb3db759ca071debdacc64e1e2db.zip |
Kernel: Make PerformanceEventBuffer::add_process fallible with ErrorOr
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/PerformanceEventBuffer.cpp | 21 | ||||
-rw-r--r-- | Kernel/PerformanceEventBuffer.h | 2 | ||||
-rw-r--r-- | Kernel/PerformanceManager.h | 4 | ||||
-rw-r--r-- | Kernel/Process.cpp | 11 |
4 files changed, 22 insertions, 16 deletions
diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index 9a339c5f04..0b87a8b317 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -313,29 +313,34 @@ OwnPtr<PerformanceEventBuffer> PerformanceEventBuffer::try_create_with_size(size return adopt_own_if_nonnull(new (nothrow) PerformanceEventBuffer(buffer_or_error.release_value())); } -void PerformanceEventBuffer::add_process(const Process& process, ProcessEventType event_type) +ErrorOr<void> PerformanceEventBuffer::add_process(const Process& process, ProcessEventType event_type) { SpinlockLocker locker(process.address_space().get_lock()); OwnPtr<KString> executable; if (process.executable()) - executable = MUST(process.executable()->try_serialize_absolute_path()); + executable = TRY(process.executable()->try_serialize_absolute_path()); else - executable = MUST(KString::formatted("<{}>", process.name())); + executable = TRY(KString::formatted("<{}>", process.name())); - [[maybe_unused]] auto rc = append_with_ip_and_bp(process.pid(), 0, 0, 0, + TRY(append_with_ip_and_bp(process.pid(), 0, 0, 0, event_type == ProcessEventType::Create ? PERF_EVENT_PROCESS_CREATE : PERF_EVENT_PROCESS_EXEC, - 0, process.pid().value(), 0, executable->view()); + 0, process.pid().value(), 0, executable->view())); + ErrorOr<void> result; process.for_each_thread([&](auto& thread) { - [[maybe_unused]] auto rc = append_with_ip_and_bp(process.pid(), thread.tid().value(), + result = append_with_ip_and_bp(process.pid(), thread.tid().value(), 0, 0, PERF_EVENT_THREAD_CREATE, 0, 0, 0, nullptr); + return result.is_error() ? IterationDecision::Break : IterationDecision::Continue; }); + TRY(result); for (auto const& region : process.address_space().regions()) { - [[maybe_unused]] auto rc = append_with_ip_and_bp(process.pid(), 0, - 0, 0, PERF_EVENT_MMAP, 0, region->range().base().get(), region->range().size(), region->name()); + TRY(append_with_ip_and_bp(process.pid(), 0, + 0, 0, PERF_EVENT_MMAP, 0, region->range().base().get(), region->range().size(), region->name())); } + + return {}; } ErrorOr<FlatPtr> PerformanceEventBuffer::register_string(NonnullOwnPtr<KString> string) diff --git a/Kernel/PerformanceEventBuffer.h b/Kernel/PerformanceEventBuffer.h index aa5a21bcb0..e07ca5ce1b 100644 --- a/Kernel/PerformanceEventBuffer.h +++ b/Kernel/PerformanceEventBuffer.h @@ -121,7 +121,7 @@ public: ErrorOr<void> to_json(KBufferBuilder&) const; - void add_process(const Process&, ProcessEventType event_type); + ErrorOr<void> add_process(const Process&, ProcessEventType event_type); ErrorOr<FlatPtr> register_string(NonnullOwnPtr<KString>); diff --git a/Kernel/PerformanceManager.h b/Kernel/PerformanceManager.h index 99ac5af73a..aba2e199b0 100644 --- a/Kernel/PerformanceManager.h +++ b/Kernel/PerformanceManager.h @@ -18,14 +18,14 @@ public: { if (g_profiling_all_threads) { VERIFY(g_global_perf_events); - g_global_perf_events->add_process(process, ProcessEventType::Create); + (void)g_global_perf_events->add_process(process, ProcessEventType::Create); } } inline static void add_process_exec_event(Process& process) { if (auto* event_buffer = process.current_perf_events_buffer()) { - event_buffer->add_process(process, ProcessEventType::Exec); + (void)event_buffer->add_process(process, ProcessEventType::Exec); } } diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index de1f395742..1c29c14249 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -788,11 +788,12 @@ void Process::tracer_trap(Thread& thread, const RegisterState& regs) bool Process::create_perf_events_buffer_if_needed() { - if (!m_perf_event_buffer) { - m_perf_event_buffer = PerformanceEventBuffer::try_create_with_size(4 * MiB); - m_perf_event_buffer->add_process(*this, ProcessEventType::Create); - } - return !!m_perf_event_buffer; + if (m_perf_event_buffer) + return true; + m_perf_event_buffer = PerformanceEventBuffer::try_create_with_size(4 * MiB); + if (!m_perf_event_buffer) + return false; + return !m_perf_event_buffer->add_process(*this, ProcessEventType::Create).is_error(); } void Process::delete_perf_events_buffer() |