background image

43-6 Vol. 3D

ENCLAVE CODE DEBUG AND PROFILING

43.5.2.2   LBR Stack on Opt-out Entry

An opt-out entry into an enclave suppresses last branch recording facilities, and enclave exit after an opt-out entry 
un-suppresses last branch recording facilities.
Opt-out entry into an enclave does not push any record on LBR stack.
If last branch recording facilities were enabled at the time of enclave entry, then EEXIT following such an enclave 
entry pushes one record on LBR stack. The MSR_LASTBRANCH_n_FROM_IP of such record holds the linear address 
of the instruction (EENTER or ERESUME) that was used to enter the enclave, while the 
MSR_LASTBRANCH_n_TO_IP of such record holds linear address of the destination of EEXIT. 
Additionally, if last branch recording facilities were enabled at the time of enclave entry, then an AEX after such an 
entry pushes one record on LBR stack, before pushing record for the event causing the AEX if the event pushes a 
record on LBR stack. The MSR_LASTBRANCH_n_FROM_IP of the new record holds linear address of the instruction 
(EENTER or ERESUME) that was used to enter the enclave, while MSR_LASTBRANCH_n_TO_IP of the new record 
holds linear address of the AEP. If the event causing AEX pushes a record on LBR stack, then the 
MSR_LASTBRANCH_n_FROM_IP for that record holds linear address of the AEP.
Figure 43-4 shows an example of LBR stack manipulation after an opt-out entry. Every arrow in this picture indi-
cates a branch record pushed on the LBR stack. The “From IP” of the branch record contains the linear address of 
the instruction located at the start of the arrow, while the “To IP” of the branch record contains the linear address 
of the instruction at the end of the arrow.

Figure 43-3.  LBR Stack Interaction with Opt-in Entry

Inst1

BR2

Inst3

EEXIT

Inst4

AEP

EENTER

Inst4

IRET

OS

Inst4

AEP

AEP

ERESUME

BR5

Inst6

Inst7

Fault