File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 33
44use cfg_if:: cfg_if;
55
6- pub mod memcpy_trivial;
7-
6+ /// The type signature of a `memcpy` function
87pub type Memcpy = unsafe fn ( dst : * mut u8 , src : * const u8 , bytes : usize ) ;
98
10- pub static ALL_MEMCPYS : & [ Memcpy ] = & [
9+ /// Assert the arguments of `memcpy` are correct
10+ fn memcpy_assert ( dst : * mut u8 , src : * const u8 , bytes : usize ) {
11+ let src_before_dst = ( src as usize + bytes) <= dst as usize ;
12+ let dst_before_src = ( dst as usize + bytes) <= src as usize ;
13+ let buffers_do_not_overlap = src_before_dst || dst_before_src;
14+ debug_assert ! ( buffers_do_not_overlap) ;
15+
16+ // Buffers larger than isize::max_value are bogus.
17+ // See https://doc.rust-lang.org/std/primitive.pointer.html#method.offset
18+
19+ let size_fits_in_signed_offset = bytes <= isize:: max_value ( ) as usize ;
20+ debug_assert ! ( size_fits_in_signed_offset) ;
21+ }
22+
23+ pub mod memcpy_trivial;
24+
25+ /// Ensure sure all implementations have the same type
26+ static ALL_MEMCPYS : & [ Memcpy ] = & [
1127 memcpy_trivial:: memcpy,
1228] ;
Original file line number Diff line number Diff line change 11pub unsafe fn memcpy ( dst : * mut u8 , src : * const u8 , bytes : usize ) {
2+ crate :: memcpy_assert ( dst, src, bytes) ;
3+
24 for i in 0 ..bytes {
35 let dst_byte = dst. add ( i) ;
46 let src_byte = src. add ( i) ;
You can’t perform that action at this time.
0 commit comments