xref: /linux/tools/testing/selftests/rseq/rseq-x86-thread-pointer.h (revision 59e6295fac26b8e85c1ea859cdd89fa1e47519d7)
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 #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 /* !GCC 11 */
33 
34 #ifdef __cplusplus
35 }
36 #endif
37 
38 #endif
39