5-12 Vol. 3
PROTECTION
loads the segment selector into the segment register if the DPL is numerically greater
than or equal to both the CPL and the RPL. Otherwise, a general-protection fault is
generated and the segment register is not loaded.
Figure 5-5 shows four procedures (located in codes segments A, B, C, and D), each
running at different privilege levels and each attempting to access the same data
segment.
1. The procedure in code segment A is able to access data segment E using segment
selector E1, because the CPL of code segment A and the RPL of segment selector
E1 are equal to the DPL of data segment E.
2. The procedure in code segment B is able to access data segment E using segment
selector E2, because the CPL of code segment B and the RPL of segment selector
E2 are both numerically lower than (more privileged) than the DPL of data
segment E. A code segment B procedure can also access data segment E using
segment selector E1.
3. The procedure in code segment C is not able to access data segment E using
segment selector E3 (dotted line), because the CPL of code segment C and the
RPL of segment selector E3 are both numerically greater than (less privileged)
than the DPL of data segment E. Even if a code segment C procedure were to use
segment selector E1 or E2, such that the RPL would be acceptable, it still could
not access data segment E because its CPL is not privileged enough.
4. The procedure in code segment D should be able to access data segment E
because code segment D’s CPL is numerically less than the DPL of data segment
E. However, the RPL of segment selector E3 (which the code segment D
procedure is using to access data segment E) is numerically greater than the DPL
of data segment E, so access is not allowed. If the code segment D procedure
were to use segment selector E1 or E2 to access the data segment, access would
be allowed.
Figure 5-4. Privilege Check for Data Access
CPL
RPL
DPL
Privilege
Check
Data-Segment Descriptor
CS Register
Segment Selector
For Data Segment