From 2f718d40d63513ee02674fc36dd7d7cab013bcae Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Sat, 10 Mar 2018 19:01:54 +0000 Subject: [PATCH 1/5] mman: mman.h should be located at sys/mman.h - Update target location of mman.h to sys/mman.h - Add more types to sys/type.h --- include/sys/types.h | 3 +++ src/mman/build.rs | 2 +- src/mman/cbindgen.toml | 4 ++-- src/platform/src/types.rs | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/sys/types.h b/include/sys/types.h index 0db183a796..3efc6300b3 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/mman/build.rs b/src/mman/build.rs index 652a2ae435..19d21bd491 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 84677294aa..783348bace 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 45ae64499d..9268bf55c3 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; From c6f16547ff7d2203adbde284db632268a02e644b Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Sat, 10 Mar 2018 19:03:13 +0000 Subject: [PATCH 2/5] resource: Add crate for sys/resource.h Add the basics of sys/resource.h so that work can begin on sys/wait.h --- Cargo.lock | 10 ++++++++ Cargo.toml | 3 ++- src/resource/Cargo.toml | 11 +++++++++ src/resource/build.rs | 11 +++++++++ src/resource/cbindgen.toml | 6 +++++ src/resource/src/lib.rs | 49 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/resource/Cargo.toml create mode 100644 src/resource/build.rs create mode 100644 src/resource/cbindgen.toml create mode 100644 src/resource/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 316b19b9aa..919f68bce5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,6 +257,7 @@ dependencies = [ "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", @@ -277,6 +278,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" diff --git a/Cargo.toml b/Cargo.toml index fd952f3902..52bd487e6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,14 @@ 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" } 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" } diff --git a/src/resource/Cargo.toml b/src/resource/Cargo.toml new file mode 100644 index 0000000000..30cee97017 --- /dev/null +++ b/src/resource/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "resource" +version = "0.1.0" +authors = ["Dan Robertson "] + +[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 0000000000..a8c03a627e --- /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 0000000000..f9c595b682 --- /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 0000000000..26b1d702a8 --- /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!(); +} From ca7f3a00e665abe78b532d9a7b73e4bac98bcc7a Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Sat, 10 Mar 2018 21:10:12 +0000 Subject: [PATCH 3/5] wait: Add crate for sys/wait.h Add the basics of sys/wait.h so that we get a bit closer to being able to compile libc-test. --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/wait/Cargo.toml | 11 +++++++++++ src/wait/build.rs | 11 +++++++++++ src/wait/cbindgen.toml | 6 ++++++ src/wait/src/lib.rs | 43 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+) create mode 100644 src/wait/Cargo.toml create mode 100644 src/wait/build.rs create mode 100644 src/wait/cbindgen.toml create mode 100644 src/wait/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 919f68bce5..1aa856883c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -266,6 +266,7 @@ dependencies = [ "sys_time 0.1.0", "time 0.1.0", "unistd 0.1.0", + "wait 0.1.0", "wctype 0.1.0", ] @@ -622,6 +623,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 52bd487e6e..8cbf11754b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,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/src/wait/Cargo.toml b/src/wait/Cargo.toml new file mode 100644 index 0000000000..50d48a5efe --- /dev/null +++ b/src/wait/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "wait" +version = "0.1.0" +authors = ["Dan Robertson "] + +[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 0000000000..53a786af45 --- /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 0000000000..186d5f9573 --- /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 0000000000..51fdd28569 --- /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!(); +} From f29e6b00d7d61c89d8b39942bc57019f3edd9ad5 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Sat, 10 Mar 2018 21:10:20 +0000 Subject: [PATCH 4/5] fenv: Add crate for fenv.h Add a crate for building out stub functions and structures for the fenv header. --- Cargo.lock | 10 +++++++ Cargo.toml | 1 + src/fenv/Cargo.toml | 10 +++++++ src/fenv/build.rs | 11 ++++++++ src/fenv/cbindgen.toml | 6 ++++ src/fenv/src/lib.rs | 62 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+) create mode 100644 src/fenv/Cargo.toml create mode 100644 src/fenv/build.rs create mode 100644 src/fenv/cbindgen.toml create mode 100644 src/fenv/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 1aa856883c..386e266cae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,6 +96,15 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "fenv" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "platform 0.1.0", + "resource 0.1.0", +] + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -254,6 +263,7 @@ dependencies = [ "ctype 0.1.0", "errno 0.1.0", "fcntl 0.1.0", + "fenv 0.1.0", "grp 0.1.0", "mman 0.1.0", "platform 0.1.0", diff --git a/Cargo.toml b/Cargo.toml index 8cbf11754b..d4594535b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-built ctype = { path = "src/ctype" } errno = { path = "src/errno" } fcntl = { path = "src/fcntl" } +fenv = { path = "src/fenv" } grp = { path = "src/grp" } semaphore = { path = "src/semaphore" } mman = { path = "src/mman" } diff --git a/src/fenv/Cargo.toml b/src/fenv/Cargo.toml new file mode 100644 index 0000000000..ed3b2142f1 --- /dev/null +++ b/src/fenv/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "fenv" +version = "0.1.0" +authors = ["Dan Robertson "] + +[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 0000000000..a79287ee76 --- /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 0000000000..4d3d6737c2 --- /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 0000000000..b97e7e3b5e --- /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!(); +} From 3699b53ba260c7e108c3bb03578b3b2672bb2672 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Sat, 10 Mar 2018 21:10:24 +0000 Subject: [PATCH 5/5] float: Add crate for float.h Add a crate with stubbed functions for the float.h header. --- Cargo.lock | 11 ++++++++++- Cargo.toml | 1 + include/bits/float.h | 6 ++++++ src/float/Cargo.toml | 11 +++++++++++ src/float/build.rs | 11 +++++++++++ src/float/cbindgen.toml | 6 ++++++ src/float/src/lib.rs | 19 +++++++++++++++++++ 7 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 include/bits/float.h create mode 100644 src/float/Cargo.toml create mode 100644 src/float/build.rs create mode 100644 src/float/cbindgen.toml create mode 100644 src/float/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 386e266cae..b9ae70624b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,15 @@ version = "0.1.0" dependencies = [ "cbindgen 0.5.0", "platform 0.1.0", - "resource 0.1.0", +] + +[[package]] +name = "float" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "fenv 0.1.0", + "platform 0.1.0", ] [[package]] @@ -264,6 +272,7 @@ dependencies = [ "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", diff --git a/Cargo.toml b/Cargo.toml index d4594535b1..55d8d5e913 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ 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" } diff --git a/include/bits/float.h b/include/bits/float.h new file mode 100644 index 0000000000..c62ae491dc --- /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/src/float/Cargo.toml b/src/float/Cargo.toml new file mode 100644 index 0000000000..3ae7acb3fe --- /dev/null +++ b/src/float/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "float" +version = "0.1.0" +authors = ["Dan Robertson "] + +[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 0000000000..e9b224fd13 --- /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 0000000000..bbb97a8139 --- /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 0000000000..e594fdba78 --- /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, + } +}