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 
8 #ifndef _RSEQ_X86_THREAD_POINTER
9 #define _RSEQ_X86_THREAD_POINTER
10 
11 #include <features.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #if __GNUC_PREREQ (11, 1)
rseq_thread_pointer(void)18 static inline void *rseq_thread_pointer(void)
19 {
20 	return __builtin_thread_pointer();
21 }
22 #else
23 static inline void *rseq_thread_pointer(void)
24 {
25 	void *__result;
26 
27 # ifdef __x86_64__
28 	__asm__ ("mov %%fs:0, %0" : "=r" (__result));
29 # else
30 	__asm__ ("mov %%gs:0, %0" : "=r" (__result));
31 # endif
32 	return __result;
33 }
34 #endif /* !GCC 11 */
35 
36 #ifdef __cplusplus
37 }
38 #endif
39 
40 #endif
41