diff --git a/Cargo.lock b/Cargo.lock index bf133296d9150f78f6017deadaa0424707e06235..33c65495906295504d5f89a4feb80a0227d8ba3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,9 +25,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "cbindgen" version = "0.5.2" dependencies = [ - "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", "standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -42,19 +42,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clap" -version = "2.31.2" +version = "2.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -190,15 +190,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -212,6 +212,7 @@ dependencies = [ name = "platform" version = "0.1.0" dependencies = [ + "ralloc 1.0.0", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -257,7 +258,7 @@ dependencies = [ [[package]] name = "rand" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -339,7 +340,7 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.66" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", @@ -371,7 +372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -418,7 +419,6 @@ dependencies = [ "fcntl 0.1.0", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "platform 0.1.0", - "ralloc 1.0.0", "string 0.1.0", "va_list 0.1.0", ] @@ -431,8 +431,7 @@ dependencies = [ "ctype 0.1.0", "errno 0.1.0", "platform 0.1.0", - "ralloc 1.0.0", - "rand 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "string 0.1.0", "time 0.1.0", "wchar 0.1.0", @@ -445,7 +444,6 @@ dependencies = [ "cbindgen 0.5.2", "errno 0.1.0", "platform 0.1.0", - "ralloc 1.0.0", ] [[package]] @@ -550,7 +548,7 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -570,7 +568,7 @@ name = "toml" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -667,8 +665,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1" "checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" "checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d" -"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" -"checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536" +"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e" +"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)" = "<none>" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" @@ -677,17 +675,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739" "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac" +"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" -"checksum rand 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0d9f869af32e387d9e0f2bdb64326b8ac84c81d5e55459d0bc7526b0fdb3671" +"checksum rand 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6802c0e883716383777e147b7c21323d5de7527257c8b6dc1365a7f2983e90f6" "checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ebbb026ba4a707c25caec2db5ef59ad8b41f7ad77cad06257e06229c891f376" -"checksum serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a2d9a9ac5120e0f768801ca2b58ad6eec929dc9d1d616c162f208869c2ce95" +"checksum serde 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)" = "210e5a3b159c566d7527e9b22e44be73f2e0fcc330bb78fef4dbccb56d2e74c8" "checksum serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc323d694dc925829725ec6c890156d8e70ae5202919869cb00fe2eff3788" "checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab" "checksum serde_json 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "84b8035cabe9b35878adec8ac5fe03d5f6bc97ff6edd7ccb96b44c1276ba390e" @@ -699,7 +697,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693" +"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" "checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9" "checksum unborrow 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e92e959f029e4f8ee25d70d15ab58d2b46f98a17bc238b9265ff0c26f6f3d67f" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" diff --git a/ralloc b/ralloc index 867c809039aef77dbce22e98b1009b8995dfa868..afb62216d39919e528d7dbc68070f8917e9bb373 160000 --- a/ralloc +++ b/ralloc @@ -1 +1 @@ -Subproject commit 867c809039aef77dbce22e98b1009b8995dfa868 +Subproject commit afb62216d39919e528d7dbc68070f8917e9bb373 diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index fc9ac5290a345df26682cc8174d952224b575961..36bb335b63b1dddb2e21d1972d00a4301093cf2d 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -51,6 +51,8 @@ impl Stack { #[inline(never)] #[no_mangle] pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! { + use core::fmt::Write; + extern "C" { fn main(argc: isize, argv: *const *const u8) -> c_int; } diff --git a/src/platform/Cargo.toml b/src/platform/Cargo.toml index e25b8251c0c6bb44761c2f5a8af2e7eda0c70881..04c0c791362edcb0a02052c8065e371280f11715 100644 --- a/src/platform/Cargo.toml +++ b/src/platform/Cargo.toml @@ -3,6 +3,10 @@ name = "platform" version = "0.1.0" authors = ["Jeremy Soller <jackpot51@gmail.com>"] +[dependencies.ralloc] +path = "../../ralloc" +default-features = false + [target.'cfg(target_os = "linux")'.dependencies] sc = "0.2" diff --git a/src/platform/src/lib.rs b/src/platform/src/lib.rs index 1838b29edd05177f16eaa3d985a158f888e6fc0a..ecf930a67e437ce34162bd3c57e03c523e51e10b 100644 --- a/src/platform/src/lib.rs +++ b/src/platform/src/lib.rs @@ -4,6 +4,8 @@ #![allow(non_camel_case_types)] //TODO #![feature(thread_local)] +extern crate ralloc; + #[cfg(all(not(feature = "no_std"), target_os = "linux"))] #[macro_use] extern crate sc; @@ -28,6 +30,9 @@ use core::fmt; use types::*; +#[global_allocator] +static ALLOCATOR: ralloc::Allocator = ralloc::Allocator; + //TODO #[thread_local] #[allow(non_upper_case_globals)] #[no_mangle] @@ -92,6 +97,38 @@ pub unsafe fn memcpy(s1: *mut c_void, s2: *const c_void, n: usize) -> *mut c_voi s1 } +pub unsafe fn alloc(size: usize, offset: usize, align: usize) -> *mut c_void { + let ptr = ralloc::alloc(size + offset, align); + if !ptr.is_null() { + *(ptr as *mut u64) = (size + offset) as u64; + *(ptr as *mut u64).offset(1) = align as u64; + ptr.offset(offset as isize) as *mut c_void + } else { + ptr as *mut c_void + } +} + +pub unsafe fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void { + let old_ptr = (ptr as *mut u8).offset(-16); + let old_size = *(old_ptr as *mut u64); + let align = *(old_ptr as *mut u64).offset(1); + let ptr = ralloc::realloc(old_ptr, old_size as usize, size + 16, align as usize); + if !ptr.is_null() { + *(ptr as *mut u64) = (size + 16) as u64; + *(ptr as *mut u64).offset(1) = align; + ptr.offset(16) as *mut c_void + } else { + ptr as *mut c_void + } +} + +pub unsafe fn free(ptr: *mut c_void) { + let ptr = (ptr as *mut u8).offset(-16); + let size = *(ptr as *mut u64); + let _align = *(ptr as *mut u64).offset(1); + ralloc::free(ptr, size as usize); +} + pub trait Write: fmt::Write { fn write_u8(&mut self, byte: u8) -> fmt::Result; } diff --git a/src/stdio/Cargo.toml b/src/stdio/Cargo.toml index 8261bc765aef949aefd0a371dbab44774e0f05c5..9931ddd6fd18cac764b8fe89420b377dc1fb5539 100644 --- a/src/stdio/Cargo.toml +++ b/src/stdio/Cargo.toml @@ -12,6 +12,5 @@ errno = { path = "../errno"} fcntl = { path = "../fcntl" } lazy_static = { version = "*", features = ["nightly", "spin_no_std"] } platform = { path = "../platform" } -ralloc = { path = "../../ralloc", default-features = false } string = { path = "../string" } va_list = { path = "../../va_list", features = ["no_std"] } diff --git a/src/stdio/src/helpers.rs b/src/stdio/src/helpers.rs index a2c433cb7e2d3da2ba8f2e48397cb54b837dea7c..2b3289e0ee6c77735be3d7a227b6f0b273fa88a2 100644 --- a/src/stdio/src/helpers.rs +++ b/src/stdio/src/helpers.rs @@ -6,7 +6,6 @@ use errno; use fcntl::*; use platform; use platform::types::*; -use ralloc; /// Parse mode flags as a string and output a mode flags integer pub unsafe fn parse_mode_flags(mode_str: *const c_char) -> i32 { @@ -63,7 +62,7 @@ pub unsafe fn _fdopen(fd: c_int, mode: *const c_char) -> Option<*mut FILE> { flags |= F_APP; } - let f = ralloc::alloc(mem::size_of::<FILE>(), 1) as *mut FILE; + let f = platform::alloc(mem::size_of::<FILE>(), 16, 8) as *mut FILE; // Allocate the file if f.is_null() { None diff --git a/src/stdio/src/lib.rs b/src/stdio/src/lib.rs index 54d3e1969bb50913accec8e0fb785fc32f0e44b8..90bec70958efcd509871d1c449ad41b5ade76cea 100644 --- a/src/stdio/src/lib.rs +++ b/src/stdio/src/lib.rs @@ -12,7 +12,6 @@ extern crate fcntl; #[macro_use] extern crate lazy_static; extern crate platform; -extern crate ralloc; extern crate string; extern crate va_list as vl; @@ -238,15 +237,13 @@ pub extern "C" fn cuserid(_s: *mut c_char) -> *mut c_char { /// prior to using this function. #[no_mangle] pub extern "C" fn fclose(stream: &mut FILE) -> c_int { - use ralloc::free; flockfile(stream); let r = helpers::fflush_unlocked(stream) | platform::close(stream.fd); if stream.flags & constants::F_PERM == 0 { // Not one of stdin, stdout or stderr unsafe { - free( - stream as *mut _ as *mut _, - mem::size_of::<FILE>() + BUFSIZ + UNGET, + platform::free( + stream as *mut FILE as *mut c_void ); } } else { diff --git a/src/stdlib/Cargo.toml b/src/stdlib/Cargo.toml index 1122990e1d1261c12f2659f63406591b1878548c..8da566d3626bd19d23811bac772521584fc45437 100644 --- a/src/stdlib/Cargo.toml +++ b/src/stdlib/Cargo.toml @@ -9,10 +9,9 @@ cbindgen = { path = "../../cbindgen" } [dependencies] platform = { path = "../platform" } -ralloc = { path = "../../ralloc", default-features = false } ctype = { path = "../ctype" } errno = { path = "../errno" } rand = { version = "0.5.2", default-features = false } time = { path = "../time" } wchar = { path = "../wchar" } -string = { path = "../string" } \ No newline at end of file +string = { path = "../string" } diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index 7b2ebd258a1463e30f27bf40f86c7e0cb815dd46..139e592b5859d912eb9a62c74189d42f0aec7934 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -6,7 +6,6 @@ extern crate ctype; extern crate errno; extern crate platform; -extern crate ralloc; extern crate rand; extern crate string; extern crate time; @@ -25,9 +24,6 @@ use platform::types::*; mod sort; -#[global_allocator] -static ALLOCATOR: ralloc::Allocator = ralloc::Allocator; - pub const EXIT_FAILURE: c_int = 1; pub const EXIT_SUCCESS: c_int = 0; pub const RAND_MAX: c_int = 2147483647; @@ -233,7 +229,7 @@ pub extern "C" fn erand(xsubi: [c_ushort; 3]) -> c_double { } #[no_mangle] -pub unsafe extern "C" fn exit(status: c_int) { +pub unsafe extern "C" fn exit(status: c_int) -> ! { for i in (0..ATEXIT_FUNCS.len()).rev() { if let Some(func) = ATEXIT_FUNCS[i] { (func)(); @@ -255,10 +251,7 @@ pub extern "C" fn fcvt( #[no_mangle] pub unsafe extern "C" fn free(ptr: *mut c_void) { - let ptr = (ptr as *mut u8).offset(-16); - let size = *(ptr as *mut u64); - let _align = *(ptr as *mut u64).offset(1); - ralloc::free(ptr, size as usize); + platform::free(ptr); } #[no_mangle] @@ -333,20 +326,9 @@ pub extern "C" fn lrand48() -> c_long { unimplemented!(); } -unsafe fn malloc_inner(size: usize, offset: usize, align: usize) -> *mut c_void { - let ptr = ralloc::alloc(size + offset, align); - if !ptr.is_null() { - *(ptr as *mut u64) = (size + offset) as u64; - *(ptr as *mut u64).offset(1) = align as u64; - ptr.offset(offset as isize) as *mut c_void - } else { - ptr as *mut c_void - } -} - #[no_mangle] pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void { - malloc_inner(size, 16, 8) + platform::alloc(size, 16, 8) } #[no_mangle] @@ -356,7 +338,7 @@ pub unsafe extern "C" fn memalign(alignment: size_t, size: size_t) -> *mut c_voi align *= 2; } - malloc_inner(size, align / 2, align) + platform::alloc(size, align / 2, align) } #[no_mangle] @@ -511,17 +493,7 @@ pub extern "C" fn random() -> c_long { #[no_mangle] pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void { - let old_ptr = (ptr as *mut u8).offset(-16); - let old_size = *(old_ptr as *mut u64); - let align = *(old_ptr as *mut u64).offset(1); - let ptr = ralloc::realloc(old_ptr, old_size as usize, size + 16, align as usize); - if !ptr.is_null() { - *(ptr as *mut u64) = (size + 16) as u64; - *(ptr as *mut u64).offset(1) = align; - ptr.offset(16) as *mut c_void - } else { - ptr as *mut c_void - } + platform::realloc(ptr, size) } #[no_mangle] @@ -832,15 +804,7 @@ pub extern "C" fn unlockpt(fildes: c_int) -> c_int { #[no_mangle] pub unsafe extern "C" fn valloc(size: size_t) -> *mut c_void { - let align = 4096; - let ptr = ralloc::alloc(size + 16, align); - if !ptr.is_null() { - *(ptr as *mut u64) = (size + 16) as u64; - *(ptr as *mut u64).offset(1) = align as u64; - ptr.offset(16) as *mut c_void - } else { - ptr as *mut c_void - } + memalign(4096, size) } #[no_mangle] diff --git a/src/string/Cargo.toml b/src/string/Cargo.toml index f134d7ff7a43a9a6ba5c93beeb21c917895af4be..bed689a677fc520b9a97e3bb16742afbd8369b06 100644 --- a/src/string/Cargo.toml +++ b/src/string/Cargo.toml @@ -9,5 +9,4 @@ cbindgen = { path = "../../cbindgen" } [dependencies] platform = { path = "../platform" } -ralloc = { path = "../../ralloc", default-features = false } errno = { path = "../errno" } diff --git a/src/string/src/lib.rs b/src/string/src/lib.rs index 5a7d1ecb5cb77eee88170e8686197fac898c55f8..776166a0f25e2b1e5fc05a514784d4ba2bde8f7c 100644 --- a/src/string/src/lib.rs +++ b/src/string/src/lib.rs @@ -3,7 +3,6 @@ extern crate errno; extern crate platform; -extern crate ralloc; use core::cmp; use core::mem; @@ -192,7 +191,7 @@ pub unsafe extern "C" fn strndup(s1: *const c_char, size: usize) -> *mut c_char let len = strnlen(s1, size); // the "+ 1" is to account for the NUL byte - let buffer = ralloc::alloc(len + 1, 1) as *mut c_char; + let buffer = platform::alloc(len + 1, 16, 8) as *mut c_char; if buffer.is_null() { platform::errno = ENOMEM as c_int; } else {