0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

ircd::info: Proper prctl check for cpuid availability.

This commit is contained in:
Jason Volk 2022-08-20 11:30:09 -07:00
parent a2826400a8
commit a3226b3b38
3 changed files with 26 additions and 11 deletions

View file

@ -1313,6 +1313,7 @@ RB_CHK_SYSHEADER(gnu/libc-version.h, [GNU_LIBC_VERSION_H])
RB_CHK_SYSHEADER(gnu/lib-names.h, [GNU_LIB_NAMES_H])
dnl linux platform
RB_CHK_SYSHEADER(asm/prctl.h, [ASM_PRCTL_H])
RB_CHK_SYSHEADER(sys/auxv.h, [SYS_AUXV_H])
RB_CHK_SYSHEADER(sys/sysinfo.h, [SYS_SYSINFO_H])
RB_CHK_SYSHEADER(sys/eventfd.h, [SYS_EVENTFD_H])

View file

@ -110,6 +110,7 @@ namespace ircd::info::hardware::x86
uint8_t llc_assoc(const uint8_t) noexcept;
uint128_t cpuid(const uint &leaf, const uint &subleaf) noexcept;
extern const bool cpuid_enabled;
extern const uint128_t manufact;
extern const uint128_t features;
extern const uint128_t extended_features;

View file

@ -10,8 +10,10 @@
#include <RB_INC_UNISTD_H
#include <RB_INC_CPUID_H
#include <RB_INC_ASM_PRCTL_H
#include <RB_INC_SYS_AUXV_H
#include <RB_INC_SYS_SYSINFO_H
#include <RB_INC_SYS_SYSCALL_H
#include <RB_INC_GNU_LIBC_VERSION_H
namespace ircd::info
@ -275,6 +277,16 @@ ircd::info::dump_cpu_info_x86()
// x86::x86
//
decltype(ircd::info::hardware::x86::cpuid_enabled)
ircd::info::hardware::x86::cpuid_enabled
{
#if defined(__x86_64__) && defined(HAVE_ASM_PRCTL_H)
sys::call<SYS_arch_prctl, sys::call::NOTHROW>(ARCH_GET_CPUID, nullptr) == 1
#else
false
#endif
};
decltype(ircd::info::hardware::x86::manufact)
ircd::info::hardware::x86::manufact
{
@ -430,17 +442,18 @@ ircd::info::hardware::x86::cpuid(const uint &leaf,
const uint &subleaf)
noexcept
{
uint32_t reg[4];
asm volatile
(
"cpuid" "\n\t"
: "=a" (reg[0]),
"=b" (reg[1]),
"=c" (reg[2]),
"=d" (reg[3])
: "0" (leaf),
"2" (subleaf)
);
uint32_t reg[4] {0};
if(likely(cpuid_enabled))
asm volatile
(
"cpuid" "\n\t"
: "=a" (reg[0]),
"=b" (reg[1]),
"=c" (reg[2]),
"=d" (reg[3])
: "0" (leaf),
"2" (subleaf)
);
return uint128_t
{