From ab3a2a024fb58d5ad3e893f1d5694468b187b2d3 Mon Sep 17 00:00:00 2001 From: Raoul Strackx Date: Tue, 29 Mar 2022 15:31:42 +0200 Subject: [PATCH] Unify copying data from enclave to userspace --- library/std/src/sys/sgx/abi/usercalls/alloc.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/library/std/src/sys/sgx/abi/usercalls/alloc.rs b/library/std/src/sys/sgx/abi/usercalls/alloc.rs index 3792a3820a5..9a64b7e4b15 100644 --- a/library/std/src/sys/sgx/abi/usercalls/alloc.rs +++ b/library/std/src/sys/sgx/abi/usercalls/alloc.rs @@ -225,13 +225,9 @@ fn new_uninit_bytes(size: usize) -> Self { /// Copies `val` into freshly allocated space in user memory. pub fn new_from_enclave(val: &T) -> Self { unsafe { - let ret = Self::new_uninit_bytes(mem::size_of_val(val)); - ptr::copy( - val as *const T as *const u8, - ret.0.as_ptr() as *mut u8, - mem::size_of_val(val), - ); - ret + let mut user = Self::new_uninit_bytes(mem::size_of_val(val)); + user.copy_from_enclave(val); + user } }