You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by di...@apache.org on 2020/10/27 04:37:32 UTC

[incubator-teaclave-sgx-sdk] 01/01: compiler: bump up to nightly-2020-10-25 for new AllocRef trait and AllocError

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

dingyu pushed a commit to branch support-new-allocator
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git

commit c6fd975d5a511aca8c6b027a2351f4c67faaec7a
Author: Yu Ding <di...@gmail.com>
AuthorDate: Mon Oct 26 21:37:08 2020 -0700

    compiler: bump up to nightly-2020-10-25 for new AllocRef trait and AllocError
---
 rust-toolchain               |  2 +-
 sgx_alloc/src/system.rs      | 42 +++++++++++++++++++++---------------------
 sgx_trts/src/oom.rs          | 12 ++++++------
 sgx_tstd/src/error.rs        |  4 ++--
 sgx_tstd/src/lib.rs          |  1 +
 sgx_tstd/src/sync/condvar.rs |  6 +++---
 sgx_tstd/src/sys/cmath.rs    |  4 ++--
 7 files changed, 36 insertions(+), 35 deletions(-)

diff --git a/rust-toolchain b/rust-toolchain
index 641cabd..148ed93 100644
--- a/rust-toolchain
+++ b/rust-toolchain
@@ -1 +1 @@
-nightly-2020-09-10
+nightly-2020-10-25
diff --git a/sgx_alloc/src/system.rs b/sgx_alloc/src/system.rs
index 47ac408..f6f2e7f 100644
--- a/sgx_alloc/src/system.rs
+++ b/sgx_alloc/src/system.rs
@@ -23,7 +23,7 @@
 //! 2018-06-22 Add liballoc components here
 
 use core::alloc::{
-    AllocErr, AllocRef, GlobalAlloc, Layout,
+    AllocError, AllocRef, GlobalAlloc, Layout,
 };
 use core::intrinsics;
 use core::ptr::{self, NonNull};
@@ -43,7 +43,7 @@ pub struct System;
 
 impl System {
     #[inline]
-    fn alloc_impl(&mut self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocErr> {
+    fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocError> {
         match layout.size() {
             0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
             // SAFETY: `layout` is non-zero in size,
@@ -53,7 +53,7 @@ impl System {
                 } else {
                     GlobalAlloc::alloc(self, layout)
                 };
-                let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
+                let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
                 Ok(NonNull::slice_from_raw_parts(ptr, size))
             },
         }
@@ -62,12 +62,12 @@ impl System {
     // Safety: Same as `AllocRef::grow`
     #[inline]
     unsafe fn grow_impl(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
         zeroed: bool,
-    ) -> Result<NonNull<[u8]>, AllocErr> {
+    ) -> Result<NonNull<[u8]>, AllocError> {
         debug_assert!(
             new_layout.size() >= old_layout.size(),
             "`new_layout.size()` must be greater than or equal to `old_layout.size()`"
@@ -85,7 +85,7 @@ impl System {
                 intrinsics::assume(new_size >= old_layout.size());
 
                 let raw_ptr = GlobalAlloc::realloc(self, ptr.as_ptr(), old_layout, new_size);
-                let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
+                let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
                 if zeroed {
                     raw_ptr.add(old_size).write_bytes(0, new_size - old_size);
                 }
@@ -100,7 +100,7 @@ impl System {
             old_size => {
                 let new_ptr = self.alloc_impl(new_layout, zeroed)?;
                 ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), old_size);
-                self.dealloc(ptr, old_layout);
+                core::alloc::AllocRef::dealloc(self, ptr, old_layout);
                 Ok(new_ptr)
             },
         }
@@ -109,17 +109,17 @@ impl System {
 
 unsafe impl AllocRef for System {
     #[inline]
-    fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
+    fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
         self.alloc_impl(layout, false)
     }
 
     #[inline]
-    fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
+    fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
          self.alloc_impl(layout, true)
     }
 
     #[inline]
-    unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
+    unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout) {
         if layout.size() != 0 {
             GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
         }
@@ -127,37 +127,37 @@ unsafe impl AllocRef for System {
 
     #[inline]
     unsafe fn grow(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
-    ) -> Result<NonNull<[u8]>, AllocErr> {
+    ) -> Result<NonNull<[u8]>, AllocError> {
          // SAFETY: all conditions must be upheld by the caller
          self.grow_impl(ptr, old_layout, new_layout, false)
     }
 
     #[inline]
     unsafe fn grow_zeroed(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
-    ) -> Result<NonNull<[u8]>, AllocErr> {
+    ) -> Result<NonNull<[u8]>, AllocError> {
         // SAFETY: all conditions must be upheld by the caller
         self.grow_impl(ptr, old_layout, new_layout, true)
     }
 
     #[inline]
     unsafe fn shrink(
-        &mut self,
+        &self,
         ptr: NonNull<u8>,
         old_layout: Layout,
         new_layout: Layout,
-    ) -> Result<NonNull<[u8]>, AllocErr> {
+    ) -> Result<NonNull<[u8]>, AllocError> {
          match new_layout.size() {
              // SAFETY: conditions must be upheld by the caller
              0 => {
-                 self.dealloc(ptr, old_layout);
+                 core::alloc::AllocRef::dealloc(self, ptr, old_layout);
                  Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
              },
              // SAFETY: `new_size` is non-zero. Other conditions must be upheld by the caller
@@ -166,7 +166,7 @@ unsafe impl AllocRef for System {
                  intrinsics::assume(new_size <= old_layout.size());
 
                  let raw_ptr = GlobalAlloc::realloc(self, ptr.as_ptr(), old_layout, new_size);
-                 let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
+                 let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
                  Ok(NonNull::slice_from_raw_parts(ptr, new_size))
              },
 
@@ -176,9 +176,9 @@ unsafe impl AllocRef for System {
              // `new_ptr`. Thus, the call to `copy_nonoverlapping` is safe. The safety contract
              // for `dealloc` must be upheld by the caller.
              new_size => {
-                 let new_ptr = self.alloc(new_layout)?;
+                 let new_ptr = core::alloc::AllocRef::alloc(self, new_layout)?;
                  ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), new_size);
-                 self.dealloc(ptr, old_layout);
+                 core::alloc::AllocRef::dealloc(self, ptr, old_layout);
                  Ok(new_ptr)
              },
          }
@@ -233,7 +233,7 @@ mod platform {
             if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
                 libc::calloc(layout.size(), 1) as *mut u8
             } else {
-                let ptr = self.alloc(layout);
+                let ptr = GlobalAlloc::alloc(self, layout);
                 if !ptr.is_null() {
                     ptr::write_bytes(ptr, 0, layout.size());
                 }
diff --git a/sgx_trts/src/oom.rs b/sgx_trts/src/oom.rs
index d14fd19..ad6530a 100644
--- a/sgx_trts/src/oom.rs
+++ b/sgx_trts/src/oom.rs
@@ -16,7 +16,7 @@
 // under the License..
 
 use crate::trts;
-use core::alloc::AllocErr;
+use core::alloc::AllocError;
 use core::mem;
 use core::ptr;
 use core::sync::atomic::{AtomicPtr, Ordering};
@@ -24,13 +24,13 @@ use core::sync::atomic::{AtomicPtr, Ordering};
 static SGX_OOM_HANDLER: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
 
 #[allow(clippy::needless_pass_by_value)]
-fn default_oom_handler(_err: AllocErr) -> ! {
+fn default_oom_handler(_err: AllocError) -> ! {
     trts::rsgx_abort()
 }
 
-pub fn rsgx_oom(err: AllocErr) -> ! {
+pub fn rsgx_oom(err: AllocError) -> ! {
     let hook = SGX_OOM_HANDLER.load(Ordering::SeqCst);
-    let handler: fn(AllocErr) -> ! = if hook.is_null() {
+    let handler: fn(AllocError) -> ! = if hook.is_null() {
         default_oom_handler
     } else {
         unsafe { mem::transmute(hook) }
@@ -42,13 +42,13 @@ pub fn rsgx_oom(err: AllocErr) -> ! {
 ///
 /// To avoid recursive OOM failures, it is critical that the OOM handler does
 /// not allocate any memory itself.
-pub fn set_oom_handler(handler: fn(AllocErr) -> !) {
+pub fn set_oom_handler(handler: fn(AllocError) -> !) {
     SGX_OOM_HANDLER.store(handler as *mut (), Ordering::SeqCst);
 }
 
 /// Unregisters the current custom handler, returning it.
 ///
-pub fn take_oom_handler() -> fn(AllocErr) -> ! {
+pub fn take_oom_handler() -> fn(AllocError) -> ! {
     let hook = SGX_OOM_HANDLER.swap(ptr::null_mut(), Ordering::SeqCst);
     if hook.is_null() {
         default_oom_handler
diff --git a/sgx_tstd/src/error.rs b/sgx_tstd/src/error.rs
index f01d8a0..7fd4d49 100644
--- a/sgx_tstd/src/error.rs
+++ b/sgx_tstd/src/error.rs
@@ -17,7 +17,7 @@
 
 #[cfg(feature = "backtrace")]
 use crate::backtrace::Backtrace;
-use core::alloc::{AllocErr, LayoutErr};
+use core::alloc::{AllocError, LayoutErr};
 use core::array;
 use core::any::TypeId;
 use core::cell;
@@ -203,7 +203,7 @@ impl Error for ! {
     }
 }
 
-impl Error for AllocErr {
+impl Error for AllocError {
     fn description(&self) -> &str {
         "memory allocation failed"
     }
diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs
index 08b52e0..74d1ca7 100644
--- a/sgx_tstd/src/lib.rs
+++ b/sgx_tstd/src/lib.rs
@@ -56,6 +56,7 @@
 #![feature(char_error_internals)]
 #![feature(concat_idents)]
 #![feature(const_fn)]
+#![feature(const_fn_fn_ptr_basics)]
 #![feature(core_intrinsics)]
 #![feature(custom_test_frameworks)]
 #![feature(dropck_eyepatch)]
diff --git a/sgx_tstd/src/sync/condvar.rs b/sgx_tstd/src/sync/condvar.rs
index 71929c8..48aefbe 100644
--- a/sgx_tstd/src/sync/condvar.rs
+++ b/sgx_tstd/src/sync/condvar.rs
@@ -32,7 +32,7 @@ use sgx_trts::oom;
 use sgx_trts::libc;
 use core::sync::atomic::{AtomicUsize, Ordering};
 use core::fmt;
-use core::alloc::AllocErr;
+use core::alloc::AllocError;
 use alloc_crate::boxed::Box;
 use crate::sync::{mutex, SgxThreadMutex, SgxMutexGuard};
 use crate::sys_common::poison::{self, LockResult, PoisonError};
@@ -426,7 +426,7 @@ impl SgxCondvar {
             let ret = self.inner.broadcast();
             match ret {
                 Err(r) if r == libc::ENOMEM => {
-                    oom::rsgx_oom(AllocErr)
+                    oom::rsgx_oom(AllocError)
                 },
                 _ => {},
             }
@@ -483,4 +483,4 @@ impl Drop for SgxCondvar {
         let result = unsafe { self.inner.destroy() };
         debug_assert_eq!(result, Ok(()), "Error when destroy an SgxCondvar: {}", result.unwrap_err());
     }
-}
\ No newline at end of file
+}
diff --git a/sgx_tstd/src/sys/cmath.rs b/sgx_tstd/src/sys/cmath.rs
index a21825c..c5df605 100644
--- a/sgx_tstd/src/sys/cmath.rs
+++ b/sgx_tstd/src/sys/cmath.rs
@@ -17,7 +17,7 @@
 
 use sgx_libc::{c_float, c_double};
 
-#[link_name = "sgx_tstdc"]
+#[link(name = "sgx_tstdc")]
 extern "C" {
     pub fn acos(n: c_double) -> c_double;
     pub fn acosf(n: c_float) -> c_float;
@@ -45,4 +45,4 @@ extern "C" {
     pub fn tanf(n: c_float) -> c_float;
     pub fn tanh(n: c_double) -> c_double;
     pub fn tanhf(n: c_float) -> c_float;
-}
\ No newline at end of file
+}


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