Skip to content

Commit b3f814f

Browse files
authored
Rollup merge of #58182 - jethrogb:jb/sgx-bytebuffer-len-0, r=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
2 parents 7e72d06 + d89ebdd commit b3f814f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/libstd/os/fortanix_sgx/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod usercalls {
1616
/// Primitives for allocating memory in userspace as well as copying data
1717
/// to and from user memory.
1818
pub mod alloc {
19-
pub use sys::abi::usercalls::alloc;
19+
pub use sys::abi::usercalls::alloc::*;
2020
}
2121

2222
/// Lowest-level interfaces to usercalls and usercall ABI type definitions.

src/libstd/sys/sgx/abi/usercalls/alloc.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,12 @@ impl UserRef<super::raw::ByteBuffer> {
537537
pub fn copy_user_buffer(&self) -> Vec<u8> {
538538
unsafe {
539539
let buf = self.to_enclave();
540-
User::from_raw_parts(buf.data as _, buf.len).to_enclave()
540+
if buf.len > 0 {
541+
User::from_raw_parts(buf.data as _, buf.len).to_enclave()
542+
} else {
543+
// Mustn't look at `data` or call `free` if `len` is `0`.
544+
Vec::with_capacity(0)
545+
}
541546
}
542547
}
543548
}

src/libstd/sys/sgx/abi/usercalls/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ pub fn read(fd: Fd, buf: &mut [u8]) -> IoResult<usize> {
2222
#[unstable(feature = "sgx_platform", issue = "56975")]
2323
pub fn read_alloc(fd: Fd) -> IoResult<Vec<u8>> {
2424
unsafe {
25-
let mut userbuf = alloc::User::<ByteBuffer>::uninitialized();
25+
let userbuf = ByteBuffer { data: ::ptr::null_mut(), len: 0 };
26+
let mut userbuf = alloc::User::new_from_enclave(&userbuf);
2627
raw::read_alloc(fd, userbuf.as_raw_mut_ptr()).from_sgx_result()?;
2728
Ok(userbuf.copy_user_buffer())
2829
}

0 commit comments

Comments
 (0)