Skip to content

Commit

Permalink
Rollup merge of rust-lang#58182 - jethrogb:jb/sgx-bytebuffer-len-0, r…
Browse files Browse the repository at this point in the history
…=joshtriplett

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
  • Loading branch information
kennytm authored Feb 5, 2019
2 parents 7e72d06 + d89ebdd commit b3f814f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libstd/os/fortanix_sgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod usercalls {
/// Primitives for allocating memory in userspace as well as copying data
/// to and from user memory.
pub mod alloc {
pub use sys::abi::usercalls::alloc;
pub use sys::abi::usercalls::alloc::*;
}

/// Lowest-level interfaces to usercalls and usercall ABI type definitions.
Expand Down
7 changes: 6 additions & 1 deletion src/libstd/sys/sgx/abi/usercalls/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,12 @@ impl UserRef<super::raw::ByteBuffer> {
pub fn copy_user_buffer(&self) -> Vec<u8> {
unsafe {
let buf = self.to_enclave();
User::from_raw_parts(buf.data as _, buf.len).to_enclave()
if buf.len > 0 {
User::from_raw_parts(buf.data as _, buf.len).to_enclave()
} else {
// Mustn't look at `data` or call `free` if `len` is `0`.
Vec::with_capacity(0)
}
}
}
}
3 changes: 2 additions & 1 deletion src/libstd/sys/sgx/abi/usercalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub fn read(fd: Fd, buf: &mut [u8]) -> IoResult<usize> {
#[unstable(feature = "sgx_platform", issue = "56975")]
pub fn read_alloc(fd: Fd) -> IoResult<Vec<u8>> {
unsafe {
let mut userbuf = alloc::User::<ByteBuffer>::uninitialized();
let userbuf = ByteBuffer { data: ::ptr::null_mut(), len: 0 };
let mut userbuf = alloc::User::new_from_enclave(&userbuf);
raw::read_alloc(fd, userbuf.as_raw_mut_ptr()).from_sgx_result()?;
Ok(userbuf.copy_user_buffer())
}
Expand Down

0 comments on commit b3f814f

Please sign in to comment.