You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by rd...@apache.org on 2022/09/21 11:29:07 UTC

[incubator-teaclave-sgx-sdk] branch v2.0.0-preview updated: Fix memory alignment issues with calling instructions in Hyper and Sim mode

This is an automated email from the ASF dual-hosted git repository.

rduan pushed a commit to branch v2.0.0-preview
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git


The following commit(s) were added to refs/heads/v2.0.0-preview by this push:
     new 38e1d932 Fix memory alignment issues with calling instructions in Hyper and Sim mode
38e1d932 is described below

commit 38e1d932aedd06ab650cc47b4c14b75ea1086dea
Author: volcano <vo...@163.com>
AuthorDate: Wed Sep 21 19:28:53 2022 +0800

    Fix memory alignment issues with calling instructions in Hyper and Sim mode
---
 sgx_trts/src/inst/hyper/inst.rs | 41 +++++++++++++----------------------------
 sgx_trts/src/inst/hyper/mod.rs  |  4 ++--
 sgx_trts/src/inst/sim/mod.rs    |  4 ++--
 3 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/sgx_trts/src/inst/hyper/inst.rs b/sgx_trts/src/inst/hyper/inst.rs
index 16d577f0..ba5ffa80 100644
--- a/sgx_trts/src/inst/hyper/inst.rs
+++ b/sgx_trts/src/inst/hyper/inst.rs
@@ -57,23 +57,14 @@ impl EncluInst {
     pub fn ereport(ti: &AlignTargetInfo, rd: &AlignReportData) -> Result<AlignReport, u32> {
         unsafe {
             let mut report = MaybeUninit::uninit();
-            asm!("
-                push rbx
-                push rcx
-                push rdx
-
-                mov rbx, {ti}
-                mov rcx, {rd}
-                mov rdx, {report_ptr}
-                vmmcall
-
-                pop rdx
-                pop rcx
-                pop rbx",
-                ti = in(reg) ti,
-                rd = in(reg) rd,
-                report_ptr = in(reg) report.as_mut_ptr(),
+            asm!(
+                "xchg rbx, {0}",
+                "vmmcall",
+                "mov rbx, {0}",
+                inout(reg) ti => _,
                 in("rax") HyperCall::EReport as u64,
+                in("rcx") rd,
+                in("rdx") report.as_mut_ptr(),
             );
             Ok(report.assume_init())
         }
@@ -87,19 +78,13 @@ impl EncluInst {
     pub fn egetkey(kr: &AlignKeyRequest) -> Result<AlignKey, u32> {
         unsafe {
             let mut key = MaybeUninit::uninit();
-            asm!("
-                push rbx
-                push rcx
-
-                mov rbx, {kr}
-                mov rcx, {key_ptr}
-                vmmcall
-
-                pop rcx
-                pop rbx",
-                kr = in(reg) kr,
-                key_ptr = in(reg) key.as_mut_ptr(),
+            asm!(
+                "xchg rbx, {0}",
+                "enclu",
+                "mov rbx, {0}",
+                inout(reg) kr => _,
                 in("rax") HyperCall::EGetkey as u64,
+                in("rcx") key.as_mut_ptr(),
             );
             Ok(key.assume_init())
         }
diff --git a/sgx_trts/src/inst/hyper/mod.rs b/sgx_trts/src/inst/hyper/mod.rs
index 9beea235..00989896 100644
--- a/sgx_trts/src/inst/hyper/mod.rs
+++ b/sgx_trts/src/inst/hyper/mod.rs
@@ -63,11 +63,11 @@ pub unsafe extern "C" fn se3(
             }
             Err(e) => e as usize,
         },
-        Enclu::EAccept => match EncluInst::eaccept(rbx, &*(rcx as *const Secinfo)) {
+        Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const Secinfo), rcx) {
             Ok(_) => 0,
             Err(e) => e as usize,
         },
-        Enclu::EModpe => match EncluInst::emodpe(rbx, &*(rcx as *const Secinfo)) {
+        Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const Secinfo), rcx) {
             Ok(_) => 0,
             Err(e) => e as usize,
         },
diff --git a/sgx_trts/src/inst/sim/mod.rs b/sgx_trts/src/inst/sim/mod.rs
index ec0be7fe..6c87832f 100644
--- a/sgx_trts/src/inst/sim/mod.rs
+++ b/sgx_trts/src/inst/sim/mod.rs
@@ -66,11 +66,11 @@ pub unsafe extern "C" fn se3(
             }
             Err(e) => e as usize,
         },
-        Enclu::EAccept => match EncluInst::eaccept(rbx, &*(rcx as *const Secinfo)) {
+        Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const Secinfo), rcx) {
             Ok(_) => 0,
             Err(e) => e as usize,
         },
-        Enclu::EModpe => match EncluInst::emodpe(rbx, &*(rcx as *const Secinfo)) {
+        Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const Secinfo), rcx) {
             Ok(_) => 0,
             Err(e) => e as usize,
         },


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org