wrpkru

Write Protection Key Rights

WRPKRU

Writes EAX/EDX to PKRU register.

Details

Writes the value in EAX to the Protection Key Rights User register (PKRU); EDX must be zero. PKRU controls read/write access permissions for pages with protection keys (0–15). This instruction is a serializing operation and is available only in 64-bit mode at user mode (CPL=3). No flags are set; if EDX is nonzero, #GP(0) is raised.

Pseudocode Operation

// Write EAX to PKRU, EDX must be zero
IF (EDX ≠ 0) THEN
  #GP(0); // General Protection Fault
ELSE
  PKRU ← EAX;
END;
// No flags modified; instruction is serializing

Example

WRPKRU

Encoding

Binary Layout
0F
+0
01
+1
EF
+2
 
Format Legacy
Opcode NP 0F 01 EF
Extension PKU

Operands

Reference (Intel® SDM)

Instruction Forms

Opcode Instruction Op/En 64/32-bit Mode CPUID Description
NP 0F 01 EF WRPKRU ZO V/V OSPKE Writes EAX into PKRU.

Description

Writes the value of EAX into PKRU. ECX and EDX must be 0 when WRPKRU is executed; otherwise, a generalprotection exception (#GP) occurs. WRPKRU can be executed only if CR4.PKE = 1; otherwise, an invalid-opcode exception (#UD) occurs. Software can discover the value of CR4.PKE by examining CPUID.07H.00H:ECX.OSPKE[4]. On processors that support the Intel 64 Architecture, the high-order 32-bits of RCX, RDX, and RAX are ignored. WRPKRU will never execute speculatively. Memory accesses affected by PKRU register will not execute (even speculatively) until all prior executions of WRPKRU have completed execution and updated the PKRU register.

Operation

IF (ECX = 0 AND EDX = 0)
THEN PKRU := EAX;
ELSE #GP(0);
FI;

Flags Affected

None. C/C++ Compiler Intrinsic Equivalent WRPKRU void _wrpkru(uint32_t);

Exceptions

Protected Mode Exceptions

#GP(0) If ECX ≠ 0. If EDX ≠ 0. #UD If the LOCK prefix is used. If CR4.PKE = 0.

Real-Address Mode Exceptions

Same exceptions as in protected mode.

Virtual-8086 Mode Exceptions

Same exceptions as in protected mode.

Compatibility Mode Exceptions

Same exceptions as in protected mode. WRPKRU—Write Data to User Page Key Register Vol. 2D 6-14

64-Bit Mode Exceptions

Same exceptions as in protected mode. WRPKRU—Write Data to User Page Key Register Vol. 2D 6-15