tst-tls5.h 559 B

12345678910111213141516171819202122232425262728
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <tls.h>
  4. #if USE_TLS && HAVE___THREAD
  5. struct tls_obj
  6. {
  7. const char *name;
  8. uintptr_t addr;
  9. size_t size;
  10. size_t align;
  11. };
  12. extern struct tls_obj tls_registry[];
  13. #define TLS_REGISTER(x) \
  14. static void __attribute__((constructor)) \
  15. tls_register_##x (void) \
  16. { \
  17. size_t i; \
  18. for (i = 0; tls_registry[i].name; ++i); \
  19. tls_registry[i].name = #x; \
  20. tls_registry[i].addr = (uintptr_t) &x; \
  21. tls_registry[i].size = sizeof (x); \
  22. tls_registry[i].align = __alignof__ (x); \
  23. }
  24. #endif