added simple c file to test for PKU

parent 34969265
#include <stdio.h>
static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
unsigned int *ecx, unsigned int *edx)
/* ecx is often an input as well as an output. */
asm volatile(
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx)
: "0" (*eax), "2" (*ecx));
/* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx) */
#define X86_FEATURE_PKU (1<<3) /* Protection Keys for Userspace */
#define X86_FEATURE_OSPKE (1<<4) /* OS Protection Keys Enable */
static inline int cpu_has_pku(void)
unsigned int eax;
unsigned int ebx;
unsigned int ecx;
unsigned int edx;
eax = 0x7;
ecx = 0x0;
__cpuid(&eax, &ebx, &ecx, &edx);
if (!(ecx & X86_FEATURE_PKU)) {
printf("cpu does not have PKU\n");
return 0;
if (!(ecx & X86_FEATURE_OSPKE)) {
printf("cpu does not have OSPKE\n");
return 0;
return 1;
int main() {
int has_pku = cpu_has_pku();
printf("CPU has PKU: %d\n", has_pku);
return has_pku;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment