pkru寄存器只能存16个pk,但操作系统切换线程/进程时可以保存pkru,所以是每个线程都能用16个pk。
内存页对应的pk编号存在页表项的第5962位(挨着NX),4bit, 编号015
~ PGD Entry ~ Present ──────┐
Read/Write ──────┐|
User/Supervisor ──────┐||
Page Write Through ──────┐|||
Page Cache Disabled ──────┐ ||||
Accessed ──────┐| ||||
Ignored ──────┐|| ||||
Reserved ──────┐||| ||||
┌─ NX ┌─ Reserved Ignored ──┬──┐ |||| ||||
|┌───────────┐ |┌──────────────────────────────────────────────┐ | | |||| ||||
|| Ignored | || PUD Physical Address | | | |||| ||||
|| | || | | | |||| ||||
0000 0000 0000 0000 0000 0000 0000 0001 0010 0011 1111 1100 1010 0000 0110 0111
56 48 40 32 24 16 8 0
Figure 1. An overview of the MPK architecture. MPK checks the permission of a page per thread according to (1) the PKRU register. The intersection between (2) MPK permissions and (3) page permissions described on the page table determines (4) the effective permissions. Perm.: permission; N/A: not applicable; pkey: protection key; r/w: readable and writable; x/o: executable only; r/w/x: readable, writable and executable.