summary refs log tree commit diff
path: root/src/libstd/sys/sgx
AgeCommit message (Collapse)AuthorLines
2019-02-26Auto merge of #58357 - sfackler:vectored-io, r=alexcrichtonbors-27/+75
Add vectored read and write support This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies. r? @alexcrichton
2019-02-24Fix sgxSteven Fackler-3/+3
2019-02-24Rollup merge of #58454 - pitdicker:windows_stdio, r=alexcrichtonMazdak Farrokhzad-19/+12
Refactor Windows stdio and remove stdin double buffering I was looking for something nice and small to work on, tried to tackle a few FIXME's in Windows stdio, and things grew from there. This part of the standard library contains some tricky code, and has changed over the years to handle more corner cases. It could use some refactoring and extra comments. Changes/fixes: - Made `StderrRaw` `pub(crate)`, to remove the `Write` implementations on `sys::Stderr` (used unsynchronised for panic output). - Remove the unused `Read` implementation on `sys::windows::stdin` - The `windows::stdio::Output` enum made sense when we cached the handles, but we can use simple functions like `is_console` now that we get the handle on every read/write - `write` can now calculate the number of written bytes as UTF-8 when we can't write all `u16`s. - If `write` could only write one half of a surrogate pair, attempt another write for the other because user code can't reslice in any way that would allow us to write it otherwise. - Removed the double buffering on stdin. Documentation on the unexposed `StdinRaw` says: 'This handle is not synchronized or buffered in any fashion'; which is now true. - `sys::windows::Stdin` now always only partially fills its buffer, so we can guarantee any arbitrary UTF-16 can be re-encoded without losing any data. - `sys::windows::STDIN_BUF_SIZE` is slightly larger to compensate. There should be no real change in the number of syscalls the buffered `Stdin` does. This buffer is a little larger, while the extra buffer on Stdin is gone. - `sys::windows::Stdin` now attempts to handle unpaired surrogates at its buffer boundary. - `sys::windows::Stdin` no langer allocates for its buffer, but the UTF-16 decoding still does. ### Testing I did some manual testing of reading and writing to console. The console does support UTF-16 in some sense, but doesn't supporting displaying characters outside the BMP. - compile stage 1 stdlib with a tiny value for `MAX_BUFFER_SIZE` to make it easier to catch corner cases - run a simple test program that reads on stdin, and echo's to stdout - write some lines with plenty of ASCII and emoji in a text editor - copy and paste in console to stdin - return with `\r\n\` or CTRL-Z - copy and paste in text editor - check it round-trips ----- Fixes https://github.com/rust-lang/rust/issues/23344. All but one of the suggestions in that issue are now implemented. the missing one is: > * When reading data, we require the entire set of input to be valid UTF-16. We should instead attempt to read as much of the input as possible as valid UTF-16, only returning an error for the actual invalid elements. For example if we read 10 elements, 5 of which are valid UTF-16, the 6th is bad, and then the remaining are all valid UTF-16, we should probably return the first 5 on a call to `read`, then return an error, then return the remaining on the next call to `read`. Stdin in Console mode is dealing with text directly input by a user. In my opinion getting an unpaired surrogate is quite unlikely in that case, and a valid reason to error on the entire line of input (which is probably short). Dealing with it is incompatible with an unbuffered stdin, which seems the more interesting guarantee to me.
2019-02-20Use standard Read/Write traits in sys::stdioPaul Dicker-8/+14
2019-02-20Remove sys::*::Stderr Write implementationPaul Dicker-13/+0
2019-02-14SGX target: fix panic = abortJethro Beekman-0/+1
2019-02-13impl Deref/DerefMut for IoVec typesSteven Fackler-5/+5
Returning &'a mut [u8] was unsound, and we may as well just have them directly deref to their slices to make it easier to work with them.
2019-02-13Add vectored read and write supportSteven Fackler-26/+74
This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies.
2019-02-13Auto merge of #58235 - jethrogb:jb/sgx-usercall-internals, r=alexcrichtonbors-81/+59
SGX target: simplify usercall internals This moves logic from assembly to Rust and removes the special case for exit/panic handling, merging it with regular usercall handling. Also, this fixes a bug in the exit usercall introduced in a75ae00. The bug would make regular exits look like panics with high probability. It would also with some probability leak information through uncleared registers. cc @VardhanThigle r? @alexcrichton
2019-02-10libs: doc commentsAlexander Regueiro-29/+36
2019-02-10Auto merge of #58129 - RalfJung:maybe-uninit, r=cramertjbors-2/+2
MaybeUninit: some docs, rename into_inner -> into_initialized, return &mut from set
2019-02-10fix SGX build failuresRalf Jung-2/+2
2019-02-06SGX target: simplify usercall internalsJethro Beekman-81/+59
This moves logic from assembly to Rust and removes the special case for exit/panic handling, merging it with regular usercall handling. Also, this fixes a bug in the exit usercall introduced in a75ae00. The bug would make regular exits look like panics with high probability. It would also with some probability leak information through uncleared registers.
2019-02-06Rollup merge of #58182 - jethrogb:jb/sgx-bytebuffer-len-0, r=joshtriplettkennytm-2/+8
SGX target: handle empty user buffers correctly Also, expose correct items in `os::fortanix_sgx::usercalls::alloc` * [read_alloc documentation](https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.read_alloc) * [Clarified ByteBuffer documentation](https://github.com/fortanix/rust-sgx/pull/94/files#diff-ca843ad9e25cacd63a80579c0f7efa56) r? @joshtriplett
2019-02-05SGX target: handle empty user buffers correctlyJethro Beekman-2/+8
2019-02-04Remove stray FIXMEJethro Beekman-3/+0
2019-02-01Fix `std::os::fortanix_sgx::usercalls::raw::UsercallNrs`Jethro Beekman-4/+9
Fixes https://github.com/fortanix/rust-sgx/issues/88
2019-01-29SGX target: improve panic & exit handlingJethro Beekman-22/+32
2019-01-26Replace deprecated ATOMIC_INIT constsMark Rousskov-4/+37
2019-01-24Rollup merge of #57860 - jethrogb:jb/sgx-os-ffi, r=joshtriplettMazdak Farrokhzad-0/+110
Add os::fortanix_sgx::ffi module This uses the same byte slice accessors that Unix has. The [ABI specifies](https://docs.rs/fortanix-sgx-abi/0.3.2/fortanix_sgx_abi/struct.ByteBuffer.html) byte slices.
2019-01-23Add os::fortanix_sgx::ffi moduleJethro Beekman-0/+110
2019-01-21Expose alloc/dealloc properly for SGX libunwindJethro Beekman-0/+15
2019-01-13Fix breakage from #56988 and workaround for #57569Vardhan Thigle-0/+9
2019-01-13Adding Build automation for x86_64-fortanix-unknown-sgxVardhan Thigle-0/+10
2019-01-12Rollup merge of #57511 - jethrogb:jb/fix-undef, r=cramertjMazdak Farrokhzad-2/+2
Fix undefined behavior From the [`MaybeUninit::get_mut` docs](https://doc.rust-lang.org/std/mem/union.MaybeUninit.html): > It is up to the caller to guarantee that the the MaybeUninit really is in an initialized state, otherwise this will immediately cause undefined behavior. r? @joshtriplett
2019-01-11Fix undefined behaviorJethro Beekman-2/+2
2019-01-09Exposing enclave image-base to the enclave applicationVardhan Thigle-7/+5
image-base could be used by crates like backtrace to providing to make symbol resolution easier.
2019-01-08Supporting backtrace for x86_64-fortanix-unknown-sgx.Vardhan Thigle-9/+82
2018-12-28remove remaining copyright headersMatthias Krüger-30/+0
2018-12-27Auto merge of #57119 - jethrogb:jb/sgx-os-mod2, r=joshtriplettbors-10/+303
Add `io` and `arch` modules to `std::os::fortanix_sgx` This PR adds two more (unstable) modules to `std::os::fortanix_sgx` for the `x86_64-fortanix-unknown-sgx` target. ### io `io` allows conversion between raw file descriptors and Rust types, similar to `std::os::unix::io`. ### arch `arch` exposes the `ENCLU[EREPORT]` and `ENCLU[EGETKEY]` instructions. The current functions are very likely not going to be the final form of these functions (see also https://github.com/fortanix/rust-sgx/issues/15), but this should be sufficient to enable experimentation in libraries. I tried using the actual types (from the [`sgx-isa` crate](https://crates.io/crates/sgx-isa)) instead of byte arrays, but that would make `std` dependent on the `bitflags` crate which I didn't want to do at this time.
2018-12-25Remove licensesMark Rousskov-340/+0
2018-12-25Add `io` and `arch` modules to `std::os::fortanix_sgx`Jethro Beekman-10/+303
2018-12-24Rollup merge of #56978 - jethrogb:jb/sgx-os-mod, r=joshtriplettMazdak Farrokhzad-53/+269
Add `std::os::fortanix_sgx` module This PR adds the `std::os::sgx` module to expose platform-specific APIs behind the `sgx_platform` feature gate. Depends on https://github.com/rust-lang/rust/pull/56972 to be able to meaningfully build `std::os` documentation for non-standard targets. Tracking issue: https://github.com/rust-lang/rust/issues/56975
2018-12-23Rollup merge of #56979 - VardhanThigle:Vardhan/rust-sgx-unwind-support, ↵kennytm-6/+139
r=alexcrichton Adding unwinding support for x86_64_fortanix_unknown_sgx target. Unwinding support is provided by our port of LLVM's libunwind which is available from https://github.com/fortanix/libunwind/tree/release_50. libunwind requires support for rwlock and printing to stderr, which is only provided by `std` for this target. This poses two problems: 1) how to expose the `std` functionality to C and 2) dependency inversion. ### Exposing `std` For exposing the functionality we chose to expose the following symbols: * __rust_rwlock_rdlock * __rust_rwlock_wrlock * __rust_rwlock_unlock * __rust_print_err * __rust_abort Also, the following are needed from `alloc`: * __rust_alloc * __rust_dealloc #### Rust RWLock in C In `libunwind`, RWLock is initialized as a templated static variable: ```c pthread_rwlock_t DwarfFDECache<A>::_lock = PTHREAD_RWLOCK_INITIALIZER; ``` I don't know of a good way to use the Rust sys::rwlock::RWLock type and initializer there. We could have a static global variable in Rust, but that doesn't work with the templating. The variable needs to be initialized statically, since this target doesn't support the .init section. Currently, I just used a byte array and standard C array initialization. The mapping between this C type and the Rust type needs to be manually maintained. There is a compile-time check and a unit test to make sure the Rust versions of these C definitions match the actual Rust type. If any reviewer knows of a better solution, please do tell. ### Dependency inversion issue `std` depends on `panic_unwind` which depends on `libunwind`, and `libunwind` depends on `std`. This is not normally supported by Rust's linking system. Therefore we use raw C exports from `std` *and* `libunwind.a` is linked last in the target `post_link_objects` instead of being built as part of the Rust `libunwind`. Currently, all C exports are defined in `src/libstd/sys/sgx/rwlock.rs` to overcome LTO issues. Only the `__rust_rwlock_*` definitions *need* to live there for privacy reasons. Once again, if any reviewer knows of a better solution, please do tell. r? @alexcrichton
2018-12-21Auto merge of #56813 - oli-obk:main_🧶, r=pnkfelixbors-1/+0
Always run rustc in a thread cc @ishitatsuyuki @eddyb r? @pnkfelix [Previously](https://github.com/rust-lang/rust/pull/48575) we moved to only producing threads when absolutely necessary. Even before we opted to only create threads in some cases, which [is unsound](https://github.com/rust-lang/rust/pull/48575#issuecomment-380635967) due to the way we use thread local storage.
2018-12-20Add `std::os::fortanix_sgx` moduleJethro Beekman-54/+255
2018-12-19Adding unwinding support for x86_64_fortanix_unknown_sgx target.Vardhan Thigle-6/+139
2018-12-19Revert "Remove some dead code from `sgx`"Jethro Beekman-0/+15
This reverts commit 134661917bf4b086b027a2c58219d50ba57a1453.
2018-12-14Remove dead codeOliver Scherer-1/+0
2018-12-14Rollup merge of #56708 - oli-obk:stability_internal_const_fn, r=alexcrichtonkennytm-22/+0
Remove some unnecessary feature gates fixes #56585 cc @jethrogb
2018-12-13Fix checked_add/sub for sys/sgx/time.rsLinus Färnstrand-11/+7
2018-12-11Remove some dead code from `sgx`Oliver Scherer-15/+0
2018-12-11Remove unnecessary feature gates from const fnsOliver Scherer-7/+0
2018-12-07SGX target: implement command-line arguments and environment variablesJethro Beekman-25/+70
2018-12-07SGX target: implement timeJethro Beekman-3/+9
2018-12-07SGX target: implement networkingJethro Beekman-53/+167
2018-12-07SGX target: implement streamsJethro Beekman-28/+134
2018-12-07SGX target: implement synchronization primitives and threadingJethro Beekman-76/+828
2018-12-07SGX target: implement user memory managementJethro Beekman-5/+500
2018-12-07SGX target: add thread local storageJethro Beekman-17/+277