From e9c9b2e448ad9026f9e6704d80f5afefd0ce8aa6 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 5 Nov 2024 13:46:53 -0500 Subject: [PATCH] kernel/condition_variable: Make the debug type fetcher a static function. No behavioral change intended. --- headers/private/kernel/condition_variable.h | 6 ++--- src/system/kernel/condition_variable.cpp | 30 ++++++++++----------- src/system/kernel/thread.cpp | 2 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/headers/private/kernel/condition_variable.h b/headers/private/kernel/condition_variable.h index 6648fe5f13..d7c4121a53 100644 --- a/headers/private/kernel/condition_variable.h +++ b/headers/private/kernel/condition_variable.h @@ -1,6 +1,6 @@ /* * Copyright 2007-2011, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2019, Haiku, Inc. All rights reserved. + * Copyright 2019-2024, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _KERNEL_CONDITION_VARIABLE_H @@ -75,8 +75,10 @@ public: const void* Object() const { return fObject; } const char* ObjectType() const { return fObjectType; } + // Debug methods. static void ListAll(); void Dump() const; + static status_t DebugGetType(ConditionVariable* cvar, char* name, size_t size); private: static int32 _Notify(const void* object, bool all, status_t result); @@ -97,8 +99,6 @@ protected: friend struct ConditionVariableEntry; friend struct ConditionVariableHashDefinition; - friend ssize_t debug_condition_variable_type_strlcpy(ConditionVariable* cvar, - char* name, size_t size); }; diff --git a/src/system/kernel/condition_variable.cpp b/src/system/kernel/condition_variable.cpp index c600733089..1f870066bf 100644 --- a/src/system/kernel/condition_variable.cpp +++ b/src/system/kernel/condition_variable.cpp @@ -471,6 +471,20 @@ ConditionVariable::Dump() const } +/*static*/ status_t +ConditionVariable::DebugGetType(ConditionVariable* cvar, char* name, size_t size) +{ + // Use debug_memcpy to handle faults in case the structure is corrupt. + const char* pointer; + status_t status = debug_memcpy(B_CURRENT_TEAM, &pointer, + (int8*)cvar + offsetof(ConditionVariable, fObjectType), sizeof(const char*)); + if (status != B_OK) + return status; + + return debug_strlcpy(B_CURRENT_TEAM, name, pointer, size); +} + + static int list_condition_variables(int argc, char** argv) { @@ -503,7 +517,6 @@ dump_condition_variable(int argc, char** argv) set_debug_variable("_cvar", (addr_t)variable); set_debug_variable("_object", (addr_t)variable->Object()); - } else kprintf("no condition variable at or with key %p\n", (void*)address); @@ -536,18 +549,3 @@ condition_variable_init() "\n" "Lists all published condition variables\n", 0); } - - -ssize_t -debug_condition_variable_type_strlcpy(ConditionVariable* cvar, char* name, size_t size) -{ - const int32 typePointerOffset = offsetof(ConditionVariable, fObjectType); - - const char* pointer; - status_t status = debug_memcpy(B_CURRENT_TEAM, &pointer, - (int8*)cvar + typePointerOffset, sizeof(const char*)); - if (status != B_OK) - return status; - - return debug_strlcpy(B_CURRENT_TEAM, name, pointer, size); -} diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 6e394808bc..e53755322a 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -1711,7 +1711,7 @@ _dump_thread_info(Thread *thread, bool shortInfo) case THREAD_BLOCK_TYPE_CONDITION_VARIABLE: { char name[5]; - ssize_t length = debug_condition_variable_type_strlcpy( + ssize_t length = ConditionVariable::DebugGetType( (ConditionVariable*)thread->wait.object, name, sizeof(name)); if (length > 0) kprintf("cvar:%*s %p ", 4, name, thread->wait.object);