File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed
library/std/src/sys/sgx/abi/usercalls Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -317,7 +317,7 @@ where
317317/// * The `dst` pointer is null
318318/// * The `src` memory range is not in enclave memory
319319/// * The `dst` memory range is not in user memory
320- unsafe fn copy_to_userspace ( src : * const u8 , dst : * mut u8 , len : usize ) {
320+ pub ( crate ) unsafe fn copy_to_userspace ( src : * const u8 , dst : * mut u8 , len : usize ) {
321321 unsafe fn copy_bytewise_to_userspace ( src : * const u8 , dst : * mut u8 , len : usize ) {
322322 unsafe {
323323 let seg_sel: u16 = 0 ;
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ use crate::time::{Duration, Instant};
66pub ( crate ) mod alloc;
77#[ macro_use]
88pub ( crate ) mod raw;
9+ #[ cfg( test) ]
10+ mod tests;
911
1012use self :: raw:: * ;
1113
Original file line number Diff line number Diff line change 1+ use super :: alloc:: copy_to_userspace;
2+ use super :: alloc:: User ;
3+
4+ #[ test]
5+ fn test_copy_function ( ) {
6+ let mut src = [ 0u8 ; 100 ] ;
7+ let mut dst = User :: < [ u8 ] > :: uninitialized ( 100 ) ;
8+
9+ for i in 0 ..src. len ( ) {
10+ src[ i] = i as _ ;
11+ }
12+
13+ for size in 0 ..48 {
14+ // For all possible alignment
15+ for offset in 0 ..8 {
16+ // overwrite complete dst
17+ dst. copy_from_enclave ( & [ 0u8 ; 100 ] ) ;
18+
19+ // Copy src[0..size] to dst + offset
20+ unsafe { copy_to_userspace ( src. as_ptr ( ) , dst. as_mut_ptr ( ) . offset ( offset) , size) } ;
21+
22+ // Verify copy
23+ for byte in 0 ..size {
24+ unsafe {
25+ assert_eq ! ( * dst. as_ptr( ) . offset( offset + byte as isize ) , src[ byte as usize ] ) ;
26+ }
27+ }
28+ }
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments