Override dlclose() to do nothing.

Provide a custom no-op implementation of dlclose(), in order to prevent shared
object data from disappearing from profiler view. The server makes queries for
program executable code, which has to be always available, otherwise wrong
data may be provided, or the program may crash, due to referencing no longer
mapped memory.

The dlclose() documentation states that the function internally decreases the
reference count, and only does unload the shared object when the count reaches
zero. There is no guarantee that the shared object data will be unloaded
immediately after any dlclose call originating from the program. This function
override exploits this fact.
This commit is contained in:
Bartosz Taudul 2022-10-28 01:21:52 +02:00
parent 898140fbda
commit 970468f937
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 27 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "client/tracy_rpmalloc.cpp"
#include "client/TracyDxt1.cpp"
#include "client/TracyAlloc.cpp"
#include "client/TracyOverride.cpp"
#if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
# include "libbacktrace/alloc.cpp"

View File

@ -0,0 +1,26 @@
#ifdef TRACY_ENABLE
# ifdef __linux__
# include "TracyDebug.hpp"
# ifdef TRACY_VERBOSE
# include <dlfcn.h>
# include <link.h>
# endif
extern "C" int dlclose( void* hnd )
{
#ifdef TRACY_VERBOSE
struct link_map* lm;
if( dlinfo( hnd, RTLD_DI_LINKMAP, &lm ) == 0 )
{
TracyDebug( "Overriding dlclose for %s\n", lm->l_name );
}
else
{
TracyDebug( "Overriding dlclose for unknown object (%s)\n", dlerror() );
}
#endif
return 0;
}
# endif
#endif