projects/linux·blob master · refs

38 lines · 699 B

1/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
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
12extern "C" {
13#endif
14
15#if __GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1)
16static inline void *rseq_thread_pointer(void)
17{
18 return __builtin_thread_pointer();
19}
20#else
21static 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