background image

Vol. 3D 39-11

ENCLAVE OPERATION

39.5.6 

Eviction of a Version Array Page

VA pages do not belong to any enclave and tracking with ETRACK isn’t necessary. When evicting the VA page, a slot 
in a different VA page must be specified in order to provide versioning of the evicted VA page. 
1. Select a slot in a Version Array page other than the page being evicted. 

— If no VA page exists with an empty slot, create a new one using the EPA leaf function. 

2. Evict the page using the EWB leaf function with parameters include the effective-address pointer to the EPC 

page, the VA slot, a 4K byte buffer to hold the encrypted page contents, and a 128 byte buffer to hold page 
metadata. The last three elements are tied together cryptographically and must be used to later reload the 
page.

39.5.7 

Allocating a Regular Page

On processors that support SGX2, allocating a new page to an already initialized enclave is accomplished by 
invoking the EAUG leaf function. Typically, the enclave requests that the OS allocate a new page at a particular 
location within the enclave’s address space. Once allocated, the page remains in a pending state until the enclave 
executes the corresponding EACCEPT leaf function to accept the new page into the enclave. Page allocation opera-
tions may be batched to improve efficiency. 
The typical process for allocating a regular page is as follows: 
1. Enclave requests additional memory from OS when the current allocation becomes insufficient. 
2. The OS invokes the EAUG leaf function to add a new memory page to the enclave. 

a. EAUG may only be called on a free EPC page. 
b. Successful completion of the EAUG instruction places the target page in the VALID and PENDING state. 
c. All dynamically created pages have the type PT_REG and content of all zeros. 

3. The OS maps the page in the enclave context's mapping tables.
4. The enclave issues an EACCEPT instruction, which verifies the page’s attributes and clears the PENDING state. 

At that point the page becomes accessible for normal enclave use. 

39.5.8 

Allocating a TCS Page 

On processors that support SGX2, allocating a new TCS page to an already initialized enclave is a two-step process. 
First the OS allocates a regular page with a call to EAUG. This page must then be accepted and initialized by the 
enclave to which it belongs. Once the page has been initialized with appropriate values for a TCS page, the enclave 
requests the OS to change the page’s type to PT_TCS. This change must also be accepted. As with allocating a 
regular page, TCS allocation operations may be batched. 
A typical process for allocating a TCS page is as follows: 
1. Enclave requests an additional page from the OS. 
2. The OS invokes EAUG to add a new regular memory page to the enclave. 

a. EAUG may only be called on a free EPC page. 
b. Successful completion of the EAUG instruction places the target page in the VALID and PENDING state. 

3. The OS maps the page in the enclave context's mapping tables.
4. The enclave issues an EACCEPT instruction, at which point the page becomes accessible for normal enclave 

use. 

5. The enclave initializes the contents of the new page. 
6. The enclave requests that the OS convert the page from type PT_REG to PT_TCS. 
7. OS issues an EMODT instruction on the page. 

a. The parameters to EMODT indicate that the regular page should be converted into a TCS.