Skip to content

Commit

Permalink
RTlib: use static TLS for the tramp guard (#99)
Browse files Browse the repository at this point in the history
With dynamic TLS, the call to __tls_get_addr() could reach additional
instrumented code, infinitely recursing back to check the tramp guard.
Static TLS is a limited resource, but this case in RTlib is special
enough to warrant it for safety alone, nevermind performance.
  • Loading branch information
cuviper authored and wrwilliams committed Jun 17, 2016
1 parent ada1d13 commit 73cd001
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dyninstAPI_RT/src/RTcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ int fakeTickCount;
#if defined(_MSC_VER)
#define TLS_VAR __declspec(thread)
#else
#define TLS_VAR __thread
// Note, the initial-exec model gives us static TLS which can be accessed
// directly, unlike dynamic TLS that calls __tls_get_addr(). Such calls risk
// recursing back to us if they're also instrumented, ad infinitum. Static TLS
// must be used very sparingly though, because it is a limited resource.
// *** This case is very special -- do not use IE in general libraries! ***
#define TLS_VAR __thread __attribute__ ((tls_model("initial-exec")))
#endif

TLS_VAR int DYNINST_tls_tramp_guard = 1;
static TLS_VAR char DYNINST_tls_tramp_guard = 1;

DLLEXPORT int DYNINST_lock_tramp_guard()
{
Expand Down

0 comments on commit 73cd001

Please sign in to comment.