1/* Inline functions for x86 CPU features.
 2   This file is part of the GNU C Library.
 3   Copyright (C) 2024-2025 Free Software Foundation, Inc.
 4
 5   The GNU C Library is free software; you can redistribute it and/or
 6   modify it under the terms of the GNU Lesser General Public
 7   License as published by the Free Software Foundation; either
 8   version 2.1 of the License, or (at your option) any later version.
 9
10   The GNU C Library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with the GNU C Library; if not, see
17   <https://www.gnu.org/licenses/>.  */
18
19#ifndef _SYS_PLATFORM_X86_H
20# error "Never include <bits/platform/features.h> directly; use <sys/platform/x86.h> instead."
21#endif
22
23/* Bits in the feature_1 field in TCB.  */
24
25enum
26{
27  x86_feature_1_ibt		= 1U << 0,
28  x86_feature_1_shstk		= 1U << 1
29};
30
31static __inline__ bool
32x86_cpu_cet_active (unsigned int __index)
33{
34#ifdef __x86_64__
35  unsigned int __feature_1;
36# ifdef __LP64__
37  __asm__ ("mov %%fs:72, %0" : "=r" (__feature_1));
38# else
39  __asm__ ("mov %%fs:40, %0" : "=r" (__feature_1));
40# endif
41  if (__index == x86_cpu_IBT)
42    return __feature_1 & x86_feature_1_ibt;
43  else
44    return __feature_1 & x86_feature_1_shstk;
45#else
46  return false;
47#endif
48}