| 1 |
|
| 2 | |
| 3 | * rseq-x86-thread-pointer.h
|
| 4 | *
|
| 5 | * (C) Copyright 2021 - Mathieu Desnoyers <[email protected]>
|
| 6 |
|
| 7 |
|
| 8 | #ifndef _RSEQ_X86_THREAD_POINTER
|
| 9 | #define _RSEQ_X86_THREAD_POINTER
|
| 10 |
|
| 11 | #ifdef __cplusplus
|
| 12 | extern "C" {
|
| 13 | #endif
|
| 14 |
|
| 15 | #if __GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1)
|
| 16 | static inline void *rseq_thread_pointer(void)
|
| 17 | {
|
| 18 | return __builtin_thread_pointer();
|
| 19 | }
|
| 20 | #else
|
| 21 | static inline void *rseq_thread_pointer(void)
|
| 22 | {
|
| 23 | void *__result;
|
| 24 |
|
| 25 | # ifdef __x86_64__
|
| 26 | __asm__ ("mov %%fs:0, %0" : "=r" (__result));
|
| 27 | # else
|
| 28 | __asm__ ("mov %%gs:0, %0" : "=r" (__result));
|
| 29 | # endif
|
| 30 | return __result;
|
| 31 | }
|
| 32 | #endif
|
| 33 |
|
| 34 | #ifdef __cplusplus
|
| 35 | }
|
| 36 | #endif
|
| 37 |
|
| 38 | #endif
|