-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make compatible as submodule to libstd #119
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks OK, but I would like to see the actual libstd integration code for a proper review.
75d184b
to
8f4860d
Compare
856e59d
to
edfe2a2
Compare
ab001c5
to
21a842c
Compare
21a842c
to
e30113e
Compare
236e043
to
3a9b689
Compare
In SGX, invalid return values can happen and you must check for them. Specifically in the case of synchronization primitives, you must not unwind on an error, see rust-lang/rust#59614. Therefore, you should apply something like the following: diff --git a/core/src/thread_parker/sgx.rs b/core/src/thread_parker/sgx.rs
index ed511ce..e323801 100644
--- a/core/src/thread_parker/sgx.rs
+++ b/core/src/thread_parker/sgx.rs
@@ -19,6 +19,9 @@ use super::libstd::{
};
use core::sync::atomic::{AtomicBool, Ordering};
+#[cfg(not(feature = "i-am-libstd"))]
+use std::panic as rtabort;
+
// Helper type for putting a thread to sleep until some other thread wakes it up
pub struct ThreadParker {
parked: AtomicBool,
@@ -55,7 +58,10 @@ impl ThreadParker {
pub fn park(&self) {
while self.parked.load(Ordering::Acquire) {
let result = usercalls::wait(EV_UNPARK, WAIT_INDEFINITE);
- debug_assert_eq!(result.expect("wait returned error") & EV_UNPARK, EV_UNPARK);
+ match result.map(|eventset| eventset & EV_UNPARK) {
+ Ok(EV_UNPARK) => {}
+ _ => rtabort!("usercall wait returned an invalid value"),
+ }
}
}
@@ -65,7 +71,7 @@ impl ThreadParker {
#[inline]
pub fn park_until(&self, _timeout: Instant) -> bool {
// FIXME: https://github.com/fortanix/rust-sgx/issues/31
- panic!("timeout not supported in SGX");
+ rtabort!("timeout not supported in SGX");
}
// Locks the parker to prevent the target thread from exiting. This is
@@ -90,13 +96,11 @@ impl UnparkHandle {
#[inline]
pub fn unpark(self) {
let result = usercalls::send(EV_UNPARK, Some(self.0));
- if cfg!(debug_assertions) {
- if let Err(error) = result {
- // `InvalidInput` may be returned if the thread we send to has
- // already been unparked and exited.
- if error.kind() != io::ErrorKind::InvalidInput {
- panic!("send returned an unexpected error: {:?}", error);
- }
+ if let Err(error) = result {
+ // `InvalidInput` may be returned if the thread we send to has
+ // already been unparked and exited.
+ if error.kind() != io::ErrorKind::InvalidInput {
+ rtabort!("send returned an unexpected error: {:?}", error);
}
}
} |
@jethrogb |
SGX is an security isolation mechanism for running code on untrusted systems. Therefore, the program must detect when the system is trying to manipulate it into an invalid state. If any manipulation is detected, the program must abort and most definitely not try to continue normally. You can read more about these types of attacks in the Iago attacks paper. The error checks in the |
@jethrogb Could you evaluate my attempt to implement what you suggested over in the testing branch: https://github.com/faern/parking_lot/blob/as-libstd-submodule-test/core/src/thread_parker/sgx.rs#L23-L30 ? I applied something very similar to your patch. But I used Not sure it's a good idea to try to unwind or print anything when running outside libstd. Both unwinding and printing to stderr involves locking locks in the background. I suspect doing so if the parking impl is in an inconsistent state might either deadlock or double-panic. |
LGTM. But note that |
833482f
to
82c1f49
Compare
39f3917
to
c1569fd
Compare
8edd981
to
c8c9340
Compare
133: Add version detection for stabilized atomics and checked_add r=Amanieu a=faern Automatically detecting Rust >= 1.34 and make good use of the now stable `AtomicU{8,32}` types as well as `Instant::checked_add`. This has been broken out from #119 since that PR is a bit large and this commit is not really related to the crate being used in libstd. We don't really know when the libstd stuff will be merged anyway, and this could be immediately useful to anyone using `parking_lot` on the latest stable Rust. I'm just generally against "let's just put this in the already open PR, it'll be fine". I find it usually creates more problems than it solves. Co-authored-by: Linus Färnstrand <[email protected]>
9ac9a6e
to
c88b2c2
Compare
Is there any newer version of this work, or any chance this one could be revived? Or perhaps I just need some helpful advise. I imagine this PR includes making the parking_lot types (like |
There are no plans to make parking_lot fully API-compatible with libstd. This PR does not do this. The plan for libstd integration is for the libstd types to become wrappers around |
Are there libstd PR's for that I could look at? Thanks for your work in any case! I definitely have found it faster than libstd, for example in the blocking-permit crate I'm working on. |
You can have a look at rust-lang/rust#56410 but I don't think it will help you much. |
Closing since this is not going to happen. |
Preparing to include this repository as a git submodule under libstd over at rust-lang/rust#56410
This is work in progress. Would like feedback, plus get confirmation from the CI that it works everywhere.