diff --git a/.gitmodules b/.gitmodules index e74985c934..1476a84826 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "core_io"] path = core_io url = https://gitlab.redox-os.org/redox-os/core_io.git +[submodule "posix-regex"] + path = posix-regex + url = https://gitlab.redox-os.org/redox-os/posix-regex.git diff --git a/Cargo.lock b/Cargo.lock index 6373598afd..4f82714bd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,12 +27,12 @@ version = "0.5.2" dependencies = [ "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.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.80 (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.30 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -50,7 +50,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -70,11 +70,11 @@ dependencies = [ [[package]] name = "compiler_builtins" version = "0.1.0" -source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#b69172a8baf47948dca6057235a5c9cdd337d6c1" +source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#939cbca6e9d829265d6cf006d3532142a4061cd3" [[package]] name = "core_io" -version = "0.1.20180619" +version = "0.1.20181107" dependencies = [ "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -115,11 +115,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -132,15 +131,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -151,7 +150,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "posix-regex" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" @@ -197,12 +195,20 @@ name = "rand" version = "0.5.5" 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)", + "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" -version = "0.2.1" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -230,14 +236,14 @@ dependencies = [ "cbitset 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)", - "core_io 0.1.20180619", - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "posix-regex 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core_io 0.1.20181107", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "posix-regex 0.1.0", "ralloc 1.0.0", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)", "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "va_list 0.1.0", ] @@ -274,7 +280,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.79" +version = "1.0.80" 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)", @@ -301,17 +307,17 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.30" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "spin" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -384,10 +390,10 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -429,11 +435,6 @@ name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "winapi" version = "0.3.6" @@ -459,23 +460,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum cbitset 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3a9afa72f63942dd7e7f01c67b863ce9df35c523ae10e3dddd3eec8f1e07eac" "checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" -"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" +"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "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)" = "" "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.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" +"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" +"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" -"checksum posix-regex 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "58b31ca4f5022c6c0a22206d63c177be2f418355db5a713db22bd901c6ac0db3" "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.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" -"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" +"checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" +"checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" "checksum redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)" = "" "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" @@ -484,11 +485,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7" "checksum sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ebbb026ba4a707c25caec2db5ef59ad8b41f7ad77cad06257e06229c891f376" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" -"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9" +"checksum serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "15c141fc7027dd265a47c090bf864cf62b42c4d228bbcf4e51a0c9e2b0d3f7ef" "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.30 (registry+https://github.com/rust-lang/crates.io-index)" = "7f60a296fed15c3edbbe9aa83b646531459e565c525b0ab628deb1a4b28e4180" -"checksum spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "37b5646825922b96b5d7d676b5bb3458a54498e96ed7b0ce09dc43a07038fea4" +"checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce" +"checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f" "checksum standalone-quote 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcedac1d6d98e7e9d1d6e628f5635af9566688ae5f6cea70a3976f495ae8d839" "checksum standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "115808f5187c07c23cb93eee49d542fae54c6e8285d3a24c6ff683fcde9243db" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" @@ -497,13 +498,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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.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 toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4a2ecc31b0351ea18b3fe11274b8db6e4d82bce861bbb22e6dbed40417902c65" "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" "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.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "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" diff --git a/Cargo.toml b/Cargo.toml index dfb97528db..afbc0f2ced 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,14 +12,14 @@ members = ["src/crt0", "src/crti", "src/crtn", "cbindgen"] exclude = ["core_io", "ralloc"] [build-dependencies] -cc = "1.0.17" +cc = "1.0.25" [dependencies] cbitset = "0.1.0" core_io = { path = "core_io", features = ["collections"] } -lazy_static = { version = "*", features = ["nightly", "spin_no_std"] } -posix-regex = { version = "0.1", features = ["no_std"] } -rand = { version = "0.5.2", default-features = false } +lazy_static = { version = "1.2.0", features = ["nightly", "spin_no_std"] } +posix-regex = { path = "posix-regex", features = ["no_std"] } +rand = { version = "0.5.5", default-features = false } va_list = { path = "va_list", features = ["no_std"] } [dependencies.compiler_builtins] @@ -33,11 +33,11 @@ default-features = false optional = true [target.'cfg(target_os = "linux")'.dependencies] -sc = "0.2" +sc = "0.2.2" [target.'cfg(target_os = "redox")'.dependencies] redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git", branch = "relibc" } -spin = "0.4" +spin = "0.4.10" [features] #default = ["trace"] diff --git a/core_io b/core_io index 5a15b81b2f..eb72048307 160000 --- a/core_io +++ b/core_io @@ -1 +1 @@ -Subproject commit 5a15b81b2f24dd3fd36d95e41433a23b46903fd3 +Subproject commit eb7204830786d7cbb776c6a878c7a59569840484 diff --git a/posix-regex b/posix-regex new file mode 160000 index 0000000000..eccf84478c --- /dev/null +++ b/posix-regex @@ -0,0 +1 @@ +Subproject commit eccf84478c7a60a2869bbe438cb1d2507c9f45b2 diff --git a/rust-toolchain b/rust-toolchain index a47068b222..48887947cd 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2018-06-19 +nightly-2018-11-07 diff --git a/src/c_str.rs b/src/c_str.rs index cb37b89593..f9b5f9c91a 100644 --- a/src/c_str.rs +++ b/src/c_str.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use alloc::arc::Arc; use alloc::borrow::{Borrow, Cow, ToOwned}; use alloc::boxed::Box; use alloc::rc::Rc; use alloc::string::String; +use alloc::sync::Arc; use alloc::vec::Vec; use core::ascii; use core::cmp::Ordering; diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index ca2c2ff2e2..1b64be4e73 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -5,7 +5,6 @@ #![feature(lang_items)] #![feature(linkage)] #![feature(naked_functions)] -#![feature(panic_implementation)] #[no_mangle] #[naked] @@ -29,7 +28,7 @@ pub unsafe extern "C" fn _start() { ); } -#[panic_implementation] +#[panic_handler] #[linkage = "weak"] #[no_mangle] pub extern "C" fn rust_begin_unwind(_pi: &::core::panic::PanicInfo) -> ! { diff --git a/src/crti/src/lib.rs b/src/crti/src/lib.rs index 673d443907..9843734faf 100644 --- a/src/crti/src/lib.rs +++ b/src/crti/src/lib.rs @@ -3,7 +3,6 @@ #![no_std] #![feature(global_asm)] #![feature(linkage)] -#![feature(panic_implementation)] // https://wiki.osdev.org/Creating_a_C_Library#crtbegin.o.2C_crtend.o.2C_crti.o.2C_and_crtn.o #[cfg(target_arch = "x86_64")] @@ -46,7 +45,7 @@ global_asm!(r#" // Body will be filled in by gcc and ended by crtn.o "#); -#[panic_implementation] +#[panic_handler] #[linkage = "weak"] #[no_mangle] pub extern "C" fn rust_begin_unwind(_pi: &::core::panic::PanicInfo) -> ! { diff --git a/src/crtn/src/lib.rs b/src/crtn/src/lib.rs index 371c2e7716..b0ae758465 100644 --- a/src/crtn/src/lib.rs +++ b/src/crtn/src/lib.rs @@ -3,7 +3,6 @@ #![no_std] #![feature(global_asm)] #![feature(linkage)] -#![feature(panic_implementation)] // https://wiki.osdev.org/Creating_a_C_Library#crtbegin.o.2C_crtend.o.2C_crti.o.2C_and_crtn.o #[cfg(target_arch = "x86_64")] @@ -36,7 +35,7 @@ global_asm!(r#" ret "#); -#[panic_implementation] +#[panic_handler] #[linkage = "weak"] #[no_mangle] pub extern "C" fn rust_begin_unwind(_pi: &::core::panic::PanicInfo) -> ! { diff --git a/src/header/_oldlib/dns/answer.rs b/src/header/_oldlib/dns/answer.rs deleted file mode 100644 index d50570bbbd..0000000000 --- a/src/header/_oldlib/dns/answer.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use alloc::String; -use alloc::Vec; - -#[derive(Clone, Debug)] -pub struct DnsAnswer { - pub name: String, - pub a_type: u16, - pub a_class: u16, - pub ttl_a: u16, - pub ttl_b: u16, - pub data: Vec -} diff --git a/src/header/_oldlib/dns/mod.rs b/src/header/_oldlib/dns/mod.rs deleted file mode 100644 index 94cc2b0747..0000000000 --- a/src/header/_oldlib/dns/mod.rs +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub use self::answer::DnsAnswer; -pub use self::query::DnsQuery; - -use core::slice; -use core::u16; -use alloc::String; -use alloc::Vec; - -mod answer; -mod query; - -#[allow(non_camel_case_types)] -#[derive(Copy, Clone, Debug, Default)] -#[repr(packed)] -pub struct n16 { - inner: u16 -} - -impl n16 { - pub fn as_bytes(&self) -> &[u8] { - unsafe { slice::from_raw_parts((&self.inner as *const u16) as *const u8, 2) } - } - - pub fn from_bytes(bytes: &[u8]) -> Self { - n16 { - inner: unsafe { slice::from_raw_parts(bytes.as_ptr() as *const u16, bytes.len()/2)[0] } - } - } -} - -impl From for n16 { - fn from(value: u16) -> Self { - n16 { - inner: value.to_be() - } - } -} - -impl From for u16 { - fn from(value: n16) -> Self { - u16::from_be(value.inner) - } -} - -#[derive(Clone, Debug)] -pub struct Dns { - pub transaction_id: u16, - pub flags: u16, - pub queries: Vec, - pub answers: Vec -} - -impl Dns { - pub fn compile(&self) -> Vec { - let mut data = Vec::new(); - - macro_rules! push_u8 { - ($value:expr) => { - data.push($value); - }; - }; - - macro_rules! push_n16 { - ($value:expr) => { - data.extend_from_slice(n16::from($value).as_bytes()); - }; - }; - - push_n16!(self.transaction_id); - push_n16!(self.flags); - push_n16!(self.queries.len() as u16); - push_n16!(self.answers.len() as u16); - push_n16!(0); - push_n16!(0); - - for query in self.queries.iter() { - for part in query.name.split('.') { - push_u8!(part.len() as u8); - data.extend_from_slice(part.as_bytes()); - } - push_u8!(0); - push_n16!(query.q_type); - push_n16!(query.q_class); - } - - data - } - - pub fn parse(data: &[u8]) -> Result { - let name_ind = 0b11000000; - let mut i = 0; - - macro_rules! pop_u8 { - () => { - { - i += 1; - if i > data.len() { - return Err(format!("{}: {}: pop_u8", file!(), line!())); - } - data[i - 1] - } - }; - }; - - macro_rules! pop_n16 { - () => { - { - i += 2; - if i > data.len() { - return Err(format!("{}: {}: pop_n16", file!(), line!())); - } - u16::from(n16::from_bytes(&data[i - 2 .. i])) - } - }; - }; - - macro_rules! pop_data { - () => { - { - let mut data = Vec::new(); - - let data_len = pop_n16!(); - for _data_i in 0..data_len { - data.push(pop_u8!()); - } - - data - } - }; - }; - - macro_rules! pop_name { - () => { - { - let mut name = String::new(); - let old_i = i; - - loop { - let name_len = pop_u8!(); - if name_len & name_ind == name_ind { - i -= 1; - i = (pop_n16!() - ((name_ind as u16) << 8)) as usize; - continue; - } - if name_len == 0 { - break; - } - if ! name.is_empty() { - name.push('.'); - } - for _name_i in 0..name_len { - name.push(pop_u8!() as char); - } - } - - if i <= old_i { - i = old_i + 2; - } - - name - } - }; - }; - - let transaction_id = pop_n16!(); - let flags = pop_n16!(); - let queries_len = pop_n16!(); - let answers_len = pop_n16!(); - pop_n16!(); - pop_n16!(); - - let mut queries = Vec::new(); - for _query_i in 0..queries_len { - queries.push(DnsQuery { - name: pop_name!(), - q_type: pop_n16!(), - q_class: pop_n16!() - }); - } - - let mut answers = Vec::new(); - for _answer_i in 0..answers_len { - answers.push(DnsAnswer { - name: pop_name!(), - a_type: pop_n16!(), - a_class: pop_n16!(), - ttl_a: pop_n16!(), - ttl_b: pop_n16!(), - data: pop_data!() - }); - } - - Ok(Dns { - transaction_id: transaction_id, - flags: flags, - queries: queries, - answers: answers, - }) - } -} diff --git a/src/header/_oldlib/dns/query.rs b/src/header/_oldlib/dns/query.rs deleted file mode 100644 index f0b536fd60..0000000000 --- a/src/header/_oldlib/dns/query.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use alloc::String; - -#[derive(Clone, Debug)] -pub struct DnsQuery { - pub name: String, - pub q_type: u16, - pub q_class: u16 -} diff --git a/src/header/_oldlib/event.rs b/src/header/_oldlib/event.rs deleted file mode 100644 index 297a18f201..0000000000 --- a/src/header/_oldlib/event.rs +++ /dev/null @@ -1,51 +0,0 @@ -use core::slice; -use libc::{c_int, c_uint}; -use syscall::error::{Error, EINVAL}; -use types::{fd_set, pollfd, timeval, FD_SETSIZE, POLLIN, POLLOUT, NFDBITS}; - -libc_fn!(unsafe poll(fds: *mut pollfd, nfds: c_uint, timeout: c_int) -> Result { - let fds = slice::from_raw_parts_mut(fds, nfds as usize); - - let mut ret = 0; - for fd in fds.iter_mut() { - // always ready for read or write - fd.revents = fd.events & (POLLIN | POLLOUT); - if fd.revents != 0 { - ret += 1; - } - } - - Ok(ret) -}); - -libc_fn!(unsafe select(nfds: c_int, readfds: *mut fd_set, writefds: *mut fd_set, errorfds: *mut fd_set, _timeout: *mut timeval) -> Result { - if nfds < 0 || nfds > FD_SETSIZE as i32 { - return Err(Error::new(EINVAL)); - } - - let mut ret = 0; - for i in 0..nfds as usize { - if ! readfds.is_null() { - // always ready to read - if ((*readfds).fds_bits[i/NFDBITS] & (1 << (i % NFDBITS))) != 0 { - ret += 1; - } - } - - if ! writefds.is_null() { - // always ready to write - if ((*writefds).fds_bits[i/NFDBITS] & (1 << (i % NFDBITS))) != 0 { - ret += 1; - } - } - - if ! errorfds.is_null() { - // report no errors - if ((*errorfds).fds_bits[i/NFDBITS] & (1 << (i % NFDBITS))) != 0 { - (*errorfds).fds_bits[i/NFDBITS] &= !(1 << (i % NFDBITS)); - } - } - } - - Ok(ret) -}); diff --git a/src/header/_oldlib/file.rs b/src/header/_oldlib/file.rs deleted file mode 100644 index 72dcea0bd9..0000000000 --- a/src/header/_oldlib/file.rs +++ /dev/null @@ -1,188 +0,0 @@ -use syscall::{self, O_CLOEXEC, O_STAT, O_CREAT, O_EXCL, O_DIRECTORY, O_WRONLY, O_NOFOLLOW, TimeSpec}; -use core::slice; -use libc::{c_int, c_char, off_t, mode_t, size_t, ssize_t}; -use ::types::{utimbuf, timeval}; - -pub const PATH_MAX: usize = 4096; - - -libc_fn!(unsafe access(path: *mut c_char, _amode: c_int) -> Result { - // XXX amode - ::RawFile::open(::cstr_to_slice(path), O_CLOEXEC | O_STAT)?; - Ok(0) -}); - -libc_fn!(unsafe _close(file: c_int) -> Result { - Ok(syscall::close(file as usize)? as c_int) -}); - -libc_fn!(unsafe dup(file: c_int) -> Result { - Ok(syscall::dup(file as usize, &[])? as c_int) -}); - -libc_fn!(unsafe dup2(file: c_int, newfile: c_int) -> Result { - Ok(syscall::dup2(file as usize, newfile as usize, &[])? as c_int) -}); - -libc_fn!(unsafe _fstat(file: c_int, st: *mut syscall::Stat) -> Result { - Ok(syscall::fstat(file as usize, &mut *st)? as c_int) -}); - -libc_fn!(unsafe _fsync(file: c_int) -> Result { - Ok(syscall::fsync(file as usize)? as c_int) -}); - -libc_fn!(unsafe ftruncate(file: c_int, len: off_t) -> Result { - Ok(syscall::ftruncate(file as usize, len as usize)? as c_int) -}); - -libc_fn!(unsafe _lseek(file: c_int, ptr: off_t, dir: c_int) -> Result { - Ok(syscall::lseek(file as usize, ptr as isize, dir as usize)? as off_t) -}); - - -libc_fn!(unsafe mkdir(path: *mut c_char, mode: mode_t) -> Result { - let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | (mode as usize & 0o777); - ::RawFile::open(::cstr_to_slice(path), flags)?; - Ok(0) -}); - -libc_fn!(unsafe _open(path: *mut c_char, flags: c_int, mode: mode_t) -> Result { - let mut path = ::cstr_to_slice(path); - // XXX hack; use better method if possible - if path == b"/dev/null" { - path = b"null:" - } - Ok(syscall::open(path, flags as usize | (mode as usize & 0o777))? as c_int) -}); - -libc_fn!(unsafe pipe(pipefd: *mut [c_int; 2]) -> c_int { - pipe2(pipefd, 0) -}); - -libc_fn!(unsafe pipe2(pipefd: *mut [c_int; 2], flags: c_int) -> Result { - let mut syspipefd = [(*pipefd)[0] as usize, (*pipefd)[1] as usize]; - syscall::pipe2(&mut syspipefd, flags as usize)?; - (*pipefd)[0] = syspipefd[0] as c_int; - (*pipefd)[1] = syspipefd[1] as c_int; - Ok(0) -}); - -libc_fn!(unsafe _read(file: c_int, buf: *mut c_char, len: c_int) -> Result { - let buf = slice::from_raw_parts_mut(buf as *mut u8, len as usize); - Ok(syscall::read(file as usize, buf)? as c_int) -}); - -libc_fn!(unsafe rmdir(path: *mut c_char) -> Result { - Ok(syscall::rmdir(::cstr_to_slice(path))? as c_int) -}); - -libc_fn!(unsafe _stat(path: *const c_char, st: *mut syscall::Stat) -> Result { - let fd = ::RawFile::open(::cstr_to_slice(path), O_CLOEXEC | O_STAT)?; - Ok(syscall::fstat(*fd, &mut *st)? as c_int) -}); - -libc_fn!(unsafe lstat(path: *const c_char, st: *mut syscall::Stat) -> Result { - let fd = ::RawFile::open(::cstr_to_slice(path), O_CLOEXEC | O_STAT | O_NOFOLLOW)?; - Ok(syscall::fstat(*fd, &mut *st)? as c_int) -}); - -libc_fn!(unsafe _unlink(path: *mut c_char) -> Result { - Ok(syscall::unlink(::cstr_to_slice(path))? as c_int) -}); - -libc_fn!(unsafe _write(file: c_int, buf: *const c_char, len: c_int) -> Result { - let buf = slice::from_raw_parts(buf as *const u8, len as usize); - Ok(syscall::write(file as usize, buf)? as c_int) -}); - -libc_fn!(unsafe chmod(path: *mut c_char, mode: mode_t) -> Result { - Ok(syscall::chmod(::cstr_to_slice(path), mode as usize)? as c_int) -}); - -libc_fn!(unsafe realpath(path: *const c_char, resolved_path: *mut c_char) -> Result<*mut c_char> { - let fd = ::RawFile::open(::cstr_to_slice(path), O_STAT)?; - - let resolved_path = ::MallocNull::new(resolved_path, PATH_MAX); - let buf = slice::from_raw_parts_mut(resolved_path.as_mut_ptr() as *mut u8, PATH_MAX-1); - let length = syscall::fpath(*fd, buf)?; - buf[length] = b'\0'; - - Ok(resolved_path.into_raw()) -}); - -libc_fn!(unsafe _rename(old: *const c_char, new: *const c_char) -> Result { - // XXX fix this horror when the kernel provides rename() or link() - let old = ::cstr_to_slice(old); - let new = ::cstr_to_slice(new); - let buf = ::file_read_all(old)?; - - let mut stat = syscall::Stat::default(); - let fd = ::RawFile::open(old, syscall::O_STAT)?; - syscall::fstat(*fd, &mut stat)?; - drop(fd); - let mode = (stat.st_mode & 0o777) as usize; - - let fd = ::RawFile::open(new, O_CREAT | O_WRONLY | mode)?; - syscall::write(*fd, &buf)?; - syscall::unlink(old)?; - Ok(0) -}); - -libc_fn!(fsync(fd: c_int) -> Result { - Ok(syscall::fsync(fd as usize)? as c_int) -}); - -libc_fn!(unsafe symlink(path1: *const c_char, path2: *const c_char) -> Result { - let fd = ::RawFile::open(::cstr_to_slice(path2), syscall::O_SYMLINK | syscall::O_CREAT | syscall::O_WRONLY | 0o777)?; - syscall::write(*fd, ::cstr_to_slice(path1))?; - Ok(0) -}); - -libc_fn!(unsafe readlink(path: *const c_char, buf: *const c_char, bufsize: size_t) -> Result { - let fd = ::RawFile::open(::cstr_to_slice(path), syscall::O_SYMLINK | syscall::O_RDONLY)?; - let count = syscall::read(*fd, slice::from_raw_parts_mut(buf as *mut u8, bufsize))?; - Ok(count as ssize_t) -}); - -libc_fn!(unsafe utime(path: *mut c_char, times: *const utimbuf) -> Result { - let times = if times.is_null() { - let mut tp = TimeSpec::default(); - syscall::clock_gettime(syscall::flag::CLOCK_REALTIME, &mut tp)?; - [tp, tp] - } else { - [TimeSpec { tv_sec: (*times).actime, tv_nsec: 0 }, - TimeSpec { tv_sec: (*times).modtime, tv_nsec: 0 }] - }; - let fd = ::RawFile::open(::cstr_to_slice(path), 0)?; - syscall::futimens(*fd, ×)?; - Ok(0) -}); - -libc_fn!(unsafe utimes(path: *mut c_char, times: *const [timeval; 2]) -> Result { - let times = [TimeSpec { tv_sec: (*times)[0].tv_sec, tv_nsec: (*times)[0].tv_usec as i32 * 1000 }, - TimeSpec { tv_sec: (*times)[1].tv_sec, tv_nsec: (*times)[0].tv_usec as i32 * 1000 }]; - let fd = ::RawFile::open(::cstr_to_slice(path), 0)?; - syscall::futimens(*fd, ×)?; - Ok(0) -}); - -libc_fn!(unsafe futimens(fd: c_int, times: *const [TimeSpec; 2]) -> Result { - // XXX UTIME_NOW and UTIME_OMIT (in redoxfs?) - syscall::futimens(fd as usize, &*times)?; - Ok(0) -}); - -// XXX variadic -libc_fn!(_fcntl(file: c_int, cmd: c_int, arg: c_int) -> Result { - Ok(syscall::fcntl(file as usize, cmd as usize, arg as usize)? as c_int) -}); - -libc_fn!(_isatty(file: c_int) -> c_int { - if let Ok(fd) = syscall::dup(file as usize, b"termios") { - let _ = syscall::close(fd); - 1 - } else { - 0 - } -}); diff --git a/src/header/_oldlib/folder.rs b/src/header/_oldlib/folder.rs deleted file mode 100644 index 1406684b15..0000000000 --- a/src/header/_oldlib/folder.rs +++ /dev/null @@ -1,94 +0,0 @@ -extern crate libc; -extern crate core; -use ::{c_int, c_char}; -use syscall::{self, O_CLOEXEC, O_RDONLY, O_DIRECTORY}; -use core::ptr::null; -use core::default::Default; -use alloc::boxed::Box; -use ::file::PATH_MAX; -use ::types::{ino_t, off_t}; -use libc::*; - -#[repr(C)] -pub struct dirent { - pub d_ino: ino_t, - pub d_off: off_t, - pub d_reclen: c_ushort, - pub d_type: c_uchar, - pub d_name: [c_char; PATH_MAX] -} -impl core::default::Default for dirent { - fn default() -> dirent { - dirent { - d_ino: 0, - d_off: 0, - d_reclen: 0, - d_type: 0, - d_name: [0; PATH_MAX], - } - } -} - -pub struct DIR { - pub fd: ::RawFile, - pub ent: dirent, - pub buf: [u8; PATH_MAX], - pub count: usize, - pub pos: usize -} - -libc_fn!(unsafe opendir(path: *mut c_char) -> Result<*mut DIR> { - let path = ::cstr_to_slice(path); - let fd = ::RawFile::open(path, O_RDONLY | O_CLOEXEC | O_DIRECTORY)?; - let dir = Box::new(DIR { - fd, - ent: dirent::default(), - buf: [0; PATH_MAX], - count: 0, - pos: 0 - - }); - Ok(Box::into_raw(dir)) -}); - -libc_fn!(unsafe readdir(dir: *mut DIR) -> Result<*const dirent> { - if let Some(dir) = dir.as_mut() { - let mut i = 0; - 'outer: while i < PATH_MAX - 1 { - while dir.pos < dir.count { - dir.ent.d_name[i] = dir.buf[dir.pos] as c_char; - dir.pos += 1; - if dir.buf[dir.pos-1] == b'\n' { - break 'outer; - } - i += 1; - } - dir.count = syscall::read(*dir.fd, &mut dir.buf)?; - if dir.count == 0 { - break; - } - dir.pos = 0; - } - if i != 0 { - dir.ent.d_name[i] = 0; - return Ok(&dir.ent); - } - } - Ok(null()) -}); - -libc_fn!(unsafe rewinddir(dir: *mut DIR) { - if let Some(dir) = dir.as_mut() { - dir.count = 0; - let _ = syscall::lseek(*dir.fd, 0, syscall::SEEK_SET); - } -}); - -libc_fn!(unsafe closedir(dir: *mut DIR) -> Result { - Box::from_raw(dir); - Ok(0) -}); - -libc_fn!(unsafe dirfd(dir: *mut DIR) -> Result { - Ok(*(*dir).fd as i32) -}); diff --git a/src/header/_oldlib/hostname.rs b/src/header/_oldlib/hostname.rs deleted file mode 100644 index 5618a87f07..0000000000 --- a/src/header/_oldlib/hostname.rs +++ /dev/null @@ -1,107 +0,0 @@ -use core::ptr::null; -use core::{mem, str, slice}; -use alloc::vec::IntoIter; -use alloc::string::ToString; -use alloc::{Vec, String}; -use ::dns::{Dns, DnsQuery}; -use syscall::{self, Result, EINVAL, Error}; -use libc::{c_char, size_t, c_int}; -use ::types::{in_addr, hostent}; - -static mut HOST_ENTRY: hostent = hostent { h_name: null(), h_aliases: null(), h_addrtype: 0, h_length: 0, h_addr_list: null() }; -static mut HOST_NAME: Option> = None; -static mut HOST_ALIASES: [*const c_char; 1] = [null()]; -static mut HOST_ADDR: Option = None; -static mut HOST_ADDR_LIST: [*const c_char; 2] = [null(); 2]; - -struct LookupHost(IntoIter); - -impl Iterator for LookupHost { - type Item = in_addr; - fn next(&mut self) -> Option { - self.0.next() - } -} - -// Modified from rust/sys/redox/net/mod.rs -fn lookup_host(host: &str) -> Result { - // XXX better error handling - let ip_string = String::from_utf8(::file_read_all("/etc/net/ip")?) - .or(Err(Error::new(syscall::EIO)))?; - let ip: Vec = ip_string.trim().split(".").map(|part| part.parse::() - .unwrap_or(0)).collect(); - - let dns_string = String::from_utf8(::file_read_all("/etc/net/dns")?) - .or(Err(Error::new(syscall::EIO)))?; - let dns: Vec = dns_string.trim().split(".").map(|part| part.parse::() - .unwrap_or(0)).collect(); - - if ip.len() == 4 && dns.len() == 4 { - let mut timespec = syscall::TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_REALTIME, &mut timespec).unwrap(); - let tid = (timespec.tv_nsec >> 16) as u16; - - let packet = Dns { - transaction_id: tid, - flags: 0x0100, - queries: vec![DnsQuery { - name: host.to_string(), - q_type: 0x0001, - q_class: 0x0001, - }], - answers: vec![] - }; - - let packet_data = packet.compile(); - - let fd = ::RawFile::open(format!("udp:/{}.{}.{}.{}:0", - ip[0], ip[1], ip[2], ip[3]).as_bytes(), - syscall::O_RDWR)?; - - let timeout = syscall::TimeSpec { - tv_sec: 5, - tv_nsec: 0, - }; - let rt = fd.dup(b"read_timeout")?; - syscall::write(*rt, &timeout)?; - drop(rt); - let wt = fd.dup(b"write_timeout")?; - syscall::write(*wt, &timeout)?; - drop(wt); - - let sendrecvfd = fd.dup(format!("{}.{}.{}.{}:53", dns[0], dns[1], dns[2], dns[3]).as_bytes())?; - syscall::write(*sendrecvfd, &packet_data)?; - let mut buf = [0; 65536]; - let count = syscall::read(*sendrecvfd, &mut buf)?; - drop(sendrecvfd); - drop(fd); - - match Dns::parse(&buf[.. count]) { - Ok(response) => { - let mut addrs = vec![]; - for answer in response.answers.iter() { - if answer.a_type == 0x0001 && answer.a_class == 0x0001 - && answer.data.len() == 4 - { - let addr = in_addr { - s_addr: [answer.data[0], answer.data[1], answer.data[2], answer.data[3]] - }; - addrs.push(addr); - } - } - Ok(LookupHost(addrs.into_iter())) - }, - Err(_err) => Err(Error::new(EINVAL)) - } - } else { - Err(Error::new(EINVAL)) - } -} - -libc_fn!(unsafe gethostname(name: *mut c_char, namelen: size_t) -> Result { - let slice = slice::from_raw_parts_mut(name as *mut u8, namelen); - let fd = ::RawFile::open("/etc/hostname", syscall::O_RDONLY)?; - let len = syscall::read(*fd, &mut slice[..namelen-1])?; - slice[len] = b'\0'; - Ok(0) -}); diff --git a/src/header/_oldlib/lib.rs b/src/header/_oldlib/lib.rs deleted file mode 100644 index 6e65237244..0000000000 --- a/src/header/_oldlib/lib.rs +++ /dev/null @@ -1,211 +0,0 @@ -#![no_std] -#![feature( - alloc, - allocator_api, - alloc_system, - compiler_builtins_lib, - const_fn, - const_ptr_null, - core_intrinsics, - global_allocator, - lang_items, - linkage, - const_size_of, - const_cell_new, -)] - -#[macro_use] -extern crate alloc; -extern crate alloc_system; -extern crate byteorder; -extern crate compiler_builtins; -extern crate libc; -extern crate syscall; -extern crate redox_termios; - -use alloc::Vec; -use alloc::String; -use alloc::fmt::Write; -use alloc::boxed::Box; -use core::{ptr, mem, intrinsics, slice, str}; -use libc::{c_int, c_void, c_char, size_t}; - -#[macro_use] -mod macros; -mod types; -mod dns; -mod mallocnull; -mod rawfile; -pub mod event; -pub mod process; -pub mod file; -pub mod folder; -pub mod time; -pub mod unimpl; -pub mod user; -pub mod redox; -pub mod socket; -pub mod hostname; -pub mod termios; -pub mod netdb; - -pub use mallocnull::MallocNull; -pub use rawfile::RawFile; - -#[global_allocator] -static ALLOCATOR: alloc_system::System = alloc_system::System; - -extern "C" { - // Newlib uses this function instead of just a global to support reentrancy - pub fn __errno() -> *mut c_int; - pub fn malloc(size: size_t) -> *mut c_void; - pub fn free(ptr: *mut c_void); - pub fn strlen(s: *const c_char) -> size_t; - pub fn __libc_fini_array(); - pub static mut environ: *mut *mut c_char; -} - -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) -} -pub unsafe fn cstr_to_slice_mut<'a>(buf: *const c_char) -> &'a mut [u8] { - slice::from_raw_parts_mut(buf as *mut u8, ::strlen(buf) as usize) -} - -pub fn file_read_all>(path: T) -> syscall::Result> { - let fd = RawFile::open(path, syscall::O_RDONLY)?; - - let mut st = syscall::Stat::default(); - syscall::fstat(*fd, &mut st)?; - let size = st.st_size as usize; - - let mut buf = Vec::with_capacity(size); - unsafe { buf.set_len(size) }; - syscall::read(*fd, buf.as_mut_slice())?; - - Ok(buf) -} - -/// Implements an `Iterator` which returns on either newline or EOF. -#[derive(Clone, Copy)] -pub struct RawLineBuffer { - fd: usize, - cur: usize, - read: usize, - buf: [u8; 8 * 1024], -} - -impl Default for RawLineBuffer { - fn default() -> RawLineBuffer { - RawLineBuffer { - fd: 0, - cur: 0, - read: 0, - buf: unsafe { mem::uninitialized() }, - } - } -} - -impl RawLineBuffer { - fn new(fd: usize) -> RawLineBuffer { - RawLineBuffer { - fd: fd, - cur: 0, - read: 0, - buf: unsafe { mem::uninitialized() }, - } - } -} - -impl Iterator for RawLineBuffer { - type Item = syscall::Result>; - fn next(&mut self) -> Option { - if self.cur != 0 && self.read != 0 { - if let Some(mut pos) = self.buf[self.cur..self.read].iter().position( - |&x| x == b'\n', - ) - { - pos += self.cur + 1; - let line = unsafe { str::from_utf8_unchecked(&self.buf[self.cur..pos]) }; - let boxed_array: Box<[u8]> = Box::from(line.as_bytes()); - let boxed_line: Box = unsafe { mem::transmute(boxed_array) }; - self.cur = pos; - return Some(Ok(boxed_line)); - } - - let mut temp: [u8; 8 * 1024] = unsafe { mem::uninitialized() }; - unsafe { - ptr::copy(self.buf[self.cur..].as_ptr(), temp.as_mut_ptr(), self.read); - ptr::swap(self.buf.as_mut_ptr(), temp.as_mut_ptr()); - }; - - self.read -= self.cur; - self.cur = 0; - } - - let end = match syscall::read(self.fd, &mut self.buf[self.cur..]).unwrap() { - 0 => return None, - read => { - self.read += read; - self.buf[..self.read] - .iter() - .position(|&x| x == b'\n') - .unwrap_or(0) - } - }; - - self.cur = end; - let line = unsafe { str::from_utf8_unchecked(&self.buf[..end]) }; - let boxed_array: Box<[u8]> = Box::from(line.as_bytes()); - let boxed_line: Box = unsafe { mem::transmute(boxed_array) }; - - Some(Ok(boxed_line)) - } -} - -#[no_mangle] -pub unsafe extern "C" fn __errno_location() -> *mut c_int { - __errno() -} - -#[lang = "eh_personality"] -pub extern "C" fn eh_personality() {} - -#[lang = "panic_fmt"] -#[linkage = "weak"] -#[no_mangle] -pub extern "C" fn rust_begin_unwind(_msg: core::fmt::Arguments, - _file: &'static str, - _line: u32, - _col: u32) -> ! { - let mut s = String::new(); - let _ = s.write_fmt(_msg); - let _ = syscall::write(2, _file.as_bytes()); - let _ = syscall::write(2, "\n".as_bytes()); - let _ = syscall::write(2, s.as_bytes()); - let _ = syscall::write(2, "\n".as_bytes()); - unsafe { intrinsics::abort() } -} - -libc_fn!(unsafe initialize_standard_library() { - let mut buf = file_read_all("env:").unwrap(); - let size = buf.len(); - buf.push(0); - - let mut vars = Vec::new(); - - vars.push(&mut buf[0] as *mut u8 as *mut c_char); - for i in 0..size { - if buf[i] == b'\n' { - if i != size - 1 { - vars.push(&mut buf[i + 1] as *mut u8 as *mut c_char); - } - buf[i] = b'\0'; - } - } - vars.push(ptr::null_mut()); - - environ = vars.as_mut_ptr(); - mem::forget(vars); // Do not free memory - mem::forget(buf); -}); diff --git a/src/header/_oldlib/macros.rs b/src/header/_oldlib/macros.rs deleted file mode 100644 index 85d8c37334..0000000000 --- a/src/header/_oldlib/macros.rs +++ /dev/null @@ -1,120 +0,0 @@ -use core::ptr; -use core::any::Any; - - -/// This struct converts to `NULL` for raw pointers, and `-1` for signed -/// integers. -pub struct Fail; - -impl Into<*const T> for Fail { - #[inline(always)] - fn into(self) -> *const T { - ptr::null() - } -} - -impl Into<*mut T> for Fail { - #[inline(always)] - fn into(self) -> *mut T { - ptr::null_mut() - } -} - -macro_rules! int_fail { - ($type:ty) => ( - impl Into<$type> for Fail { - #[inline(always)] - fn into(self) -> $type { - -1 - } - } - ) -} - -int_fail!(i8); -int_fail!(i16); -int_fail!(i32); -int_fail!(i64); -int_fail!(isize); - -/// If `res` is `Err(..)`, set `errno` and return `-1` or `NULL`, otherwise -/// unwrap. -macro_rules! try_call { - ($res:expr) => ( - match $res { - Ok(val) => val, - Err(err) => { - *::__errno() = err.errno; - return ::macros::Fail.into(); - } - } - ); -} - -/// Declares a libc function. The body should return syscall::Result, which -/// is used to set errno on error with try_call! -/// -/// ``` -/// libc_fn!(foo(arg: c_int) -> c_int) { -/// Ok(arg) -/// } -/// ``` -/// -/// The `unsafe` keyword can be added to make the function unsafe: -/// -/// ``` -/// libc_fn!(unsafe foo(arg: c_int) -> c_int) { -/// Ok(arg) -/// } -/// ``` -macro_rules! libc_fn { - // The next 2 cases handle Result return values, and convert to errno+return - // Call with arguments and return value - ($name:ident($($aname:ident : $atype:ty),*) -> Result<$rtype:ty> $content:block) => { - #[no_mangle] - pub extern "C" fn $name($($aname: $atype,)*) -> $rtype { - #[inline(always)] - fn inner($($aname: $atype,)*) -> ::syscall::Result<$rtype> { - $content - } - unsafe { try_call!(inner($($aname,)*)) } - } - }; - // Call with `unsafe` keyword (and arguments, return value) - (unsafe $name:ident($($aname:ident : $atype:ty),*) -> Result<$rtype:ty> $content:block) => { - #[no_mangle] - pub unsafe extern "C" fn $name($($aname: $atype,)*) -> $rtype { - #[inline(always)] - unsafe fn inner($($aname: $atype,)*) -> ::syscall::Result<$rtype> { - $content - } - try_call!(inner($($aname,)*)) - } - }; - // The next 2 cases handle non-Result return values - ($name:ident($($aname:ident : $atype:ty),*) -> $rtype:ty $content:block) => { - #[no_mangle] - pub extern "C" fn $name($($aname: $atype,)*) -> $rtype { - $content - } - }; - (unsafe $name:ident($($aname:ident : $atype:ty),*) -> $rtype:ty $content:block) => { - #[no_mangle] - pub unsafe extern "C" fn $name($($aname: $atype,)*) -> $rtype { - $content - } - }; - // The next 2 cases handle calls with no return value - ($name:ident($($aname:ident : $atype:ty),*) $content:block) => { - #[no_mangle] - pub extern "C" fn $name($($aname: $atype,)*) { - $content - } - }; - (unsafe $name:ident($($aname:ident : $atype:ty),*) $content:block) => { - #[no_mangle] - pub unsafe extern "C" fn $name($($aname: $atype,)*) { - $content - } - }; -} diff --git a/src/header/_oldlib/mallocnull.rs b/src/header/_oldlib/mallocnull.rs deleted file mode 100644 index 25640b7be0..0000000000 --- a/src/header/_oldlib/mallocnull.rs +++ /dev/null @@ -1,46 +0,0 @@ -use core::mem; -use libc::{c_void, size_t}; - -/// Malloc memory if pointer is null, and free on drop -pub struct MallocNull { - value: *mut T, - free_on_drop: bool -} - -impl MallocNull { - pub fn new(ptr: *mut T, size: usize) -> MallocNull { - if ptr.is_null() { - MallocNull { - value: unsafe { ::malloc(size as size_t) as *mut T }, - free_on_drop: true - } - } else { - MallocNull { - value: ptr, - free_on_drop: false - } - } - } - - pub fn into_raw(self) -> *mut T { - let ptr = self.value; - mem::forget(self); - ptr - } - - pub fn as_ptr(&self) -> *const T { - self.value - } - - pub fn as_mut_ptr(&self) -> *mut T { - self.value - } -} - -impl Drop for MallocNull { - fn drop(&mut self) { - if self.free_on_drop { - unsafe { ::free(self.value as *mut c_void) }; - } - } -} diff --git a/src/header/_oldlib/netdb.rs b/src/header/_oldlib/netdb.rs deleted file mode 100644 index 68e6a9aa32..0000000000 --- a/src/header/_oldlib/netdb.rs +++ /dev/null @@ -1,727 +0,0 @@ -use libc; -use types::{in_addr, sockaddr, socklen_t}; -use RawLineBuffer; -use core::ptr::null; -use core::{mem, str}; -use alloc::vec::IntoIter; -use alloc::string::ToString; -use alloc::{Vec, String}; -use alloc::str::SplitWhitespace; -use alloc::boxed::Box; -use dns::{Dns, DnsQuery}; -use syscall::{self, Result, EINVAL, Error}; -use libc::c_char; - -const MAXADDRS: usize = 35; -const MAXALIASES: usize = 35; - -struct LookupHost(IntoIter); - -impl Iterator for LookupHost { - type Item = in_addr; - fn next(&mut self) -> Option { - self.0.next() - } -} - -#[repr(C)] -pub struct hostent { - h_name: *const libc::c_char, - h_aliases: *const *const libc::c_char, - h_addrtype: libc::c_int, - h_length: libc::c_int, - h_addr_list: *const *const libc::c_char, -} - -/* - *#[repr(C)] - *pub struct netent { - * n_name: *const libc::c_char, [> official name of net <] - * n_aliases: *const *const libc::c_char, [> alias list <] - * n_addrtype: libc::c_int, [> net address type <] - * n_net: libc::c_ulong, [> network # <] - *} - */ - -#[repr(C)] -pub struct servent { - s_name: *const libc::c_char, /* official service name */ - s_aliases: *const *const libc::c_char, /* alias list */ - s_port: libc::c_int, /* port # */ - s_proto: *const libc::c_char, /* protocol to use */ -} - -#[repr(C)] -pub struct protoent { - p_name: *const libc::c_char, /* official protocol name */ - p_aliases: *const *const libc::c_char, /* alias list */ - p_proto: libc::c_int, /* protocol # */ -} - -#[repr(C)] -pub struct addrinfo { - ai_flags: libc::c_int, /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ - ai_family: libc::c_int, /* PF_xxx */ - ai_socktype: libc::c_int, /* SOCK_xxx */ - ai_protocol: libc::c_int, /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ - ai_addrlen: libc::size_t, /* length of ai_addr */ - ai_canonname: *const libc::c_char, /* canonical name for hostname */ - ai_addr: *const sockaddr, /* binary address */ - ai_next: *const addrinfo, /* next structure in linked list */ -} - -static mut HOSTDB: usize = 0; -//static mut NETDB: usize = 0; -static mut PROTODB: usize = 0; -static mut SERVDB: usize = 0; - -/* - *static mut NET_ENTRY: netent = netent { - * n_name: 0 as *const libc::c_char, - * n_aliases: 0 as *const *const libc::c_char, - * n_addrtype: 0, - * n_net: 0 as u64, - *}; - *static mut NET_NAME: Option> = None; - *static mut NET_ALIASES: [*const c_char; MAXALIASES] = [null(); MAXALIASES]; - *static mut NET_NUM: Option = None; - */ - -static mut HOST_ENTRY: hostent = hostent { - h_name: 0 as *const libc::c_char, - h_aliases: 0 as *const *const libc::c_char, - h_addrtype: 0, - h_length: 0, - h_addr_list: 0 as *const *const libc::c_char, -}; -static mut HOST_NAME: Option> = None; -static mut HOST_ALIASES: Option>> = None; -static mut HOST_ADDR: Option = None; -static mut HOST_ADDR_LIST: [*const c_char; 2] = [null(); 2]; -static mut H_LINE: RawLineBuffer = RawLineBuffer { - fd: 0, - cur: 0, - read: 0, - buf: [0; 8 * 1024], -}; - -static mut PROTO_ENTRY: protoent = protoent { - p_name: 0 as *const libc::c_char, - p_aliases: 0 as *const *const libc::c_char, - p_proto: 0 as libc::c_int, -}; -static mut PROTO_NAME: Option> = None; -static mut PROTO_ALIASES: Option>> = None; -static mut PROTO_NUM: Option = None; -static mut P_LINE: RawLineBuffer = RawLineBuffer { - fd: 0, - cur: 0, - read: 0, - buf: [0; 8 * 1024], -}; - -static mut SERV_ENTRY: servent = servent { - s_name: 0 as *const libc::c_char, - s_aliases: 0 as *const *const libc::c_char, - s_port: 0 as libc::c_int, - s_proto: 0 as *const libc::c_char, -}; -static mut SERV_NAME: Option> = None; -static mut SERV_ALIASES: Option>> = None; -static mut SERV_PORT: Option = None; -static mut SERV_PROTO: Option> = None; -static mut S_LINE: RawLineBuffer = RawLineBuffer { - fd: 0, - cur: 0, - read: 0, - buf: [0; 8 * 1024], -}; - - -fn lookup_host(host: &str) -> Result { - // XXX better error handling - let ip_string = String::from_utf8(::file_read_all("/etc/net/ip")?).or(Err( - Error::new(syscall::EIO), - ))?; - let ip: Vec = ip_string - .trim() - .split(".") - .map(|part| part.parse::().unwrap_or(0)) - .collect(); - - let dns_string = String::from_utf8(::file_read_all("/etc/net/dns")?).or(Err( - Error::new(syscall::EIO), - ))?; - let dns: Vec = dns_string - .trim() - .split(".") - .map(|part| part.parse::().unwrap_or(0)) - .collect(); - - if ip.len() == 4 && dns.len() == 4 { - let mut timespec = syscall::TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_REALTIME, &mut timespec).unwrap(); - let tid = (timespec.tv_nsec >> 16) as u16; - - let packet = Dns { - transaction_id: tid, - flags: 0x0100, - queries: vec![ - DnsQuery { - name: host.to_string(), - q_type: 0x0001, - q_class: 0x0001, - }, - ], - answers: vec![], - }; - - let packet_data = packet.compile(); - - let fd = ::RawFile::open( - format!("udp:/{}.{}.{}.{}:0", ip[0], ip[1], ip[2], ip[3]).as_bytes(), - syscall::O_RDWR, - )?; - - let timeout = syscall::TimeSpec { - tv_sec: 5, - tv_nsec: 0, - }; - let rt = fd.dup(b"read_timeout")?; - syscall::write(*rt, &timeout)?; - drop(rt); - let wt = fd.dup(b"write_timeout")?; - syscall::write(*wt, &timeout)?; - drop(wt); - - let sendrecvfd = fd.dup( - format!("{}.{}.{}.{}:53", dns[0], dns[1], dns[2], dns[3]) - .as_bytes(), - )?; - syscall::write(*sendrecvfd, &packet_data)?; - let mut buf = [0; 65536]; - let count = syscall::read(*sendrecvfd, &mut buf)?; - drop(sendrecvfd); - drop(fd); - - match Dns::parse(&buf[..count]) { - Ok(response) => { - let mut addrs = vec![]; - for answer in response.answers.iter() { - if answer.a_type == 0x0001 && answer.a_class == 0x0001 && - answer.data.len() == 4 - { - let addr = in_addr { - s_addr: [ - answer.data[0], - answer.data[1], - answer.data[2], - answer.data[3], - ], - }; - addrs.push(addr); - } - } - Ok(LookupHost(addrs.into_iter())) - } - Err(_err) => Err(Error::new(EINVAL)), - } - } else { - Err(Error::new(EINVAL)) - } -} - -unsafe fn lookup_addr(addr: in_addr) -> Result>> { - // XXX better error handling - let ip_string = String::from_utf8(::file_read_all("/etc/net/ip")?).or(Err( - Error::new(syscall::EIO), - ))?; - let ip: Vec = ip_string - .trim() - .split(".") - .map(|part| part.parse::().unwrap_or(0)) - .collect(); - - let dns_string = String::from_utf8(::file_read_all("/etc/net/dns")?).or(Err( - Error::new(syscall::EIO), - ))?; - let dns: Vec = dns_string - .trim() - .split(".") - .map(|part| part.parse::().unwrap_or(0)) - .collect(); - - let mut addr_vec: Vec = addr.s_addr.to_vec(); - addr_vec.reverse(); - let mut name: Vec = vec![]; - for octet in addr_vec { - for ch in format!("{}", octet).as_bytes() { - name.push(*ch); - } - name.push(b"."[0]); - } - name.pop(); - for ch in b".IN-ADDR.ARPA" { - name.push(*ch); - } - let _ = syscall::write(2, name.as_slice()); - let _ = syscall::write(2, "\n".as_bytes()); - - if ip.len() == 4 && dns.len() == 4 { - let mut timespec = syscall::TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_REALTIME, &mut timespec).unwrap(); - let tid = (timespec.tv_nsec >> 16) as u16; - - let packet = Dns { - transaction_id: tid, - flags: 0x0100, - queries: vec![ - DnsQuery { - name: String::from_utf8(name).unwrap(), - q_type: 0x000C, - q_class: 0x0001, - }, - ], - answers: vec![], - }; - - let packet_data = packet.compile(); - - let fd = ::RawFile::open( - format!("udp:/{}.{}.{}.{}:0", ip[0], ip[1], ip[2], ip[3]).as_bytes(), - syscall::O_RDWR, - )?; - - let timeout = syscall::TimeSpec { - tv_sec: 5, - tv_nsec: 0, - }; - let rt = fd.dup(b"read_timeout")?; - syscall::write(*rt, &timeout)?; - drop(rt); - let wt = fd.dup(b"write_timeout")?; - syscall::write(*wt, &timeout)?; - drop(wt); - - let sendrecvfd = fd.dup( - format!("{}.{}.{}.{}:53", dns[0], dns[1], dns[2], dns[3]) - .as_bytes(), - )?; - syscall::write(*sendrecvfd, &packet_data)?; - let mut buf = [0; 65536]; - let count = syscall::read(*sendrecvfd, &mut buf)?; - drop(sendrecvfd); - drop(fd); - - match Dns::parse(&buf[..count]) { - Ok(response) => { - let _ = syscall::write(2, format!("{:?}", response).as_bytes()); - let _ = syscall::write(2, "\n".as_bytes()); - let mut names = vec![]; - for answer in response.answers.iter() { - - if answer.a_type == 0x000C && answer.a_class == 0x0001 - { - // answer.data is encoded kinda weird. - // Basically length-prefixed strings for each - // subsection of the domain. - // We need to parse this to insert periods where - // they belong (ie at the end of each string) - let data = parse_data(answer.data.clone()); - names.push(data); - } - } - Ok(names) - } - Err(_err) => Err(Error::new(EINVAL)), - } - } else { - Err(Error::new(EINVAL)) - } -} - -fn parse_data(mut data: Vec) -> Vec { - let mut cursor = 0; - let mut offset = 0; - let mut index = 0; - let mut output = data.clone(); - while index < data.len() - 1 { - offset = data[index] as usize; - index = cursor + offset + 1; - output[index] = '.' as u8; - cursor = index; - } - //we don't want an extra period at the end - output.pop(); - return output -} - - - -libc_fn!(unsafe endhostent() { - let _ = syscall::close(HOSTDB); -}); - -/* - *libc_fn!(unsafe endnetent() { - * let _ = syscall::close(NETDB); - *}); - */ - -libc_fn!(unsafe endprotoent() { - let _ = syscall::close(PROTODB); -}); - -libc_fn!(unsafe endservent() { - let _ = syscall::close(SERVDB); -}); - - -libc_fn!(unsafe gethostbyaddr(v: *const libc::c_void, length: socklen_t, format: libc::c_int) -> Result <*const hostent> { - let mut addr: in_addr = *(v as *mut in_addr); - match lookup_addr(addr) { - Ok(s) => { - HOST_ADDR_LIST = [addr.s_addr.as_mut_ptr() as *const c_char, null()]; - let host_name = s[0].to_vec(); - HOST_ENTRY = hostent { - h_name: host_name.as_ptr() as *const c_char, - h_aliases: [null();2].as_mut_ptr(), - h_addrtype: format, - h_length: length as i32, - h_addr_list: HOST_ADDR_LIST.as_ptr() - }; - HOST_NAME = Some(host_name); - return Ok(&HOST_ENTRY) - } - Err(err) => Err(err) - } -}); - -libc_fn!(unsafe gethostbyname(name: *const c_char) -> Result<*const hostent> { - // XXX h_errno - let mut addr = mem::uninitialized(); - let mut host_addr = if ::socket::inet_aton(name, &mut addr) == 1 { - addr - } else { - // XXX - let mut host = lookup_host(str::from_utf8_unchecked(::cstr_to_slice(name)))?; - host.next().ok_or(Error::new(syscall::ENOENT))? // XXX - }; - - let host_name: Vec = ::cstr_to_slice(name).to_vec(); - HOST_ADDR_LIST = [host_addr.s_addr.as_mut_ptr() as *const c_char, null()]; - HOST_ADDR = Some(host_addr); - - HOST_ENTRY = hostent { - h_name: host_name.as_ptr() as *const c_char, - h_aliases: [null();2].as_mut_ptr(), - h_addrtype: ::socket::AF_INET, - h_length: 4, - h_addr_list: HOST_ADDR_LIST.as_ptr() - }; - - HOST_NAME = Some(host_name); - - Ok(&HOST_ENTRY as *const hostent) -}); - -libc_fn!(unsafe gethostent() -> *const hostent { - if HOSTDB == 0 { - HOSTDB = syscall::open("/etc/hosts", syscall::O_RDONLY).unwrap(); - H_LINE = RawLineBuffer::new(HOSTDB); - } - - let mut r: Box = Box::default(); - while r.is_empty() || r.split_whitespace().next() == None || r.starts_with("#") { - r = match H_LINE.next() { - Some(Ok(s)) => s, - Some(Err(_)) => return null(), - None => return null(), - }; - } - - - let mut iter: SplitWhitespace = r.split_whitespace(); - - let mut addr_vec = iter.next().unwrap().as_bytes().to_vec(); - addr_vec.push(b'\0'); - let addr_cstr = addr_vec.as_slice().as_ptr() as *const i8; - let mut addr = mem::uninitialized(); - ::socket::inet_aton(addr_cstr, &mut addr); - HOST_ADDR_LIST = [addr.s_addr.as_mut_ptr() as *const c_char, null()]; - HOST_ADDR = Some(addr); - - let mut host_name = iter.next().unwrap().as_bytes().to_vec(); - host_name.push(b'\0'); - - let mut host_aliases: Vec> = Vec::new(); - - loop { - let mut alias = match iter.next() { - Some(s) => s.as_bytes().to_vec(), - None => break - }; - alias.push(b'\0'); - host_aliases.push(alias); - } - - //push a 0 so c doesn't segfault when it tries to read the next entry - host_aliases.push(vec![b'\0']); - - HOST_ENTRY = hostent { - h_name: host_name.as_ptr() as *const c_char, - h_aliases: host_aliases.as_slice().as_ptr() as *const *const i8, - h_addrtype: ::socket::AF_INET, - h_length: 4, - h_addr_list: HOST_ADDR_LIST.as_ptr() - }; - HOST_ALIASES = Some(host_aliases); - HOST_NAME = Some(host_name); - &HOST_ENTRY as *const hostent -}); - -/* - *libc_fn!(getnetbyaddr(net: libc::uint32_t, net_type: libc::c_int) -> Result<*const netent> { - * if NETDB == 0 { - * NETDB = syscall::open("/etc/networks", syscall::O_RDONLY).unwrap(); - * } - *}); - * - *libc_fn!(getnetbyname(name: *const libc::c_char) -> Result<*const netent> { - * if NETDB == 0 { - * NETDB = syscall::open("/etc/networks", syscall::O_RDONLY).unwrap(); - * } - *}); - * - */ - - -/* - *libc_fn!(getnetent() -> Result<*const netent> { - * if NETDB == 0 { - * NETDB = syscall::open("/etc/networks", syscall::O_RDONLY).unwrap(); - * } - * - *}); - */ - -libc_fn!(unsafe getprotobyname(name: *const libc::c_char) -> Result<*const protoent> { - setprotoent(0); - let mut p: *const protoent; - while {p=getprotoent(); - p!=null()} { - if libc::strcmp((*p).p_name, name) == 0 { - return Ok(p); - } - loop { - let mut cp = (*p).p_aliases; - if cp == null() { - break; - } - if libc::strcmp(*cp, name) == 0 { - return Ok(p); - } - cp = cp.offset(1); - } - } - endprotoent(); - Err(Error::new(syscall::ENOENT)) -}); - -libc_fn!(unsafe getprotobynumber(number: libc::c_int) -> Result<*const protoent> { - setprotoent(0); - let mut p: *const protoent; - while {p=getprotoent(); - p!=null()} { - if (*p).p_proto == number { - return Ok(p); - } - } - endprotoent(); - Err(Error::new(syscall::ENOENT)) - }); - -libc_fn!(unsafe getprotoent() -> *const protoent { - if PROTODB == 0 { - PROTODB = syscall::open("/etc/protocols", syscall::O_RDONLY).unwrap(); - P_LINE = RawLineBuffer::new(PROTODB); - } - - let mut r: Box = Box::default(); - while r.is_empty() || r.split_whitespace().next() == None || r.starts_with("#") { - r = match P_LINE.next() { - Some(Ok(s)) => s, - Some(Err(_)) => return null(), - None => return null(), - }; - } - - let mut iter: SplitWhitespace = r.split_whitespace(); - let mut proto_name: Vec = iter.next().unwrap().as_bytes().to_vec(); - proto_name.push(b'\0'); - - let mut num = iter.next().unwrap().as_bytes().to_vec(); - num.push(b'\0'); - PROTO_NUM = Some(libc::atoi(num.as_slice().as_ptr() as *mut i8)); - - let mut proto_aliases: Vec> = Vec::new(); - loop { - let mut alias = match iter.next() { - Some(s) => s.as_bytes().to_vec(), - None => break - }; - alias.push(b'\0'); - proto_aliases.push(alias); - } - //push a 0 so c doesn't segfault when it tries to read the next entry - proto_aliases.push(vec![b'\0']); - - PROTO_ENTRY = protoent { - p_name: proto_name.as_slice().as_ptr() as *const c_char, - p_aliases: proto_aliases.iter().map(|x| x.as_ptr() as *const i8).collect::>().as_ptr(), - p_proto: PROTO_NUM.unwrap() - }; - PROTO_ALIASES = Some(proto_aliases); - PROTO_NAME = Some(proto_name); - &PROTO_ENTRY as *const protoent -}); - -libc_fn!(unsafe getservbyname(name: *const libc::c_char, proto: *const libc::c_char) -> Result<*const servent> { - setservent(0); - let mut p: *const servent; - while {p=getservent(); - p!=null()} { - if libc::strcmp((*p).s_name, name) == 0 && libc::strcmp((*p).s_proto, proto) == 0 { - return Ok(p); - } - loop { - let mut cp = (*p).s_aliases; - if cp == null() { - break; - } - if libc::strcmp(*cp, name) == 0 && libc::strcmp((*p).s_proto, proto) == 0 { - return Ok(p); - } - cp = cp.offset(1); - } - } - Err(Error::new(syscall::ENOENT)) -}); - -libc_fn!(unsafe getservbyport(port: libc::c_int, proto: *const libc::c_char) -> Result<*const servent> { - setprotoent(0); - let mut p: *const servent; - while {p=getservent(); - p!=null()} { - if (*p).s_port == port && libc::strcmp((*p).s_proto, proto) == 0 { - return Ok(p); - } - } - endprotoent(); - Err(Error::new(syscall::ENOENT)) - -}); - -libc_fn!(unsafe getservent() -> *const servent { - if SERVDB == 0 { - SERVDB = syscall::open("/etc/services", syscall::O_RDONLY).unwrap(); - S_LINE = RawLineBuffer::new(SERVDB); - } - - let mut r: Box = Box::default(); - while r.is_empty() || r.split_whitespace().next() == None || r.starts_with("#") { - r = match S_LINE.next() { - Some(Ok(s)) => s, - Some(Err(_)) => return null(), - None => return null(), - }; - } - let mut iter: SplitWhitespace = r.split_whitespace(); - - let mut serv_name: Vec = iter.next().unwrap().as_bytes().to_vec(); - serv_name.push(b'\0'); - - let port_proto = iter.next().unwrap(); - let mut split = port_proto.split("/"); - let port = libc::atoi(split.next().unwrap().as_ptr() as *const i8); - SERV_PORT = Some(port); - let proto = split.next().unwrap().as_bytes().to_vec(); - - let mut serv_aliases: Vec> = Vec::new(); - loop { - let mut alias = match iter.next() { - Some(s) => s.as_bytes().to_vec(), - None => break - }; - alias.push(b'\0'); - serv_aliases.push(alias); - } - //push a 0 so c doesn't segfault when it tries to read the next entry - serv_aliases.push(vec![b'\0']); - - SERV_ENTRY = servent { - s_name: serv_name.as_slice().as_ptr() as *const c_char, - s_aliases: serv_aliases.iter().map(|x| x.as_ptr() as *const i8).collect::>().as_ptr(), - s_port: SERV_PORT.unwrap(), - s_proto: proto.as_slice().as_ptr() as *const c_char - }; - - SERV_ALIASES = Some(serv_aliases); - SERV_NAME = Some(serv_name); - SERV_PROTO = Some(proto); - &SERV_ENTRY as *const servent - -}); - -libc_fn!(unsafe sethostent(stayopen: libc::c_int) { - if HOSTDB == 0 { - HOSTDB = syscall::open("/etc/hosts", syscall::O_RDONLY).unwrap(); - } else { - let _ = syscall::lseek(HOSTDB, 0, syscall::SEEK_SET); - } - H_LINE = RawLineBuffer::new(HOSTDB); -}); - -/* - *libc_fn!(unsafe setnetent(stayopen: libc::c_int) { - * if NETDB == 0 { - * NETDB = syscall::open("/etc/networks", syscall::O_RDONLY).unwrap(); - * } else { - * let _ = syscall::lseek(NETDB, 0, syscall::SEEK_SET); - * } - *}); - */ - -libc_fn!(unsafe setprotoent(stayopen: libc::c_int) { - if PROTODB == 0 { - PROTODB = syscall::open("/etc/protocols", syscall::O_RDONLY).unwrap(); - } else { - let _ = syscall::lseek(PROTODB, 0, syscall::SEEK_SET); - } - P_LINE = RawLineBuffer::new(PROTODB); -}); - -libc_fn!(unsafe setservent(stayopen: libc::c_int) { - if SERVDB == 0 { - SERVDB = syscall::open("/etc/services", syscall::O_RDONLY).unwrap(); - } else { - let _ = syscall::lseek(SERVDB, 0, syscall::SEEK_SET); - } - S_LINE = RawLineBuffer::new(SERVDB); -}); - -//libc_fn!(getaddrinfo(node: *const libc::c_char, service: *const libc::c_char, hints: *const addrinfo, res: *mut *mut addrinfo) -> libc::c_int { - -//}); - -//libc_fn!(getnameinfo(addr: *const sockaddr, addrlen: socklen_t, host: *mut libc::c_char, hostlen: socklen_t, serv: *mut libc::c_char, servlen: socklen_t, flags: libc::c_int) -> libc::c_int { - -//}); - -//libc_fn!(freeaddrinfo(res: *mut addrinfo) { - -//}); - -//libc_fn!(gai_strerror(errcode: libc::c_int) -> *const libc::c_char { - -//}); diff --git a/src/header/_oldlib/process.rs b/src/header/_oldlib/process.rs deleted file mode 100644 index e0fcc62955..0000000000 --- a/src/header/_oldlib/process.rs +++ /dev/null @@ -1,207 +0,0 @@ -use libc::{c_char, c_int, c_void, size_t, gid_t, uid_t, ptrdiff_t}; -use ::types::pid_t; -use core::slice; -use alloc::Vec; -use syscall::error::{Error, EINVAL}; -use syscall; - -const MAXPATHLEN: usize = 1024; -static mut CURR_BRK: usize = 0; - -libc_fn!(unsafe chdir(path: *const c_char) -> Result { - Ok(syscall::chdir(::cstr_to_slice(path))? as c_int) -}); - -libc_fn!(unsafe fchdir(fd: c_int) -> Result { - let mut buf = [0; MAXPATHLEN]; - let length = syscall::fpath(fd as usize, &mut buf)?; - Ok(syscall::chdir(&buf[0..length])? as c_int) -}); - -libc_fn!(unsafe _exit(code: c_int) { - ::__libc_fini_array(); - syscall::exit(code as usize).unwrap(); -}); - -libc_fn!(unsafe _execve(name: *const c_char, argv: *const *const c_char, env: *const *const c_char) -> Result { - let mut env = env; - while !(*env).is_null() { - let slice = ::cstr_to_slice(*env); - // Should always contain a =, but worth checking - if let Some(sep) = slice.iter().position(|&c| c == b'=') { - let mut path = b"env:".to_vec(); - path.extend_from_slice(&slice[..sep]); - if let Ok(fd) = ::RawFile::open(&path, syscall::O_WRONLY | syscall::O_CREAT) { - let _ = syscall::write(*fd, &slice[sep+1..]); - } - } - env = env.offset(1); - } - - let mut args: Vec<[usize; 2]> = Vec::new(); - let mut arg = argv; - while !(*arg).is_null() { - args.push([*arg as usize, ::strlen(*arg)]); - arg = arg.offset(1); - } - - Ok(syscall::execve(::cstr_to_slice(name), &args)? as c_int) -}); - -libc_fn!(unsafe _fork() -> Result { - Ok(syscall::clone(0)? as c_int) -}); - -libc_fn!(unsafe vfork() -> Result { - Ok(syscall::clone(syscall::CLONE_VFORK)? as c_int) -}); - -libc_fn!(unsafe getcwd(buf: *mut c_char, size: size_t) -> Result<*const c_char> { - let mut size = size; - if size == 0 { - size = ::file::PATH_MAX; - } - let buf = ::MallocNull::new(buf, size); - let slice = slice::from_raw_parts_mut(buf.as_mut_ptr() as *mut u8, size); - let count = syscall::getcwd(&mut slice[..size-1])?; - slice[count] = b'\0'; - Ok(buf.into_raw()) - // FIXME: buffer too small -}); - -libc_fn!(unsafe getwd(buf: *mut c_char) -> Result<*const c_char> { - - if buf.is_null() { - Err(Error::new(EINVAL)) - } else { - let mut tmp: [u8; MAXPATHLEN] = [0; MAXPATHLEN]; - syscall::getcwd(&mut tmp)?; - slice::from_raw_parts_mut(buf as *mut u8, MAXPATHLEN) - .copy_from_slice(&mut tmp); - Ok(buf) - } -}); - -libc_fn!(unsafe _getpid() -> pid_t { - syscall::getpid().unwrap() as pid_t -}); - -libc_fn!(unsafe getppid() -> pid_t { - syscall::getppid().unwrap() as pid_t -}); - -libc_fn!(unsafe getegid() -> gid_t { - syscall::getegid().unwrap() as gid_t -}); - -libc_fn!(unsafe geteuid() -> uid_t { - syscall::geteuid().unwrap() as uid_t -}); - -libc_fn!(unsafe getgid() -> gid_t { - syscall::getgid().unwrap() as gid_t -}); - -libc_fn!(unsafe getuid() -> uid_t { - syscall::getuid().unwrap() as uid_t -}); - -libc_fn!(unsafe _kill(pid: c_int, sig: c_int) -> Result { - Ok(syscall::kill(pid as usize, sig as usize)? as c_int) -}); - -libc_fn!(unsafe _brk(end_data_segment: *mut c_void) -> Result { - CURR_BRK = syscall::brk(end_data_segment as usize)?; - Ok(0) -}); - -libc_fn!(unsafe _sbrk(increment: ptrdiff_t) -> *mut c_void { - if CURR_BRK == 0 { - CURR_BRK = syscall::brk(0).unwrap(); - } - let old_brk = CURR_BRK; - if increment != 0 { - let addr = if increment >= 0 { - old_brk + increment as usize - } else { - old_brk - (-increment) as usize - }; - CURR_BRK = match syscall::brk(addr) { - Ok(x) => x, - Err(err) => { - *::__errno() = err.errno; - return -1 as isize as *mut c_void; - } - } - } - old_brk as *mut c_void -}); - -libc_fn!(unsafe _sched_yield() -> Result { - Ok(syscall::sched_yield()? as c_int) -}); - -libc_fn!(unsafe _system(s: *const c_char) -> Result { - match syscall::clone(0)? { - 0 => { - let shell = "/bin/sh"; - let arg1 = "-c"; - let args = [ - [shell.as_ptr() as usize, shell.len()], - [arg1.as_ptr() as usize, arg1.len()], - [s as usize, ::strlen(s)] - ]; - syscall::execve(shell, &args)?; - syscall::exit(100)?; - unreachable!() - } - pid => { - let mut status = 0; - syscall::waitpid(pid, &mut status, 0)?; - Ok(status as c_int) - } - } -}); - -libc_fn!(unsafe setregid(rgid: gid_t, egid: gid_t) -> Result { - Ok(syscall::setregid(rgid as usize, egid as usize)? as c_int) -}); - -libc_fn!(unsafe setegid(egid: gid_t) -> Result { - Ok(syscall::setregid(-1isize as usize, egid as usize)? as c_int) -}); - -libc_fn!(unsafe setgid(gid: gid_t) -> Result { - Ok(syscall::setregid(gid as usize, gid as usize)? as c_int) -}); - -libc_fn!(unsafe setreuid(ruid: uid_t, euid: uid_t) -> Result { - Ok(syscall::setreuid(ruid as usize, euid as usize)? as c_int) -}); - -libc_fn!(unsafe seteuid(euid: uid_t) -> Result { - Ok(syscall::setreuid(-1isize as usize, euid as usize)? as c_int) -}); - -libc_fn!(unsafe setuid(uid: uid_t) -> Result { - Ok(syscall::setreuid(uid as usize, uid as usize)? as c_int) -}); - -libc_fn!(unsafe _wait(status: *mut c_int) -> Result { - let mut buf = 0; - let res = syscall::waitpid(0, &mut buf, 0)?; - *status = buf as c_int; - Ok(res as c_int) -}); - -libc_fn!(unsafe waitpid(pid: pid_t, status: *mut c_int, options: c_int) -> Result { - let mut buf = 0; - let pid = if pid == -1 { - 0 - } else { - pid as usize - }; - let res = syscall::waitpid(pid as usize, &mut buf, options as usize)?; - *status = buf as c_int; - Ok(res as c_int) -}); diff --git a/src/header/_oldlib/rawfile.rs b/src/header/_oldlib/rawfile.rs deleted file mode 100644 index 4aeec266f6..0000000000 --- a/src/header/_oldlib/rawfile.rs +++ /dev/null @@ -1,28 +0,0 @@ -use syscall; -use core::ops::Deref; - -pub struct RawFile(usize); - -impl RawFile { - pub fn open>(path: T, flags: usize) -> syscall::Result { - syscall::open(path, flags).map(RawFile) - } - - pub fn dup(&self, buf: &[u8]) -> syscall::Result { - syscall::dup(self.0, buf).map(RawFile) - } -} - -impl Drop for RawFile { - fn drop(&mut self) { - let _ = syscall::close(self.0); - } -} - -impl Deref for RawFile { - type Target = usize; - - fn deref(&self) -> &usize { - &self.0 - } -} diff --git a/src/header/_oldlib/redox.rs b/src/header/_oldlib/redox.rs deleted file mode 100644 index d386cd7d7f..0000000000 --- a/src/header/_oldlib/redox.rs +++ /dev/null @@ -1,40 +0,0 @@ -use syscall; -use libc::{c_int, c_char, c_void, size_t}; -use core::slice; - -libc_fn!(unsafe redox_fevent(file: c_int, flags: c_int) -> Result { - Ok(syscall::fevent(file as usize, flags as usize)? as c_int) -}); - -libc_fn!(unsafe redox_fpath(file: c_int, buf: *mut c_char, len: size_t) -> Result { - let buf = slice::from_raw_parts_mut(buf as *mut u8, len); - Ok(syscall::fpath(file as usize, buf)? as c_int) -}); - -libc_fn!(unsafe redox_fmap(file: c_int, offset: size_t, size: size_t) -> Result<*mut c_void> { - Ok(syscall::fmap(file as usize, offset, size)? as *mut c_void) -}); - -libc_fn!(unsafe redox_funmap(addr: *mut c_void) -> Result { - Ok(syscall::funmap(addr as usize)? as c_int) -}); - -libc_fn!(unsafe redox_physalloc(size: size_t) -> Result<*mut c_void> { - Ok(syscall::physalloc(size)? as *mut c_void) -}); - -libc_fn!(unsafe redox_physfree(physical_address: *mut c_void, size: size_t) -> Result { - Ok(syscall::physfree(physical_address as usize, size)? as c_int) -}); - -libc_fn!(unsafe redox_physmap(physical_address: *mut c_void, size: size_t, flags: c_int) -> Result<*mut c_void> { - Ok(syscall::physmap(physical_address as usize, size, flags as usize)? as *mut c_void) -}); - -libc_fn!(unsafe redox_physunmap(virtual_address: *mut c_void) -> Result { - Ok(syscall::physunmap(virtual_address as usize)? as c_int) -}); - -libc_fn!(unsafe redox_virttophys(virtual_address: *mut c_void) -> Result<*mut c_void> { - Ok(syscall::virttophys(virtual_address as usize)? as *mut c_void) -}); diff --git a/src/header/_oldlib/socket.rs b/src/header/_oldlib/socket.rs deleted file mode 100644 index f0232b9688..0000000000 --- a/src/header/_oldlib/socket.rs +++ /dev/null @@ -1,248 +0,0 @@ -use core::str::{self, FromStr}; -use core::mem; -use core::ptr; -use libc::{c_int, c_char, size_t, c_void, ssize_t}; -use ::types::{socklen_t, in_addr, sockaddr, sockaddr_in}; -use syscall::{self, O_RDWR}; -use syscall::error::{Error, EPROTOTYPE, EPROTONOSUPPORT, EAFNOSUPPORT, EINVAL, EOPNOTSUPP, ENOBUFS, ENOSPC}; -use core::slice; -use byteorder::{BigEndian, ByteOrder}; - - -pub const AF_INET: c_int = 2; -pub const SOCK_STREAM: c_int = 1; -pub const SOCK_DGRAM: c_int = 2; - -static mut NTOA_ADDR: [c_char; 16] = [0; 16]; - -libc_fn!(unsafe inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_int { - // TODO: octal/hex - inet_pton(AF_INET, cp, inp as *mut c_void) -}); - -libc_fn!(unsafe inet_ntoa(addr: in_addr) -> *const c_char { - inet_ntop(AF_INET, &addr as *const in_addr as *const c_void, NTOA_ADDR.as_mut_ptr(), 16) -}); - -libc_fn!(unsafe inet_pton(domain: c_int, src: *const c_char, dest: *mut c_void) -> Result { - if domain != AF_INET { - Err(Error::new(EAFNOSUPPORT)) - } else { - let s_addr = &mut ((*(dest as *mut in_addr)).s_addr); - let mut octets = str::from_utf8_unchecked(::cstr_to_slice(src)).split('.'); - for i in 0..4 { - if let Some(n) = octets.next().and_then(|x| u8::from_str(x).ok()) { - s_addr[i] = n; - } else { - return Ok(0); - } - } - if octets.next() == None { - Ok(1) // Success - } else { - Ok(0) - } - } -}); - -libc_fn!(unsafe inet_ntop(domain: c_int, src: *const c_void, dest: *mut c_char, size: socklen_t) -> Result<*const c_char> { - if domain != AF_INET { - Err(Error::new(EAFNOSUPPORT)) - } else if size < 16 { - Err(Error::new(ENOSPC)) - } else { - let s_addr = (&*(src as *const in_addr)).s_addr; - let addr = format!("{}.{}.{}.{}\0", s_addr[0], s_addr[1], s_addr[2], s_addr[3]); - ptr::copy(addr.as_ptr() as *const c_char, dest, addr.len()); - Ok(dest) - } -}); - -libc_fn!(unsafe socket(domain: c_int, type_: c_int, protocol: c_int) -> Result { - if domain != AF_INET { - Err(Error::new(EAFNOSUPPORT)) - } else if protocol != 0 { - Err(Error::new(EPROTONOSUPPORT)) - } else { - let fd = match type_ { - SOCK_STREAM => syscall::open("tcp:", O_RDWR), - SOCK_DGRAM => syscall::open("udp:", O_RDWR), - _ => Err(Error::new(EPROTOTYPE)) - }?; - Ok(fd as c_int) - } -}); - -libc_fn!(unsafe connect(socket: c_int, address: *const sockaddr, _address_len: socklen_t) -> Result { - // XXX with UDP, should recieve messages only from that peer after this - // XXX Check address_len - if (*address).sa_family as i32 != AF_INET { - return Err(Error::new(EINVAL)) - }; - let address = &*(address as *const sockaddr_in); - let s_addr =address.sin_addr.s_addr; - let path = format!("{}.{}.{}.{}:{}", s_addr[0], s_addr[1], s_addr[2], s_addr[3], ntohs(address.sin_port)); - let fd = syscall::dup(socket as usize, path.as_bytes())?; - let ret = syscall::dup2(fd, socket as usize, &vec![]); - let _ = syscall::close(fd); - ret?; - Ok(0) -}); - -libc_fn!(unsafe bind(socket: c_int, address: *const sockaddr, _address_len: socklen_t) -> Result { - // XXX Check address_len - if (*address).sa_family as i32 != AF_INET { - return Err(Error::new(EINVAL)) - }; - let address = &*(address as *const sockaddr_in); - let s_addr =address.sin_addr.s_addr; - let path = format!("/{}.{}.{}.{}:{}", s_addr[0], s_addr[1], s_addr[2], s_addr[3], ntohs(address.sin_port)); - let fd = syscall::dup(socket as usize, path.as_bytes())?; - let ret = syscall::dup2(fd, socket as usize, &vec![]); - let _ = syscall::close(fd); - ret?; - Ok(0) -}); - -libc_fn!(unsafe listen(_socket: c_int, _backlog: c_int) -> Result { - // TODO - Ok(0) -}); - -libc_fn!(unsafe recv(socket: c_int, buffer: *mut c_void, length: size_t, flags: c_int) -> Result { - // XXX flags - if flags != 0 { - Err(Error::new(EOPNOTSUPP)) - } else { - let buf = slice::from_raw_parts_mut(buffer as *mut u8, length); - Ok(syscall::read(socket as usize, buf)? as ssize_t) - } -}); - -libc_fn!(unsafe send(socket: c_int, buffer: *const c_void, length: size_t, flags: c_int) -> Result { - if flags != 0 { - Err(Error::new(EOPNOTSUPP)) - } else { - let buf = slice::from_raw_parts(buffer as *const u8, length); - Ok(syscall::write(socket as usize, buf)? as ssize_t) - } -}); - -libc_fn!(unsafe recvfrom(socket: c_int, buffer: *mut c_void, length: size_t, flags: c_int, _address: *const sockaddr, _address_len: *const socklen_t) -> Result { - let fd = syscall::dup(socket as usize, b"listen")?; - let mut path = [0; 4096]; - syscall::fpath(socket as usize, &mut path)?; - // XXX process path and write to address - let ret = recv(socket, buffer, length, flags); - syscall::close(fd)?; - Ok(ret) -}); - -libc_fn!(unsafe sendto(socket: c_int, message: *const c_void, length: size_t, flags: c_int, dest_addr: *const sockaddr, _dest_len: socklen_t) -> Result { - // XXX test dest_len - if (*dest_addr).sa_family as i32 == AF_INET { - let addr = &*(dest_addr as *const sockaddr_in); - let s_addr = addr.sin_addr.s_addr; - let url = format!("{}.{}.{}.{}:{}", s_addr[0], s_addr[1], s_addr[2], s_addr[3], ntohs(addr.sin_port)); - let fd = syscall::dup(socket as usize, url.as_bytes())?; - let ret = send(fd as c_int, message, length, flags); - syscall::close(fd)?; - Ok(ret) - } else { - Err(Error::new(EOPNOTSUPP)) - } -}); - -libc_fn!(unsafe getpeername(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> Result { - // XXX will need to be changed for other sockaddr types - if *address_len < mem::size_of::() { - return Err(Error::new(ENOBUFS)); - } - *address_len = mem::size_of::(); - let addr = &mut *(address as *mut sockaddr_in); - addr.sin_family = AF_INET as u16; - - let mut path = [0; 4096]; - syscall::fpath(socket as usize, &mut path)?; - let start; - let sep; - let end; - { - let mut iter = path.iter(); - start = iter.position(|x| *x == b':').ok_or(Error::new(EINVAL))? + 1; - sep = start + iter.position(|x| *x == b':').ok_or(Error::new(EINVAL))?; - end = sep + 1 + iter.position(|x| *x == b'/').ok_or(Error::new(EINVAL))?; - } - path[sep] = b'\0'; - - if inet_aton(&path[start] as *const u8 as *const c_char, &mut addr.sin_addr) == 1 { - if let Ok(port) = u16::from_str(str::from_utf8_unchecked(&path[sep+1..end])) { - addr.sin_port = htons(port); - Ok(0) - } else { - Err(Error::new(EINVAL)) - } - } else { - Err(Error::new(EINVAL)) // ? - } -}); - -libc_fn!(unsafe getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> Result { - // XXX will need to be changed for other sockaddr types - if *address_len < mem::size_of::() { - return Err(Error::new(ENOBUFS)); - } - *address_len = mem::size_of::(); - let addr = &mut *(address as *mut sockaddr_in); - addr.sin_family = AF_INET as u16; - - let mut path = [0; 4096]; - syscall::fpath(socket as usize, &mut path)?; - let start; - let sep; - let end; - { - let mut iter = path.iter(); - start = iter.position(|x| *x == b'/').ok_or(Error::new(EINVAL))? + 1; - sep = start + iter.position(|x| *x == b':').ok_or(Error::new(EINVAL))?; - end = sep + 1 + iter.position(|x| *x == b'\0').ok_or(Error::new(EINVAL))?; - } - path[sep] = b'\0'; - - if inet_aton(&path[start] as *const u8 as *const c_char, &mut addr.sin_addr) == 1 { - if let Ok(port) = u16::from_str(str::from_utf8_unchecked(&path[sep+1..end])) { - addr.sin_port = htons(port); - Ok(0) - } else { - Err(Error::new(EINVAL)) - } - } else { - Err(Error::new(EINVAL)) // ? - } -}); - -libc_fn!(htonl(hostlong: u32) -> [u8; 4] { - let mut netlong = [0; 4]; - BigEndian::write_u32(&mut netlong, hostlong); - netlong -}); - -libc_fn!(htons(hostshort: u16) -> [u8; 2] { - let mut netshort = [0; 2]; - BigEndian::write_u16(&mut netshort, hostshort); - netshort -}); - -libc_fn!(ntohl(netlong: [u8; 4]) -> u32 { - BigEndian::read_u32(&netlong) -}); - -libc_fn!(ntohs(netshort: [u8; 2]) -> u16 { - BigEndian::read_u16(&netshort) -}); - -libc_fn!(setsockopt(socket: c_int, level: c_int, option_name: c_int, option_value: *const c_void, option_len: socklen_t) -> Result { - syscall::write(2, format!("unimplemented: setsockopt({}, {}, {}, {:?}, {})\n", - socket, level, option_name, option_value, option_len).as_bytes()).unwrap(); - Err(Error::new(syscall::ENOSYS)) -}); diff --git a/src/header/_oldlib/termios.rs b/src/header/_oldlib/termios.rs deleted file mode 100644 index c2bceab83a..0000000000 --- a/src/header/_oldlib/termios.rs +++ /dev/null @@ -1,93 +0,0 @@ -#![allow(non_camel_case_types)] - -use libc::{self, c_int}; -use redox_termios::{tcflag_t, Termios}; -use syscall::{self, EINVAL, Error}; -use ::types::pid_t; - -type speed_t = libc::c_uint; - -// tcsetattr args -pub const TCSANOW: tcflag_t = 0x1; -pub const TCSADRAIN: tcflag_t = 0x2; -pub const TCSAFLUSH: tcflag_t = 0x4; - -// tcflush args -pub const TCIFLUSH: tcflag_t = 0x1; -pub const TCIOFLUSH: tcflag_t = 0x3; -pub const TCOFLUSH: tcflag_t = 0x2; - -// tcflow args -pub const TCIOFF: tcflag_t = 0x1; -pub const TCION: tcflag_t = 0x2; -pub const TCOOFF: tcflag_t = 0x4; -pub const TCOON: tcflag_t = 0x8; - -libc_fn!(unsafe tcgetattr(fd: c_int, tio: *mut Termios) -> Result { - let fd = syscall::dup(fd as usize, b"termios")?; - let res = syscall::read(fd, &mut *tio); - let _ = syscall::close(fd); - - if res? == (&*tio).len() { - Ok(0) - } else { - Err(Error::new(EINVAL)) - } -}); - -libc_fn!(unsafe tcsetattr(fd: c_int, _arg: c_int, tio: *mut Termios) -> Result { - let fd = syscall::dup(fd as usize, b"termios")?; - let res = syscall::write(fd, &*tio); - let _ = syscall::close(fd); - - if res? == (&*tio).len() { - Ok(0) - } else { - Err(Error::new(EINVAL)) - } -}); - -libc_fn!(cfgetispeed(_tio: *mut Termios) -> speed_t { - // TODO - 0 as speed_t -}); - -libc_fn!(cfgetospeed(_tio: *mut Termios) -> speed_t { - // TODO - 0 as speed_t -}); - -libc_fn!(cfsetispeed(_tio: *mut Termios, _speed: speed_t) -> Result { - // TODO - Ok(0) -}); - -libc_fn!(cfsetospeed(_tio: *mut Termios, _speed: speed_t) -> Result { - // TODO - Ok(0) -}); - -libc_fn!(tcdrain(_i: c_int) -> Result { - // TODO - Ok(0) -}); - -libc_fn!(tcflow(_fd: c_int, _arg: c_int) -> Result { - // TODO - Ok(0) -}); - -libc_fn!(tcflush(_fd: c_int, _arg: c_int) -> Result { - // TODO - Ok(0) -}); - -libc_fn!(unsafe tcgetsid(_fd: c_int) -> pid_t { - // TODO - ::process::_getpid() -}); - -libc_fn!(tcsendbreak(_fd: c_int, _arg: c_int) -> Result { - // TODO - Ok(0) -}); diff --git a/src/header/_oldlib/time.rs b/src/header/_oldlib/time.rs deleted file mode 100644 index c233fd614e..0000000000 --- a/src/header/_oldlib/time.rs +++ /dev/null @@ -1,25 +0,0 @@ -use syscall; -use syscall::data::TimeSpec; -use syscall::error::{Error, EFAULT}; -use libc::{c_int, c_void}; -use types::timeval; - -libc_fn!(unsafe clock_gettime(clk_id: c_int, tp: *mut TimeSpec) -> Result { - Ok(syscall::clock_gettime(clk_id as usize, &mut *tp)? as c_int) -}); - -libc_fn!(unsafe _gettimeofday(tv: *mut timeval, _tz: *const c_void) -> Result { - if !tv.is_null() { - let mut tp = TimeSpec::default(); - syscall::clock_gettime(syscall::flag::CLOCK_REALTIME, &mut tp)?; - (*tv).tv_sec = tp.tv_sec; - (*tv).tv_usec = (tp.tv_nsec / 1000) as i64; - Ok(0) - } else { - Err(Error::new(EFAULT)) - } -}); - -libc_fn!(unsafe nanosleep(req: *const TimeSpec, rem: *mut TimeSpec) -> Result { - Ok(syscall::nanosleep(&*req, &mut *rem)? as c_int) -}); diff --git a/src/header/_oldlib/types.rs b/src/header/_oldlib/types.rs deleted file mode 100644 index 5f022cb9a8..0000000000 --- a/src/header/_oldlib/types.rs +++ /dev/null @@ -1,110 +0,0 @@ -#![allow(non_camel_case_types, dead_code)] - -use libc; - -pub type pid_t = libc::c_int; - -pub type time_t = i64; -pub type suseconds_t = libc::c_long; - -// Socket related types -pub type in_addr_t = [u8; 4]; -pub type sa_family_t = u16; -pub type socklen_t = libc::size_t; -pub type in_port_t = [u8; 2]; - -// Statvfs types -pub type dev_t = libc::c_ulong; -pub type ino_t = libc::c_ulong; -pub type mode_t = libc::c_uint; -pub type nlink_t = libc::c_ulong; -pub type uid_t = libc::c_uint; -pub type gid_t = libc::c_uint; -pub type off_t = libc::c_long; -pub type blksize_t = libc::c_long; -pub type blkcnt_t = libc::c_long; -pub type fsblkcnt_t = libc::c_ulong; -pub type fsfilcnt_t = libc::c_ulong; -pub type __fsword_t = libc::c_long; - -#[repr(C)] -pub struct fsid_t { - __val: [libc::c_int; 2] -} - -#[repr(C)] -#[derive(Clone,Copy)] -pub struct in_addr { - pub s_addr: in_addr_t -} - -#[repr(C)] -pub struct sockaddr { - pub sa_family: sa_family_t, - sa_data: [libc::c_char; 14] -} - -#[repr(C)] -pub struct sockaddr_in { - pub sin_family: sa_family_t, - pub sin_port: in_port_t, - pub sin_addr: in_addr, - __pad: [u8; 8] -} - -#[repr(C)] -pub struct hostent { - pub h_name: *const libc::c_char, - pub h_aliases: *const *const libc::c_char, - pub h_addrtype: libc::c_int, - pub h_length: libc::c_int, - pub h_addr_list: *const *const libc::c_char -} - -#[repr(C)] -#[derive(Debug)] -pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t -} - -#[repr(C)] -pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t -} - -pub type fd_mask = libc::c_ulong; -pub const FD_SETSIZE: usize = 64; -pub const NFDBITS: usize = 8 * 8; // Bits in a fd_mask - -#[repr(C)] -#[derive(Debug)] -pub struct fd_set { - pub fds_bits: [fd_mask; (FD_SETSIZE + NFDBITS - 1) / NFDBITS] -} - -pub const POLLIN: libc::c_short = 0x0001; -pub const POLLPRI: libc::c_short = 0x0002; -pub const POLLOUT: libc::c_short = 0x0004; -pub const POLLERR: libc::c_short = 0x0008; -pub const POLLHUP: libc::c_short = 0x0010; -pub const POLLNVAL: libc::c_short = 0x0020; - -#[repr(C)] -pub struct pollfd { - pub fd: libc::c_int, - pub events: libc::c_short, - pub revents: libc::c_short, -} - -#[repr(C)] -pub struct passwd { - pub pw_name: *const libc::c_char, - pub pw_passwd: *const libc::c_char, - pub pw_uid: libc::uid_t, - pub pw_gid: libc::gid_t, - pub pw_gecos: *const libc::c_char, - pub pw_dir: *const libc::c_char, - pub pw_shell: *const libc::c_char -} diff --git a/src/header/_oldlib/unimpl.rs b/src/header/_oldlib/unimpl.rs deleted file mode 100644 index 56c4aa4bc5..0000000000 --- a/src/header/_oldlib/unimpl.rs +++ /dev/null @@ -1,66 +0,0 @@ -use syscall; -use libc::{c_uint, c_int, c_char, gid_t, uid_t, c_void, c_long, mode_t}; -use syscall::error::{Error, EACCES, EPERM, EINVAL}; - -#[allow(non_camel_case_types)] -type clock_t = c_long; - -macro_rules! UNIMPL { - // Call with arguments and return value - ($func:ident, $err:ident) => {{ - let err = Error::new($err); - let _ = syscall::write(2, format!("unimplemented: {}: {}\n", - stringify!($func), err).as_bytes()); - Err(err) - }}; -} - -libc_fn!(alarm(_seconds: c_uint) -> c_uint { - let _ = syscall::write(2, "unimplemented: alarm\n".as_bytes()); - 0 -}); - -libc_fn!(chown(_path: *mut c_char, _order: uid_t, _group: gid_t) -> Result { - UNIMPL!(chown, EACCES) -}); - -libc_fn!(_getdtablesize() -> Result { - Ok(65536) -}); - -// XXX variadic -libc_fn!(_ioctl(_file: c_int, _request: c_int) -> Result { - UNIMPL!(_ioctl, EINVAL) -}); - -libc_fn!(_link(_old: *const c_char, _new: *const c_char) -> Result { - UNIMPL!(_link, EPERM) -}); - -/* -libc_fn!(sysconf(_name: c_int) -> Result { - UNIMPL!(sysconf, EINVAL) -}); -*/ - -// XXX type of argument pointer -libc_fn!(_times(_buf: *mut c_void) -> Result { - UNIMPL!(_times, EINVAL) -}); - -libc_fn!(umask(_mode: mode_t) -> mode_t { - // All permissions granted - 0o000 -}); - -libc_fn!(ttyname(_fd: c_int) -> Result<*const c_char> { - UNIMPL!(ttyname, EINVAL) -}); - -libc_fn!(fpathconf(_fildes: c_int, _name: c_int) -> Result { - UNIMPL!(fpathconf, EINVAL) -}); - -libc_fn!(getlogin() -> Result<*const c_char> { - UNIMPL!(getlogin, EINVAL) -}); diff --git a/src/header/_oldlib/user.rs b/src/header/_oldlib/user.rs deleted file mode 100644 index 3de26a89d2..0000000000 --- a/src/header/_oldlib/user.rs +++ /dev/null @@ -1,95 +0,0 @@ -use core::ptr::null; -use libc::{uid_t, gid_t, c_char}; -use ::types::passwd; -use syscall::{Error, ENOENT}; -use alloc::string::{String, ToString}; -use core::str::FromStr; - -static mut PASSWD: passwd = passwd { - pw_name: null(), - pw_passwd: null(), - pw_uid: 0, - pw_gid: 0, - pw_gecos: null(), - pw_dir: null(), - pw_shell: null() -}; - -static mut PW_NAME: Option = None; -static mut PW_PASSWD: Option = None; -static mut PW_GECOS: Option = None; -static mut PW_DIR: Option = None; -static mut PW_SHELL: Option = None; - -macro_rules! try_opt { - ($e:expr) =>( - match $e { - Some(v) => v, - None => return None, - } - ) -} - -unsafe fn parse_passwd(pwd: &str) -> Option<*const passwd> { - let mut parts = pwd.split(';'); - - let name = try_opt!(parts.next()).to_string() + "\0"; - let passwd = try_opt!(parts.next()).to_string() + "\0"; - let uid = if let Ok(uid) = uid_t::from_str(try_opt!(parts.next())) { - uid - } else { - return None - }; - let gid = if let Ok(gid) = gid_t::from_str(try_opt!(parts.next())) { - gid - } else { - return None - }; - let gecos = try_opt!(parts.next()).to_string() + "\0"; - let dir = try_opt!(parts.next()).to_string() + "\0"; - let shell = try_opt!(parts.next()).to_string() + "\0"; - - PASSWD = passwd { - pw_name: name.as_ptr() as *const c_char, - pw_passwd: passwd.as_ptr() as *const c_char, - pw_uid: uid, - pw_gid: gid, - pw_gecos: gecos.as_ptr() as *const c_char, - pw_dir: dir.as_ptr() as *const c_char, - pw_shell: shell.as_ptr() as *const c_char - }; - - PW_NAME = Some(name); - PW_PASSWD = Some(passwd); - PW_GECOS = Some(gecos); - PW_DIR = Some(dir); - PW_SHELL = Some(shell); - - Some(&PASSWD as *const _) -} - -libc_fn!(unsafe getpwnam(name: *const c_char) -> Result<*const passwd> { - if let Ok(passwd_string) = String::from_utf8(::file_read_all("/etc/passwd")?) { - for line in passwd_string.lines() { - if line.split(';').nth(0).map(str::as_bytes) == Some(::cstr_to_slice(name)) { - if let Some(pass) = parse_passwd(line) { - return Ok(pass); - } - } - } - } - Err(Error::new(ENOENT)) -}); - -libc_fn!(unsafe getpwuid(uid: uid_t) -> Result<*const passwd> { - if let Ok(passwd_string) = String::from_utf8(::file_read_all("/etc/passwd")?) { - for line in passwd_string.lines() { - if line.split(';').nth(2).map(uid_t::from_str) == Some(Ok(uid)) { - if let Some(pass) = parse_passwd(line) { - return Ok(pass); - } - } - } - } - Err(Error::new(ENOENT)) -}); diff --git a/src/header/netdb/dns/answer.rs b/src/header/netdb/dns/answer.rs index 14866aca84..402864a746 100644 --- a/src/header/netdb/dns/answer.rs +++ b/src/header/netdb/dns/answer.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use alloc::String; -use alloc::Vec; +use alloc::string::String; +use alloc::vec::Vec; #[derive(Clone, Debug)] pub struct DnsAnswer { diff --git a/src/header/netdb/dns/mod.rs b/src/header/netdb/dns/mod.rs index 46c0c67344..88da2275d7 100644 --- a/src/header/netdb/dns/mod.rs +++ b/src/header/netdb/dns/mod.rs @@ -11,8 +11,8 @@ pub use self::answer::DnsAnswer; pub use self::query::DnsQuery; -use alloc::String; -use alloc::Vec; +use alloc::string::String; +use alloc::vec::Vec; use core::slice; use core::u16; diff --git a/src/header/netdb/dns/query.rs b/src/header/netdb/dns/query.rs index 842e730e7e..0ac852f4e4 100644 --- a/src/header/netdb/dns/query.rs +++ b/src/header/netdb/dns/query.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use alloc::String; +use alloc::string::String; #[derive(Clone, Debug)] pub struct DnsQuery { diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs index c6de7d8f07..0f81980ca9 100644 --- a/src/header/netdb/mod.rs +++ b/src/header/netdb/mod.rs @@ -7,9 +7,8 @@ use core::{mem, ptr, str}; use alloc::boxed::Box; use alloc::str::SplitWhitespace; -use alloc::string::ToString; -use alloc::vec::IntoIter; -use alloc::{String, Vec}; +use alloc::string::{String, ToString}; +use alloc::vec::{IntoIter, Vec}; use c_str::{CStr, CString}; diff --git a/src/header/stdio/scanf.rs b/src/header/stdio/scanf.rs index b6de51a5d7..8595d2be3f 100644 --- a/src/header/stdio/scanf.rs +++ b/src/header/stdio/scanf.rs @@ -1,5 +1,5 @@ -use alloc::String; -use alloc::Vec; +use alloc::string::String; +use alloc::vec::Vec; use io::Read; use platform::types::*; use va_list::VaList; diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index 2b7888f429..5443ebc738 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -1,6 +1,6 @@ //! strings implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/strings.h.html -use alloc::Vec; +use alloc::vec::Vec; use core::ptr; use platform::types::*; diff --git a/src/lib.rs b/src/lib.rs index 465e1da9c0..189cca34fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,6 @@ #![feature(global_asm)] #![feature(lang_items)] #![feature(linkage)] -#![feature(panic_implementation)] #![feature(str_internals)] #![feature(thread_local)] @@ -51,7 +50,7 @@ use platform::{Allocator, Pal, Sys}; static ALLOCATOR: Allocator = Allocator; #[cfg(not(test))] -#[panic_implementation] +#[panic_handler] #[linkage = "weak"] #[no_mangle] pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index df4f67adba..26e4e21ce3 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -171,7 +171,7 @@ impl Pal for Sys { mut argv: *const *mut c_char, mut envp: *const *mut c_char, ) -> c_int { - use alloc::Vec; + use alloc::vec::Vec; let mut file = match File::open(path, fcntl::O_RDONLY | fcntl::O_CLOEXEC) { Ok(file) => file, diff --git a/src/start.rs b/src/start.rs index 9399eb2fe5..0d7d832e0d 100644 --- a/src/start.rs +++ b/src/start.rs @@ -1,4 +1,4 @@ -use alloc::Vec; +use alloc::vec::Vec; use core::ptr; use header::{stdio, stdlib};