diff options
| author | David Tolnay <dtolnay@gmail.com> | 2019-11-27 10:28:39 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2019-11-29 18:37:58 -0800 |
| commit | c34fbfaad38cf5829ef5cfe780dc9d58480adeaa (patch) | |
| tree | e57b66ed06aec18dc13ff7f14a243ca3dc3c27d1 /src/libstd/sys/sgx/abi/usercalls | |
| parent | 9081929d45f12d3f56d43b1d6db7519981580fc9 (diff) | |
| download | rust-c34fbfaad38cf5829ef5cfe780dc9d58480adeaa.tar.gz rust-c34fbfaad38cf5829ef5cfe780dc9d58480adeaa.zip | |
Format libstd/sys with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd/sys *that are not involved in any currently open PR*
to minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8
With the list of files from the script in outstanding_files, the
relevant commands were:
$ find src/libstd/sys -name '*.rs' \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ rg libstd/sys outstanding_files | xargs git checkout --
Repeating this process several months apart should get us coverage of
most of the rest of the files.
To confirm no funny business:
$ git checkout $THIS_COMMIT^
$ git show --pretty= --name-only $THIS_COMMIT \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ git diff $THIS_COMMIT # there should be no difference
Diffstat (limited to 'src/libstd/sys/sgx/abi/usercalls')
| -rw-r--r-- | src/libstd/sys/sgx/abi/usercalls/alloc.rs | 99 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/abi/usercalls/mod.rs | 67 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/abi/usercalls/raw.rs | 32 |
3 files changed, 107 insertions, 91 deletions
diff --git a/src/libstd/sys/sgx/abi/usercalls/alloc.rs b/src/libstd/sys/sgx/abi/usercalls/alloc.rs index 75dd0d429c2..b54c115a2b6 100644 --- a/src/libstd/sys/sgx/abi/usercalls/alloc.rs +++ b/src/libstd/sys/sgx/abi/usercalls/alloc.rs @@ -1,14 +1,14 @@ #![allow(unused)] -use crate::ptr::{self, NonNull}; -use crate::mem; use crate::cell::UnsafeCell; +use crate::mem; +use crate::ops::{CoerceUnsized, Deref, DerefMut, Index, IndexMut}; +use crate::ptr::{self, NonNull}; use crate::slice; -use crate::ops::{Deref, DerefMut, Index, IndexMut, CoerceUnsized}; use crate::slice::SliceIndex; -use fortanix_sgx_abi::*; use super::super::mem::is_user_range; +use fortanix_sgx_abi::*; /// A type that can be safely read from or written to userspace. /// @@ -109,9 +109,7 @@ pub unsafe trait UserSafe { /// * the pointer is null. /// * the pointed-to range is not in user memory. unsafe fn check_ptr(ptr: *const Self) { - let is_aligned = |p| -> bool { - 0 == (p as usize) & (Self::align_of() - 1) - }; + let is_aligned = |p| -> bool { 0 == (p as usize) & (Self::align_of() - 1) }; assert!(is_aligned(ptr as *const u8)); assert!(is_user_range(ptr as _, mem::size_of_val(&*ptr))); @@ -183,7 +181,10 @@ impl<T: ?Sized> NewUserRef<NonNull<T>> for NonNull<UserRef<T>> { } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T: ?Sized> User<T> where T: UserSafe { +impl<T: ?Sized> User<T> +where + T: UserSafe, +{ // This function returns memory that is practically uninitialized, but is // not considered "unspecified" or "undefined" for purposes of an // optimizing compiler. This is achieved by returning a pointer from @@ -211,7 +212,7 @@ impl<T: ?Sized> User<T> where T: UserSafe { ptr::copy( val as *const T as *const u8, ret.0.as_ptr() as *mut u8, - mem::size_of_val(val) + mem::size_of_val(val), ); ret } @@ -244,7 +245,10 @@ impl<T: ?Sized> User<T> where T: UserSafe { } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T> User<T> where T: UserSafe { +impl<T> User<T> +where + T: UserSafe, +{ /// Allocate space for `T` in user memory. pub fn uninitialized() -> Self { Self::new_uninit_bytes(mem::size_of::<T>()) @@ -252,7 +256,10 @@ impl<T> User<T> where T: UserSafe { } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T> User<[T]> where [T]: UserSafe { +impl<T> User<[T]> +where + [T]: UserSafe, +{ /// Allocate space for a `[T]` of `n` elements in user memory. pub fn uninitialized(n: usize) -> Self { Self::new_uninit_bytes(n * mem::size_of::<T>()) @@ -278,7 +285,10 @@ impl<T> User<[T]> where [T]: UserSafe { } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T: ?Sized> UserRef<T> where T: UserSafe { +impl<T: ?Sized> UserRef<T> +where + T: UserSafe, +{ /// Creates a `&UserRef<[T]>` from a raw pointer. /// /// # Safety @@ -309,7 +319,7 @@ impl<T: ?Sized> UserRef<T> where T: UserSafe { /// * The pointed-to range is not in user memory pub unsafe fn from_mut_ptr<'a>(ptr: *mut T) -> &'a mut Self { T::check_ptr(ptr); - &mut*(ptr as *mut Self) + &mut *(ptr as *mut Self) } /// Copies `val` into user memory. @@ -319,11 +329,11 @@ impl<T: ?Sized> UserRef<T> where T: UserSafe { /// the source. This can happen for dynamically-sized types such as slices. pub fn copy_from_enclave(&mut self, val: &T) { unsafe { - assert_eq!(mem::size_of_val(val), mem::size_of_val( &*self.0.get() )); + assert_eq!(mem::size_of_val(val), mem::size_of_val(&*self.0.get())); ptr::copy( val as *const T as *const u8, self.0.get() as *mut T as *mut u8, - mem::size_of_val(val) + mem::size_of_val(val), ); } } @@ -335,11 +345,11 @@ impl<T: ?Sized> UserRef<T> where T: UserSafe { /// the source. This can happen for dynamically-sized types such as slices. pub fn copy_to_enclave(&self, dest: &mut T) { unsafe { - assert_eq!(mem::size_of_val(dest), mem::size_of_val( &*self.0.get() )); + assert_eq!(mem::size_of_val(dest), mem::size_of_val(&*self.0.get())); ptr::copy( self.0.get() as *const T as *const u8, dest as *mut T as *mut u8, - mem::size_of_val(dest) + mem::size_of_val(dest), ); } } @@ -356,7 +366,10 @@ impl<T: ?Sized> UserRef<T> where T: UserSafe { } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T> UserRef<T> where T: UserSafe { +impl<T> UserRef<T> +where + T: UserSafe, +{ /// Copies the value from user memory into enclave memory. pub fn to_enclave(&self) -> T { unsafe { ptr::read(self.0.get()) } @@ -364,7 +377,10 @@ impl<T> UserRef<T> where T: UserSafe { } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T> UserRef<[T]> where [T]: UserSafe { +impl<T> UserRef<[T]> +where + [T]: UserSafe, +{ /// Creates a `&UserRef<[T]>` from a raw thin pointer and a slice length. /// /// # Safety @@ -396,7 +412,7 @@ impl<T> UserRef<[T]> where [T]: UserSafe { /// * The pointed-to range does not fit in the address space /// * The pointed-to range is not in user memory pub unsafe fn from_raw_parts_mut<'a>(ptr: *mut T, len: usize) -> &'a mut Self { - &mut*(<[T]>::from_raw_sized(ptr as _, len * mem::size_of::<T>()).as_ptr() as *mut Self) + &mut *(<[T]>::from_raw_sized(ptr as _, len * mem::size_of::<T>()).as_ptr() as *mut Self) } /// Obtain a raw pointer to the first element of this user slice. @@ -439,20 +455,18 @@ impl<T> UserRef<[T]> where [T]: UserSafe { /// Returns an iterator over the slice. pub fn iter(&self) -> Iter<'_, T> - where T: UserSafe // FIXME: should be implied by [T]: UserSafe? + where + T: UserSafe, // FIXME: should be implied by [T]: UserSafe? { - unsafe { - Iter((&*self.as_raw_ptr()).iter()) - } + unsafe { Iter((&*self.as_raw_ptr()).iter()) } } /// Returns an iterator that allows modifying each value. pub fn iter_mut(&mut self) -> IterMut<'_, T> - where T: UserSafe // FIXME: should be implied by [T]: UserSafe? + where + T: UserSafe, // FIXME: should be implied by [T]: UserSafe? { - unsafe { - IterMut((&mut*self.as_raw_mut_ptr()).iter_mut()) - } + unsafe { IterMut((&mut *self.as_raw_mut_ptr()).iter_mut()) } } } @@ -468,9 +482,7 @@ impl<'a, T: UserSafe> Iterator for Iter<'a, T> { #[inline] fn next(&mut self) -> Option<Self::Item> { - unsafe { - self.0.next().map(|e| UserRef::from_ptr(e)) - } + unsafe { self.0.next().map(|e| UserRef::from_ptr(e)) } } } @@ -486,14 +498,15 @@ impl<'a, T: UserSafe> Iterator for IterMut<'a, T> { #[inline] fn next(&mut self) -> Option<Self::Item> { - unsafe { - self.0.next().map(|e| UserRef::from_mut_ptr(e)) - } + unsafe { self.0.next().map(|e| UserRef::from_mut_ptr(e)) } } } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T: ?Sized> Deref for User<T> where T: UserSafe { +impl<T: ?Sized> Deref for User<T> +where + T: UserSafe, +{ type Target = UserRef<T>; fn deref(&self) -> &Self::Target { @@ -502,18 +515,24 @@ impl<T: ?Sized> Deref for User<T> where T: UserSafe { } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T: ?Sized> DerefMut for User<T> where T: UserSafe { +impl<T: ?Sized> DerefMut for User<T> +where + T: UserSafe, +{ fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { &mut*self.0.as_ptr() } + unsafe { &mut *self.0.as_ptr() } } } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T: ?Sized> Drop for User<T> where T: UserSafe { +impl<T: ?Sized> Drop for User<T> +where + T: UserSafe, +{ fn drop(&mut self) { unsafe { let ptr = (*self.0.as_ptr()).0.get(); - super::free(ptr as _, mem::size_of_val(&mut*ptr), T::align_of()); + super::free(ptr as _, mem::size_of_val(&mut *ptr), T::align_of()); } } } @@ -550,7 +569,7 @@ where #[inline] fn index_mut(&mut self, index: I) -> &mut UserRef<I::Output> { unsafe { - if let Some(slice) = index.get_mut(&mut*self.as_raw_mut_ptr()) { + if let Some(slice) = index.get_mut(&mut *self.as_raw_mut_ptr()) { UserRef::from_mut_ptr(slice) } else { rtabort!("index out of range for user slice"); diff --git a/src/libstd/sys/sgx/abi/usercalls/mod.rs b/src/libstd/sys/sgx/abi/usercalls/mod.rs index fca62e028de..ae803ee47a6 100644 --- a/src/libstd/sys/sgx/abi/usercalls/mod.rs +++ b/src/libstd/sys/sgx/abi/usercalls/mod.rs @@ -1,5 +1,5 @@ use crate::cmp; -use crate::io::{Error as IoError, Result as IoResult, IoSlice, IoSliceMut}; +use crate::io::{Error as IoError, IoSlice, IoSliceMut, Result as IoResult}; use crate::time::Duration; pub(crate) mod alloc; @@ -26,7 +26,7 @@ pub fn read(fd: Fd, bufs: &mut [IoSliceMut<'_>]) -> IoResult<usize> { userbuf[index..end].copy_to_enclave(&mut buf[..buflen]); index += buf.len(); } else { - break + break; } } Ok(userbuf.len()) @@ -60,7 +60,7 @@ pub fn write(fd: Fd, bufs: &[IoSlice<'_>]) -> IoResult<usize> { userbuf[index..end].copy_from_enclave(&buf[..buflen]); index += buf.len(); } else { - break + break; } } raw::write(fd, userbuf.as_ptr(), userbuf.len()).from_sgx_result() @@ -90,11 +90,8 @@ pub fn bind_stream(addr: &str) -> IoResult<(Fd, String)> { unsafe { let addr_user = alloc::User::new_from_enclave(addr.as_bytes()); let mut local = alloc::User::<ByteBuffer>::uninitialized(); - let fd = raw::bind_stream( - addr_user.as_ptr(), - addr_user.len(), - local.as_raw_mut_ptr() - ).from_sgx_result()?; + let fd = raw::bind_stream(addr_user.as_ptr(), addr_user.len(), local.as_raw_mut_ptr()) + .from_sgx_result()?; let local = string_from_bytebuffer(&local, "bind_stream", "local_addr"); Ok((fd, local)) } @@ -106,13 +103,10 @@ pub fn accept_stream(fd: Fd) -> IoResult<(Fd, String, String)> { unsafe { let mut bufs = alloc::User::<[ByteBuffer; 2]>::uninitialized(); let mut buf_it = alloc::UserRef::iter_mut(&mut *bufs); // FIXME: can this be done - // without forcing coercion? + // without forcing coercion? let (local, peer) = (buf_it.next().unwrap(), buf_it.next().unwrap()); - let fd = raw::accept_stream( - fd, - local.as_raw_mut_ptr(), - peer.as_raw_mut_ptr() - ).from_sgx_result()?; + let fd = raw::accept_stream(fd, local.as_raw_mut_ptr(), peer.as_raw_mut_ptr()) + .from_sgx_result()?; let local = string_from_bytebuffer(&local, "accept_stream", "local_addr"); let peer = string_from_bytebuffer(&peer, "accept_stream", "peer_addr"); Ok((fd, local, peer)) @@ -126,14 +120,15 @@ pub fn connect_stream(addr: &str) -> IoResult<(Fd, String, String)> { let addr_user = alloc::User::new_from_enclave(addr.as_bytes()); let mut bufs = alloc::User::<[ByteBuffer; 2]>::uninitialized(); let mut buf_it = alloc::UserRef::iter_mut(&mut *bufs); // FIXME: can this be done - // without forcing coercion? + // without forcing coercion? let (local, peer) = (buf_it.next().unwrap(), buf_it.next().unwrap()); let fd = raw::connect_stream( addr_user.as_ptr(), addr_user.len(), local.as_raw_mut_ptr(), - peer.as_raw_mut_ptr() - ).from_sgx_result()?; + peer.as_raw_mut_ptr(), + ) + .from_sgx_result()?; let local = string_from_bytebuffer(&local, "connect_stream", "local_addr"); let peer = string_from_bytebuffer(&peer, "connect_stream", "peer_addr"); Ok((fd, local, peer)) @@ -183,25 +178,25 @@ pub use self::raw::free; fn check_os_error(err: Result) -> i32 { // FIXME: not sure how to make sure all variants of Error are covered - if err == Error::NotFound as _ || - err == Error::PermissionDenied as _ || - err == Error::ConnectionRefused as _ || - err == Error::ConnectionReset as _ || - err == Error::ConnectionAborted as _ || - err == Error::NotConnected as _ || - err == Error::AddrInUse as _ || - err == Error::AddrNotAvailable as _ || - err == Error::BrokenPipe as _ || - err == Error::AlreadyExists as _ || - err == Error::WouldBlock as _ || - err == Error::InvalidInput as _ || - err == Error::InvalidData as _ || - err == Error::TimedOut as _ || - err == Error::WriteZero as _ || - err == Error::Interrupted as _ || - err == Error::Other as _ || - err == Error::UnexpectedEof as _ || - ((Error::UserRangeStart as _)..=(Error::UserRangeEnd as _)).contains(&err) + if err == Error::NotFound as _ + || err == Error::PermissionDenied as _ + || err == Error::ConnectionRefused as _ + || err == Error::ConnectionReset as _ + || err == Error::ConnectionAborted as _ + || err == Error::NotConnected as _ + || err == Error::AddrInUse as _ + || err == Error::AddrNotAvailable as _ + || err == Error::BrokenPipe as _ + || err == Error::AlreadyExists as _ + || err == Error::WouldBlock as _ + || err == Error::InvalidInput as _ + || err == Error::InvalidData as _ + || err == Error::TimedOut as _ + || err == Error::WriteZero as _ + || err == Error::Interrupted as _ + || err == Error::Other as _ + || err == Error::UnexpectedEof as _ + || ((Error::UserRangeStart as _)..=(Error::UserRangeEnd as _)).contains(&err) { err } else { diff --git a/src/libstd/sys/sgx/abi/usercalls/raw.rs b/src/libstd/sys/sgx/abi/usercalls/raw.rs index e4694a8827a..e0ebf860618 100644 --- a/src/libstd/sys/sgx/abi/usercalls/raw.rs +++ b/src/libstd/sys/sgx/abi/usercalls/raw.rs @@ -3,8 +3,8 @@ #[unstable(feature = "sgx_platform", issue = "56975")] pub use fortanix_sgx_abi::*; -use crate::ptr::NonNull; use crate::num::NonZeroU64; +use crate::ptr::NonNull; #[repr(C)] struct UsercallReturn(u64, u64); @@ -25,9 +25,14 @@ extern "C" { /// Panics if `nr` is `0`. #[unstable(feature = "sgx_platform", issue = "56975")] #[inline] -pub unsafe fn do_usercall(nr: NonZeroU64, p1: u64, p2: u64, p3: u64, p4: u64, abort: bool) - -> (u64, u64) -{ +pub unsafe fn do_usercall( + nr: NonZeroU64, + p1: u64, + p2: u64, + p3: u64, + p4: u64, + abort: bool, +) -> (u64, u64) { let UsercallReturn(a, b) = usercall(nr, p1, p2, abort as _, p3, p4); (a, b) } @@ -109,11 +114,7 @@ define_ra!(<T> *mut T); impl RegisterArgument for bool { fn from_register(a: Register) -> bool { - if a != 0 { - true - } else { - false - } + if a != 0 { true } else { false } } fn into_register(self) -> Register { self as _ @@ -152,16 +153,17 @@ impl<T: RegisterArgument> ReturnValue for T { impl<T: RegisterArgument, U: RegisterArgument> ReturnValue for (T, U) { fn from_registers(_call: &'static str, regs: (Register, Register)) -> Self { - ( - T::from_register(regs.0), - U::from_register(regs.1) - ) + (T::from_register(regs.0), U::from_register(regs.1)) } } macro_rules! return_type_is_abort { - (!) => { true }; - ($r:ty) => { false }; + (!) => { + true + }; + ($r:ty) => { + false + }; } // In this macro: using `$r:tt` because `$r:ty` doesn't match ! in `return_type_is_abort` |
