Skip to content

Commit 773a0a2

Browse files
committed
Add start functions, switch allocation crate to ralloc
1 parent 3e7543a commit 773a0a2

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

src/librustc_back/target/redox_base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub fn opts() -> TargetOptions {
4040
target_family: Some("redox".to_string()),
4141
linker_is_gnu: true,
4242
no_default_libraries: true,
43-
lib_allocation_crate: "alloc_system".to_string(),
44-
exe_allocation_crate: "alloc_system".to_string(),
43+
lib_allocation_crate: "ralloc".to_string(),
44+
exe_allocation_crate: "ralloc".to_string(),
4545
has_elf_tls: true,
4646
panic_strategy: PanicStrategy::Abort,
4747
.. Default::default()

src/libstd/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ pub use core_collections::vec;
423423
#[stable(feature = "rust1", since = "1.0.0")]
424424
pub use std_unicode::char;
425425

426+
// Reexport the start module on platforms that provide it
427+
#[unstable(feature = "start_fn", issue="0")]
428+
#[cfg(target_os = "redox")]
429+
pub use sys::start::*;
430+
426431
pub mod f32;
427432
pub mod f64;
428433

src/libstd/sys/redox/start.rs

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use sys::syscall::exit;
22

3-
#[allow(private_no_mangle_fns)]
3+
#[unstable(feature = "start_fn", issue = "0")]
44
#[no_mangle]
55
#[naked]
66
#[cfg(target_arch = "x86")]
@@ -15,7 +15,7 @@ pub unsafe fn _start() {
1515
let _ = exit(0);
1616
}
1717

18-
#[allow(private_no_mangle_fns)]
18+
#[unstable(feature = "start_fn", issue = "0")]
1919
#[no_mangle]
2020
#[naked]
2121
#[cfg(target_arch = "x86_64")]
@@ -30,7 +30,7 @@ pub unsafe fn _start() {
3030
let _ = exit(0);
3131
}
3232

33-
#[allow(private_no_mangle_fns)]
33+
#[unstable(feature = "start_fn", issue = "0")]
3434
#[no_mangle]
3535
pub unsafe extern "C" fn _start_stack(stack: *const usize){
3636
extern "C" {
@@ -41,3 +41,78 @@ pub unsafe extern "C" fn _start_stack(stack: *const usize){
4141
let argv = stack.offset(1) as *const *const u8;
4242
let _ = exit(main(argc, argv));
4343
}
44+
45+
/// Memcpy
46+
///
47+
/// Copy N bytes of memory from one location to another.
48+
#[unstable(feature = "start_fn", issue = "0")]
49+
#[no_mangle]
50+
pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8,
51+
n: usize) -> *mut u8 {
52+
let mut i = 0;
53+
while i < n {
54+
*((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
55+
i += 1;
56+
}
57+
58+
dest
59+
}
60+
61+
/// Memmove
62+
///
63+
/// Copy N bytes of memory from src to dest. The memory areas may overlap.
64+
#[unstable(feature = "start_fn", issue = "0")]
65+
#[no_mangle]
66+
pub unsafe extern fn memmove(dest: *mut u8, src: *const u8,
67+
n: usize) -> *mut u8 {
68+
if src < dest as *const u8 {
69+
let mut i = n;
70+
while i != 0 {
71+
i -= 1;
72+
*((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
73+
}
74+
} else {
75+
let mut i = 0;
76+
while i < n {
77+
*((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
78+
i += 1;
79+
}
80+
}
81+
82+
dest
83+
}
84+
85+
/// Memset
86+
///
87+
/// Fill a block of memory with a specified value.
88+
#[unstable(feature = "start_fn", issue = "0")]
89+
#[no_mangle]
90+
pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 {
91+
let mut i = 0;
92+
while i < n {
93+
*((dest as usize + i) as *mut u8) = c as u8;
94+
i += 1;
95+
}
96+
97+
dest
98+
}
99+
100+
/// Memcmp
101+
///
102+
/// Compare two blocks of memory.
103+
#[unstable(feature = "start_fn", issue = "0")]
104+
#[no_mangle]
105+
pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
106+
let mut i = 0;
107+
108+
while i < n {
109+
let a = *((s1 as usize + i) as *const u8);
110+
let b = *((s2 as usize + i) as *const u8);
111+
if a != b {
112+
return a as i32 - b as i32
113+
}
114+
i += 1;
115+
}
116+
117+
0
118+
}

0 commit comments

Comments
 (0)