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 | |
| 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')
| -rw-r--r-- | src/libstd/sys/sgx/abi/mod.rs | 18 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/abi/panic.rs | 12 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/abi/reloc.rs | 12 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/abi/thread.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/abi/tls.rs | 29 | ||||
| -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 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/args.rs | 13 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/cmath.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/ext/io.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/ext/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/fd.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/fs.rs | 28 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/net.rs | 81 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/os.rs | 27 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/path.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/process.rs | 29 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/stack_overflow.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/stdio.rs | 14 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/thread.rs | 16 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/thread_local.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/time.rs | 5 |
23 files changed, 270 insertions, 252 deletions
diff --git a/src/libstd/sys/sgx/abi/mod.rs b/src/libstd/sys/sgx/abi/mod.rs index 0f107de83f0..87e7a5da2b7 100644 --- a/src/libstd/sys/sgx/abi/mod.rs +++ b/src/libstd/sys/sgx/abi/mod.rs @@ -1,11 +1,11 @@ #![cfg_attr(test, allow(unused))] // RT initialization logic is not compiled for test -use core::sync::atomic::{AtomicUsize, Ordering}; use crate::io::Write; +use core::sync::atomic::{AtomicUsize, Ordering}; // runtime features -mod reloc; pub(super) mod panic; +mod reloc; // library features pub mod mem; @@ -38,14 +38,16 @@ unsafe extern "C" fn tcs_init(secondary: bool) { UNINIT => { reloc::relocate_elf_rela(); RELOC_STATE.store(DONE, Ordering::Release); - }, + } // We need to wait until the initialization is done. - BUSY => while RELOC_STATE.load(Ordering::Acquire) == BUSY { - core::arch::x86_64::_mm_pause() - }, + BUSY => { + while RELOC_STATE.load(Ordering::Acquire) == BUSY { + core::arch::x86_64::_mm_pause() + } + } // Initialization is done. - DONE => {}, - _ => unreachable!() + DONE => {} + _ => unreachable!(), } } diff --git a/src/libstd/sys/sgx/abi/panic.rs b/src/libstd/sys/sgx/abi/panic.rs index 2401476716f..229b3b3291f 100644 --- a/src/libstd/sys/sgx/abi/panic.rs +++ b/src/libstd/sys/sgx/abi/panic.rs @@ -16,21 +16,13 @@ fn empty_user_slice() -> &'static mut UserRef<[u8]> { impl SgxPanicOutput { pub(crate) fn new() -> Option<Self> { - if unsafe { DEBUG == 0 } { - None - } else { - Some(SgxPanicOutput(None)) - } + if unsafe { DEBUG == 0 } { None } else { Some(SgxPanicOutput(None)) } } fn init(&mut self) -> &mut &'static mut UserRef<[u8]> { self.0.get_or_insert_with(|| unsafe { let ptr = take_debug_panic_buf_ptr(); - if ptr.is_null() { - empty_user_slice() - } else { - UserRef::from_raw_parts_mut(ptr, 1024) - } + if ptr.is_null() { empty_user_slice() } else { UserRef::from_raw_parts_mut(ptr, 1024) } }) } } diff --git a/src/libstd/sys/sgx/abi/reloc.rs b/src/libstd/sys/sgx/abi/reloc.rs index 6dd24c524fc..02dff0ad29f 100644 --- a/src/libstd/sys/sgx/abi/reloc.rs +++ b/src/libstd/sys/sgx/abi/reloc.rs @@ -1,5 +1,5 @@ -use crate::slice::from_raw_parts; use super::mem; +use crate::slice::from_raw_parts; const R_X86_64_RELATIVE: u32 = 8; @@ -11,18 +11,20 @@ struct Rela<T> { } pub fn relocate_elf_rela() { - extern { + extern "C" { static RELA: u64; static RELACOUNT: usize; } - if unsafe { RELACOUNT } == 0 { return } // unsafe ok: link-time constant + if unsafe { RELACOUNT } == 0 { + return; + } // unsafe ok: link-time constant let relas = unsafe { - from_raw_parts::<Rela<u64>>(mem::rel_ptr(RELA), RELACOUNT) // unsafe ok: link-time constant + from_raw_parts::<Rela<u64>>(mem::rel_ptr(RELA), RELACOUNT) // unsafe ok: link-time constant }; for rela in relas { - if rela.info != (/*0 << 32 |*/ R_X86_64_RELATIVE as u64) { + if rela.info != (/*0 << 32 |*/R_X86_64_RELATIVE as u64) { rtabort!("Invalid relocation"); } unsafe { *mem::rel_ptr_mut::<*const ()>(rela.offset) = mem::rel_ptr(rela.addend) }; diff --git a/src/libstd/sys/sgx/abi/thread.rs b/src/libstd/sys/sgx/abi/thread.rs index c17fa2d0015..ef55b821a2b 100644 --- a/src/libstd/sys/sgx/abi/thread.rs +++ b/src/libstd/sys/sgx/abi/thread.rs @@ -6,6 +6,8 @@ use fortanix_sgx_abi::Tcs; /// is a one-to-one correspondence of the ID to the address of the TCS. #[unstable(feature = "sgx_platform", issue = "56975")] pub fn current() -> Tcs { - extern "C" { fn get_tcs_addr() -> Tcs; } + extern "C" { + fn get_tcs_addr() -> Tcs; + } unsafe { get_tcs_addr() } } diff --git a/src/libstd/sys/sgx/abi/tls.rs b/src/libstd/sys/sgx/abi/tls.rs index 03e08ad547d..81a766e367d 100644 --- a/src/libstd/sys/sgx/abi/tls.rs +++ b/src/libstd/sys/sgx/abi/tls.rs @@ -1,11 +1,11 @@ -use crate::sync::atomic::{AtomicUsize, Ordering}; -use crate::ptr; -use crate::mem; +use self::sync_bitset::*; use crate::cell::Cell; +use crate::mem; use crate::num::NonZeroUsize; -use self::sync_bitset::*; +use crate::ptr; +use crate::sync::atomic::{AtomicUsize, Ordering}; -#[cfg(target_pointer_width="64")] +#[cfg(target_pointer_width = "64")] const USIZE_BITS: usize = 64; const TLS_KEYS: usize = 128; // Same as POSIX minimum const TLS_KEYS_BITSET_SIZE: usize = (TLS_KEYS + (USIZE_BITS - 1)) / USIZE_BITS; @@ -50,18 +50,18 @@ impl Key { #[repr(C)] pub struct Tls { - data: [Cell<*mut u8>; TLS_KEYS] + data: [Cell<*mut u8>; TLS_KEYS], } pub struct ActiveTls<'a> { - tls: &'a Tls + tls: &'a Tls, } impl<'a> Drop for ActiveTls<'a> { fn drop(&mut self) { let value_with_destructor = |key: usize| { let ptr = TLS_DESTRUCTOR[key].load(Ordering::Relaxed); - unsafe { mem::transmute::<_,Option<unsafe extern fn(*mut u8)>>(ptr) } + unsafe { mem::transmute::<_, Option<unsafe extern "C" fn(*mut u8)>>(ptr) } .map(|dtor| (&self.tls.data[key], dtor)) }; @@ -99,7 +99,7 @@ impl Tls { &*(get_tls_ptr() as *const Tls) } - pub fn create(dtor: Option<unsafe extern fn(*mut u8)>) -> Key { + pub fn create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key { let index = if let Some(index) = TLS_KEY_IN_USE.set() { index } else { @@ -127,10 +127,10 @@ impl Tls { } mod sync_bitset { - use crate::sync::atomic::{AtomicUsize, Ordering}; + use super::{TLS_KEYS_BITSET_SIZE, USIZE_BITS}; use crate::iter::{Enumerate, Peekable}; use crate::slice::Iter; - use super::{TLS_KEYS_BITSET_SIZE, USIZE_BITS}; + use crate::sync::atomic::{AtomicUsize, Ordering}; /// A bitset that can be used synchronously. pub(super) struct SyncBitset([AtomicUsize; TLS_KEYS_BITSET_SIZE]); @@ -146,10 +146,7 @@ mod sync_bitset { /// Not atomic. pub fn iter(&self) -> SyncBitsetIter<'_> { - SyncBitsetIter { - iter: self.0.iter().enumerate().peekable(), - elem_idx: 0, - } + SyncBitsetIter { iter: self.0.iter().enumerate().peekable(), elem_idx: 0 } } pub fn clear(&self, index: usize) { @@ -171,7 +168,7 @@ mod sync_bitset { current, current | (1 << trailing_ones), Ordering::AcqRel, - Ordering::Relaxed + Ordering::Relaxed, ) { Ok(_) => return Some(idx * USIZE_BITS + trailing_ones), Err(previous) => current = previous, 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` diff --git a/src/libstd/sys/sgx/args.rs b/src/libstd/sys/sgx/args.rs index a84ab413876..b47a48e752c 100644 --- a/src/libstd/sys/sgx/args.rs +++ b/src/libstd/sys/sgx/args.rs @@ -1,9 +1,9 @@ use super::abi::usercalls::{alloc, raw::ByteBuffer}; use crate::ffi::OsString; +use crate::slice; use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sys::os_str::Buf; use crate::sys_common::FromInner; -use crate::slice; #[cfg_attr(test, linkage = "available_externally")] #[export_name = "_ZN16__rust_internals3std3sys3sgx4args4ARGSE"] @@ -14,8 +14,9 @@ type ArgsStore = Vec<OsString>; pub unsafe fn init(argc: isize, argv: *const *const u8) { if argc != 0 { let args = alloc::User::<[ByteBuffer]>::from_raw_parts(argv as _, argc as _); - let args = args.iter() - .map( |a| OsString::from_inner(Buf { inner: a.copy_user_buffer() }) ) + let args = args + .iter() + .map(|a| OsString::from_inner(Buf { inner: a.copy_user_buffer() })) .collect::<ArgsStore>(); ARGS.store(Box::into_raw(Box::new(args)) as _, Ordering::Relaxed); } @@ -30,11 +31,7 @@ pub unsafe fn cleanup() { pub fn args() -> Args { let args = unsafe { (ARGS.load(Ordering::Relaxed) as *const ArgsStore).as_ref() }; - if let Some(args) = args { - Args(args.iter()) - } else { - Args([].iter()) - } + if let Some(args) = args { Args(args.iter()) } else { Args([].iter()) } } pub struct Args(slice::Iter<'static, OsString>); diff --git a/src/libstd/sys/sgx/cmath.rs b/src/libstd/sys/sgx/cmath.rs index 5aabdc1c8d3..b89238f1da8 100644 --- a/src/libstd/sys/sgx/cmath.rs +++ b/src/libstd/sys/sgx/cmath.rs @@ -1,7 +1,7 @@ #![cfg(not(test))] // These symbols are all defined in `compiler-builtins` -extern { +extern "C" { pub fn acos(n: f64) -> f64; pub fn acosf(n: f32) -> f32; pub fn asin(n: f64) -> f64; diff --git a/src/libstd/sys/sgx/ext/io.rs b/src/libstd/sys/sgx/ext/io.rs index fc88d10d3ed..8aa84a550d2 100644 --- a/src/libstd/sys/sgx/ext/io.rs +++ b/src/libstd/sys/sgx/ext/io.rs @@ -4,8 +4,8 @@ //! description of [`TryIntoRawFd`](trait.TryIntoRawFd.html) for more details. #![unstable(feature = "sgx_platform", issue = "56975")] -pub use crate::sys::abi::usercalls::raw::Fd as RawFd; use crate::net; +pub use crate::sys::abi::usercalls::raw::Fd as RawFd; use crate::sys::{self, AsInner, FromInner, IntoInner, TryIntoInner}; /// A trait to extract the raw SGX file descriptor from an underlying @@ -60,11 +60,15 @@ pub trait TryIntoRawFd: Sized { } impl AsRawFd for net::TcpStream { - fn as_raw_fd(&self) -> RawFd { *self.as_inner().as_inner().as_inner().as_inner() } + fn as_raw_fd(&self) -> RawFd { + *self.as_inner().as_inner().as_inner().as_inner() + } } impl AsRawFd for net::TcpListener { - fn as_raw_fd(&self) -> RawFd { *self.as_inner().as_inner().as_inner().as_inner() } + fn as_raw_fd(&self) -> RawFd { + *self.as_inner().as_inner().as_inner().as_inner() + } } impl FromRawFd for net::TcpStream { diff --git a/src/libstd/sys/sgx/ext/mod.rs b/src/libstd/sys/sgx/ext/mod.rs index 51b2659da83..258ad3cd218 100644 --- a/src/libstd/sys/sgx/ext/mod.rs +++ b/src/libstd/sys/sgx/ext/mod.rs @@ -1,5 +1,5 @@ #![unstable(feature = "sgx_platform", issue = "56975")] pub mod arch; -pub mod io; pub mod ffi; +pub mod io; diff --git a/src/libstd/sys/sgx/fd.rs b/src/libstd/sys/sgx/fd.rs index a1c4af81966..7da2424a642 100644 --- a/src/libstd/sys/sgx/fd.rs +++ b/src/libstd/sys/sgx/fd.rs @@ -1,9 +1,9 @@ use fortanix_sgx_abi::Fd; +use super::abi::usercalls; use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem; use crate::sys::{AsInner, FromInner, IntoInner}; -use super::abi::usercalls; #[derive(Debug)] pub struct FileDesc { @@ -15,7 +15,9 @@ impl FileDesc { FileDesc { fd: fd } } - pub fn raw(&self) -> Fd { self.fd } + pub fn raw(&self) -> Fd { + self.fd + } /// Extracts the actual filedescriptor without closing it. pub fn into_raw(self) -> Fd { @@ -46,7 +48,9 @@ impl FileDesc { } impl AsInner<Fd> for FileDesc { - fn as_inner(&self) -> &Fd { &self.fd } + fn as_inner(&self) -> &Fd { + &self.fd + } } impl IntoInner<Fd> for FileDesc { diff --git a/src/libstd/sys/sgx/fs.rs b/src/libstd/sys/sgx/fs.rs index e9095b375fe..e6160d1457d 100644 --- a/src/libstd/sys/sgx/fs.rs +++ b/src/libstd/sys/sgx/fs.rs @@ -1,7 +1,7 @@ use crate::ffi::OsString; use crate::fmt; use crate::hash::{Hash, Hasher}; -use crate::io::{self, SeekFrom, IoSlice, IoSliceMut}; +use crate::io::{self, IoSlice, IoSliceMut, SeekFrom}; use crate::path::{Path, PathBuf}; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; @@ -15,14 +15,14 @@ pub struct ReadDir(Void); pub struct DirEntry(Void); #[derive(Clone, Debug)] -pub struct OpenOptions { } +pub struct OpenOptions {} pub struct FilePermissions(Void); pub struct FileType(Void); #[derive(Debug)] -pub struct DirBuilder { } +pub struct DirBuilder {} impl FileAttr { pub fn size(&self) -> u64 { @@ -78,8 +78,7 @@ impl PartialEq for FilePermissions { } } -impl Eq for FilePermissions { -} +impl Eq for FilePermissions {} impl fmt::Debug for FilePermissions { fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -115,8 +114,7 @@ impl PartialEq for FileType { } } -impl Eq for FileType { -} +impl Eq for FileType {} impl Hash for FileType { fn hash<H: Hasher>(&self, _h: &mut H) { @@ -164,15 +162,15 @@ impl DirEntry { impl OpenOptions { pub fn new() -> OpenOptions { - OpenOptions { } + OpenOptions {} } - pub fn read(&mut self, _read: bool) { } - pub fn write(&mut self, _write: bool) { } - pub fn append(&mut self, _append: bool) { } - pub fn truncate(&mut self, _truncate: bool) { } - pub fn create(&mut self, _create: bool) { } - pub fn create_new(&mut self, _create_new: bool) { } + pub fn read(&mut self, _read: bool) {} + pub fn write(&mut self, _write: bool) {} + pub fn append(&mut self, _append: bool) {} + pub fn truncate(&mut self, _truncate: bool) {} + pub fn create(&mut self, _create: bool) {} + pub fn create_new(&mut self, _create_new: bool) {} } impl File { @@ -235,7 +233,7 @@ impl File { impl DirBuilder { pub fn new() -> DirBuilder { - DirBuilder { } + DirBuilder {} } pub fn mkdir(&self, _p: &Path) -> io::Result<()> { diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index f9eca9f4cb3..f36687b4d3d 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -1,12 +1,12 @@ -use crate::fmt; -use crate::io::{self, IoSlice, IoSliceMut}; -use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr, ToSocketAddrs}; -use crate::time::Duration; -use crate::sys::{unsupported, Void, sgx_ineffective, AsInner, FromInner, IntoInner, TryIntoInner}; -use crate::sys::fd::FileDesc; use crate::convert::TryFrom; use crate::error; +use crate::fmt; +use crate::io::{self, IoSlice, IoSliceMut}; +use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr, ToSocketAddrs}; use crate::sync::Arc; +use crate::sys::fd::FileDesc; +use crate::sys::{sgx_ineffective, unsupported, AsInner, FromInner, IntoInner, TryIntoInner, Void}; +use crate::time::Duration; use super::abi::usercalls; @@ -25,13 +25,15 @@ impl Socket { } impl AsInner<FileDesc> for Socket { - fn as_inner(&self) -> &FileDesc { &self.inner } + fn as_inner(&self) -> &FileDesc { + &self.inner + } } impl TryIntoInner<FileDesc> for Socket { fn try_into_inner(self) -> Result<FileDesc, Socket> { let Socket { inner, local_addr } = self; - Arc::try_unwrap(inner).map_err(|inner| Socket { inner, local_addr } ) + Arc::try_unwrap(inner).map_err(|inner| Socket { inner, local_addr }) } } @@ -59,8 +61,7 @@ impl fmt::Debug for TcpStream { res.field("peer", peer); } - res.field("fd", &self.inner.inner.as_inner()) - .finish() + res.field("fd", &self.inner.inner.as_inner()).finish() } } @@ -69,10 +70,12 @@ fn io_err_to_addr(result: io::Result<&SocketAddr>) -> io::Result<String> { Ok(saddr) => Ok(saddr.to_string()), // need to downcast twice because io::Error::into_inner doesn't return the original // value if the conversion fails - Err(e) => if e.get_ref().and_then(|e| e.downcast_ref::<NonIpSockAddr>()).is_some() { - Ok(e.into_inner().unwrap().downcast::<NonIpSockAddr>().unwrap().host) - } else { - Err(e) + Err(e) => { + if e.get_ref().and_then(|e| e.downcast_ref::<NonIpSockAddr>()).is_some() { + Ok(e.into_inner().unwrap().downcast::<NonIpSockAddr>().unwrap().host) + } else { + Err(e) + } } } } @@ -94,8 +97,10 @@ impl TcpStream { pub fn connect_timeout(addr: &SocketAddr, dur: Duration) -> io::Result<TcpStream> { if dur == Duration::default() { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout")); + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "cannot set a 0 duration timeout", + )); } Self::connect(Ok(addr)) // FIXME: ignoring timeout } @@ -103,20 +108,24 @@ impl TcpStream { pub fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> { match dur { Some(dur) if dur == Duration::default() => { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout")); + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "cannot set a 0 duration timeout", + )); } - _ => sgx_ineffective(()) + _ => sgx_ineffective(()), } } pub fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()> { match dur { Some(dur) if dur == Duration::default() => { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout")); + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "cannot set a 0 duration timeout", + )); } - _ => sgx_ineffective(()) + _ => sgx_ineffective(()), } } @@ -190,7 +199,9 @@ impl TcpStream { } impl AsInner<Socket> for TcpStream { - fn as_inner(&self) -> &Socket { &self.inner } + fn as_inner(&self) -> &Socket { + &self.inner + } } // `Inner` includes `peer_addr` so that a `TcpStream` maybe correctly @@ -220,8 +231,7 @@ impl fmt::Debug for TcpListener { res.field("addr", addr); } - res.field("fd", &self.inner.inner.as_inner()) - .finish() + res.field("fd", &self.inner.inner.as_inner()).finish() } } @@ -273,7 +283,9 @@ impl TcpListener { } impl AsInner<Socket> for TcpListener { - fn as_inner(&self) -> &Socket { &self.inner } + fn as_inner(&self) -> &Socket { + &self.inner + } } impl IntoInner<Socket> for TcpListener { @@ -367,23 +379,19 @@ impl UdpSocket { match self.0 {} } - pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) - -> io::Result<()> { + pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> { match self.0 {} } - pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) - -> io::Result<()> { + pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> { match self.0 {} } - pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) - -> io::Result<()> { + pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> { match self.0 {} } - pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) - -> io::Result<()> { + pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> { match self.0 {} } @@ -428,7 +436,7 @@ impl fmt::Debug for UdpSocket { #[derive(Debug)] pub struct NonIpSockAddr { - host: String + host: String, } impl error::Error for NonIpSockAddr { @@ -511,8 +519,7 @@ pub mod netc { } #[derive(Copy, Clone)] - pub struct sockaddr { - } + pub struct sockaddr {} pub type socklen_t = usize; } diff --git a/src/libstd/sys/sgx/os.rs b/src/libstd/sys/sgx/os.rs index 8b12c49edba..2c5b3134219 100644 --- a/src/libstd/sys/sgx/os.rs +++ b/src/libstd/sys/sgx/os.rs @@ -1,17 +1,17 @@ use fortanix_sgx_abi::{Error, RESULT_SUCCESS}; +use crate::collections::HashMap; use crate::error::Error as StdError; -use crate::ffi::{OsString, OsStr}; +use crate::ffi::{OsStr, OsString}; use crate::fmt; use crate::io; use crate::path::{self, PathBuf}; use crate::str; -use crate::sys::{unsupported, Void, sgx_ineffective, decode_error_kind}; -use crate::collections::HashMap; -use crate::vec; -use crate::sync::Mutex; use crate::sync::atomic::{AtomicUsize, Ordering}; +use crate::sync::Mutex; use crate::sync::Once; +use crate::sys::{decode_error_kind, sgx_ineffective, unsupported, Void}; +use crate::vec; pub fn errno() -> i32 { RESULT_SUCCESS @@ -52,7 +52,9 @@ impl<'a> Iterator for SplitPaths<'a> { pub struct JoinPathsError; pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError> - where I: Iterator<Item=T>, T: AsRef<OsStr> +where + I: Iterator<Item = T>, + T: AsRef<OsStr>, { Err(JoinPathsError) } @@ -89,26 +91,21 @@ fn create_env_store() -> &'static EnvStore { ENV_INIT.call_once(|| { ENV.store(Box::into_raw(Box::new(EnvStore::default())) as _, Ordering::Relaxed) }); - unsafe { - &*(ENV.load(Ordering::Relaxed) as *const EnvStore) - } + unsafe { &*(ENV.load(Ordering::Relaxed) as *const EnvStore) } } pub type Env = vec::IntoIter<(OsString, OsString)>; pub fn env() -> Env { let clone_to_vec = |map: &HashMap<OsString, OsString>| -> Vec<_> { - map.iter().map(|(k, v)| (k.clone(), v.clone()) ).collect() + map.iter().map(|(k, v)| (k.clone(), v.clone())).collect() }; - get_env_store() - .map(|env| clone_to_vec(&env.lock().unwrap()) ) - .unwrap_or_default() - .into_iter() + get_env_store().map(|env| clone_to_vec(&env.lock().unwrap())).unwrap_or_default().into_iter() } pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { - Ok(get_env_store().and_then(|s| s.lock().unwrap().get(k).cloned() )) + Ok(get_env_store().and_then(|s| s.lock().unwrap().get(k).cloned())) } pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { diff --git a/src/libstd/sys/sgx/path.rs b/src/libstd/sys/sgx/path.rs index b5fd7e3ae6d..06c9df3ff54 100644 --- a/src/libstd/sys/sgx/path.rs +++ b/src/libstd/sys/sgx/path.rs @@ -1,5 +1,5 @@ -use crate::path::Prefix; use crate::ffi::OsStr; +use crate::path::Prefix; #[inline] pub fn is_sep_byte(b: u8) -> bool { diff --git a/src/libstd/sys/sgx/process.rs b/src/libstd/sys/sgx/process.rs index edf933d10e0..4702e5c5492 100644 --- a/src/libstd/sys/sgx/process.rs +++ b/src/libstd/sys/sgx/process.rs @@ -32,32 +32,28 @@ pub enum Stdio { impl Command { pub fn new(_program: &OsStr) -> Command { - Command { - env: Default::default() - } + Command { env: Default::default() } } - pub fn arg(&mut self, _arg: &OsStr) { - } + pub fn arg(&mut self, _arg: &OsStr) {} pub fn env_mut(&mut self) -> &mut CommandEnv { &mut self.env } - pub fn cwd(&mut self, _dir: &OsStr) { - } + pub fn cwd(&mut self, _dir: &OsStr) {} - pub fn stdin(&mut self, _stdin: Stdio) { - } + pub fn stdin(&mut self, _stdin: Stdio) {} - pub fn stdout(&mut self, _stdout: Stdio) { - } + pub fn stdout(&mut self, _stdout: Stdio) {} - pub fn stderr(&mut self, _stderr: Stdio) { - } + pub fn stderr(&mut self, _stderr: Stdio) {} - pub fn spawn(&mut self, _default: Stdio, _needs_stdin: bool) - -> io::Result<(Process, StdioPipes)> { + pub fn spawn( + &mut self, + _default: Stdio, + _needs_stdin: bool, + ) -> io::Result<(Process, StdioPipes)> { unsupported() } } @@ -106,8 +102,7 @@ impl PartialEq for ExitStatus { } } -impl Eq for ExitStatus { -} +impl Eq for ExitStatus {} impl fmt::Debug for ExitStatus { fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/libstd/sys/sgx/stack_overflow.rs b/src/libstd/sys/sgx/stack_overflow.rs index e63fa2bed65..a2d13d11849 100644 --- a/src/libstd/sys/sgx/stack_overflow.rs +++ b/src/libstd/sys/sgx/stack_overflow.rs @@ -7,8 +7,6 @@ impl Handler { } #[cfg_attr(test, allow(dead_code))] -pub unsafe fn init() { -} +pub unsafe fn init() {} -pub unsafe fn cleanup() { -} +pub unsafe fn cleanup() {} diff --git a/src/libstd/sys/sgx/stdio.rs b/src/libstd/sys/sgx/stdio.rs index a575401f5f6..716c174bd53 100644 --- a/src/libstd/sys/sgx/stdio.rs +++ b/src/libstd/sys/sgx/stdio.rs @@ -1,11 +1,11 @@ use fortanix_sgx_abi as abi; use crate::io; -use crate::sys::fd::FileDesc; #[cfg(not(test))] use crate::slice; #[cfg(not(test))] use crate::str; +use crate::sys::fd::FileDesc; pub struct Stdin(()); pub struct Stdout(()); @@ -19,7 +19,9 @@ fn with_std_fd<F: FnOnce(&FileDesc) -> R, R>(fd: abi::Fd, f: F) -> R { } impl Stdin { - pub fn new() -> io::Result<Stdin> { Ok(Stdin(())) } + pub fn new() -> io::Result<Stdin> { + Ok(Stdin(())) + } } impl io::Read for Stdin { @@ -29,7 +31,9 @@ impl io::Read for Stdin { } impl Stdout { - pub fn new() -> io::Result<Stdout> { Ok(Stdout(())) } + pub fn new() -> io::Result<Stdout> { + Ok(Stdout(())) + } } impl io::Write for Stdout { @@ -43,7 +47,9 @@ impl io::Write for Stdout { } impl Stderr { - pub fn new() -> io::Result<Stderr> { Ok(Stderr(())) } + pub fn new() -> io::Result<Stderr> { + Ok(Stderr(())) + } } impl io::Write for Stderr { diff --git a/src/libstd/sys/sgx/thread.rs b/src/libstd/sys/sgx/thread.rs index b9f42d4ad1c..9b515eb82de 100644 --- a/src/libstd/sys/sgx/thread.rs +++ b/src/libstd/sys/sgx/thread.rs @@ -10,8 +10,8 @@ pub struct Thread(task_queue::JoinHandle); pub const DEFAULT_MIN_STACK_SIZE: usize = 4096; mod task_queue { - use crate::sync::{Mutex, MutexGuard, Once}; use crate::sync::mpsc; + use crate::sync::{Mutex, MutexGuard, Once}; pub type JoinHandle = mpsc::Receiver<()>; @@ -41,7 +41,7 @@ mod task_queue { pub(super) fn lock() -> MutexGuard<'static, Vec<Task>> { unsafe { - TASK_QUEUE_INIT.call_once(|| TASK_QUEUE = Some(Default::default()) ); + TASK_QUEUE_INIT.call_once(|| TASK_QUEUE = Some(Default::default())); TASK_QUEUE.as_ref().unwrap().lock().unwrap() } } @@ -49,9 +49,7 @@ mod task_queue { impl Thread { // unsafe: see thread::Builder::spawn_unchecked for safety requirements - pub unsafe fn new(_stack: usize, p: Box<dyn FnOnce()>) - -> io::Result<Thread> - { + pub unsafe fn new(_stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> { let mut queue_lock = task_queue::lock(); usercalls::launch_thread()?; let (task, handle) = task_queue::Task::new(p); @@ -86,6 +84,10 @@ impl Thread { pub mod guard { pub type Guard = !; - pub unsafe fn current() -> Option<Guard> { None } - pub unsafe fn init() -> Option<Guard> { None } + pub unsafe fn current() -> Option<Guard> { + None + } + pub unsafe fn init() -> Option<Guard> { + None + } } diff --git a/src/libstd/sys/sgx/thread_local.rs b/src/libstd/sys/sgx/thread_local.rs index e0d0fe76957..b21784475f0 100644 --- a/src/libstd/sys/sgx/thread_local.rs +++ b/src/libstd/sys/sgx/thread_local.rs @@ -1,9 +1,9 @@ -use super::abi::tls::{Tls, Key as AbiKey}; +use super::abi::tls::{Key as AbiKey, Tls}; pub type Key = usize; #[inline] -pub unsafe fn create(dtor: Option<unsafe extern fn(*mut u8)>) -> Key { +pub unsafe fn create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key { Tls::create(dtor).as_usize() } diff --git a/src/libstd/sys/sgx/time.rs b/src/libstd/sys/sgx/time.rs index 4659f7ba71f..e2f6e6dba69 100644 --- a/src/libstd/sys/sgx/time.rs +++ b/src/libstd/sys/sgx/time.rs @@ -1,5 +1,5 @@ -use crate::time::Duration; use super::abi::usercalls; +use crate::time::Duration; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct Instant(Duration); @@ -40,8 +40,7 @@ impl SystemTime { SystemTime(usercalls::insecure_time()) } - pub fn sub_time(&self, other: &SystemTime) - -> Result<Duration, Duration> { + pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) } |
