about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeremy Soller <jackpot51@gmail.com>2016-12-15 13:10:37 -0700
committerJeremy Soller <jackpot51@gmail.com>2016-12-15 16:33:23 -0700
commit773a0a2edb9a79733aca9f07f1fa8d7d155c4abc (patch)
treefff31001bfc5d96d04ebea5367d157a5738c2f01
parent3e7543a16ec6450b8fe0c3d50bc341b5f143cc54 (diff)
downloadrust-773a0a2edb9a79733aca9f07f1fa8d7d155c4abc.tar.gz
rust-773a0a2edb9a79733aca9f07f1fa8d7d155c4abc.zip
Add start functions, switch allocation crate to ralloc
-rw-r--r--src/librustc_back/target/redox_base.rs4
-rw-r--r--src/libstd/lib.rs5
-rw-r--r--src/libstd/sys/redox/start.rs81
3 files changed, 85 insertions, 5 deletions
diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs
index a04ec81e973..fc4c68276b6 100644
--- a/src/librustc_back/target/redox_base.rs
+++ b/src/librustc_back/target/redox_base.rs
@@ -40,8 +40,8 @@ pub fn opts() -> TargetOptions {
         target_family: Some("redox".to_string()),
         linker_is_gnu: true,
         no_default_libraries: true,
-        lib_allocation_crate: "alloc_system".to_string(),
-        exe_allocation_crate: "alloc_system".to_string(),
+        lib_allocation_crate: "ralloc".to_string(),
+        exe_allocation_crate: "ralloc".to_string(),
         has_elf_tls: true,
         panic_strategy: PanicStrategy::Abort,
         .. Default::default()
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 3c9e66a469c..6a1bb1268d7 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -423,6 +423,11 @@ pub use core_collections::vec;
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use std_unicode::char;
 
+// Reexport the start module on platforms that provide it
+#[unstable(feature = "start_fn", issue="0")]
+#[cfg(target_os = "redox")]
+pub use sys::start::*;
+
 pub mod f32;
 pub mod f64;
 
diff --git a/src/libstd/sys/redox/start.rs b/src/libstd/sys/redox/start.rs
index b689be1cf4d..87f58a4773c 100644
--- a/src/libstd/sys/redox/start.rs
+++ b/src/libstd/sys/redox/start.rs
@@ -1,6 +1,6 @@
 use sys::syscall::exit;
 
-#[allow(private_no_mangle_fns)]
+#[unstable(feature = "start_fn", issue = "0")]
 #[no_mangle]
 #[naked]
 #[cfg(target_arch = "x86")]
@@ -15,7 +15,7 @@ pub unsafe fn _start() {
     let _ = exit(0);
 }
 
-#[allow(private_no_mangle_fns)]
+#[unstable(feature = "start_fn", issue = "0")]
 #[no_mangle]
 #[naked]
 #[cfg(target_arch = "x86_64")]
@@ -30,7 +30,7 @@ pub unsafe fn _start() {
     let _ = exit(0);
 }
 
-#[allow(private_no_mangle_fns)]
+#[unstable(feature = "start_fn", issue = "0")]
 #[no_mangle]
 pub unsafe extern "C" fn _start_stack(stack: *const usize){
     extern "C" {
@@ -41,3 +41,78 @@ pub unsafe extern "C" fn _start_stack(stack: *const usize){
     let argv = stack.offset(1) as *const *const u8;
     let _ = exit(main(argc, argv));
 }
+
+/// Memcpy
+///
+/// Copy N bytes of memory from one location to another.
+#[unstable(feature = "start_fn", issue = "0")]
+#[no_mangle]
+pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8,
+                            n: usize) -> *mut u8 {
+    let mut i = 0;
+    while i < n {
+        *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
+        i += 1;
+    }
+
+    dest
+}
+
+/// Memmove
+///
+/// Copy N bytes of memory from src to dest. The memory areas may overlap.
+#[unstable(feature = "start_fn", issue = "0")]
+#[no_mangle]
+pub unsafe extern fn memmove(dest: *mut u8, src: *const u8,
+                             n: usize) -> *mut u8 {
+    if src < dest as *const u8 {
+        let mut i = n;
+        while i != 0 {
+            i -= 1;
+            *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
+        }
+    } else {
+        let mut i = 0;
+        while i < n {
+            *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
+            i += 1;
+        }
+    }
+
+    dest
+}
+
+/// Memset
+///
+/// Fill a block of memory with a specified value.
+#[unstable(feature = "start_fn", issue = "0")]
+#[no_mangle]
+pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 {
+    let mut i = 0;
+    while i < n {
+        *((dest as usize + i) as *mut u8) = c as u8;
+        i += 1;
+    }
+
+    dest
+}
+
+/// Memcmp
+///
+/// Compare two blocks of memory.
+#[unstable(feature = "start_fn", issue = "0")]
+#[no_mangle]
+pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
+    let mut i = 0;
+
+    while i < n {
+        let a = *((s1 as usize + i) as *const u8);
+        let b = *((s2 as usize + i) as *const u8);
+        if a != b {
+            return a as i32 - b as i32
+        }
+        i += 1;
+    }
+
+    0
+}