Add cpu.has_pku()
From the Intel Software Developer's Manual 2A:
Initial EAX Value: 7
ECX Bit 03: PKU, supports protection keys for user-mode pages if 1.
LOW_COVERAGE_REASON=Added a test, but it's hardware specific
Change-Id: I3d83e00dc66e04d4b5d0924fd11eeb03ce2b4972
Bug: v8:13355
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3934852
Reviewed-by: Daniel Cheng <[email protected]>
Commit-Queue: Stephen Röttger <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1056215}
diff --git a/base/cpu_unittest.cc b/base/cpu_unittest.cc
index 88cc992..402e386 100644
--- a/base/cpu_unittest.cc
+++ b/base/cpu_unittest.cc
@@ -72,6 +72,14 @@
// Execute an AVX 2 instruction.
__asm__ __volatile__("vpunpcklbw %%ymm0, %%ymm0, %%ymm0\n" : : : "xmm0");
}
+
+ if (cpu.has_pku()) {
+ // rdpkru
+ uint32_t pkru;
+ __asm__ __volatile__(".byte 0x0f,0x01,0xee\n"
+ : "=a"(pkru)
+ : "c"(0), "d"(0));
+ }
// Visual C 32 bit and ClangCL 32/64 bit test.
#elif defined(COMPILER_MSVC) && (defined(ARCH_CPU_32_BITS) || \
(defined(ARCH_CPU_64_BITS) && defined(__clang__)))