]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sys/sgx/thread.rs
SGX target: convert a bunch of panics to aborts
[rust.git] / src / libstd / sys / sgx / thread.rs
index 13569062ac184cfd99675c800c0c0bb9d33de149..565a523ebe06f3461907456a162965b169c2ac57 100644 (file)
@@ -1,3 +1,4 @@
+#![cfg_attr(test, allow(dead_code))] // why is this necessary?
 use crate::boxed::FnBox;
 use crate::ffi::CStr;
 use crate::io;
@@ -33,7 +34,11 @@ pub(super) fn run(self) {
         }
     }
 
+    #[cfg_attr(test, linkage = "available_externally")]
+    #[export_name = "_ZN16__rust_internals3std3sys3sgx6thread15TASK_QUEUE_INITE"]
     static TASK_QUEUE_INIT: Once = Once::new();
+    #[cfg_attr(test, linkage = "available_externally")]
+    #[export_name = "_ZN16__rust_internals3std3sys3sgx6thread10TASK_QUEUEE"]
     static mut TASK_QUEUE: Option<Mutex<Vec<Task>>> = None;
 
     pub(super) fn lock() -> MutexGuard<'static, Vec<Task>> {
@@ -57,17 +62,15 @@ pub unsafe fn new(_stack: usize, p: Box<dyn FnBox()>)
     }
 
     pub(super) fn entry() {
-        let mut guard = task_queue::lock();
-        let task = guard.pop().expect("Thread started but no tasks pending");
-        drop(guard); // make sure to not hold the task queue lock longer than necessary
+        let mut pending_tasks = task_queue::lock();
+        let task = rtunwrap!(Some, pending_tasks.pop());
+        drop(pending_tasks); // make sure to not hold the task queue lock longer than necessary
         task.run()
     }
 
     pub fn yield_now() {
-        assert_eq!(
-            usercalls::wait(0, usercalls::raw::WAIT_NO).unwrap_err().kind(),
-            io::ErrorKind::WouldBlock
-        );
+        let wait_error = rtunwrap!(Err, usercalls::wait(0, usercalls::raw::WAIT_NO));
+        rtassert!(wait_error.kind() == io::ErrorKind::WouldBlock);
     }
 
     pub fn set_name(_name: &CStr) {
@@ -75,7 +78,7 @@ pub fn set_name(_name: &CStr) {
     }
 
     pub fn sleep(_dur: Duration) {
-        panic!("can't sleep"); // FIXME
+        rtabort!("can't sleep"); // FIXME
     }
 
     pub fn join(self) {