rseq-x86-thread-pointer.h 687 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
  2. /*
  3. * rseq-x86-thread-pointer.h
  4. *
  5. * (C) Copyright 2021 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  6. */
  7. #ifndef _RSEQ_X86_THREAD_POINTER
  8. #define _RSEQ_X86_THREAD_POINTER
  9. #include <features.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #if __GNUC_PREREQ (11, 1)
  14. static inline void *rseq_thread_pointer(void)
  15. {
  16. return __builtin_thread_pointer();
  17. }
  18. #else
  19. static inline void *rseq_thread_pointer(void)
  20. {
  21. void *__result;
  22. # ifdef __x86_64__
  23. __asm__ ("mov %%fs:0, %0" : "=r" (__result));
  24. # else
  25. __asm__ ("mov %%gs:0, %0" : "=r" (__result));
  26. # endif
  27. return __result;
  28. }
  29. #endif /* !GCC 11 */
  30. #ifdef __cplusplus
  31. }
  32. #endif
  33. #endif