diff --git a/.gitmodules b/.gitmodules index 6d57d168a7b3dc0b645a1d57d7d59a1f2871d1db..cde224a0c5ec9febe9d4270b683dca366c94583a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "ralloc"] path = ralloc url = https://github.com/redox-os/ralloc.git +[submodule "va_list"] + path = va_list + url = https://github.com/redox-os/va_list-rs.git diff --git a/Cargo.lock b/Cargo.lock index 50b797789329e5ef31680aa03a2e622fa2b7bf70..ada4d0b66da37b1d1db0f6c0e9b3bd499435660a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,6 +97,11 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "gcc" +version = "0.3.54" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "grp" version = "0.1.0" @@ -140,6 +145,14 @@ dependencies = [ "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mman" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "platform 0.1.0", +] + [[package]] name = "num-traits" version = "0.2.1" @@ -177,6 +190,7 @@ dependencies = [ name = "platform" version = "0.1.0" dependencies = [ + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -197,6 +211,7 @@ dependencies = [ name = "ralloc_shim" version = "0.1.1" dependencies = [ + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -231,6 +246,7 @@ dependencies = [ "ctype 0.1.0", "fcntl 0.1.0", "grp 0.1.0", + "mman 0.1.0", "platform 0.1.0", "stdio 0.1.0", "stdlib 0.1.0", @@ -411,7 +427,7 @@ version = "0.1.0" dependencies = [ "cbindgen 0.5.0", "platform 0.1.0", - "va_list 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "va_list 0.1.0", ] [[package]] @@ -529,7 +545,16 @@ dependencies = [ [[package]] name = "va_list" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "va_list-helper 0.0.2", +] + +[[package]] +name = "va_list-helper" +version = "0.0.2" +dependencies = [ + "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "vec_map" @@ -575,6 +600,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)" = "56aebce561378d99a0bb578f8cb15b6114d2a1814a6c7949bbe646d968bb4fa9" @@ -618,7 +644,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum va_list 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7365862faee55ed0dbc112491aa5f0451ca01bf98afcc6463183b5aaa5bd3128" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" diff --git a/platform/Cargo.toml b/platform/Cargo.toml index d0e3478f296d229eed1f9d67d683097ac76e7a3e..e25b8251c0c6bb44761c2f5a8af2e7eda0c70881 100644 --- a/platform/Cargo.toml +++ b/platform/Cargo.toml @@ -3,5 +3,8 @@ name = "platform" version = "0.1.0" authors = ["Jeremy Soller <jackpot51@gmail.com>"] -[dependencies] +[target.'cfg(target_os = "linux")'.dependencies] sc = "0.2" + +[target.'cfg(target_os = "redox")'.dependencies] +redox_syscall = "0.1" diff --git a/platform/src/lib.rs b/platform/src/lib.rs index 1a33ffa31823a2780558e4e00abb4bb066c1ecaa..f8fdb8e18eba00fd877abc9188bbc626f976bdf2 100644 --- a/platform/src/lib.rs +++ b/platform/src/lib.rs @@ -20,7 +20,22 @@ pub mod types; use core::fmt; -use types::c_int; +use types::*; + +pub unsafe fn c_str(s: *const c_char) -> &'static [u8] { + use core::slice; + + let mut size = 0; + + loop { + if *s.offset(size) == 0 { + break; + } + size += 1; + } + + slice::from_raw_parts(s as *const u8, size as usize) +} pub struct FileWriter(pub c_int); diff --git a/platform/src/redox/mod.rs b/platform/src/redox/mod.rs index 7964839ec2035f9ccda42d8caf07fc4248e3d9e2..9bae6859ebe3dfe0f713b5ac9d21994fe703aab5 100644 --- a/platform/src/redox/mod.rs +++ b/platform/src/redox/mod.rs @@ -1,4 +1,7 @@ use core::slice; +use syscall; +use c_str; +use types::*; pub unsafe fn cstr_to_slice<'a>(buf: *const c_char) -> &'a [u8] { slice::from_raw_parts(buf as *const u8, ::strlen(buf) as usize) @@ -8,22 +11,30 @@ pub fn chdir(path: *const c_char) -> c_int { syscall::chdir(cstr_to_slice(path))? as c_int } -pub fn close(fildes: c_int) -> c_int { - syscall::close(fildes as usize)? as c_int +pub fn close(fd: c_int) -> c_int { + syscall::close(fd as usize); + 0 } -pub fn dup(fildes: c_int) -> c_int { - syscall::dup(file as usize, &[])? as c_int +pub fn dup(fd: c_int) -> c_int { + syscall::dup(fd as usize, &[])? as c_int } -pub fn dup2(fildes: c_int, fildes2) -> c_int { - syscall::dup2(fildes as usize, fildes2 as usize, &[])? as c_int +pub fn dup2(fd1: c_int, fd2) -> c_int { + syscall::dup2(fd1 as usize, fd2 as usize, &[])? as c_int +} pub fn exit(status: c_int) -> ! { - syscall::exit(status); + syscall::exit(status as usize); + loop {} +} + +pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + let path = unsafe { c_str(path) }; + syscall::open(path, (oflag as usize) | (mode as usize)).unwrap() as c_int } pub fn write(fd: c_int, buf: &[u8]) -> ssize_t { - syscall::write(fd, buf); + syscall::write(fd as usize, buf); buf.len() as ssize_t } diff --git a/ralloc b/ralloc index b521bac28702de86c7c4eef9641ec83c6ac38224..31b781a287748c10671a6c7e4415093d2dd4df4a 160000 --- a/ralloc +++ b/ralloc @@ -1 +1 @@ -Subproject commit b521bac28702de86c7c4eef9641ec83c6ac38224 +Subproject commit 31b781a287748c10671a6c7e4415093d2dd4df4a diff --git a/src/lib.rs b/src/lib.rs index 63815d70bec90d5669db6f7c01f6a00e4504c203..c4245e69c8e27a6c04ab7b8e80c7456c3709b373 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ extern crate platform; extern crate ctype; extern crate fcntl; extern crate grp; +extern crate mman; extern crate stdio; extern crate stdlib; extern crate string; diff --git a/src/stdio/Cargo.toml b/src/stdio/Cargo.toml index 78c082e15add37be8ca15b49e03a4617183d010a..c74b048852e1033ad82bc59abd8cd9b2e8d4b45a 100644 --- a/src/stdio/Cargo.toml +++ b/src/stdio/Cargo.toml @@ -9,4 +9,4 @@ cbindgen = { path = "../../cbindgen" } [dependencies] platform = { path = "../../platform" } -va_list = { version = "0.1", features = ["no_std"] } +va_list = { path = "../../va_list", features = ["no_std"] } diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index 91ddb0723d6b9dfff0a167ba4b202ba7362d5798..5beef27eea9262f84210d586249cfc9717d492dc 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -116,8 +116,7 @@ pub unsafe extern "C" fn exit(status: c_int) { use core::mem; for i in (0..ATEXIT_FUNCS.len()).rev() { - if ATEXIT_FUNCS[i] != None { - let func = mem::transmute::<usize, extern "C" fn()>(ATEXIT_FUNCS[i].unwrap()); + if let Some(func) = ATEXIT_FUNCS[i] { (func)(); } } diff --git a/src/string/src/lib.rs b/src/string/src/lib.rs index eb98911358dda695825aee8bda1e8b910010e226..e597532763bace6d39720fd53c6ff60317e5cc3d 100644 --- a/src/string/src/lib.rs +++ b/src/string/src/lib.rs @@ -104,16 +104,7 @@ pub extern "C" fn strerror(errnum: c_int) -> *mut c_char { #[no_mangle] pub unsafe extern "C" fn strlen(s: *const c_char) -> size_t { - let mut size = 0; - - loop { - if *s.offset(size) == 0 { - break; - } - size += 1; - } - - size as size_t + platform::c_str(s).len() as size_t } #[no_mangle] diff --git a/tests/Makefile b/tests/Makefile index 8d98779817e439dd33837e9f338a6769f4254f35..f3a5ff7366692c77f4d108082d76f0fa692d36b0 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -14,16 +14,18 @@ clean: run: $(BINS) for bin in $(BINS); do echo "\\033[1m$${bin}\\033[0m"; ./$${bin} test args; done +GCCHEAD=\ + -nostdinc \ + -nostdlib \ + -I ../include \ + -I ../target/include \ + -I ../openlibm/include \ + -I ../openlibm/src \ + ../target/debug/libcrt0.a + +GCCTAIL=\ + ../target/debug/libc.a \ + ../openlibm/libopenlibm.a + %: %.c - gcc \ - -nostdinc \ - -nostdlib \ - -I ../include \ - -I ../target/include \ - -I ../openlibm/include \ - -I ../openlibm/src \ - ../target/debug/libcrt0.a \ - $< \ - ../target/debug/libc.a \ - ../openlibm/libopenlibm.a \ - -o $@ + gcc -fno-stack-protector $(GCCHEAD) $< $(GCCTAIL) -o $@ diff --git a/va_list b/va_list new file mode 160000 index 0000000000000000000000000000000000000000..4762a184501beedbb58ea218f0c84fea85685c35 --- /dev/null +++ b/va_list @@ -0,0 +1 @@ +Subproject commit 4762a184501beedbb58ea218f0c84fea85685c35