Add TRACY_PLATFORM_HEADER hook for unsupported platforms.

Extension point so private/unsupported platforms can plug in their own implementations of the kernel/libc primitives Tracy depends on, without patching the `#if`/`#elif` chains.

Projects supply a platform header via `-DTRACY_PLATFORM_HEADER="\"my_platform.h\""` at build time. Tracy includes it in any TU that needs the hooks. The header toggles per-category `TRACY_HAS_CUSTOM_*` macros and declares matching `tracy::Platform*` functions.

Available hooks:

- `TRACY_HAS_CUSTOM_THREAD_ID` → `PlatformGetThreadId`
- `TRACY_HAS_CUSTOM_USER_INFO` → `PlatformGetHostname`, `PlatformGetUserLogin`, `PlatformGetUserFullName`
- `TRACY_HAS_CUSTOM_SAFE_COPY` → `PlatformSafeMemcpy`
- `TRACY_HAS_CUSTOM_ALLOCATOR` → `PlatformMalloc`, `PlatformFree`, `PlatformRealloc`, `PlatformAllocatorInit`, `PlatformAllocatorThreadInit`, `PlatformAllocatorFinalize`, `PlatformAllocatorThreadFinalize`

Each hook is wired as the first arm of its respective `#if`/`#elif` chain, so existing supported platforms are unaffected.

Template files in `examples/CustomPlatform/` and a new subsection in `manual/tracy.tex` document the mechanism.
This commit is contained in:
Clément Grégoire
2026-05-24 15:41:52 +02:00
parent 84570487bf
commit f93d17a96f
14 changed files with 253 additions and 20 deletions

View File

@@ -51,6 +51,10 @@
#include "TracySystem.hpp"
#ifdef TRACY_PLATFORM_HEADER
# include TRACY_PLATFORM_HEADER
#endif
#if defined _WIN32
extern "C" typedef HRESULT (WINAPI *t_SetThreadDescription)( HANDLE, PCWSTR );
extern "C" typedef HRESULT (WINAPI *t_GetThreadDescription)( HANDLE, PWSTR* );
@@ -69,7 +73,9 @@ namespace detail
TRACY_API uint32_t GetThreadHandleImpl()
{
#if defined _WIN32
#if defined TRACY_HAS_CUSTOM_THREAD_ID
return PlatformGetThreadId();
#elif defined _WIN32
static_assert( sizeof( decltype( GetCurrentThreadId() ) ) <= sizeof( uint32_t ), "Thread handle too big to fit in protocol" );
return uint32_t( GetCurrentThreadId() );
#elif defined __APPLE__
@@ -341,7 +347,9 @@ TRACY_API const char* GetEnvVar( const char* name )
TRACY_API const char* GetUserLogin()
{
#if defined _WIN32
#if defined TRACY_HAS_CUSTOM_USER_INFO
return PlatformGetUserLogin();
#elif defined _WIN32
# if defined TRACY_WIN32_NO_DESKTOP
return "(?)";
# else
@@ -363,7 +371,9 @@ TRACY_API const char* GetUserLogin()
TRACY_API const char* GetUserFullName()
{
#if defined _WIN32
#if defined TRACY_HAS_CUSTOM_USER_INFO
return PlatformGetUserFullName();
#elif defined _WIN32
static char buf[1024];
ULONG size = sizeof( buf );
if( GetUserNameExA( NameDisplay, buf, &size ) ) return buf;