Skip to content
Commits on Source (7)
......@@ -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]]
......@@ -598,6 +596,7 @@ name = "unistd"
version = "0.1.0"
dependencies = [
"cbindgen 0.5.2",
"errno 0.1.0",
"platform 0.1.0",
"stdio 0.1.0",
"string 0.1.0",
......@@ -667,8 +666,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 +676,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 +698,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"
......
......@@ -11,6 +11,7 @@ fn main() {
.flag("-I")
.flag(&format!("{}/include", crate_dir))
.flag("-fno-stack-protector")
.file("src/c/dlmalloc.c")
.file("src/c/fcntl.c")
.file("src/c/stdio.c")
.compile("relibc_c");
......
Subproject commit 867c809039aef77dbce22e98b1009b8995dfa868
Subproject commit f9b8c35fe8a58c0216b06d24832408fe2d9c0206
This diff is collapsed.
......@@ -47,5 +47,3 @@ int execle(const char *path, const char* argv0, ...)
return execve(path, argv, envp);
}
}
#endif
......@@ -5,6 +5,7 @@
#![feature(linkage)]
#![feature(naked_functions)]
#![feature(panic_implementation)]
#![feature(lang_items)]
extern crate platform;
......@@ -51,6 +52,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;
}
......@@ -72,3 +75,19 @@ pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
platform::exit(1);
}
#[lang = "oom"]
#[linkage = "weak"]
#[no_mangle]
pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
use core::fmt::Write;
let mut w = platform::FileWriter(2);
let _ = w.write_fmt(format_args!(
"RELIBC OOM: {} bytes aligned to {} bytes\n",
layout.size(),
layout.align()
));
platform::exit(1);
}
......@@ -3,6 +3,11 @@ name = "platform"
version = "0.1.0"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
[dependencies.ralloc]
path = "../../ralloc"
default-features = false
optional = true
[target.'cfg(target_os = "linux")'.dependencies]
sc = "0.2"
......
use core::alloc::{GlobalAlloc, Layout};
use types::*;
extern "C" {
fn dlmalloc(bytes: size_t) -> *mut c_void;
fn dlmemalign(alignment: size_t, bytes: size_t) -> *mut c_void;
fn dlrealloc(oldmem: *mut c_void, bytes: size_t) -> *mut c_void;
fn dlfree(mem: *mut c_void);
}
pub struct Allocator;
unsafe impl<'a> GlobalAlloc for Allocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
dlmemalign(layout.align(), layout.size()) as *mut u8
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
dlfree(ptr as *mut c_void)
}
}
pub unsafe fn alloc(size: usize) -> *mut c_void {
dlmalloc(size)
}
pub unsafe fn alloc_align(size: usize, alignment: usize) -> *mut c_void {
dlmemalign(alignment, size)
}
pub unsafe fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void {
dlrealloc(ptr, size)
}
pub unsafe fn free(ptr: *mut c_void) {
dlfree(ptr)
}
extern crate ralloc;
pub use ralloc::Allocator;
unsafe fn alloc_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
}
}
pub unsafe fn alloc(size: usize) -> *mut c_void {
alloc_inner(size, 16, 8)
}
pub unsafe fn alloc_align(size: usize, alignment: usize) -> *mut c_void {
let mut align = 32;
while align <= alignment {
align *= 2;
}
alloc_inner(size, align/2, align)
}
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);
}
//! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html
#![no_std]
#![allow(non_camel_case_types)]
#![feature(alloc)]
#![feature(allocator_api)]
//TODO #![feature(thread_local)]
extern crate alloc;
#[cfg(all(not(feature = "no_std"), target_os = "linux"))]
#[macro_use]
extern crate sc;
......@@ -12,6 +14,16 @@ extern crate sc;
#[macro_use]
pub extern crate syscall;
pub use allocator::*;
#[cfg(not(feature = "ralloc"))]
#[path = "allocator/dlmalloc.rs"]
mod allocator;
#[cfg(feature = "ralloc")]
#[path = "allocator/ralloc.rs"]
mod allocator;
pub use sys::*;
#[cfg(all(not(feature = "no_std"), target_os = "linux"))]
......@@ -28,6 +40,9 @@ use core::fmt;
use types::*;
#[global_allocator]
static ALLOCATOR: Allocator = Allocator;
//TODO #[thread_local]
#[allow(non_upper_case_globals)]
#[no_mangle]
......
......@@ -19,15 +19,8 @@ pub fn e(sys: usize) -> usize {
}
}
pub fn brk(addr: *const c_void) -> c_int {
unsafe {
let newbrk = syscall!(BRK, addr);
if newbrk < addr as usize {
-1
} else {
0
}
}
pub fn brk(addr: *mut c_void) -> *mut c_void {
unsafe { syscall!(BRK, addr) as *mut c_void }
}
pub fn chdir(path: *const c_char) -> c_int {
......
......@@ -22,8 +22,8 @@ pub fn e(sys: Result<usize, syscall::Error>) -> usize {
}
}
pub fn brk(addr: *const c_void) -> c_int {
e(unsafe { syscall::brk(addr as usize) }) as c_int
pub fn brk(addr: *mut c_void) -> *mut c_void {
unsafe { syscall::brk(addr as usize).unwrap_or(0) as *mut c_void }
}
pub fn chdir(path: *const c_char) -> c_int {
......@@ -72,6 +72,71 @@ pub fn exit(status: c_int) -> ! {
loop {}
}
pub unsafe extern "C" fn execve(
path: *const c_char,
argv: *const *mut c_char,
envp: *const *mut c_char,
) -> c_int {
use alloc::Vec;
use syscall::flag::*;
let mut env = envp;
while !(*env).is_null() {
let slice = c_str(*env);
// Should always contain a =, but worth checking
if let Some(sep) = slice.iter().position(|&c| c == b'=') {
// If the environment variable has no name, do not attempt
// to add it to the env.
if sep > 0 {
let mut path = b"env:".to_vec();
path.extend_from_slice(&slice[..sep]);
match syscall::open(&path, O_WRONLY | O_CREAT) {
Ok(fd) => {
// If the environment variable has no value, there
// is no need to write anything to the env scheme.
if sep + 1 < slice.len() {
let n = match syscall::write(fd, &slice[sep + 1..]) {
Ok(n) => n,
err => {
return e(err) as c_int;
}
};
}
// Cleanup after adding the variable.
match syscall::close(fd) {
Ok(_) => (),
err => {
return e(err) as c_int;
}
}
}
err => {
return e(err) as c_int;
}
}
}
}
env = env.offset(1);
}
let mut len = 0;
for i in 0.. {
if (*argv.offset(i)).is_null() {
len = i;
break;
}
}
let mut args: Vec<[usize; 2]> = Vec::with_capacity(len as usize);
let mut arg = argv;
while !(*arg).is_null() {
args.push([*arg as usize, c_str(*arg).len()]);
arg = arg.offset(1);
}
e(syscall::execve(c_str(path), &args)) as c_int
}
pub fn fchdir(fd: c_int) -> c_int {
let path: &mut [u8] = &mut [0; 4096];
if e(syscall::fpath(fd as usize, path)) == !0 {
......
......@@ -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"] }
......@@ -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>()) as *mut FILE;
// Allocate the file
if f.is_null() {
None
......
......@@ -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 {
......
......@@ -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" }
......@@ -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,30 +326,14 @@ 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)
}
#[no_mangle]
pub unsafe extern "C" fn memalign(alignment: size_t, size: size_t) -> *mut c_void {
let mut align = 32;
while align <= alignment as usize {
align *= 2;
}
malloc_inner(size, align / 2, align)
platform::alloc_align(size, alignment)
}
#[no_mangle]
......@@ -511,17 +488,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 +799,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]
......
......@@ -9,5 +9,4 @@ cbindgen = { path = "../../cbindgen" }
[dependencies]
platform = { path = "../platform" }
ralloc = { path = "../../ralloc", default-features = false }
errno = { path = "../errno" }
......@@ -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) as *mut c_char;
if buffer.is_null() {
platform::errno = ENOMEM as c_int;
} else {
......
......@@ -8,6 +8,7 @@ build = "build.rs"
cbindgen = { path = "../../cbindgen" }
[dependencies]
errno = { path = "../errno" }
platform = { path = "../platform" }
stdio = { path = "../stdio" }
string = { path = "../string" }
......