SUSE / libpulp

libpulp enables live patching in user space applications.
GNU Lesser General Public License v2.1
55 stars 11 forks source link

Add support for TLS variables #88

Closed giulianobelinassi closed 2 years ago

giulianobelinassi commented 2 years ago

TLS variables (declared with __thread keyword) are global variables private to each thread. They are implemented by allocating a new variable every time a thread is spawn.

To reference an TLS variable on a livepatch, one can use the following notation:

where banner is the original TLS variable we want to reference, and ti is a variable that will holds the TLS offset metadata required to access banner. Note that ti is not a pointer or reference, but a instance of tls_index.

To reference the original TLS variable, one can write:

void *__tls_get_addr(tls_index *);
void *reference_to_banner = __tls_get_addr(&ti);

and then reference_to_banner will contain a pointer to the original var in current thread.

Signed-off-by: Giuliano Belinassi gbelinassi@suse.de

susematz commented 2 years ago

Very nice! That's a major feature. The implementation seems sound, I like it.