From 621c68352bdd140ae699700858507c095ba1f3ce Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 1 Jan 2022 17:33:39 +0100 Subject: [PATCH] Call RtlWalkFrameChain directly from inlined function. --- client/TracyCallstack.cpp | 13 ++----------- client/TracyCallstack.hpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index a8d5f729..c76b24e3 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -65,13 +65,12 @@ CallstackEntry cb_data[MaxCbTrace]; extern "C" { - typedef unsigned long (__stdcall *t_RtlWalkFrameChain)( void**, unsigned long, unsigned long ); typedef DWORD (__stdcall *t_SymAddrIncludeInlineTrace)( HANDLE hProcess, DWORD64 Address ); typedef BOOL (__stdcall *t_SymQueryInlineTrace)( HANDLE hProcess, DWORD64 StartAddress, DWORD StartContext, DWORD64 StartRetAddress, DWORD64 CurAddress, LPDWORD CurContext, LPDWORD CurFrameIndex ); typedef BOOL (__stdcall *t_SymFromInlineContext)( HANDLE hProcess, DWORD64 Address, ULONG InlineContext, PDWORD64 Displacement, PSYMBOL_INFO Symbol ); typedef BOOL (__stdcall *t_SymGetLineFromInlineContext)( HANDLE hProcess, DWORD64 qwAddr, ULONG InlineContext, DWORD64 qwModuleBaseAddress, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line64 ); - t_RtlWalkFrameChain RtlWalkFrameChain = 0; + TRACY_API ___tracy_t_RtlWalkFrameChain ___tracy_RtlWalkFrameChain = 0; t_SymAddrIncludeInlineTrace _SymAddrIncludeInlineTrace = 0; t_SymQueryInlineTrace _SymQueryInlineTrace = 0; t_SymFromInlineContext _SymFromInlineContext = 0; @@ -102,7 +101,7 @@ size_t s_krnlCacheCnt; void InitCallstack() { - RtlWalkFrameChain = (t_RtlWalkFrameChain)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlWalkFrameChain" ); + ___tracy_RtlWalkFrameChain = (___tracy_t_RtlWalkFrameChain)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlWalkFrameChain" ); _SymAddrIncludeInlineTrace = (t_SymAddrIncludeInlineTrace)GetProcAddress( GetModuleHandleA( "dbghelp.dll" ), "SymAddrIncludeInlineTrace" ); _SymQueryInlineTrace = (t_SymQueryInlineTrace)GetProcAddress( GetModuleHandleA( "dbghelp.dll" ), "SymQueryInlineTrace" ); _SymFromInlineContext = (t_SymFromInlineContext)GetProcAddress( GetModuleHandleA( "dbghelp.dll" ), "SymFromInlineContext" ); @@ -208,14 +207,6 @@ void InitCallstack() #endif } -TRACY_API uintptr_t* CallTrace( int depth ) -{ - auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) ); - const auto num = RtlWalkFrameChain( (void**)( trace + 1 ), depth, 0 ); - *trace = num; - return trace; -} - const char* DecodeCallstackPtrFast( uint64_t ptr ) { static char ret[MaxNameSize]; diff --git a/client/TracyCallstack.hpp b/client/TracyCallstack.hpp index 1db3f20a..217d69e6 100644 --- a/client/TracyCallstack.hpp +++ b/client/TracyCallstack.hpp @@ -55,12 +55,19 @@ const char* GetKernelModulePath( uint64_t addr ); #if TRACY_HAS_CALLSTACK == 1 -TRACY_API uintptr_t* CallTrace( int depth ); +extern "C" +{ + typedef unsigned long (__stdcall *___tracy_t_RtlWalkFrameChain)( void**, unsigned long, unsigned long ); + TRACY_API extern ___tracy_t_RtlWalkFrameChain ___tracy_RtlWalkFrameChain; +} static tracy_force_inline void* Callstack( int depth ) { assert( depth >= 1 && depth < 63 ); - return CallTrace( depth ); + auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) ); + const auto num = ___tracy_RtlWalkFrameChain( (void**)( trace + 1 ), depth, 0 ); + *trace = num; + return trace; } #elif TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 5