#ifdef TLS #include #include #include #define PER_THREAD_MEMORY_START typedef struct _TLS_ZONE { \ unsigned long _tls_zone_address; #define PER_THREAD_MEMORY_END } TLS_ZONE; \ int TLS_SIZE = sizeof(TLS_ZONE); unsigned long tls_address(void) { unsigned long addr; asm("mov $0x0, %%rax; \n" "mov %%gs: (%%rax), %%rbx" : "=b" (addr) ::); return addr; } #define READ_THREAD_VARIABLE(name) \ ((TLS_ZONE*)(tls_address()))->name #define WRITE_THREAD_VARIABLE(name, value) \ ((TLS_ZONE*)(tls_address()))->name = value; #endif