Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Taudul <wolf@nereid.pl>2022-10-28 02:21:52 +0300
committerBartosz Taudul <wolf@nereid.pl>2022-10-28 02:21:52 +0300
commit970468f937408883e33242d7c1417cfc5e56e8f5 (patch)
tree303b03ea05a0fcd38cb6eb57f6b62503ca79c676
parent898140fbda5eb36ecdbca25e84c0fad576888d63 (diff)
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.
-rw-r--r--public/TracyClient.cpp1
-rw-r--r--public/client/TracyOverride.cpp26
2 files changed, 27 insertions, 0 deletions
diff --git a/public/TracyClient.cpp b/public/TracyClient.cpp
index 4aa4647a..77f81a4a 100644
--- a/public/TracyClient.cpp
+++ b/public/TracyClient.cpp
@@ -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"
diff --git a/public/client/TracyOverride.cpp b/public/client/TracyOverride.cpp
new file mode 100644
index 00000000..591508a7
--- /dev/null
+++ b/public/client/TracyOverride.cpp
@@ -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