diff --git a/Cargo.lock b/Cargo.lock index 316b19b9aa5f5ecbee1d2fd42a847b1735f5a7c2..b9ae70624b63502eca9408daea085773b2af9087 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,6 +96,23 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "fenv" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "platform 0.1.0", +] + +[[package]] +name = "float" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "fenv 0.1.0", + "platform 0.1.0", +] + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -254,9 +271,12 @@ dependencies = [ "ctype 0.1.0", "errno 0.1.0", "fcntl 0.1.0", + "fenv 0.1.0", + "float 0.1.0", "grp 0.1.0", "mman 0.1.0", "platform 0.1.0", + "resource 0.1.0", "semaphore 0.1.0", "stat 0.1.0", "stdio 0.1.0", @@ -265,6 +285,7 @@ dependencies = [ "sys_time 0.1.0", "time 0.1.0", "unistd 0.1.0", + "wait 0.1.0", "wctype 0.1.0", ] @@ -277,6 +298,15 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "resource" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "platform 0.1.0", + "sys_time 0.1.0", +] + [[package]] name = "rustc-ap-proc_macro" version = "40.0.0" @@ -612,6 +642,15 @@ name = "vec_map" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "wait" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "platform 0.1.0", + "resource 0.1.0", +] + [[package]] name = "wctype" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index fd952f39026c59ca1fa7ca098a1400349bce7439..55d8d5e9131230dcb2c060bc3cf05cb1f11942ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,16 @@ members = ["src/crt0"] [dependencies] compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] } -platform = { path = "src/platform" } ctype = { path = "src/ctype" } errno = { path = "src/errno" } fcntl = { path = "src/fcntl" } +fenv = { path = "src/fenv" } +float = { path = "src/float" } grp = { path = "src/grp" } semaphore = { path = "src/semaphore" } mman = { path = "src/mman" } +platform = { path = "src/platform" } +resource = { path = "src/resource" } stat = { path = "src/stat" } stdio = { path = "src/stdio" } stdlib = { path = "src/stdlib" } @@ -26,6 +29,7 @@ string = { path = "src/string" } sys_time = { path = "src/sys_time" } time = { path = "src/time" } unistd = { path = "src/unistd" } +wait = { path = "src/wait" } wctype = { path = "src/wctype" } [profile.dev] diff --git a/include/bits/float.h b/include/bits/float.h new file mode 100644 index 0000000000000000000000000000000000000000..c62ae491dc579af5c979363ded7d4790f299cc43 --- /dev/null +++ b/include/bits/float.h @@ -0,0 +1,6 @@ +#ifndef _BITS_FLOAT_H +#define _BITS_FLOAT_H + +#define FLT_ROUNDS (flt_rounds()) + +#endif diff --git a/include/sys/types.h b/include/sys/types.h index 0db183a79686cb004db55240b67f0d7a017adcbc..3efc6300b3afd8658afb6d7eba0bb6b4d979a0c5 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -8,6 +8,7 @@ typedef long dev_t; typedef unsigned long ino_t; typedef int gid_t; + typedef int uid_t; typedef int mode_t; @@ -18,6 +19,8 @@ typedef long off_t; typedef int pid_t; +typedef unsigned id_t; + typedef long ssize_t; typedef long time_t; diff --git a/src/fenv/Cargo.toml b/src/fenv/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..ed3b2142f1ef12b8633facefa01f928e44dd88cc --- /dev/null +++ b/src/fenv/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "fenv" +version = "0.1.0" +authors = ["Dan Robertson <danlrobertson89@gmail.com>"] + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } diff --git a/src/fenv/build.rs b/src/fenv/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..a79287ee765847e4e356072d1d6e23645dd809d3 --- /dev/null +++ b/src/fenv/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/fenv.h"); +} diff --git a/src/fenv/cbindgen.toml b/src/fenv/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..4d3d6737c2adcb6decaad175de7fd8f508cb772f --- /dev/null +++ b/src/fenv/cbindgen.toml @@ -0,0 +1,6 @@ +sys_includes = ["sys/types.h"] +include_guard = "_FENV_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/fenv/src/lib.rs b/src/fenv/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..b97e7e3b5e7760c0b6268cd5330af85863e50f1d --- /dev/null +++ b/src/fenv/src/lib.rs @@ -0,0 +1,62 @@ +//! fenv.h implementation for Redox, following +//! http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fenv.h.html + +#![no_std] + +extern crate platform; + +use platform::types::*; + +pub const FE_ALL_EXCEPT: c_int = 0; +pub const FE_TONEAREST: c_int = 0; + +pub type fexcept_t = u64; + +#[repr(C)] +pub struct fenv_t { + pub cw: u64, +} + +pub unsafe extern "C" fn feclearexcept(excepts: c_int) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn fegenenv(envp: *mut fenv_t) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn fegetexceptflag(flagp: *mut fexcept_t, excepts: c_int) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn fegetround() -> c_int { + FE_TONEAREST +} + +pub unsafe extern "C" fn feholdexcept(envp: *mut fenv_t) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn feraiseexcept(except: c_int) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn fesetenv(envp: *const fenv_t) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn fesetexceptflag(flagp: *const fexcept_t, excepts: c_int) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn fesetround(round: c_int) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn fetestexcept(excepts: c_int) -> c_int { + unimplemented!(); +} + +pub unsafe extern "C" fn feupdateenv(envp: *const fenv_t) -> c_int { + unimplemented!(); +} diff --git a/src/float/Cargo.toml b/src/float/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..3ae7acb3fe4310522973543c42183a26d597b0b7 --- /dev/null +++ b/src/float/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "float" +version = "0.1.0" +authors = ["Dan Robertson <danlrobertson89@gmail.com>"] + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } +fenv = { path = "../fenv" } diff --git a/src/float/build.rs b/src/float/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..e9b224fd13a684c9821fc850fab69b5781da650b --- /dev/null +++ b/src/float/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/float.h"); +} diff --git a/src/float/cbindgen.toml b/src/float/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..bbb97a813949d4b8162914fca24b9be3e67c4f99 --- /dev/null +++ b/src/float/cbindgen.toml @@ -0,0 +1,6 @@ +sys_includes = ["sys/types.h", "bits/float.h"] +include_guard = "_FLOAT_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/float/src/lib.rs b/src/float/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..e594fdba782a6232f14e7e0b55b78015bd8001a5 --- /dev/null +++ b/src/float/src/lib.rs @@ -0,0 +1,19 @@ +//! float.h implementation for Redox, following +//! http://pubs.opengroup.org/onlinepubs/7908799/xsh/float.h.html + +#![no_std] + +extern crate fenv; +extern crate platform; + +use platform::types::*; +use fenv::{fegetround, FE_TONEAREST}; + +pub const FLT_RADIX: c_int = 2; + +pub unsafe extern "C" fn flt_rounds() -> c_int { + match fegetround() { + FE_TONEAREST => 1, + _ => -1, + } +} diff --git a/src/mman/build.rs b/src/mman/build.rs index 652a2ae435bed32fd9f38deafb6cf95bbfd50497..19d21bd491f769e36dd29ade3296f5e3263e1216 100644 --- a/src/mman/build.rs +++ b/src/mman/build.rs @@ -7,5 +7,5 @@ fn main() { fs::create_dir_all("../../target/include").expect("failed to create include directory"); cbindgen::generate(crate_dir) .expect("failed to generate bindings") - .write_to_file("../../target/include/mman.h"); + .write_to_file("../../target/include/sys/mman.h"); } diff --git a/src/mman/cbindgen.toml b/src/mman/cbindgen.toml index 84677294aa2cab886f5ff8b4e454eaabaa78b056..783348bace7698cb6f958d9452d886cc035a5120 100644 --- a/src/mman/cbindgen.toml +++ b/src/mman/cbindgen.toml @@ -1,5 +1,5 @@ -sys_includes = [] -include_guard = "_MMAN_H" +sys_includes = ["sys/types.h"] +include_guard = "_SYS_MMAN_H" language = "C" [enum] diff --git a/src/platform/src/types.rs b/src/platform/src/types.rs index 45ae64499d508ff2d7c5307a623ca10624751a99..9268bf55c319265d6cd424479ae4394720993799 100644 --- a/src/platform/src/types.rs +++ b/src/platform/src/types.rs @@ -50,6 +50,7 @@ pub type off_t = i64; pub type mode_t = u16; pub type time_t = i64; pub type pid_t = usize; +pub type id_t = usize; pub type gid_t = usize; pub type uid_t = usize; pub type dev_t = usize; diff --git a/src/resource/Cargo.toml b/src/resource/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..30cee970179f25980586034475e363b9f7c296d7 --- /dev/null +++ b/src/resource/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "resource" +version = "0.1.0" +authors = ["Dan Robertson <danlrobertson89@gmail.com>"] + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } +sys_time = { path = "../sys_time" } diff --git a/src/resource/build.rs b/src/resource/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..a8c03a627ed6139aafd260a51a5e0ee664f9ab09 --- /dev/null +++ b/src/resource/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/sys/resource.h"); +} diff --git a/src/resource/cbindgen.toml b/src/resource/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..f9c595b682de5be84f518a4cb8fcd2c1e2a098bc --- /dev/null +++ b/src/resource/cbindgen.toml @@ -0,0 +1,6 @@ +sys_includes = ["sys/types.h"] +include_guard = "_SYS_RESOURCE_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/resource/src/lib.rs b/src/resource/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..26b1d702a8b7807ded8185bcceada567255e5abf --- /dev/null +++ b/src/resource/src/lib.rs @@ -0,0 +1,49 @@ +//! sys/resource.h implementation for Redox, following +//! http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysresource.h.html + +#![no_std] + +extern crate platform; +extern crate sys_time; + +use platform::types::*; +use sys_time::timeval; + +type rlim_t = u64; + +#[repr(C)] +pub struct rlimit { + pub rlim_cur: rlim_t, + pub rlim_max: rlim_t, +} + +#[repr(C)] +pub struct rusage { + pub ru_utime: timeval, + pub ru_stime: timeval, +} + +#[no_mangle] +pub unsafe extern "C" fn getpriority(which: c_int, who: id_t) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub unsafe extern "C" fn setpriority(which: c_int, who: id_t, nice: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub unsafe extern "C" fn setrlimit(resource: c_int, rlp: *const rlimit) -> c_int { + unimplemented!(); +} diff --git a/src/wait/Cargo.toml b/src/wait/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..50d48a5efe7d627819fd979779d27326cfc535e9 --- /dev/null +++ b/src/wait/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "wait" +version = "0.1.0" +authors = ["Dan Robertson <danlrobertson89@gmail.com>"] + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } +resource = { path = "../resource" } diff --git a/src/wait/build.rs b/src/wait/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..53a786af45a1777d808df37b585f122fa42701fb --- /dev/null +++ b/src/wait/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/sys/wait.h"); +} diff --git a/src/wait/cbindgen.toml b/src/wait/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..186d5f9573063eb9d2b1e625681131b372d77d41 --- /dev/null +++ b/src/wait/cbindgen.toml @@ -0,0 +1,6 @@ +sys_includes = ["sys/types.h", "sys/resource.h"] +include_guard = "_SYS_WAIT_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/wait/src/lib.rs b/src/wait/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..51fdd28569e516767de612a1201b98fd5132eb90 --- /dev/null +++ b/src/wait/src/lib.rs @@ -0,0 +1,43 @@ +//! sys/wait.h implementation for Redox, following +//! http://pubs.opengroup.org/onlinepubs/7908799/xsh/syswait.h.html + +#![no_std] + +extern crate platform; +extern crate resource; + +use platform::types::*; +use resource::rusage; + +#[no_mangle] +pub unsafe extern "C" fn wait(stat_loc: *mut c_int) -> pid_t { + unimplemented!(); +} + +#[no_mangle] +pub unsafe extern "C" fn wait3( + stat_loc: *mut c_int, + options: c_int, + resource_usage: *mut rusage, +) -> pid_t { + unimplemented!(); +} + +/* + * TODO: implement idtype_t, id_t, and siginfo_t + * + * #[no_mangle] + * pub unsafe extern "C" fn waitid( + * idtype: idtype_t, + * id: id_t, + * infop: siginfo_t, + * options: c_int + * ) -> c_int { + * unimplemented!(); + * } + */ + +#[no_mangle] +pub unsafe extern "C" fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { + unimplemented!(); +}