summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHendiadyoin1 <leon2002.la@gmail.com>2022-02-09 15:37:40 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-14 23:28:35 +0100
commit05381753c2364ca42542b516a8fd64fbc0e45c9e (patch)
treef12189c7c876375a62959c55e8c59e3adb3232ce
parent4260638121da86a5311e8540297221b5dbb0fef6 (diff)
downloadserenity-05381753c2364ca42542b516a8fd64fbc0e45c9e.zip
Kernel: Bail out earlier from Process::lookup_stacks_directory
-rw-r--r--Kernel/ProcessSpecificExposed.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp
index b64ebdf0a8..8d93ad4944 100644
--- a/Kernel/ProcessSpecificExposed.cpp
+++ b/Kernel/ProcessSpecificExposed.cpp
@@ -59,21 +59,20 @@ ErrorOr<void> Process::traverse_stacks_directory(FileSystemID fsid, Function<Err
ErrorOr<NonnullRefPtr<Inode>> Process::lookup_stacks_directory(const ProcFS& procfs, StringView name) const
{
- ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> thread_stack_inode { ENOENT };
+ auto maybe_needle = name.to_uint();
+ if (!maybe_needle.has_value())
+ return ENOENT;
+ auto needle = maybe_needle.release_value();
- // FIXME: Try to exit the loop earlier
+ ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> thread_stack_inode { ENOENT };
for_each_thread([&](const Thread& thread) {
int tid = thread.tid().value();
VERIFY(!(tid < 0));
- if (name.to_int() == tid) {
- auto maybe_inode = ProcFSProcessPropertyInode::try_create_for_thread_stack(procfs, thread.tid(), pid());
- if (maybe_inode.is_error()) {
- thread_stack_inode = maybe_inode.release_error();
- return;
- }
-
- thread_stack_inode = maybe_inode.release_value();
+ if (needle == (unsigned)tid) {
+ thread_stack_inode = ProcFSProcessPropertyInode::try_create_for_thread_stack(procfs, thread.tid(), pid());
+ return IterationDecision::Break;
}
+ return IterationDecision::Continue;
});
if (thread_stack_inode.is_error())