| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <stdint.h> | 
|  | 2 | #include <stdlib.h> | 
|  | 3 | #include <tls.h> | 
|  | 4 |  | 
|  | 5 |  | 
|  | 6 | struct tls_obj | 
|  | 7 | { | 
|  | 8 | const char *name; | 
|  | 9 | uintptr_t addr; | 
|  | 10 | size_t size; | 
|  | 11 | size_t align; | 
|  | 12 | }; | 
|  | 13 | extern struct tls_obj tls_registry[]; | 
|  | 14 |  | 
|  | 15 | #define TLS_REGISTER(x)				\ | 
|  | 16 | static void __attribute__((constructor))	\ | 
|  | 17 | tls_register_##x (void)				\ | 
|  | 18 | {						\ | 
|  | 19 | size_t i;					\ | 
|  | 20 | for (i = 0; tls_registry[i].name; ++i);	\ | 
|  | 21 | tls_registry[i].name = #x;			\ | 
|  | 22 | tls_registry[i].addr = (uintptr_t) &x;	\ | 
|  | 23 | tls_registry[i].size = sizeof (x);		\ | 
|  | 24 | tls_registry[i].align = __alignof__ (x);	\ | 
|  | 25 | } |