1
1
use crate :: cmp;
2
2
use crate :: io:: { Error as IoError , ErrorKind , IoSlice , IoSliceMut , Result as IoResult } ;
3
+ use crate :: mem:: MaybeUninit ;
3
4
use crate :: random:: { DefaultRandomSource , Random } ;
4
5
use crate :: time:: { Duration , Instant } ;
5
6
@@ -12,11 +13,35 @@ mod tests;
12
13
use self :: raw:: * ;
13
14
14
15
/// 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.
15
40
///
16
41
/// 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`.
18
43
#[ 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 > {
20
45
unsafe {
21
46
let total_len = bufs. iter ( ) . fold ( 0usize , |sum, buf| sum. saturating_add ( buf. len ( ) ) ) ;
22
47
let mut userbuf = alloc:: User :: < [ u8 ] > :: uninitialized ( total_len) ;
@@ -48,11 +73,21 @@ pub fn read_alloc(fd: Fd) -> IoResult<Vec<u8>> {
48
73
}
49
74
50
75
/// 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.
51
86
///
52
87
/// 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`.
54
89
#[ 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 > {
56
91
unsafe {
57
92
let total_len = bufs. iter ( ) . fold ( 0usize , |sum, buf| sum. saturating_add ( buf. len ( ) ) ) ;
58
93
let mut userbuf = alloc:: User :: < [ u8 ] > :: uninitialized ( total_len) ;
0 commit comments