瀏覽代碼

Implement some functions on Linux

Jeremy Soller 7 年之前
父節點
當前提交
78e421cb72
共有 24 個文件被更改,包括 772 次插入46 次删除
  1. 0 1
      .gitignore
  2. 553 0
      Cargo.lock
  3. 3 4
      Cargo.toml
  4. 11 0
      crt0/Cargo.toml
  5. 37 0
      crt0/src/lib.rs
  6. 1 1
      fcntl/Cargo.toml
  7. 13 22
      fcntl/src/lib.rs
  8. 8 0
      fcntl/src/linux.rs
  9. 20 0
      fcntl/src/redox.rs
  10. 2 0
      include/sys/types.h
  11. 4 1
      platform/Cargo.toml
  12. 19 0
      platform/src/lib.rs
  13. 26 0
      platform/src/linux/mod.rs
  14. 8 0
      platform/src/redox/mod.rs
  15. 0 5
      platform/src/types.rs
  16. 1 0
      rust-toolchain
  17. 20 2
      src/lib.rs
  18. 7 0
      test.sh
  19. 2 0
      tests/.gitignore
  20. 12 3
      tests/Makefile
  21. 14 0
      tests/create.c
  22. 2 1
      tests/write.c
  23. 1 1
      unistd/Cargo.toml
  24. 8 5
      unistd/src/lib.rs

+ 0 - 1
.gitignore

@@ -1,2 +1 @@
-/Cargo.lock
 /target/

+ 553 - 0
Cargo.lock

@@ -0,0 +1,553 @@
+[[package]]
+name = "ansi_term"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "atty"
+version = "0.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cbindgen"
+version = "0.5.0"
+dependencies = [
+ "clap 2.30.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.27 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "standalone-syn 0.12.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tempdir 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "cfg-if"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "clap"
+version = "2.30.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.0.1 (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)",
+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "compiler_builtins"
+version = "0.1.0"
+source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#8fe94f3553f92cd6ba21aadc852bd6a3e01194db"
+
+[[package]]
+name = "crt0"
+version = "0.1.0"
+dependencies = [
+ "platform 0.1.0",
+]
+
+[[package]]
+name = "dtoa"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "fcntl"
+version = "0.1.0"
+dependencies = [
+ "cbindgen 0.5.0",
+ "platform 0.1.0",
+]
+
+[[package]]
+name = "fuchsia-zircon"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "fuchsia-zircon-sys"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "itoa"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "kernel32-sys"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "log"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "log"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "owning_ref"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "parking_lot"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot_core 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "parking_lot_core"
+version = "0.2.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "platform"
+version = "0.1.0"
+dependencies = [
+ "syscall 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "quote"
+version = "0.3.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rand"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "redox_syscall"
+version = "0.1.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "redox_termios"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "relibc"
+version = "0.1.0"
+dependencies = [
+ "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)",
+ "fcntl 0.1.0",
+ "platform 0.1.0",
+ "unistd 0.1.0",
+]
+
+[[package]]
+name = "remove_dir_all"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-ap-proc_macro"
+version = "40.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rustc-ap-rustc_errors 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-syntax 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-syntax_pos 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-ap-rustc_cratesio_shim"
+version = "40.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-ap-rustc_data_structures"
+version = "40.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot_core 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-serialize 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-ap-rustc_errors"
+version = "40.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rustc-ap-rustc_data_structures 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-serialize 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-syntax_pos 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-ap-serialize"
+version = "40.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rustc-ap-syntax"
+version = "40.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-rustc_cratesio_shim 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-rustc_data_structures 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-rustc_errors 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-serialize 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-syntax_pos 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-ap-syntax_pos"
+version = "40.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rustc-ap-rustc_data_structures 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-ap-serialize 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "serde_derive_internals"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.10"
+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.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "smallvec"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "stable_deref_trait"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "standalone-proc-macro2"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rustc-ap-proc_macro 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "standalone-quote"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rustc-ap-proc_macro 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "standalone-proc-macro2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "standalone-syn"
+version = "0.12.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rustc-ap-proc_macro 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "standalone-proc-macro2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "standalone-quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "strsim"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "syn"
+version = "0.11.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "synom"
+version = "0.11.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "syscall"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "tempdir"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "remove_dir_all 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "term"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "termion"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "toml"
+version = "0.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unicode-width"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "unicode-xid"
+version = "0.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "unicode-xid"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "unistd"
+version = "0.1.0"
+dependencies = [
+ "cbindgen 0.5.0",
+ "platform 0.1.0",
+]
+
+[[package]]
+name = "vec_map"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "winapi-build"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455"
+"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859"
+"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
+"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
+"checksum clap 2.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1c07b9257a00f3fc93b7f3c417fc15607ec7a56823bc2c37ec744e266387de5b"
+"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"
+"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
+"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"
+"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
+"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
+"checksum num-traits 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3c2bd9b9d21e48e956b763c9f37134dc62d9e95da6edb3f672cacb6caf3cd3"
+"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
+"checksum parking_lot 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd9d732f2de194336fb02fe11f9eed13d9e76f13f4315b4d88a14ca411750cd"
+"checksum parking_lot_core 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "538ef00b7317875071d5e00f603f24d16f0b474c1a5fc0ccb8b454ca72eafa79"
+"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 redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
+"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
+"checksum remove_dir_all 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d2f806b0fcdabd98acd380dc8daef485e22bcb7cddc811d1337967f2528cf5"
+"checksum rustc-ap-proc_macro 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d96f017dd18a6925618e1caf4a375ba2a5a175471172e18cc4855ac0587231ff"
+"checksum rustc-ap-rustc_cratesio_shim 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6773cafaa546d932d62eb22fe854772f4d1b973245b36727c893a9fea3dbc4c6"
+"checksum rustc-ap-rustc_data_structures 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a64e8c55c343448d6a0904e2066710be2734284d904b52b8fd064ca201ca854b"
+"checksum rustc-ap-rustc_errors 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad6d84133da5f6b51c544b981c6b405e79db0a4fca41e34d77849846ed3b9121"
+"checksum rustc-ap-serialize 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43d227b1b3de1ec6d3fb48e10799d08c073c57e45f536766e1d897d46b737e0b"
+"checksum rustc-ap-syntax 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b6e525fc674e8a75eaed08a90a6df7adfa73a66135056577722185dd7ca0771"
+"checksum rustc-ap-syntax_pos 40.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e157f53ad5c4a6cf9ae5b5be15325dd2eeca190c03ab9873cc1460788767e5e9"
+"checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526"
+"checksum serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ba7591cfe93755e89eeecdbcc668885624829b020050e6aec99c2a03bd3fd0"
+"checksum serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e03f1c9530c3fb0a0a5c9b826bdd9246a5921ae995d75f512ac917fc4dd55b5"
+"checksum serde_json 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "57781ed845b8e742fc2bf306aba8e3b408fe8c366b900e3769fbc39f49eb8b39"
+"checksum smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44db0ecb22921ef790d17ae13a3f6d15784183ff5f2a01aa32098c7498d2b4b9"
+"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
+"checksum standalone-proc-macro2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "04b0e28c7fb04d85743490bd2a24bd0ec0ff6efc74e7c848748fd9fd2b105410"
+"checksum standalone-quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "45bd227b8113ff91db4f6eadcc73928dc602af00a851f4fe65f3c1cb1a96b5e1"
+"checksum standalone-syn 0.12.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d800cb9b3b2e08877667aace544bb0882ea3d5cf3ae83c2730a9032becf1f6bd"
+"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
+"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
+"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
+"checksum syscall 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dae2c4de039bf338dd96f46621f20222c4101045dac5403b46f472608cb5b556"
+"checksum tempdir 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f73eebdb68c14bcb24aef74ea96079830e7fa7b31a6106e42ea7ee887c1e134e"
+"checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1"
+"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 toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e"
+"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 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"
+"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
+"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

+ 3 - 4
Cargo.toml

@@ -8,17 +8,16 @@ name = "c"
 crate-type = ["staticlib"]
 
 [workspace]
+members = ["crt0"]
 
 [dependencies]
+compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] }
+platform = { path = "platform" }
 fcntl = { path = "fcntl" }
 unistd = { path = "unistd" }
 
 [profile.dev]
-incremental = false
-lto = true
 panic = "abort"
 
 [profile.release]
-incremental = false
-lto = true
 panic = "abort"

+ 11 - 0
crt0/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "crt0"
+version = "0.1.0"
+authors = ["Jeremy Soller <[email protected]>"]
+
+[lib]
+name = "crt0"
+crate-type = ["staticlib"]
+
+[dependencies]
+platform = { path = "../platform" }

+ 37 - 0
crt0/src/lib.rs

@@ -0,0 +1,37 @@
+//! crt0
+
+#![no_std]
+#![feature(asm)]
+#![feature(lang_items)]
+#![feature(naked_functions)]
+
+extern crate platform;
+
+use platform::types::*;
+
+#[no_mangle]
+#[naked]
+pub unsafe extern "C" fn _start() {
+    asm!("mov rdi, rsp
+        call _start_rust"
+        :
+        :
+        :
+        : "intel"
+    );
+}
+
+#[inline(never)]
+#[no_mangle]
+pub unsafe extern "C" fn _start_rust(sp: usize) -> ! {
+    extern "C" {
+        fn main(argc: c_int, argv: *const *const c_char) -> c_int;
+    }
+
+    platform::exit(main(0, 0 as *const *const c_char));
+}
+
+#[lang = "panic_fmt"]
+pub extern "C" fn rust_begin_unwind(fmt: ::core::fmt::Arguments, file: &str, line: u32) -> ! {
+    loop {}
+}

+ 1 - 1
fcntl/Cargo.toml

@@ -8,4 +8,4 @@ build = "build.rs"
 cbindgen = { path = "../cbindgen" }
 
 [dependencies]
-common = { path = "../common" }
+platform = { path = "../platform" }

+ 13 - 22
fcntl/src/lib.rs

@@ -2,9 +2,19 @@
 
 #![no_std]
 
-extern crate common;
+extern crate platform;
 
-pub use common::*;
+use platform::types::*;
+
+pub use sys::*;
+
+#[cfg(target_os = "linux")]
+#[path="linux.rs"]
+pub mod sys;
+
+#[cfg(target_os = "redox")]
+#[path="redox.rs"]
+pub mod sys;
 
 pub const F_DUPFD: c_int = 0;
 pub const F_GETFD: c_int = 1;
@@ -21,25 +31,6 @@ pub const F_RDLCK: c_int = 0;
 pub const F_WRLCK: c_int = 1;
 pub const F_UNLCK: c_int = 2;
 
-pub const O_RDONLY: c_int =     0x0001_0000;
-pub const O_WRONLY: c_int =     0x0002_0000;
-pub const O_RDWR: c_int =       0x0003_0000;
-pub const O_NONBLOCK: c_int =   0x0004_0000;
-pub const O_APPEND: c_int =     0x0008_0000;
-pub const O_SHLOCK: c_int =     0x0010_0000;
-pub const O_EXLOCK: c_int =     0x0020_0000;
-pub const O_ASYNC: c_int =      0x0040_0000;
-pub const O_FSYNC: c_int =      0x0080_0000;
-pub const O_CLOEXEC: c_int =    0x0100_0000;
-pub const O_CREAT: c_int =      0x0200_0000;
-pub const O_TRUNC: c_int =      0x0400_0000;
-pub const O_EXCL: c_int =       0x0800_0000;
-pub const O_DIRECTORY: c_int =  0x1000_0000;
-pub const O_STAT: c_int =       0x2000_0000;
-pub const O_SYMLINK: c_int =    0x4000_0000;
-pub const O_NOFOLLOW: c_int =   0x8000_0000;
-pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR;
-
 #[no_mangle]
 pub extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int {
     open(path, O_WRONLY | O_CREAT | O_TRUNC, mode)
@@ -52,7 +43,7 @@ pub extern "C" fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
 
 #[no_mangle]
 pub extern "C" fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
-    unimplemented!();
+    platform::open(path, oflag, mode)
 }
 
 /*

+ 8 - 0
fcntl/src/linux.rs

@@ -0,0 +1,8 @@
+use platform::types::*;
+
+pub const O_RDONLY: c_int =     0x0000;
+pub const O_WRONLY: c_int =     0x0001;
+pub const O_RDWR: c_int =       0x0002;
+pub const O_CREAT: c_int =      0x0040;
+pub const O_TRUNC: c_int =      0x0200;
+pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR;

+ 20 - 0
fcntl/src/redox.rs

@@ -0,0 +1,20 @@
+use platform::types::*;
+
+pub const O_RDONLY: c_int =     0x0001_0000;
+pub const O_WRONLY: c_int =     0x0002_0000;
+pub const O_RDWR: c_int =       0x0003_0000;
+pub const O_NONBLOCK: c_int =   0x0004_0000;
+pub const O_APPEND: c_int =     0x0008_0000;
+pub const O_SHLOCK: c_int =     0x0010_0000;
+pub const O_EXLOCK: c_int =     0x0020_0000;
+pub const O_ASYNC: c_int =      0x0040_0000;
+pub const O_FSYNC: c_int =      0x0080_0000;
+pub const O_CLOEXEC: c_int =    0x0100_0000;
+pub const O_CREAT: c_int =      0x0200_0000;
+pub const O_TRUNC: c_int =      0x0400_0000;
+pub const O_EXCL: c_int =       0x0800_0000;
+pub const O_DIRECTORY: c_int =  0x1000_0000;
+pub const O_STAT: c_int =       0x2000_0000;
+pub const O_SYMLINK: c_int =    0x4000_0000;
+pub const O_NOFOLLOW: c_int =   0x8000_0000;
+pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR;

+ 2 - 0
include/sys/types.h

@@ -4,6 +4,8 @@
 typedef int gid_t;
 typedef int uid_t;
 
+typedef int mode_t;
+
 typedef long off_t;
 
 typedef int pid_t;

+ 4 - 1
common/Cargo.toml → platform/Cargo.toml

@@ -1,4 +1,7 @@
 [package]
-name = "common"
+name = "platform"
 version = "0.1.0"
 authors = ["Jeremy Soller <[email protected]>"]
+
+[dependencies]
+syscall = "0.2"

+ 19 - 0
platform/src/lib.rs

@@ -0,0 +1,19 @@
+//! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html
+
+#![no_std]
+#![allow(non_camel_case_types)]
+
+#[macro_use]
+extern crate syscall;
+
+pub use sys::*;
+
+#[cfg(all(not(feature="no_std"), target_os = "linux"))]
+#[path="linux/mod.rs"]
+mod sys;
+
+#[cfg(all(not(feature="no_std"), target_os = "redox"))]
+#[path="redox/mod.rs"]
+mod sys;
+
+pub mod types;

+ 26 - 0
platform/src/linux/mod.rs

@@ -0,0 +1,26 @@
+use types::*;
+
+pub fn close(fildes: c_int) -> c_int {
+    unsafe {
+        syscall!(CLOSE, fildes) as c_int
+    }
+}
+
+pub fn exit(status: c_int) -> ! {
+    unsafe {
+        syscall!(EXIT, status);
+    }
+    loop {}
+}
+
+pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
+    unsafe {
+        syscall!(OPEN, path, oflag, mode) as c_int
+    }
+}
+
+pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
+    unsafe {
+        syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) as ssize_t
+    }
+}

+ 8 - 0
platform/src/redox/mod.rs

@@ -0,0 +1,8 @@
+pub fn exit(status: c_int) -> ! {
+    syscall::exit(status);
+}
+
+pub fn write(fd: c_int, buf: &[u8]) -> ssize_t {
+    syscall::write(fd, buf);
+    buf.len() as ssize_t
+}

+ 0 - 5
common/src/lib.rs → platform/src/types.rs

@@ -1,8 +1,3 @@
-//! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html
-
-#![no_std]
-#![allow(non_camel_case_types)]
-
 // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
 // more optimization opportunities around it recognizing things like
 // malloc/free.

+ 1 - 0
rust-toolchain

@@ -0,0 +1 @@
+nightly-2018-03-02

+ 20 - 2
src/lib.rs

@@ -1,14 +1,32 @@
 #![no_std]
 #![feature(lang_items)]
 
+extern crate compiler_builtins;
+extern crate platform;
+
 extern crate fcntl;
 extern crate unistd;
 
 pub use fcntl::*;
 pub use unistd::*;
 
+use core::fmt;
+
+struct PanicWriter;
+
+impl fmt::Write for PanicWriter {
+    fn write_str(&mut self, s: &str) -> fmt::Result {
+        platform::write(2, s.as_bytes());
+        Ok(())
+    }
+}
+
 #[lang = "panic_fmt"]
 #[no_mangle]
-pub extern "C" fn rust_begin_unwind(fmt: ::core::fmt::Arguments, file: &str, line: u32) -> ! {
-    loop {}
+pub extern "C" fn rust_begin_unwind(fmt: fmt::Arguments, file: &str, line: u32) -> ! {
+    use fmt::Write;
+
+    let _ = PanicWriter.write_fmt(format_args!("{}:{}: {}\n", file, line, fmt));
+
+    platform::exit(1);
 }

+ 7 - 0
test.sh

@@ -0,0 +1,7 @@
+set -ex
+
+cargo build
+cargo build --manifest-path crt0/Cargo.toml
+cd tests
+make clean
+make run

+ 2 - 0
tests/.gitignore

@@ -1 +1,3 @@
+/create
+/create.out
 /write

+ 12 - 3
tests/Makefile

@@ -1,5 +1,14 @@
-write: write.c
-	gcc -nostdinc -nostdlib -I ../include -I ../target/include $< ../target/debug/libc.a -o $@
+BINS=\
+	create \
+	write
+
+all: $(BINS)
 
 clean:
-	rm -f write
+	rm -f $(BINS)
+
+run: $(BINS)
+	for bin in $(BINS); do echo "\\033[1m$${bin}\\033[0m"; ./$${bin}; done
+
+%: %.c
+	gcc -nostdinc -nostdlib -I ../include -I ../target/include ../target/debug/libcrt0.a $< ../target/debug/libc.a -o $@

+ 14 - 0
tests/create.c

@@ -0,0 +1,14 @@
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+    int fd = creat("create.out", 0755);
+    if (fd >= 0) {
+        write(fd, "Hello World!\n", 14);
+        close(fd);
+        return 0;
+    } else {
+        write(2, "creat failed\n", 14);
+        return 1;
+    }
+}

+ 2 - 1
tests/write.c

@@ -1,5 +1,6 @@
 #include <unistd.h>
 
-void _start(void) {
+int main(int argc, char **argv) {
     write(STDOUT_FILENO, "Hello World!\n", 14);
+    return 0;
 }

+ 1 - 1
unistd/Cargo.toml

@@ -8,4 +8,4 @@ build = "build.rs"
 cbindgen = { path = "../cbindgen" }
 
 [dependencies]
-common = { path = "../common" }
+platform = { path = "../platform" }

+ 8 - 5
unistd/src/lib.rs

@@ -2,9 +2,9 @@
 
 #![no_std]
 
-extern crate common;
+extern crate platform;
 
-pub use common::*;
+pub use platform::types::*;
 
 pub const NULL: c_int = 0;
 
@@ -28,7 +28,7 @@ pub const STDERR_FILENO: c_int = 2;
 
 #[no_mangle]
 pub extern "C" fn _exit(status: c_int) {
-    unimplemented!();
+    platform::exit(status)
 }
 
 #[no_mangle]
@@ -63,7 +63,7 @@ pub extern "C" fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_in
 
 #[no_mangle]
 pub extern "C" fn close(fildes: c_int) -> c_int {
-    unimplemented!();
+    platform::close(fildes)
 }
 
 #[no_mangle]
@@ -448,7 +448,10 @@ pub extern "C" fn vfork() -> pid_t {
 
 #[no_mangle]
 pub extern "C" fn write(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssize_t {
-    unimplemented!();
+    use core::slice;
+
+    let buf = unsafe { slice::from_raw_parts(buf as *const u8, nbyte as usize) };
+    platform::write(fildes, buf)
 }
 
 /*