Implement re-entrancy guard on Linux

This is best-effort as we'd otherwise have to make a lot of assumptions
about libc internals. The limitation is that a listener cannot be attached
to pthread_getspecific/pthread_setspecific.