11use crate :: cmp;
22use crate :: io:: { Error as IoError , ErrorKind , IoSlice , IoSliceMut , Result as IoResult } ;
3+ use crate :: mem:: MaybeUninit ;
34use crate :: random:: { DefaultRandomSource , Random } ;
45use crate :: time:: { Duration , Instant } ;
56
@@ -12,11 +13,35 @@ mod tests;
1213use self :: raw:: * ;
1314
1415/// Usercall `read`. See the ABI documentation for more information.
16+ #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
17+ pub fn read ( fd : Fd , buf : & mut [ u8 ] ) -> IoResult < usize > {
18+ unsafe {
19+ let mut userbuf = alloc:: User :: < [ u8 ] > :: uninitialized ( buf. len ( ) ) ;
20+ let len = raw:: read ( fd, userbuf. as_mut_ptr ( ) , userbuf. len ( ) ) . from_sgx_result ( ) ?;
21+ userbuf[ ..len] . copy_to_enclave ( & mut buf[ ..len] ) ;
22+ Ok ( len)
23+ }
24+ }
25+
26+ /// Usercall `read` with an uninitialized buffer. See the ABI documentation for
27+ /// more information.
28+ #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
29+ pub fn read_uninit ( fd : Fd , buf : & mut [ MaybeUninit < u8 > ] ) -> IoResult < usize > {
30+ unsafe {
31+ let mut userbuf = alloc:: User :: < [ u8 ] > :: uninitialized ( buf. len ( ) ) ;
32+ let len = raw:: read ( fd, userbuf. as_mut_ptr ( ) . cast ( ) , userbuf. len ( ) ) . from_sgx_result ( ) ?;
33+ userbuf[ ..len] . copy_to_enclave_uninit ( & mut buf[ ..len] ) ;
34+ Ok ( len)
35+ }
36+ }
37+
38+ /// Usercall `read` with a slice of buffers. See the ABI documentation for more
39+ /// information.
1540///
1641/// This will do a single `read` usercall and scatter the read data among
17- /// `bufs`. To read to a single buffer, just pass a slice of length one.
42+ /// `bufs`.
1843#[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
19- pub fn read ( fd : Fd , bufs : & mut [ IoSliceMut < ' _ > ] ) -> IoResult < usize > {
44+ pub fn read_vectored ( fd : Fd , bufs : & mut [ IoSliceMut < ' _ > ] ) -> IoResult < usize > {
2045 unsafe {
2146 let total_len = bufs. iter ( ) . fold ( 0usize , |sum, buf| sum. saturating_add ( buf. len ( ) ) ) ;
2247 let mut userbuf = alloc:: User :: < [ u8 ] > :: uninitialized ( total_len) ;
@@ -48,11 +73,21 @@ pub fn read_alloc(fd: Fd) -> IoResult<Vec<u8>> {
4873}
4974
5075/// Usercall `write`. See the ABI documentation for more information.
76+ #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
77+ pub fn write ( fd : Fd , buf : & [ u8 ] ) -> IoResult < usize > {
78+ unsafe {
79+ let userbuf = alloc:: User :: new_from_enclave ( buf) ;
80+ raw:: write ( fd, userbuf. as_ptr ( ) , userbuf. len ( ) ) . from_sgx_result ( )
81+ }
82+ }
83+
84+ /// Usercall `write` with a slice of buffers. See the ABI documentation for more
85+ /// information.
5186///
5287/// This will do a single `write` usercall and gather the written data from
53- /// `bufs`. To write from a single buffer, just pass a slice of length one.
88+ /// `bufs`.
5489#[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
55- pub fn write ( fd : Fd , bufs : & [ IoSlice < ' _ > ] ) -> IoResult < usize > {
90+ pub fn write_vectored ( fd : Fd , bufs : & [ IoSlice < ' _ > ] ) -> IoResult < usize > {
5691 unsafe {
5792 let total_len = bufs. iter ( ) . fold ( 0usize , |sum, buf| sum. saturating_add ( buf. len ( ) ) ) ;
5893 let mut userbuf = alloc:: User :: < [ u8 ] > :: uninitialized ( total_len) ;
0 commit comments