Created
November 9, 2021 01:41
-
-
Save bgaff/e4b5457ab1cf5126fea6327666c63441 to your computer and use it in GitHub Desktop.
11th Gen Core CPU PKRU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <sys/mman.h> | |
static uint32_t rdpkru(void) | |
{ | |
uint32_t ecx = 0; | |
uint32_t edx, pkru; | |
asm volatile(".byte 0x0f,0x01,0xee\n\t" | |
: "=a" (pkru), "=d" (edx) | |
: "c" (ecx)); | |
return pkru; | |
} | |
int main(void) { | |
int pkey = pkey_alloc(0,0); | |
assert(pkey >= 0); | |
uint32_t original_pkru = rdpkru(); | |
for (int iterations = 0; true ; iterations++) { | |
uint32_t pkru = rdpkru(); | |
if (pkru != original_pkru) { | |
fprintf(stderr, "unexpected value on iteration %d value:0x%08x expected:0x%08x\n", | |
iterations, pkru, original_pkru); | |
exit(1); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment