File tree 2 files changed +63
-0
lines changed
2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 2
2
#![ no_std]
3
3
#![ feature( asm) ]
4
4
#![ feature( core_intrinsics) ]
5
+ #![ feature( linkage) ]
5
6
#![ feature( naked_functions) ]
6
7
// TODO(rust-lang/rust#35021) uncomment when that PR lands
7
8
// #![feature(rustc_builtins)]
9
+ #![ no_builtins]
8
10
9
11
// We disable #[no_mangle] for tests so that we can verify the test results
10
12
// against the native compiler-rt implementations of the builtins.
@@ -17,6 +19,7 @@ extern crate quickcheck;
17
19
pub mod arm;
18
20
19
21
pub mod udiv;
22
+ pub mod mem;
20
23
pub mod mul;
21
24
pub mod shift;
22
25
Original file line number Diff line number Diff line change
1
+ // NOTE Copied verbatim from the rlibc crate
2
+ // cf. https://crates.io/crates/rlibc
3
+
4
+ #[ linkage = "weak" ]
5
+ #[ no_mangle]
6
+ pub unsafe extern "C" fn memcpy ( dest : * mut u8 , src : * const u8 , n : usize ) -> * mut u8 {
7
+ let mut i = 0 ;
8
+ while i < n {
9
+ * dest. offset ( i as isize ) = * src. offset ( i as isize ) ;
10
+ i += 1 ;
11
+ }
12
+ dest
13
+ }
14
+
15
+ #[ linkage = "weak" ]
16
+ #[ no_mangle]
17
+ pub unsafe extern "C" fn memmove ( dest : * mut u8 , src : * const u8 , n : usize ) -> * mut u8 {
18
+ if src < dest as * const u8 {
19
+ // copy from end
20
+ let mut i = n;
21
+ while i != 0 {
22
+ i -= 1 ;
23
+ * dest. offset ( i as isize ) = * src. offset ( i as isize ) ;
24
+ }
25
+ } else {
26
+ // copy from beginning
27
+ let mut i = 0 ;
28
+ while i < n {
29
+ * dest. offset ( i as isize ) = * src. offset ( i as isize ) ;
30
+ i += 1 ;
31
+ }
32
+ }
33
+ dest
34
+ }
35
+
36
+ #[ linkage = "weak" ]
37
+ #[ no_mangle]
38
+ pub unsafe extern "C" fn memset ( s : * mut u8 , c : i32 , n : usize ) -> * mut u8 {
39
+ let mut i = 0 ;
40
+ while i < n {
41
+ * s. offset ( i as isize ) = c as u8 ;
42
+ i += 1 ;
43
+ }
44
+ s
45
+ }
46
+
47
+ #[ linkage = "weak" ]
48
+ #[ no_mangle]
49
+ pub unsafe extern "C" fn memcmp ( s1 : * const u8 , s2 : * const u8 , n : usize ) -> i32 {
50
+ let mut i = 0 ;
51
+ while i < n {
52
+ let a = * s1. offset ( i as isize ) ;
53
+ let b = * s2. offset ( i as isize ) ;
54
+ if a != b {
55
+ return a as i32 - b as i32 ;
56
+ }
57
+ i += 1 ;
58
+ }
59
+ 0
60
+ }
You can’t perform that action at this time.
0 commit comments