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