ia32-64/x86/eremove.html
2025-07-08 02:23:29 -03:00

265 lines
9.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:x86="http://www.felixcloutier.com/x86"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style.css"></link><title>EREMOVE
— Remove a page from the EPC</title></head><body><header><nav><ul><li><a href='index.html'>Index</a></li><li>December 2023</li></ul></nav></header><h1>EREMOVE
— Remove a page from the EPC</h1>
<table>
<tr>
<th>Opcode/Instruction</th>
<th>Op/En</th>
<th>64/32 bit Mode Support</th>
<th>CPUID Feature Flag</th>
<th>Description</th></tr>
<tr>
<td>EAX = 03H ENCLS[EREMOVE]</td>
<td>IR</td>
<td>V/V</td>
<td>SGX1</td>
<td>This leaf function removes a page from the EPC.</td></tr></table>
<h2 id="instruction-operand-encoding">Instruction Operand Encoding<a class="anchor" href="#instruction-operand-encoding">
</a></h2>
<table>
<tr>
<td>Op/En</td>
<td colspan="2">EAX</td>
<td>RCX</td></tr>
<tr>
<td>IR</td>
<td>EREMOVE (In)</td>
<td>Return error code (Out)</td>
<td>Effective address of the EPC page (In)</td></tr></table>
<h3 id="description">Description<a class="anchor" href="#description">
</a></h3>
<p>This leaf function causes an EPC page to be un-associated with its SECS and be marked as unused. This instruction leaf can only be executed when the current privilege level is 0.</p>
<p>The content of RCX is an effective address of an EPC page. The DS segment is used to create linear address. Segment override is not supported.</p>
<p>The instruction fails if the operand is not properly aligned or does not refer to an EPC page or the page is in use by another thread, or other threads are running in the enclave to which the page belongs. In addition the instruction fails if the operand refers to an SECS with associations.</p>
<h2 id="eremove-memory-parameter-semantics">EREMOVE Memory Parameter Semantics<a class="anchor" href="#eremove-memory-parameter-semantics">
</a></h2>
<table>
<tr>
<td>EPCPAGE</td></tr>
<tr>
<td>Write access permitted by Enclave</td></tr></table>
<p>The instruction faults if any of the following:</p>
<h2 id="eremove-faulting-conditions">EREMOVE Faulting Conditions<a class="anchor" href="#eremove-faulting-conditions">
</a></h2>
<table>
<tr>
<td>The memory operand is not properly aligned.</td>
<td>The memory operand does not resolve in an EPC page.</td></tr>
<tr>
<td>Refers to an invalid SECS.</td>
<td>Refers to an EPC page that is locked by another thread.</td></tr>
<tr>
<td>Another Intel SGX instruction is accessing the EPC page.</td>
<td>RCX does not contain an effective address of an EPC page.</td></tr>
<tr>
<td>the EPC page refers to an SECS with associations.</td>
<td></td></tr></table>
<p>The error codes are:</p>
<figure id="tbl-38-42">
<table>
<tr>
<th>Error Code (see <span class="not-imported">Table 38-4</span>)</th>
<th>Description</th></tr>
<tr>
<td>No Error</td>
<td>EREMOVE successful.</td></tr>
<tr>
<td>SGX_CHILD_PRESENT</td>
<td>If the SECS still have enclave pages loaded into EPC.</td></tr>
<tr>
<td>SGX_ENCLAVE_ACT</td>
<td>If there are still logical processors executing inside the enclave.</td></tr></table>
<figcaption><span class="not-imported">Table 38-42</span>. EREMOVE Return Value in RAX</figcaption></figure>
<h3 id="concurrency-restrictions">Concurrency Restrictions<a class="anchor" href="#concurrency-restrictions">
</a></h3>
<figure id="tbl-38-43">
<table>
<tr>
<th rowspan="2">Leaf</th>
<th rowspan="2">Parameter</th>
<th colspan="3">Base Concurrency Restrictions</th></tr>
<tr>
<th></th>
<th>On Conflict </th>
<th></th></tr>
<tr>
<td>EREMOVE EREMOVE
Target [DS:RCX]
Exclusive #GP EREMOVE
Target [DS:RCX]
</td>
<td>Target [DS:RCX]</td>
<td></td>
<td></td>
<td></td></tr></table>
<figcaption><span class="not-imported">Table 38-43</span>. Base Concurrency Restrictions of EREMOVE</figcaption></figure>
<figure id="tbl-38-44">
<table>
<tr>
<th rowspan="3">Leaf</th>
<th rowspan="3">Parameter</th>
<th colspan="6">Additional Concurrency Restrictions</th></tr>
<tr>
<th colspan="2">vs. EACCEPT, EACCEPTCOPY, vs. EADD, EEXTEND, EINIT
vs. ETRACK, ETRACKC
Access vs. ETRACK, ETRACKC
Access On Conflict
Access vs. ETRACK, ETRACKC
Access On Conflict
EMODPE, EMODPR, EMODT</th>
<th colspan="2">vs. EADD, EEXTEND, EINIT vs. EADD, EEXTEND, EINIT
vs. ETRACK, ETRACKC
</th>
<th colspan="2">vs. ETRACK, ETRACKC</th></tr>
<tr>
<th>Access On Conflict
Access On Conflict
Access Access On Conflict
Access On Conflict
</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th></tr>
<tr>
<td>EREMOVE</td>
<td>Target [DS:RCX]</td>
<td>Concurrent</td>
<td></td>
<td>Concurrent</td>
<td></td>
<td>Concurrent</td>
<td></td></tr></table>
<figcaption><span class="not-imported">Table 38-44</span>. Additional Concurrency Restrictions of EREMOVE</figcaption></figure>
<h3 id="operation">Operation<a class="anchor" href="#operation">
</a></h3>
<h2 id="temp-variables-in-eremove-operational-flow">Temp Variables in EREMOVE Operational Flow<a class="anchor" href="#temp-variables-in-eremove-operational-flow">
</a></h2>
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Size (Bits)</th>
<th>Description</th></tr>
<tr>
<td>TMP_SECS</td>
<td>Effective Address</td>
<td>32/64</td>
<td>Effective address of the SECS destination page.</td></tr></table>
<p>IF (DS:RCX is not 4KByte Aligned)</p>
<p>THEN #GP(0); FI;</p>
<p>IF (DS:RCX does not resolve to an EPC page)</p>
<p>THEN #PF(DS:RCX); FI;</p>
<p>TMP_SECS := Get_SECS_ADDRESS();</p>
<p>(* Check the EPC page for concurrency *)</p>
<p>IF (EPC page being referenced by another Intel SGX instruction)</p>
<p>THEN</p>
<p>IF (&lt;&lt;VMX non-root operation&gt;&gt; AND &lt;&lt;ENABLE_EPC_VIRTUALIZATION_EXTENSIONS&gt;&gt;)</p>
<p>THEN</p>
<p>VMCS.Exit_reason := SGX_CONFLICT;</p>
<p>VMCS.Exit_qualification.code := EPC_PAGE_CONFLICT_EXCEPTION;</p>
<p>VMCS.Exit_qualification.error := 0;</p>
<p>VMCS.Guest-physical_address := &lt;&lt; translation of DS:RCX produced by paging &gt;&gt;;</p>
<p>VMCS.Guest-linear_address := DS:RCX;</p>
<p>Deliver VMEXIT;</p>
<p>ELSE</p>
<p>#GP(0);</p>
<p>FI;</p>
<p>FI;</p>
<p>(* if DS:RCX is already unused, nothing to do*)</p>
<p>IF ( (EPCM(DS:RCX).VALID = 0) or (EPCM(DS:RCX).PT = PT_TRIM AND EPCM(DS:RCX).MODIFIED = 0))</p>
<p>THEN GOTO DONE;</p>
<p>FI;</p>
<p>IF ( (EPCM(DS:RCX).PT = PT_VA) OR</p>
<p>((EPCM(DS:RCX).PT = PT_TRIM) AND (EPCM(DS:RCX).MODIFIED = 0)) )</p>
<p>THEN</p>
<p>EPCM(DS:RCX).VALID := 0;</p>
<p>GOTO DONE;</p>
<p>FI;</p>
<p>IF (EPCM(DS:RCX).PT = PT_SECS)</p>
<p>THEN</p>
<p>IF (DS:RCX has an EPC page associated with it)</p>
<p>THEN</p>
<p>RFLAGS.ZF := 1;</p>
<p>RAX := SGX_CHILD_PRESENT;</p>
<p>GOTO ERROR_EXIT;</p>
<p>FI;</p>
<p>(* treat SECS as having a child page when VIRTCHILDCNT is non-zero *)</p>
<p>IF (&lt;&lt;in VMX non-root operation&gt;&gt; AND</p>
<p>&lt;&lt;ENABLE_EPC_VIRTUALIZATION_EXTENSIONS&gt;&gt; AND</p>
<p>(SECS(DS:RCX).VIRTCHILDCNT ≠ 0))</p>
<p>THEN</p>
<p>RFLAGS.ZF := 1;</p>
<p>RAX := SGX_CHILD_PRESENT</p>
<p>GOTO ERROR_EXIT</p>
<p>FI;</p>
<p>EPCM(DS:RCX).VALID := 0;</p>
<p>GOTO DONE;</p>
<p>FI;</p>
<p>IF (Other threads active using SECS)</p>
<p>THEN</p>
<p>RFLAGS.ZF := 1;</p>
<p>RAX := SGX_ENCLAVE_ACT;</p>
<p>GOTO ERROR_EXIT;</p>
<p>FI;</p>
<p>IF ( (EPCM(DS:RCX).PT is PT_REG) or (EPCM(DS:RCX).PT is PT_TCS) or (EPCM(DS:RCX).PT is PT_TRIM) or</p>
<p>(EPCM(DS:RCX).PT is PT_SS_FIRST) or (EPCM(DS:RCX).PT is PT_SS_REST))</p>
<p>THEN</p>
<p>EPCM(DS:RCX).VALID := 0;</p>
<p>GOTO DONE;</p>
<p>FI;</p>
<p>DONE:</p>
<p>RAX := 0;</p>
<p>RFLAGS.ZF := 0;</p>
<p>ERROR_EXIT:</p>
<p>RFLAGS.CF,PF,AF,OF,SF := 0;</p>
<h3 id="flags-affected">Flags Affected<a class="anchor" href="#flags-affected">
</a></h3>
<p>Sets ZF if unsuccessful, otherwise cleared and RAX returns error code. Clears CF, PF, AF, OF, SF.</p>
<h3 class="exceptions" id="protected-mode-exceptions">Protected Mode Exceptions<a class="anchor" href="#protected-mode-exceptions">
</a></h3>
<table>
<tr>
<td rowspan="3">#GP(0)</td>
<td>If a memory operand effective address is outside the DS segment limit.</td></tr>
<tr>
<td>If a memory operand is not properly aligned.</td></tr>
<tr>
<td>If another Intel SGX instruction is accessing the page.</td></tr>
<tr>
<td rowspan="2">#PF(error</td>
<td>code) If a page fault occurs in accessing memory operands.</td></tr>
<tr>
<td>If the memory operand is not an EPC page.</td></tr></table>
<h3 class="exceptions" id="64-bit-mode-exceptions">64-Bit Mode Exceptions<a class="anchor" href="#64-bit-mode-exceptions">
</a></h3>
<table>
<tr>
<td rowspan="3">#GP(0)</td>
<td>If the memory operand is non-canonical form.</td></tr>
<tr>
<td>If a memory operand is not properly aligned.</td></tr>
<tr>
<td>If another Intel SGX instruction is accessing the page.</td></tr>
<tr>
<td rowspan="2">#PF(error</td>
<td>code) If a page fault occurs in accessing memory operands.</td></tr>
<tr>
<td>If the memory operand is not an EPC page.</td></tr></table><footer><p>
This UNOFFICIAL, mechanically-separated, non-verified reference is provided for convenience, but it may be
inc<span style="opacity: 0.2">omp</span>lete or b<sub>r</sub>oke<sub>n</sub> in various obvious or non-obvious
ways. Refer to <a href="https://software.intel.com/en-us/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4">Intel® 64 and IA-32 Architectures Software Developers Manual</a> for anything serious.
</p></footer></body></html>