diff options
163 files changed, 14226 insertions, 4364 deletions
diff --git a/libc/.github/issue_template.md b/libc/.github/issue_template.md new file mode 100644 index 0000000..435bf35 --- /dev/null +++ b/libc/.github/issue_template.md @@ -0,0 +1,24 @@ +<!-- +**Help us help you.** + +If you are reporting a bug, include: + +* a Minimum Working Example without any dependencies (except libc) that shows + the issue and ideally reproduces in the Rust playground +* the target triple - libc supports many targets and many APIs +* instructions to reproduce, logs (e.g. build logs, links to Travis-CI logs, + uploads to github gists, etc.). + +If you are requesting a new API, include: + +* the target triple +* link to the documentation of the API showing the type signatures, how to use + it, etc. + +In general, just please consider that the people who can help you are all very +busy, they will be helping you in their free time, there are a lot of people in +need of help so they need to prioritize to which issues they devote their free +time, etc. So try to give most of the information upfront, be concise, show +small self-contained examples (nobody has time to create a new cargo project, +set up dependencies,...), etc. Help us help you. +--> diff --git a/libc/.gitignore b/libc/.gitignore index f0ff259..bbbad4b 100644 --- a/libc/.gitignore +++ b/libc/.gitignore @@ -1,3 +1,4 @@ target Cargo.lock *~ +style diff --git a/libc/.travis.yml b/libc/.travis.yml index 52d2403..1fa0a8d 100644 --- a/libc/.travis.yml +++ b/libc/.travis.yml @@ -1,108 +1,253 @@ language: rust -rust: stable +rust: nightly sudo: required dist: xenial services: docker +stages: + - tools-and-build-and-tier1 + - tier2 + matrix: include: - # 1.13.0 compat - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.13.0 - script: rm -f Cargo.lock && cargo build + # TOOLS + - name: "Documentation" + env: TARGET=x86_64-unknown-linux-gnu + script: sh ci/dox.sh + install: + - travis_retry rustup component add rust-src + - travis_retry cargo install xargo + stage: tools-and-build-and-tier1 + - name: "Shellcheck" + install: true + script: + - shellcheck --version + - shellcheck ci/*.sh + stage: tools-and-build-and-tier1 + - name: "Style" install: true + script: + - rustc ci/style.rs && ./style src + # Disabled due to rust-lang/rustfmt#3341 + #- | + # if rustup component add rustfmt-preview ; then + # cargo fmt --all -- --check + # fi + stage: tools-and-build-and-tier1 + - name: "Semver Linux" + install: travis_retry cargo +nightly install semverver + script: sh ci/semver.sh + stage: tools-and-build-and-tier1 + - name: "Semver MacOSX" + install: travis_retry cargo +nightly install semverver + script: sh ci/semver.sh + os: osx + osx_image: xcode10 + stage: tools-and-build-and-tier1 - # build documentation - - env: TARGET=x86_64-unknown-linux-gnu + # BUILD stable, beta, nightly + - name: "Build Stable Rust" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: stable + install: true + - name: "Build Beta Rust" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: beta + install: true + - name: "Build Nightly Rust" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 rust: nightly - script: sh ci/dox.sh + install: + - travis_retry rustup component add rust-src + - travis_retry cargo install xargo + - name: "Build Stable Rust" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: stable + os: osx + osx_image: xcode10 install: true - - # stable compat - - env: TARGET=x86_64-unknown-linux-gnu + - name: "Build Beta Rust" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: beta + os: osx + osx_image: xcode10 install: true - - env: TARGET=i686-unknown-linux-gnu - - os: osx - env: TARGET=x86_64-apple-darwin + - name: "Build Nightly Rust" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: nightly + os: osx osx_image: xcode10 install: true - - os: osx - env: TARGET=i686-apple-darwin + - name: "Build Stable Rust 1.13.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.13.0 + install: true + - name: "Build Stable Rust 1.19.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.19.0 + install: true + - name: "Build Stable Rust 1.24.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.24.0 + install: true + - name: "Build Stable Rust 1.25.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.25.0 + install: true + - name: "Build Stable Rust 1.30.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.30.0 + install: true + - name: "Build Stable Rust 1.13.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.13.0 + os: osx osx_image: xcode10 - - env: TARGET=arm-linux-androideabi + install: true + - name: "Build Stable Rust 1.19.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.19.0 + os: osx + osx_image: xcode10 + install: true + - name: "Build Stable Rust 1.24.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.24.0 + os: osx + osx_image: xcode10 + install: true + - name: "Build Stable Rust 1.25.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.25.0 + os: osx + osx_image: xcode10 + install: true + - name: "Build Stable Rust 1.30.0" + script: sh ci/build.sh + stage: tools-and-build-and-tier1 + rust: 1.30.0 + os: osx + osx_image: xcode10 + install: true + - env: TARGET=i686-apple-darwin + os: osx + osx_image: xcode10 + stage: tools-and-build-and-tier1 + - env: TARGET=i686-unknown-linux-gnu + stage: tools-and-build-and-tier1 + - env: TARGET=x86_64-apple-darwin + os: osx + osx_image: xcode10 + install: true + stage: tools-and-build-and-tier1 + - env: TARGET=x86_64-unknown-linux-gnu + stage: tools-and-build-and-tier1 + install: true + + # Tier 2 targets - env: TARGET=aarch64-linux-android - # FIXME(#826) should reenable - #- env: TARGET=i686-linux-android - - env: TARGET=x86_64-linux-android - - env: TARGET=x86_64-unknown-linux-musl - - env: TARGET=i686-unknown-linux-musl - - env: TARGET=arm-unknown-linux-gnueabihf - - env: TARGET=arm-unknown-linux-musleabihf + stage: tier2 - env: TARGET=aarch64-unknown-linux-gnu + stage: tier2 - env: TARGET=aarch64-unknown-linux-musl - - env: TARGET=powerpc-unknown-linux-gnu - - env: TARGET=powerpc64-unknown-linux-gnu - - env: TARGET=powerpc64le-unknown-linux-gnu + stage: tier2 + - env: TARGET=arm-linux-androideabi + stage: tier2 + - env: TARGET=arm-unknown-linux-gnueabihf + stage: tier2 + - env: TARGET=arm-unknown-linux-musleabihf + stage: tier2 + - env: TARGET=asmjs-unknown-emscripten + stage: tier2 + - env: TARGET=i686-unknown-linux-musl + stage: tier2 + - env: TARGET=mips-unknown-linux-gnu + stage: tier2 - env: TARGET=mips-unknown-linux-musl - - env: TARGET=mipsel-unknown-linux-musl + stage: tier2 - env: TARGET=mips64-unknown-linux-gnuabi64 + stage: tier2 - env: TARGET=mips64el-unknown-linux-gnuabi64 - - env: TARGET=mips-unknown-linux-gnu + stage: tier2 + - env: TARGET=mipsel-unknown-linux-musl + stage: tier2 + - env: TARGET=powerpc-unknown-linux-gnu + stage: tier2 + - env: TARGET=powerpc64-unknown-linux-gnu + stage: tier2 + - env: TARGET=powerpc64le-unknown-linux-gnu + stage: tier2 - env: TARGET=s390x-unknown-linux-gnu + stage: tier2 - env: TARGET=sparc64-unknown-linux-gnu - - env: TARGET=asmjs-unknown-emscripten + stage: tier2 - env: TARGET=wasm32-unknown-emscripten - - # beta - - env: TARGET=x86_64-unknown-linux-gnu - rust: beta - install: true - - os: osx - env: TARGET=x86_64-apple-darwin - osx_image: xcode10 - rust: beta - install: true - - # nightly - - env: TARGET=x86_64-unknown-linux-gnu - rust: nightly - install: true - - os: osx - env: TARGET=x86_64-apple-darwin - osx_image: xcode10 - rust: nightly - install: true - # not available on stable - # without --release the build fails - # see https://github.com/rust-lang/rust/issues/45417 + stage: tier2 + - env: TARGET=x86_64-linux-android + stage: tier2 - env: TARGET=x86_64-unknown-linux-gnux32 OPT="--release" + stage: tier2 + - env: TARGET=x86_64-unknown-linux-musl + stage: tier2 + - env: TARGET=wasm32-wasi rust: nightly - - - env: TARGET=wasm32-unknown-unknown - install: rustup target add $TARGET - script: cargo build --no-default-features --target $TARGET --release - - - name: "Shellcheck" - install: true + stage: tier2 + - name: "Nintendo Switch - build libcore only" + rust: nightly + stage: tier2 + install: + - rustup component add rust-src + - (test -x $HOME/.cargo/bin/cargo-xbuild || cargo install cargo-xbuild) script: - - shellcheck --version - - shellcheck ci/*.sh + - mkdir -p target + - cd target + - wget https://github.com/devkitPro/pacman/releases/download/devkitpro-pacman-1.0.1/devkitpro-pacman.deb + - sudo dpkg -i devkitpro-pacman.deb + - sudo dkp-pacman -Sy + - sudo dkp-pacman -Syu + - sudo dkp-pacman -S -v --noconfirm switch-dev devkitA64 + - export PATH="$PATH:/opt/devkitpro/devkitA64/bin" + - export PATH="$PATH:/opt/devkitpro/tools/bin" + - cd .. + # Pull the target spec up into the current directory and then build + - mv ci/switch.json switch.json + - cargo xbuild --target switch.json + allow_failures: + # FIXME: android build bots time out irregularly + - env: TARGET=aarch64-linux-android + - env: TARGET=arm-linux-androideabi # FIXME: https://github.com/rust-lang/libc/issues/1226 - env: TARGET=asmjs-unknown-emscripten - env: TARGET=wasm32-unknown-emscripten + - name: "Semver Linux" + - name: "Semver MacOSX" + +install: travis_retry rustup target add $TARGET -install: rustup target add $TARGET script: - cargo generate-lockfile --manifest-path libc-test/Cargo.toml - - if [[ $TRAVIS_OS_NAME = "linux" ]]; then + - if [[ $TRAVIS_OS_NAME = "linux" ]] && [[ $BUILD_ONLY != "1" ]]; then sh ci/run-docker.sh $TARGET; else - export CARGO_TARGET_DIR=`pwd`/target; sh ci/run.sh $TARGET; fi - - rustc ci/style.rs && ./style src env: global: secure: "e2/3QjgRN9atOuSHp22TrYG7QVKcYUWY48Hi9b60w+r1+BhPkTseIJLte7WefRhdXtqpjjUJTooKDhnurFOeHaCT+nmBgiv+FPU893sBl4bhesY4m0vgUJVbNZcs6lTImYekWVb+aqjGdgV/XAgCw7c3kPmrZV0MzGDWL64Xaps=" diff --git a/libc/CONTRIBUTING.md b/libc/CONTRIBUTING.md new file mode 100644 index 0000000..0e5d0c6 --- /dev/null +++ b/libc/CONTRIBUTING.md @@ -0,0 +1,66 @@ +# Contributing to `libc` + +Welcome! If you are reading this document, it means you are interested in contributing +to the `libc` crate. + +## Adding an API + +Want to use an API which currently isn't bound in `libc`? It's quite easy to add +one! + +The internal structure of this crate is designed to minimize the number of +`#[cfg]` attributes in order to easily be able to add new items which apply +to all platforms in the future. As a result, the crate is organized +hierarchically based on platform. Each module has a number of `#[cfg]`'d +children, but only one is ever actually compiled. Each module then reexports all +the contents of its children. + +This means that for each platform that libc supports, the path from a +leaf module to the root will contain all bindings for the platform in question. +Consequently, this indicates where an API should be added! Adding an API at a +particular level in the hierarchy means that it is supported on all the child +platforms of that level. For example, when adding a Unix API it should be added +to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to +`src/unix/notbsd/linux/mod.rs`. + +If you're not 100% sure at what level of the hierarchy an API should be added +at, fear not! This crate has CI support which tests any binding against all +platforms supported, so you'll see failures if an API is added at the wrong +level or has different signatures across platforms. + +With that in mind, the steps for adding a new API are: + +1. Determine where in the module hierarchy your API should be added. +2. Add the API. +3. Send a PR to this repo. +4. Wait for CI to pass, fixing errors. +5. Wait for a merge! + +### Test before you commit + +We have two automated tests running on [Travis](https://travis-ci.org/rust-lang/libc): + +1. [`libc-test`](https://github.com/alexcrichton/ctest) + - `cd libc-test && cargo test` + - Use the `skip_*()` functions in `build.rs` if you really need a workaround. +2. Style checker + - `rustc ci/style.rs && ./style src` + +### Releasing your change to crates.io + +Now that you've done the amazing job of landing your new API or your new +platform in this crate, the next step is to get that sweet, sweet usage from +crates.io! The only next step is to bump the version of libc and then publish +it. If you'd like to get a release out ASAP you can follow these steps: + +1. Update the version number in `Cargo.toml`, you'll just be bumping the patch + version number. +2. Run `cargo update` to regenerate the lockfile to encode your version bump in + the lock file. You may pull in some other updated dependencies, that's ok. +3. Send a PR to this repository. It should [look like this][example], but it'd + also be nice to fill out the description with a small rationale for the + release (any rationale is ok though!) +4. Once merged the release will be tagged and published by one of the libc crate + maintainers. + +[example]: https://github.com/rust-lang/libc/pull/583 diff --git a/libc/Cargo.lock b/libc/Cargo.lock deleted file mode 100644 index a8165ea..0000000 --- a/libc/Cargo.lock +++ /dev/null @@ -1,340 +0,0 @@ -[[package]] -name = "bitflags" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "bitflags" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cc" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cfg-if" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "ctest" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_syntax 0.59.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "extprim" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "itoa" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.2.47" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.48" -dependencies = [ - "rustc-std-workspace-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc-test" -version = "0.1.0" -dependencies = [ - "ctest 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48", -] - -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "log" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-traits" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "proc-macro2" -version = "0.4.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quote" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (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]] -name = "rdrand" -version = "0.4.0" -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 = "rustc-std-workspace-core" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ryu" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_derive" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_json" -version = "1.0.36" -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.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syn" -version = "0.15.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syntex_errors" -version = "0.59.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_pos 0.59.1 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syntex_pos" -version = "0.59.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syntex_syntax" -version = "0.59.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "extprim 1.6.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.85 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_errors 0.59.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_pos 0.59.1 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "term" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" -"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" -"checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749" -"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" -"checksum ctest 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3574c0edc91c25cb50d1e4238f35ae2651b0beadf72bfec31fb4ead46b4eb5b8" -"checksum extprim 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "054bc2552b3f66fa8097e29e47255bfff583c08e737a67cbbb54b817ddaa5206" -"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 kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)" = "48450664a984b25d5b479554c29cc04e3150c97aa4c01da5604a2d4ed9151476" -"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"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 proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)" = "38fddd23d98b2144d197c0eca5705632d4fe2667d14a6be5df8934f8d74f1978" -"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" -"checksum rand 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dee497e66d8d76bf08ce20c8d36e16f93749ab0bf89975b4f8ae5cee660c2da2" -"checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" -"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum rustc-std-workspace-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1956f5517128a2b6f23ab2dadf1a976f4f5b27962e7724c2bf3d45e539ec098c" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)" = "534b8b91a95e0f71bca3ed5824752d558da048d4248c91af873b63bd60519752" -"checksum serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)" = "a915306b0f1ac5607797697148c223bedeaa36bcc2e28a01441cd638cc6567b4" -"checksum serde_json 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "574378d957d6dcdf1bbb5d562a15cbd5e644159432f84634b94e485267abbcc7" -"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" -"checksum syntex_errors 0.59.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3133289179676c9f5c5b2845bf5a2e127769f4889fcbada43035ef6bd662605e" -"checksum syntex_pos 0.59.1 (registry+https://github.com/rust-lang/crates.io-index)" = "30ab669fa003d208c681f874bbc76d91cc3d32550d16b5d9d2087cf477316470" -"checksum syntex_syntax 0.59.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03815b9f04d95828770d9c974aa39c6e1f6ef3114eb77a3ce09008a0d15dd142" -"checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1" -"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/libc/Cargo.toml b/libc/Cargo.toml index 9161644..ef500be 100644 --- a/libc/Cargo.toml +++ b/libc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libc" -version = "0.2.48" +version = "0.2.55" authors = ["The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -27,6 +27,7 @@ default = ["use_std"] use_std = [] align = [] rustc-dep-of-std = ['align', 'rustc-std-workspace-core'] +extra_traits = [] [workspace] members = ["libc-test"] diff --git a/libc/README.md b/libc/README.md index 636f10e..a974ccd 100644 --- a/libc/README.md +++ b/libc/README.md @@ -1,173 +1,103 @@ -libc +[![Travis-CI Status]][Travis-CI] [![Appveyor Status]][Appveyor] [![Cirrus-CI Status]][Cirrus-CI] [![Latest Version]][crates.io] [![Documentation]][docs.rs] ![License] + +libc - Raw FFI bindings to platforms' system libraries ==== -Raw FFI bindings to platform libraries like `libc`. +`libc` provides all of the definitions necessary to easily interoperate with C +code (or "C-like" code) on each of the platforms that Rust supports. This +includes type definitions (e.g. `c_int`), constants (e.g. `EINVAL`) as well as +function headers (e.g. `malloc`). + +This crate exports all underlying platform types, functions, and constants under +the crate root, so all items are accessible as `libc::foo`. The types and values +of all the exported APIs match the platform that libc is compiled for. -[![Build Status](https://travis-ci.org/rust-lang/libc.svg?branch=master)](https://travis-ci.org/rust-lang/libc) -[![Build status](https://ci.appveyor.com/api/projects/status/github/rust-lang/libc?svg=true)](https://ci.appveyor.com/project/rust-lang-libs/libc) -[![Build Status](https://api.cirrus-ci.com/github/rust-lang/libc.svg)](https://cirrus-ci.com/github/rust-lang/libc) -[![Latest version](https://img.shields.io/crates/v/libc.svg)](https://crates.io/crates/libc) -[![Documentation](https://docs.rs/libc/badge.svg)](https://docs.rs/libc) -![License](https://img.shields.io/crates/l/libc.svg) +More detailed information about the design of this library can be found in its +[associated RFC][rfc]. + +[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1291-promote-libc.md ## Usage -First, add the following to your `Cargo.toml`: +Add the following to your `Cargo.toml`: ```toml [dependencies] libc = "0.2" ``` -Next, add this to your crate root: +## Features -```rust -extern crate libc; -``` +* `use_std`: by default `libc` links to the standard library. Disable this + feature remove this dependency and be able to use `libc` in `#![no_std]` + crates. -Currently libc by default links to the standard library, but if you would -instead like to use libc in a `#![no_std]` situation or crate you can request -this via: +* `extra_traits`: all `struct`s implemented in `libc` are `Copy` and `Clone`. + This feature derives `Debug`, `Eq`, `Hash`, and `PartialEq`. -```toml -[dependencies] -libc = { version = "0.2", default-features = false } -``` +## Rust version support -By default libc uses private fields in structs in order to enforce a certain -memory alignment on them. These structs can be hard to instantiate outside of -libc. To make libc use `#[repr(align(x))]`, instead of the private fields, -activate the *align* feature. This requires Rust 1.25 or newer: +The minimum supported Rust toolchain version is **Rust 1.13.0** . APIs requiring +newer Rust features are only available on newer Rust toolchains: -```toml -[dependencies] -libc = { version = "0.2", features = ["align"] } -``` +| Feature | Version | +|----------------------|---------| +| `union` | 1.19.0 | +| `const mem::size_of` | 1.24.0 | +| `repr(align)` | 1.25.0 | +| `extra_traits` | 1.25.0 | +| `core::ffi::c_void` | 1.30.0 | +| `repr(packed(N))` | 1.33.0 | -## What is libc? +## Platform support -The primary purpose of this crate is to provide all of the definitions necessary -to easily interoperate with C code (or "C-like" code) on each of the platforms -that Rust supports. This includes type definitions (e.g. `c_int`), constants -(e.g. `EINVAL`) as well as function headers (e.g. `malloc`). +[Platform-specific documentation (master branch)][docs.master]. -This crate does not strive to have any form of compatibility across platforms, -but rather it is simply a straight binding to the system libraries on the -platform in question. +See +[`ci/build.sh`](https://github.com/rust-lang/libc/blob/master/libc-test/build.rs) +for the platforms on which `libc` is guaranteed to build for each Rust +toolchain. The test-matrix at [Travis-CI], [Appveyor], and [Cirrus-CI] show the +platforms in which `libc` tests are run. -## Public API +<div class="platform_docs"></div> -This crate exports all underlying platform types, functions, and constants under -the crate root, so all items are accessible as `libc::foo`. The types and values -of all the exported APIs match the platform that libc is compiled for. +## License -More detailed information about the design of this library can be found in its -[associated RFC][rfc]. +This project is licensed under either of -[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1291-promote-libc.md +* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) + ([LICENSE-APACHE](LICENSE-APACHE)) + +* [MIT License](http://opensource.org/licenses/MIT) + ([LICENSE-MIT](LICENSE-MIT)) + +at your option. + +## Contributing + +We welcome all people who want to contribute. Please see the [contributing +instructions] for more information. + +[contributing instructions]: CONTRIBUTING.md + +Contributions in any form (issues, pull requests, etc.) to this project +must adhere to Rust's [Code of Conduct]. + +[Code of Conduct]: https://www.rust-lang.org/en-US/conduct.html + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in `libc` by you, as defined in the Apache-2.0 license, shall be +dual licensed as above, without any additional terms or conditions. -## Adding an API - -Want to use an API which currently isn't bound in `libc`? It's quite easy to add -one! - -The internal structure of this crate is designed to minimize the number of -`#[cfg]` attributes in order to easily be able to add new items which apply -to all platforms in the future. As a result, the crate is organized -hierarchically based on platform. Each module has a number of `#[cfg]`'d -children, but only one is ever actually compiled. Each module then reexports all -the contents of its children. - -This means that for each platform that libc supports, the path from a -leaf module to the root will contain all bindings for the platform in question. -Consequently, this indicates where an API should be added! Adding an API at a -particular level in the hierarchy means that it is supported on all the child -platforms of that level. For example, when adding a Unix API it should be added -to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to -`src/unix/notbsd/linux/mod.rs`. - -If you're not 100% sure at what level of the hierarchy an API should be added -at, fear not! This crate has CI support which tests any binding against all -platforms supported, so you'll see failures if an API is added at the wrong -level or has different signatures across platforms. - -With that in mind, the steps for adding a new API are: - -1. Determine where in the module hierarchy your API should be added. -2. Add the API. -3. Send a PR to this repo. -4. Wait for CI to pass, fixing errors. -5. Wait for a merge! - -### Test before you commit - -We have two automated tests running on [Travis](https://travis-ci.org/rust-lang/libc): - -1. [`libc-test`](https://github.com/alexcrichton/ctest) - - `cd libc-test && cargo test` - - Use the `skip_*()` functions in `build.rs` if you really need a workaround. -2. Style checker - - `rustc ci/style.rs && ./style src` - -### Releasing your change to crates.io - -Now that you've done the amazing job of landing your new API or your new -platform in this crate, the next step is to get that sweet, sweet usage from -crates.io! The only next step is to bump the version of libc and then publish -it. If you'd like to get a release out ASAP you can follow these steps: - -1. Update the version number in `Cargo.toml`, you'll just be bumping the patch - version number. -2. Run `cargo update` to regenerate the lockfile to encode your version bump in - the lock file. You may pull in some other updated dependencies, that's ok. -3. Send a PR to this repository. It should [look like this][example], but it'd - also be nice to fill out the description with a small rationale for the - release (any rationale is ok though!) -4. Once merged the release will be tagged and published by one of the libc crate - maintainers. - -[example]: https://github.com/rust-lang/libc/pull/583 - -## Platforms and Documentation - -The following platforms are currently tested and have documentation available: - -Tested: - * [`i686-pc-windows-msvc`](https://rust-lang.github.io/libc/i686-pc-windows-msvc/libc/) - * [`x86_64-pc-windows-msvc`](https://rust-lang.github.io/libc/x86_64-pc-windows-msvc/libc/) - (Windows) - * [`i686-pc-windows-gnu`](https://rust-lang.github.io/libc/i686-pc-windows-gnu/libc/) - * [`x86_64-pc-windows-gnu`](https://rust-lang.github.io/libc/x86_64-pc-windows-gnu/libc/) - * [`i686-apple-darwin`](https://rust-lang.github.io/libc/i686-apple-darwin/libc/) - * [`x86_64-apple-darwin`](https://rust-lang.github.io/libc/x86_64-apple-darwin/libc/) - (OSX) - * `i386-apple-ios` - * `x86_64-apple-ios` - * [`i686-unknown-linux-gnu`](https://rust-lang.github.io/libc/i686-unknown-linux-gnu/libc/) - * [`x86_64-unknown-linux-gnu`](https://rust-lang.github.io/libc/x86_64-unknown-linux-gnu/libc/) - (Linux) - * [`x86_64-unknown-linux-musl`](https://rust-lang.github.io/libc/x86_64-unknown-linux-musl/libc/) - (Linux MUSL) - * [`aarch64-unknown-linux-gnu`](https://rust-lang.github.io/libc/aarch64-unknown-linux-gnu/libc/) - (Linux) - * `aarch64-unknown-linux-musl` - (Linux MUSL) - * [`sparc64-unknown-linux-gnu`](https://rust-lang.github.io/libc/sparc64-unknown-linux-gnu/libc/) - (Linux) - * [`mips-unknown-linux-gnu`](https://rust-lang.github.io/libc/mips-unknown-linux-gnu/libc/) - * [`arm-unknown-linux-gnueabihf`](https://rust-lang.github.io/libc/arm-unknown-linux-gnueabihf/libc/) - * [`arm-linux-androideabi`](https://rust-lang.github.io/libc/arm-linux-androideabi/libc/) - (Android) - * [`x86_64-unknown-freebsd`](https://rust-lang.github.io/libc/x86_64-unknown-freebsd/libc/) - * [`x86_64-unknown-openbsd`](https://rust-lang.github.io/libc/x86_64-unknown-openbsd/libc/) - * [`x86_64-rumprun-netbsd`](https://rust-lang.github.io/libc/x86_64-unknown-netbsd/libc/) - -The following may be supported, but are not guaranteed to always work: - - * `i686-unknown-freebsd` - * [`x86_64-unknown-bitrig`](https://rust-lang.github.io/libc/x86_64-unknown-bitrig/libc/) - * [`x86_64-unknown-dragonfly`](https://rust-lang.github.io/libc/x86_64-unknown-dragonfly/libc/) - * `i686-unknown-haiku` - * `x86_64-unknown-haiku` - * [`x86_64-unknown-netbsd`](https://rust-lang.github.io/libc/x86_64-unknown-netbsd/libc/) - * [`x86_64-sun-solaris`](https://rust-lang.github.io/libc/x86_64-sun-solaris/libc/) +[Travis-CI]: https://travis-ci.com/rust-lang/libc +[Travis-CI Status]: https://travis-ci.com/rust-lang/libc.svg?branch=master +[Appveyor]: https://ci.appveyor.com/project/rust-lang-libs/libc +[Appveyor Status]: https://ci.appveyor.com/api/projects/status/github/rust-lang/libc?svg=true +[Cirrus-CI]: https://cirrus-ci.com/github/rust-lang/libc +[Cirrus-CI Status]: https://api.cirrus-ci.com/github/rust-lang/libc.svg +[crates.io]: https://crates.io/crates/libc +[Latest Version]: https://img.shields.io/crates/v/libc.svg +[Documentation]: https://docs.rs/libc/badge.svg +[docs.rs]: https://docs.rs/libc +[License]: https://img.shields.io/crates/l/libc.svg +[docs.master]: https://rust-lang.github.io/libc/#platform-specific-documentation diff --git a/libc/appveyor.yml b/libc/appveyor.yml index 9fd4b26..b14230a 100644 --- a/libc/appveyor.yml +++ b/libc/appveyor.yml @@ -23,6 +23,6 @@ install: build: false test_script: - - cargo test --target %TARGET% - - cargo test --no-default-features --target %TARGET% - - cargo test --manifest-path libc-test/Cargo.toml --target %TARGET% + - cargo -vv test --target %TARGET% + - cargo -vv test --no-default-features --target %TARGET% + - cargo -vv test --manifest-path libc-test/Cargo.toml --target %TARGET% diff --git a/libc/build.rs b/libc/build.rs index 1852ed2..9b13376 100644 --- a/libc/build.rs +++ b/libc/build.rs @@ -3,12 +3,42 @@ use std::process::Command; use std::str; fn main() { - /* - * If `core::ffi::c_void` exists, libc can just re-export it. Otherwise, it - * must define an incompatible type to retain backwards-compatibility. - */ - if rustc_minor_version().expect("Failed to get rustc version") >= 30 { - println!("cargo:rustc-cfg=core_cvoid"); + let rustc_minor_ver = + rustc_minor_version().expect("Failed to get rustc version"); + let rustc_dep_of_std = + std::env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok(); + let align_cargo_feature = std::env::var("CARGO_FEATURE_ALIGN").is_ok(); + + // Rust >= 1.15 supports private module use: + if rustc_minor_ver >= 15 || rustc_dep_of_std { + println!("cargo:rustc-cfg=libc_priv_mod_use"); + } + + // Rust >= 1.19 supports unions: + if rustc_minor_ver >= 19 || rustc_dep_of_std { + println!("cargo:rustc-cfg=libc_union"); + } + + // Rust >= 1.24 supports const mem::size_of: + if rustc_minor_ver >= 24 || rustc_dep_of_std { + println!("cargo:rustc-cfg=libc_const_size_of"); + } + + // Rust >= 1.25 supports repr(align): + if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature { + println!("cargo:rustc-cfg=libc_align"); + } + + // Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it. + // Otherwise, it defines an incompatible type to retaining + // backwards-compatibility. + if rustc_minor_ver >= 30 || rustc_dep_of_std { + println!("cargo:rustc-cfg=libc_core_cvoid"); + } + + // Rust >= 1.33 supports repr(packed(N)) + if rustc_minor_ver >= 33 || rustc_dep_of_std { + println!("cargo:rustc-cfg=libc_packedN"); } } diff --git a/libc/ci/android-install-ndk.sh b/libc/ci/android-install-ndk.sh index ce11d00..54f7b2e 100644 --- a/libc/ci/android-install-ndk.sh +++ b/libc/ci/android-install-ndk.sh @@ -11,7 +11,7 @@ set -ex -curl --retry 5 -O https://dl.google.com/android/repository/android-ndk-r15b-linux-x86_64.zip +curl --retry 10 -O https://dl.google.com/android/repository/android-ndk-r15b-linux-x86_64.zip unzip -q android-ndk-r15b-linux-x86_64.zip case "$1" in diff --git a/libc/ci/android-install-sdk.sh b/libc/ci/android-install-sdk.sh index 6b5ac09..e011cfc 100644 --- a/libc/ci/android-install-sdk.sh +++ b/libc/ci/android-install-sdk.sh @@ -19,7 +19,7 @@ set -ex # which apparently magically accepts the licenses. mkdir sdk -curl --retry 5 https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip -O +curl --retry 10 https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip -O unzip -d sdk sdk-tools-linux-3859397.zip case "$1" in @@ -45,6 +45,9 @@ case "$1" in ;; esac; +# See: https://stackoverflow.com/a/51644855/1422197 +export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee' + # --no_https avoids # javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found yes | ./sdk/tools/bin/sdkmanager --licenses --no_https diff --git a/libc/ci/build.sh b/libc/ci/build.sh new file mode 100644 index 0000000..eb07c18 --- /dev/null +++ b/libc/ci/build.sh @@ -0,0 +1,214 @@ +#!/usr/bin/env sh + +# Checks that libc builds properly for all supported targets on a particular +# Rust version: + +set -ex + +RUST=${TRAVIS_RUST_VERSION} +OS=${TRAVIS_OS_NAME} + +echo "Testing Rust ${RUST} on ${OS}" + +test_target() { + CARGO="${1}" + TARGET="${2}" + NO_STD="${3}" + + opt= + if [ "${TARGET}" = "x86_64-unknown-linux-gnux32" ]; then + # FIXME: x86_64-unknown-linux-gnux32 fail to compile without + # --release + # + # See https://github.com/rust-lang/rust/issues/45417 + opt="--release" + fi + + # If there is a std component, fetch it: + if [ "${NO_STD}" != "1" ]; then + # FIXME: rustup often fails to download some artifacts due to network + # issues, so we retry this N times. + N=5 + n=0 + until [ $n -ge $N ] + do + if rustup target add "${TARGET}" --toolchain "${RUST}" ; then + break + fi + n=$((n+1)) + sleep 1 + done + fi + + # Test that libc builds without any default features (no libstd) + "$CARGO" "+${RUST}" build -vv $opt --no-default-features --target "${TARGET}" + + # Test that libc builds with default features (e.g. libstd) + # if the target supports libstd + if [ "$NO_STD" != "1" ]; then + "$CARGO" "+${RUST}" build -vv $opt --target "${TARGET}" + fi + + # Test that libc builds with the `extra_traits` feature + "$CARGO" "+${RUST}" build -vv $opt --no-default-features --target "${TARGET}" \ + --features extra_traits + + # Also test that it builds with `extra_traits` and default features: + if [ "$NO_STD" != "1" ]; then + "$CARGO" "+${RUST}" build -vv $opt --target "${TARGET}" \ + --features extra_traits + fi +} + +RUST_LINUX_TARGETS="\ +aarch64-linux-android \ +aarch64-unknown-linux-gnu \ +arm-linux-androideabi \ +arm-unknown-linux-gnueabi \ +arm-unknown-linux-gnueabihf \ +armv7-linux-androideabi \ +armv7-unknown-linux-gnueabihf \ +i586-unknown-linux-gnu \ +i686-linux-android \ +i686-unknown-freebsd \ +i686-unknown-linux-gnu \ +i686-unknown-linux-musl \ +mips-unknown-linux-gnu \ +mips-unknown-linux-musl \ +mips64-unknown-linux-gnuabi64 \ +mips64el-unknown-linux-gnuabi64 \ +mipsel-unknown-linux-gnu \ +mipsel-unknown-linux-gnu \ +mipsel-unknown-linux-musl \ +powerpc-unknown-linux-gnu \ +powerpc64-unknown-linux-gnu \ +powerpc64le-unknown-linux-gnu \ +s390x-unknown-linux-gnu \ +x86_64-unknown-freebsd \ +x86_64-unknown-linux-gnu \ +x86_64-unknown-linux-musl \ +x86_64-unknown-netbsd \ +" + +RUST_GT_1_13_LINUX_TARGETS="\ +arm-unknown-linux-musleabi \ +arm-unknown-linux-musleabihf \ +armv7-unknown-linux-musleabihf \ +sparc64-unknown-linux-gnu \ +wasm32-unknown-emscripten \ +x86_64-linux-android \ +x86_64-rumprun-netbsd \ +" +RUST_GT_1_19_LINUX_TARGETS="\ +aarch64-unknown-linux-musl \ +sparcv9-sun-solaris \ +wasm32-unknown-unknown \ +x86_64-sun-solaris \ +" +RUST_GT_1_24_LINUX_TARGETS="\ +i586-unknown-linux-musl \ +x86_64-unknown-cloudabi \ +" + +RUST_NIGHTLY_LINUX_TARGETS="\ +aarch64-fuchsia \ +armv5te-unknown-linux-gnueabi \ +armv5te-unknown-linux-musleabi \ +i686-pc-windows-gnu \ +wasm32-wasi \ +x86_64-fortanix-unknown-sgx \ +x86_64-fuchsia \ +x86_64-pc-windows-gnu \ +x86_64-unknown-linux-gnux32 \ +x86_64-unknown-redox \ +" + +RUST_OSX_TARGETS="\ +aarch64-apple-ios \ +armv7-apple-ios \ +armv7s-apple-ios \ +i386-apple-ios \ +i686-apple-darwin \ +x86_64-apple-darwin \ +x86_64-apple-ios \ +" + +# The targets are listed here alphabetically +TARGETS="" +case "${OS}" in + linux*) + TARGETS="${RUST_LINUX_TARGETS}" + + if [ "${RUST}" != "1.13.0" ]; then + TARGETS="${TARGETS} ${RUST_GT_1_13_LINUX_TARGETS}" + if [ "${RUST}" != "1.19.0" ]; then + TARGETS="${TARGETS} ${RUST_GT_1_19_LINUX_TARGETS}" + if [ "${RUST}" != "1.24.0" ]; then + TARGETS="${TARGETS} ${RUST_GT_1_24_LINUX_TARGETS}" + fi + fi + fi + + if [ "${RUST}" = "nightly" ]; then + TARGETS="${TARGETS} ${RUST_NIGHTLY_LINUX_TARGETS}" + fi + + ;; + osx*) + TARGETS="${RUST_OSX_TARGETS}" + ;; + *) + ;; +esac + +for TARGET in $TARGETS; do + test_target cargo "$TARGET" +done + +# FIXME: https://github.com/rust-lang/rust/issues/58564 +# sparc-unknown-linux-gnu +RUST_LINUX_NO_CORE_TARGETS="\ +aarch64-pc-windows-msvc \ +aarch64-unknown-cloudabi \ +aarch64-unknown-hermit \ +aarch64-unknown-netbsd \ +aarch64-unknown-openbsd \ +armebv7r-none-eabi \ +armebv7r-none-eabihf \ +armv7-unknown-cloudabi-eabihf \ +armv7r-none-eabi \ +armv7r-none-eabihf \ +i586-pc-windows-msvc \ +i686-pc-windows-msvc \ +i686-unknown-cloudabi \ +i686-unknown-haiku \ +i686-unknown-netbsd \ +i686-unknown-openbsd \ +mips-unknown-linux-uclibc \ +mipsel-unknown-linux-uclibc \ +nvptx64-nvidia-cuda \ +powerpc-unknown-linux-gnuspe \ +powerpc-unknown-netbsd \ +riscv32imac-unknown-none-elf \ +riscv32imc-unknown-none-elf \ +sparc64-unknown-netbsd \ +thumbv6m-none-eabi \ +thumbv7em-none-eabi \ +thumbv7em-none-eabihf \ +thumbv7m-none-eabi \ +thumbv7neon-linux-androideabi \ +thumbv7neon-unknown-linux-gnueabihf \ +thumbv8m.main-none-eabi \ +x86_64-pc-windows-msvc +x86_64-unknown-dragonfly \ +x86_64-unknown-haiku \ +x86_64-unknown-hermit \ +x86_64-unknown-l4re-uclibc \ +x86_64-unknown-openbsd \ +" + +if [ "${RUST}" = "nightly" ] && [ "${OS}" = "linux" ]; then + for TARGET in $RUST_LINUX_NO_CORE_TARGETS; do + test_target xargo "$TARGET" 1 + done +fi diff --git a/libc/ci/docker/aarch64-linux-android/Dockerfile b/libc/ci/docker/aarch64-linux-android/Dockerfile index 5fc83aa..1458423 100644 --- a/libc/ci/docker/aarch64-linux-android/Dockerfile +++ b/libc/ci/docker/aarch64-linux-android/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:19.04 RUN dpkg --add-architecture i386 && \ apt-get update && \ @@ -9,7 +9,7 @@ RUN dpkg --add-architecture i386 && \ python \ unzip \ expect \ - openjdk-9-jre \ + openjdk-11-jre \ libstdc++6:i386 \ libpulse0 \ gcc \ diff --git a/libc/ci/docker/aarch64-unknown-linux-gnu/Dockerfile b/libc/ci/docker/aarch64-unknown-linux-gnu/Dockerfile index 18214a3..716a445 100644 --- a/libc/ci/docker/aarch64-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/aarch64-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev ca-certificates \ gcc-aarch64-linux-gnu libc6-dev-arm64-cross qemu-user diff --git a/libc/ci/docker/aarch64-unknown-linux-musl/Dockerfile b/libc/ci/docker/aarch64-unknown-linux-musl/Dockerfile index fbc47d9..143a960 100644 --- a/libc/ci/docker/aarch64-unknown-linux-musl/Dockerfile +++ b/libc/ci/docker/aarch64-unknown-linux-musl/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc make libc6-dev git curl ca-certificates \ diff --git a/libc/ci/docker/arm-linux-androideabi/Dockerfile b/libc/ci/docker/arm-linux-androideabi/Dockerfile index a3fc64b..acc784e 100644 --- a/libc/ci/docker/arm-linux-androideabi/Dockerfile +++ b/libc/ci/docker/arm-linux-androideabi/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:19.04 RUN dpkg --add-architecture i386 && \ apt-get update && \ @@ -9,7 +9,7 @@ RUN dpkg --add-architecture i386 && \ python \ unzip \ expect \ - openjdk-9-jre \ + openjdk-11-jre \ libstdc++6:i386 \ libpulse0 \ gcc \ diff --git a/libc/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile b/libc/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile index 9fe71dc..bcdbb22 100644 --- a/libc/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile +++ b/libc/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev ca-certificates \ gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user diff --git a/libc/ci/docker/arm-unknown-linux-musleabihf/Dockerfile b/libc/ci/docker/arm-unknown-linux-musleabihf/Dockerfile index 0d493ca..e29e854 100644 --- a/libc/ci/docker/arm-unknown-linux-musleabihf/Dockerfile +++ b/libc/ci/docker/arm-unknown-linux-musleabihf/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc make libc6-dev git curl ca-certificates \ diff --git a/libc/ci/docker/asmjs-unknown-emscripten/Dockerfile b/libc/ci/docker/asmjs-unknown-emscripten/Dockerfile index 3088fc5..6c08340 100644 --- a/libc/ci/docker/asmjs-unknown-emscripten/Dockerfile +++ b/libc/ci/docker/asmjs-unknown-emscripten/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:19.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ diff --git a/libc/ci/docker/i686-linux-android/Dockerfile b/libc/ci/docker/i686-linux-android/Dockerfile index f0836c3..59ea2d7 100644 --- a/libc/ci/docker/i686-linux-android/Dockerfile +++ b/libc/ci/docker/i686-linux-android/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:19.04 RUN dpkg --add-architecture i386 && \ apt-get update && \ @@ -9,7 +9,7 @@ RUN dpkg --add-architecture i386 && \ python \ unzip \ expect \ - openjdk-9-jre \ + openjdk-11-jre \ libstdc++6:i386 \ libpulse0 \ gcc \ diff --git a/libc/ci/docker/i686-unknown-linux-gnu/Dockerfile b/libc/ci/docker/i686-unknown-linux-gnu/Dockerfile index 03f3e8e..5563a7b 100644 --- a/libc/ci/docker/i686-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/i686-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:18.04 +FROM ubuntu:19.04 RUN apt-get update RUN apt-get install -y --no-install-recommends \ gcc-multilib libc6-dev ca-certificates diff --git a/libc/ci/docker/i686-unknown-linux-musl/Dockerfile b/libc/ci/docker/i686-unknown-linux-musl/Dockerfile index b726e4d..c085c10 100644 --- a/libc/ci/docker/i686-unknown-linux-musl/Dockerfile +++ b/libc/ci/docker/i686-unknown-linux-musl/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN dpkg --add-architecture i386 RUN apt-get update diff --git a/libc/ci/docker/mips-unknown-linux-gnu/Dockerfile b/libc/ci/docker/mips-unknown-linux-gnu/Dockerfile index c66abd4..9f1bcaf 100644 --- a/libc/ci/docker/mips-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/mips-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev qemu-user ca-certificates \ diff --git a/libc/ci/docker/mips-unknown-linux-musl/Dockerfile b/libc/ci/docker/mips-unknown-linux-musl/Dockerfile index dde22fd..7f2764c 100644 --- a/libc/ci/docker/mips-unknown-linux-musl/Dockerfile +++ b/libc/ci/docker/mips-unknown-linux-musl/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev qemu-user ca-certificates qemu-system-mips curl \ diff --git a/libc/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile b/libc/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile index b9921fc..b97cdb4 100644 --- a/libc/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile +++ b/libc/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev qemu-user ca-certificates \ diff --git a/libc/ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile b/libc/ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile index 434c908..7f79452 100644 --- a/libc/ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile +++ b/libc/ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev qemu-user ca-certificates \ diff --git a/libc/ci/docker/mipsel-unknown-linux-musl/Dockerfile b/libc/ci/docker/mipsel-unknown-linux-musl/Dockerfile index 037bf64..03e8357 100644 --- a/libc/ci/docker/mipsel-unknown-linux-musl/Dockerfile +++ b/libc/ci/docker/mipsel-unknown-linux-musl/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev qemu-user ca-certificates qemu-system-mips curl \ diff --git a/libc/ci/docker/powerpc-unknown-linux-gnu/Dockerfile b/libc/ci/docker/powerpc-unknown-linux-gnu/Dockerfile index 106ada4..9fa05af 100644 --- a/libc/ci/docker/powerpc-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/powerpc-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev qemu-user ca-certificates \ @@ -7,4 +7,5 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ENV CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_LINKER=powerpc-linux-gnu-gcc \ CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_RUNNER="qemu-ppc -L /usr/powerpc-linux-gnu" \ + CC=powerpc-linux-gnu-gcc \ PATH=$PATH:/rust/bin diff --git a/libc/ci/docker/powerpc64-unknown-linux-gnu/Dockerfile b/libc/ci/docker/powerpc64-unknown-linux-gnu/Dockerfile index a6ab66a..ab40789 100644 --- a/libc/ci/docker/powerpc64-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/powerpc64-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev qemu-user ca-certificates \ diff --git a/libc/ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile b/libc/ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile index 627123e..4dcd632 100644 --- a/libc/ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libc6-dev qemu-user ca-certificates \ diff --git a/libc/ci/docker/s390x-unknown-linux-gnu/Dockerfile b/libc/ci/docker/s390x-unknown-linux-gnu/Dockerfile index 861f4f9..75c11c1 100644 --- a/libc/ci/docker/s390x-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/s390x-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ curl ca-certificates \ diff --git a/libc/ci/docker/sparc64-unknown-linux-gnu/Dockerfile b/libc/ci/docker/sparc64-unknown-linux-gnu/Dockerfile index d9edaab..d1f4503 100644 --- a/libc/ci/docker/sparc64-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/sparc64-unknown-linux-gnu/Dockerfile @@ -1,14 +1,11 @@ -FROM debian:stretch +FROM ubuntu:19.04 RUN apt-get update && apt-get install -y --no-install-recommends \ curl ca-certificates \ gcc libc6-dev \ gcc-sparc64-linux-gnu libc6-dev-sparc64-cross \ qemu-system-sparc64 openbios-sparc seabios ipxe-qemu \ - p7zip-full cpio linux-libc-dev-sparc64-cross linux-headers-4.9.0-3-common - -# Put linux/module.h into the right spot as it is not shipped by debian -RUN cp /usr/src/linux-headers-4.9.0-3-common/include/uapi/linux/module.h /usr/sparc64-linux-gnu/include/linux/ + p7zip-full cpio linux-libc-dev-sparc64-cross COPY linux-sparc64.sh / RUN bash /linux-sparc64.sh diff --git a/libc/ci/docker/wasm32-unknown-emscripten/Dockerfile b/libc/ci/docker/wasm32-unknown-emscripten/Dockerfile index 59bf7d9..de8e353 100644 --- a/libc/ci/docker/wasm32-unknown-emscripten/Dockerfile +++ b/libc/ci/docker/wasm32-unknown-emscripten/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:19.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ diff --git a/libc/ci/docker/wasm32-wasi/Dockerfile b/libc/ci/docker/wasm32-wasi/Dockerfile new file mode 100644 index 0000000..d963a44 --- /dev/null +++ b/libc/ci/docker/wasm32-wasi/Dockerfile @@ -0,0 +1,93 @@ +# In the first container we want to assemble the `wasi-sysroot` by compiling it +# from source. This requires a clang 8.0+ compiler with enough wasm support and +# then we're just running a standard `make` inside of what we clone. +FROM ubuntu:18.04 as wasi-sysroot + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + clang \ + cmake \ + curl \ + g++ \ + git \ + libc6-dev \ + libclang-dev \ + make \ + ssh \ + xz-utils + +# Fetch clang 8.0+ which is used to compile the wasi target and link our +# programs together. +RUN curl http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz | tar xJf - +RUN mv /clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04 /wasmcc + +# Note that we're using `git reset --hard` to pin to a specific commit for +# verification for now. The sysroot is currently in somewhat of a state of flux +# and is expected to have breaking changes, so this is an attempt to mitigate +# those breaking changes on `libc`'s own CI +RUN git clone https://github.com/CraneStation/wasi-sysroot && \ + cd wasi-sysroot && \ + git reset --hard eee6ee7566e26f2535eb6088c8494a112ff423b9 +RUN make -C wasi-sysroot install -j $(nproc) WASM_CC=/wasmcc/bin/clang INSTALL_DIR=/wasi-sysroot + +# This is a small wrapper script which executes the actual clang binary in +# `/wasmcc` and then is sure to pass the right `--sysroot` argument which we +# just built above. +COPY docker/wasm32-wasi/clang.sh /wasi-sysroot/bin/clang + +# In the second container we're going to build the `wasmtime` binary which is +# used to execute wasi executables. This is a standard Rust project so we're +# just checking out a known revision (which pairs with the sysroot one we +# downlaoded above) and then we're building it with Cargo +FROM ubuntu:18.04 as wasmtime + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + clang \ + cmake \ + curl \ + g++ \ + git \ + libclang-dev \ + make \ + ssh + +RUN curl -sSf https://sh.rustup.rs | sh -s -- -y +ENV PATH=/root/.cargo/bin:$PATH + +RUN apt-get install -y --no-install-recommends python +RUN git clone --recursive https://github.com/CraneStation/wasmtime wasmtime && \ + cd wasmtime && \ + git reset --hard 67edb00f29b62864b00179fe4bfa99bc29973285 +RUN cargo build --release --manifest-path wasmtime/Cargo.toml + +# And finally in the last image we're going to assemble everything together. +# We'll install things needed at runtime for now and then copy over the +# sysroot/wasmtime artifacts into their final location. +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc \ + libc6-dev \ + libxml2 \ + ca-certificates + +# Copy over clang we downloaded to link executables ... +COPY --from=wasi-sysroot /wasmcc /wasmcc/ +# ... and the sysroot we built to link executables against ... +COPY --from=wasi-sysroot /wasi-sysroot/ /wasi-sysroot/ +# ... and finally wasmtime to actually execute binaries +COPY --from=wasmtime /wasmtime/target/release/wasmtime /usr/bin/ + +# Of note here is our clang wrapper which just executes a normal clang +# executable with the right sysroot, and then we're sure to turn off the +# crt-static feature to ensure that the CRT that we're specifying with `clang` +# is used. +ENV CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime \ + CARGO_TARGET_WASM32_WASI_LINKER=/wasi-sysroot/bin/clang \ + CC_wasm32_wasi=/wasi-sysroot/bin/clang \ + PATH=$PATH:/rust/bin \ + RUSTFLAGS=-Ctarget-feature=-crt-static diff --git a/libc/ci/docker/wasm32-wasi/clang.sh b/libc/ci/docker/wasm32-wasi/clang.sh new file mode 100755 index 0000000..6f29812 --- /dev/null +++ b/libc/ci/docker/wasm32-wasi/clang.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +exec /wasmcc/bin/clang --target=wasm32-wasi --sysroot /wasi-sysroot "$@" diff --git a/libc/ci/docker/x86_64-linux-android/Dockerfile b/libc/ci/docker/x86_64-linux-android/Dockerfile index 0cfbc48..b0984c0 100644 --- a/libc/ci/docker/x86_64-linux-android/Dockerfile +++ b/libc/ci/docker/x86_64-linux-android/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:19.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ diff --git a/libc/ci/docker/x86_64-rumprun-netbsd/runtest.rs b/libc/ci/docker/x86_64-rumprun-netbsd/runtest.rs index 94b5946..7e96fbf 100644 --- a/libc/ci/docker/x86_64-rumprun-netbsd/runtest.rs +++ b/libc/ci/docker/x86_64-rumprun-netbsd/runtest.rs @@ -47,7 +47,8 @@ fn find_ok(input: &mut Read, tx: mpsc::Sender<()>) { for line in BufReader::new(input).lines() { let line = line.unwrap(); println!("{}", line); - if line.starts_with("PASSED ") && line.contains(" tests") { + if (line.starts_with("PASSED ") && line.contains(" tests")) || + line.starts_with("test result: ok"){ tx.send(()).unwrap(); } } diff --git a/libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile b/libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile index 6ab9c92..0dbb191 100644 --- a/libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile +++ b/libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:18.04 +FROM ubuntu:19.04 RUN apt-get update RUN apt-get install -y --no-install-recommends \ gcc libc6-dev ca-certificates diff --git a/libc/ci/docker/x86_64-unknown-linux-gnux32/Dockerfile b/libc/ci/docker/x86_64-unknown-linux-gnux32/Dockerfile index 03f3e8e..5563a7b 100644 --- a/libc/ci/docker/x86_64-unknown-linux-gnux32/Dockerfile +++ b/libc/ci/docker/x86_64-unknown-linux-gnux32/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:18.04 +FROM ubuntu:19.04 RUN apt-get update RUN apt-get install -y --no-install-recommends \ gcc-multilib libc6-dev ca-certificates diff --git a/libc/ci/docker/x86_64-unknown-linux-musl/Dockerfile b/libc/ci/docker/x86_64-unknown-linux-musl/Dockerfile index 0a27709..59164d2 100644 --- a/libc/ci/docker/x86_64-unknown-linux-musl/Dockerfile +++ b/libc/ci/docker/x86_64-unknown-linux-musl/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.10 +FROM ubuntu:19.04 RUN apt-get update RUN apt-get install -y --no-install-recommends \ diff --git a/libc/ci/dox.sh b/libc/ci/dox.sh index 521743e..ce55081 100644 --- a/libc/ci/dox.sh +++ b/libc/ci/dox.sh @@ -6,28 +6,65 @@ set -ex -TARGETS=$(grep html_root_url src/lib.rs | sed 's/.*".*\/\(.*\)"/\1/'| sed 's/)//') +TARGET_DOC_DIR=target/doc +README=README.md +PLATFORM_SUPPORT=platform-support.md -rm -rf target/doc -mkdir -p target/doc +rm -rf $TARGET_DOC_DIR +mkdir -p $TARGET_DOC_DIR -cp ci/landing-page-head.html target/doc/index.html +# List all targets that do currently build successfully: +# shellcheck disable=SC1003 +grep '[\d|\w|-]* \\' ci/build.sh > targets +sed -i.bak 's/ \\//g' targets +grep '^[_a-zA-Z0-9-]*$' targets > tmp && mv tmp targets -for target in $TARGETS; do - echo "documenting ${target}" +# Create a markdown list of supported platforms in $PLATFORM_SUPPORT +rm $PLATFORM_SUPPORT || true - rustdoc -o "target/doc/${target}" --target "${target}" src/lib.rs --cfg cross_platform_docs \ - --crate-name libc +printf '### Platform-specific documentation\n' >> $PLATFORM_SUPPORT - echo "<li><a href=\"/libc/${target}/libc/index.html\">${target}</a></li>" \ - >> target/doc/index.html -done +while read -r target; do + echo "documenting ${target}" -cat ci/landing-page-footer.html >> target/doc/index.html + case "${target}" in + *apple*) + # FIXME: + # We can't build docs of apple targets from Linux yet. + continue + ;; + *) + ;; + esac + + rustup target add "${target}" || true + + # If cargo doc fails, then try xargo: + if ! cargo doc --target "${target}" \ + --no-default-features --features extra_traits ; then + xargo doc --target "${target}" \ + --no-default-features --features extra_traits + fi + + cp -r "target/${target}/doc" "${TARGET_DOC_DIR}/${target}" + + echo "* [${target}](${target}/libc/index.html)" >> $PLATFORM_SUPPORT +done < targets + +# Replace <div class="platform_support"></div> with the contents of $PLATFORM_SUPPORT +cp $README $TARGET_DOC_DIR +line=$(grep -n '<div class="platform_docs"></div>' $README | cut -d ":" -f 1) + +set +x +{ head -n "$((line-1))" $README; cat $PLATFORM_SUPPORT; tail -n "+$((line+1))" $README; } > $TARGET_DOC_DIR/$README +set -x + +# Copy the licenses +cp LICENSE-* $TARGET_DOC_DIR/ # If we're on travis, not a PR, and on the right branch, publish! if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then pip install ghp_import --install-option="--prefix=$HOME/.local" - "${HOME}/.local/bin/ghp-import" -n target/doc + "${HOME}/.local/bin/ghp-import" $TARGET_DOC_DIR git push -qf "https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git" gh-pages fi diff --git a/libc/ci/ios/deploy_and_run_on_ios_simulator.rs b/libc/ci/ios/deploy_and_run_on_ios_simulator.rs index 95df52d..2075be6 100644 --- a/libc/ci/ios/deploy_and_run_on_ios_simulator.rs +++ b/libc/ci/ios/deploy_and_run_on_ios_simulator.rs @@ -129,8 +129,11 @@ fn run_app_on_simulator() { let stdout = String::from_utf8_lossy(&output.stdout); let passed = stdout.lines() - .find(|l| l.contains("PASSED")) - .map(|l| l.contains("tests")) + .find(|l| + (l.contains("PASSED") && + l.contains("tests")) || + l.contains("test result: ok") + ) .unwrap_or(false); println!("Shutting down simulator"); diff --git a/libc/ci/landing-page-footer.html b/libc/ci/landing-page-footer.html deleted file mode 100644 index 941cc8d..0000000 --- a/libc/ci/landing-page-footer.html +++ /dev/null @@ -1,3 +0,0 @@ - </ul> - </body> -</html> diff --git a/libc/ci/landing-page-head.html b/libc/ci/landing-page-head.html deleted file mode 100644 index fc69fa8..0000000 --- a/libc/ci/landing-page-head.html +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8"> - </head> - <body> - <ul> diff --git a/libc/ci/linux-s390x.sh b/libc/ci/linux-s390x.sh index a230cfe..00a7f88 100644 --- a/libc/ci/linux-s390x.sh +++ b/libc/ci/linux-s390x.sh @@ -6,8 +6,8 @@ mkdir -m 777 /qemu cd /qemu curl --retry 5 -LO https://github.com/qemu/qemu/raw/master/pc-bios/s390-ccw.img -curl --retry 5 -LO http://ftp.debian.org/debian/dists/testing/main/installer-s390x/20170828/images/generic/kernel.debian -curl --retry 5 -LO http://ftp.debian.org/debian/dists/testing/main/installer-s390x/20170828/images/generic/initrd.debian +curl --retry 5 -LO http://ftp.debian.org/debian/dists/testing/main/installer-s390x/20190410/images/generic/kernel.debian +curl --retry 5 -LO http://ftp.debian.org/debian/dists/testing/main/installer-s390x/20190410/images/generic/initrd.debian mv kernel.debian kernel mv initrd.debian initrd.gz diff --git a/libc/ci/linux-sparc64.sh b/libc/ci/linux-sparc64.sh index 7fb28d9..5580a0e 100644 --- a/libc/ci/linux-sparc64.sh +++ b/libc/ci/linux-sparc64.sh @@ -5,11 +5,11 @@ set -ex mkdir -m 777 /qemu cd /qemu -curl --retry 5 -LO https://cdimage.debian.org/cdimage/ports/9.0/sparc64/iso-cd/debian-9.0-sparc64-NETINST-1.iso -7z e debian-9.0-sparc64-NETINST-1.iso boot/initrd.gz -7z e debian-9.0-sparc64-NETINST-1.iso boot/sparc64 +curl --retry 5 -LO https://cdimage.debian.org/cdimage/ports/10.0/sparc64/iso-cd/debian-10.0-sparc64-NETINST-1.iso +7z e debian-10.0-sparc64-NETINST-1.iso boot/initrd.gz +7z e debian-10.0-sparc64-NETINST-1.iso boot/sparc64 mv sparc64 kernel -rm debian-9.0-sparc64-NETINST-1.iso +rm debian-10.0-sparc64-NETINST-1.iso mkdir init cd init diff --git a/libc/ci/run.sh b/libc/ci/run.sh index 81ebd61..427d3bf 100755 --- a/libc/ci/run.sh +++ b/libc/ci/run.sh @@ -77,7 +77,7 @@ if [ "$QEMU" != "" ]; then -net user \ -nographic \ -vga none 2>&1 | tee "${CARGO_TARGET_DIR}/out.log" - exec grep "^PASSED .* tests" "${CARGO_TARGET_DIR}/out.log" + exec egrep "^(PASSED)|(test result: ok)" "${CARGO_TARGET_DIR}/out.log" fi # FIXME: x86_64-unknown-linux-gnux32 fail to compile without --release @@ -87,13 +87,10 @@ if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then opt="--release" fi -# Building with --no-default-features is currently broken on rumprun because we -# need cfg(target_vendor), which is currently unstable. -if [ "$TARGET" != "x86_64-rumprun-netbsd" ]; then - cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml --target "${TARGET}" -fi -# Test the #[repr(align(x))] feature if this is building on Rust >= 1.25 -if [ "$(rustc --version | sed -E 's/^rustc 1\.([0-9]*)\..*/\1/')" -ge 25 ]; then - cargo test $opt --features align --manifest-path libc-test/Cargo.toml --target "${TARGET}" -fi -exec cargo test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}" +cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml \ + --target "${TARGET}" + +cargo test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}" + +cargo test $opt --features extra_traits --manifest-path libc-test/Cargo.toml \ + --target "${TARGET}" diff --git a/libc/ci/runtest-android.rs b/libc/ci/runtest-android.rs index a8f8db8..b8030c4 100644 --- a/libc/ci/runtest-android.rs +++ b/libc/ci/runtest-android.rs @@ -3,14 +3,18 @@ use std::process::Command; use std::path::{Path, PathBuf}; fn main() { - assert_eq!(env::args_os().len(), 2); - let test = PathBuf::from(env::args_os().nth(1).unwrap()); + let args = env::args_os() + .skip(1) + .filter(|arg| arg != "--quiet") + .collect::<Vec<_>>(); + assert_eq!(args.len(), 1); + let test = PathBuf::from(&args[0]); let dst = Path::new("/data/local/tmp").join(test.file_name().unwrap()); let status = Command::new("adb") .arg("wait-for-device") .status() - .expect("failed to run rumprun-bake"); + .expect("failed to run: adb wait-for-device"); assert!(status.success()); let status = Command::new("adb") @@ -18,14 +22,14 @@ fn main() { .arg(&test) .arg(&dst) .status() - .expect("failed to run rumprun-bake"); + .expect("failed to run: adb pushr"); assert!(status.success()); let output = Command::new("adb") .arg("shell") .arg(&dst) .output() - .expect("failed to run rumprun-bake"); + .expect("failed to run: adb shell"); assert!(status.success()); println!("status: {}\nstdout ---\n{}\nstderr ---\n{}", @@ -34,8 +38,10 @@ fn main() { String::from_utf8_lossy(&output.stderr)); let stdout = String::from_utf8_lossy(&output.stdout); - let mut lines = stdout.lines().filter(|l| l.starts_with("PASSED ")); - if !lines.any(|l| l.contains(" tests")) { + stdout.lines().find(|l| + (l.starts_with("PASSED ") && l.contains(" tests")) || + l.starts_with("test result: ok") + ).unwrap_or_else(|| { panic!("failed to find successful test run"); - } + }); } diff --git a/libc/ci/semver.sh b/libc/ci/semver.sh new file mode 100644 index 0000000..ac6be36 --- /dev/null +++ b/libc/ci/semver.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env sh + +# Checks that libc does not contain breaking changes for the following targets. + +set -ex + +OS=${TRAVIS_OS_NAME} + +echo "Testing Semver on ${OS}" + +TARGETS= +case "${OS}" in + *linux*) + TARGETS="\ +aarch64-fuchsia \ +aarch64-linux-android \ +aarch64-unknown-linux-gnu \ +aarch64-unknown-linux-musl \ +armv7-linux-androideabi \ +armv7-unknown-linux-gnueabihf \ +i586-unknown-linux-gnu \ +i586-unknown-linux-musl \ +i686-linux-android \ +i686-unknown-freebsd \ +i686-unknown-linux-gnu \ +i686-unknown-linux-musl \ +i686-pc-windows-gnu \ +x86_64-unknown-freebsd \ +x86_64-unknown-linux-gnu \ +x86_64-unknown-linux-musl \ +x86_64-unknown-netbsd \ +x86_64-unknown-cloudabi \ +x86_64-sun-solaris \ +x86_64-fuchsia \ +x86_64-pc-windows-gnu \ +x86_64-unknown-linux-gnux32 \ +x86_64-unknown-redox \ +x86_64-fortanix-unknown-sgx \ +wasm32-unknown-unknown \ +" + ;; + *osx*) + TARGETS="\ +aarch64-apple-ios \ +armv7-apple-ios \ +armv7s-apple-ios \ +i386-apple-ios \ +i686-apple-darwin \ +x86_64-apple-darwin \ +x86_64-apple-ios \ +" + ;; +esac + +for TARGET in $TARGETS; do + # FIXME: rustup often fails to download some artifacts due to network + # issues, so we retry this N times. + N=5 + n=0 + until [ $n -ge $N ] + do + if rustup target add "${TARGET}" ; then + break + fi + n=$((n+1)) + sleep 1 + done + + cargo +nightly semver --api-guidelines --target="${TARGET}" +done diff --git a/libc/ci/style.rs b/libc/ci/style.rs index 747e26c..481f57f 100644 --- a/libc/ci/style.rs +++ b/libc/ci/style.rs @@ -144,6 +144,9 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) { let line = if is_pub {&line[4..]} else {line}; let line_state = if line.starts_with("use ") { + if line.contains("c_void") { + continue; + } if is_pub { State::Modules } else { diff --git a/libc/ci/switch.json b/libc/ci/switch.json new file mode 100644 index 0000000..bc18948 --- /dev/null +++ b/libc/ci/switch.json @@ -0,0 +1,37 @@ +{ + "family": "unix", + "env": "newlib", + "target-env": "newlib", + "target-family": "unix", + "target-c-int-width": "32", + "target-endian": "little", + "target-pointer-width": "64", + "os": "horizon", + "arch": "aarch64", + "panic-strategy": "unwind", + "abi-blacklist": [ + "stdcall", + "fastcall", + "vectorcall", + "thiscall", + "win64", + "sysv64" + ], + "dynamic-linking" : false, + "features": "+a53,+strict-align", + "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", + "executables": true, + "position-independent-executables" : true, + "linker-flavor": "gcc", + "llvm-target": "aarch64-unknown-none", + "has-elf-tls" : false, + "linker-is-gnu" : true, + "disable-redzone" : true, + "relocation-model" : "pic", + "max-atomic-width": 128, + "exe-suffix": ".elf", + "staticlib-suffix" : ".a", + "trap-unreachable" : true, + "emit-debug-gdb-scripts" : true, + "requires-uwtable" : true +}
\ No newline at end of file diff --git a/libc/ci/test-runner-linux b/libc/ci/test-runner-linux index 5f1fb23..569fa00 100755 --- a/libc/ci/test-runner-linux +++ b/libc/ci/test-runner-linux @@ -5,7 +5,18 @@ set -e arch=$1 prog=$2 +# Skip cmsg test on linux-s390x +# https://github.com/rust-lang/libc/issues/1240 +if [ "$arch" = "s390x" ]; then + progbasename=`basename $prog` + if [ "${progbasename%%-*}" = "cmsg" ]; then + exit 0 + fi +fi + cd /qemu/init +echo "#!/bin/sh\n/prog --color=never" > run_prog.sh +chmod +x run_prog.sh cp -f $2 prog find . | cpio --create --format='newc' --quiet | gzip > ../initrd.gz cd .. @@ -15,9 +26,9 @@ timeout 30s qemu-system-$arch \ -nographic \ -kernel kernel \ -initrd initrd.gz \ - -append init=/prog > output || true + -append init=/run_prog.sh > output || true # remove kernel messages tr -d '\r' < output | egrep -v '^\[' -grep PASSED output > /dev/null +egrep "(PASSED)|(test result: ok)" output > /dev/null diff --git a/libc/libc-test/Cargo.toml b/libc/libc-test/Cargo.toml index b782a95..9862d3a 100644 --- a/libc/libc-test/Cargo.toml +++ b/libc/libc-test/Cargo.toml @@ -9,12 +9,14 @@ path = ".." default-features = false [build-dependencies] -ctest = "0.2.8" +cc = "1.0" +ctest = "0.2" [features] default = [ "use_std" ] use_std = [ "libc/use_std" ] align = [ "libc/align" ] +extra_traits = [ "libc/extra_traits" ] [[test]] name = "main" @@ -26,3 +28,7 @@ name = "linux-fcntl" path = "test/linux_fcntl.rs" harness = false +[[test]] +name = "cmsg" +path = "test/cmsg.rs" +harness = true diff --git a/libc/libc-test/build.rs b/libc/libc-test/build.rs index 5edbdf5..6541fd5 100644 --- a/libc/libc-test/build.rs +++ b/libc/libc-test/build.rs @@ -1,364 +1,799 @@ #![deny(warnings)] +extern crate cc; extern crate ctest; use std::env; -fn main() { +fn do_cc() { let target = env::var("TARGET").unwrap(); - let aarch64 = target.contains("aarch64"); - let i686 = target.contains("i686"); + if cfg!(unix) && !target.contains("wasi") { + cc::Build::new().file("src/cmsg.c").compile("cmsg"); + } +} + +fn do_ctest() { + match &env::var("TARGET").unwrap() { + t if t.contains("android") => return test_android(t), + t if t.contains("apple") => return test_apple(t), + t if t.contains("cloudabi") => return test_cloudabi(t), + t if t.contains("dragonfly") => return test_dragonflybsd(t), + t if t.contains("emscripten") => return test_emscripten(t), + t if t.contains("freebsd") => return test_freebsd(t), + t if t.contains("linux") => return test_linux(t), + t if t.contains("netbsd") => return test_netbsd(t), + t if t.contains("openbsd") => return test_openbsd(t), + t if t.contains("redox") => return test_redox(t), + t if t.contains("solaris") => return test_solaris(t), + t if t.contains("wasi") => return test_wasi(t), + t if t.contains("windows") => return test_windows(t), + t => panic!("unknown target {}", t), + } +} + +fn main() { + do_cc(); + do_ctest(); +} + +macro_rules! headers { + ($cfg:ident: $header:expr) => { + $cfg.header($header); + }; + ($cfg:ident: $($header:expr),*) => { + $(headers!($cfg: $header);)* + }; + ($cfg:ident: $($header:expr,)*) => { + $(headers!($cfg: $header);)* + }; +} + +fn test_apple(target: &str) { + assert!(target.contains("apple")); let x86_64 = target.contains("x86_64"); - let x32 = target.ends_with("gnux32"); - let windows = target.contains("windows"); - let mingw = target.contains("windows-gnu"); - let linux = target.contains("unknown-linux"); - let android = target.contains("android"); - let apple = target.contains("apple"); - let ios = target.contains("apple-ios"); - let emscripten = target.contains("asm"); - let musl = target.contains("musl") || emscripten; - let uclibc = target.contains("uclibc"); - let freebsd = target.contains("freebsd"); - let dragonfly = target.contains("dragonfly"); - let mips = target.contains("mips"); - let netbsd = target.contains("netbsd"); - let openbsd = target.contains("openbsd"); - let rumprun = target.contains("rumprun"); - let solaris = target.contains("solaris"); - let cloudabi = target.contains("cloudabi"); - let redox = target.contains("redox"); - let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly; - let mut cfg = ctest::TestGenerator::new(); - // Pull in extra goodies - if linux || android || emscripten { - cfg.define("_GNU_SOURCE", None); - } else if netbsd { - cfg.define("_NETBSD_SOURCE", Some("1")); - } else if apple { - cfg.define("__APPLE_USE_RFC_3542", None); - } else if windows { - cfg.define("_WIN32_WINNT", Some("0x8000")); - } else if solaris { - cfg.define("_XOPEN_SOURCE", Some("700")); - cfg.define("__EXTENSIONS__", None); - cfg.define("_LCONV_C99", None); - } else if freebsd { - cfg.define("_WITH_GETLINE", None); + let mut cfg = ctest::TestGenerator::new(); + cfg.flag("-Wno-deprecated-declarations"); + cfg.define("__APPLE_USE_RFC_3542", None); + + headers! { cfg: + "aio.h", + "ctype.h", + "dirent.h", + "dlfcn.h", + "errno.h", + "execinfo.h", + "fcntl.h", + "glob.h", + "grp.h", + "ifaddrs.h", + "langinfo.h", + "limits.h", + "locale.h", + "mach-o/dyld.h", + "mach/mach_time.h", + "malloc/malloc.h", + "net/bpf.h", + "net/if.h", + "net/if_arp.h", + "net/if_dl.h", + "net/if_utun.h", + "net/route.h", + "net/route.h", + "netdb.h", + "netinet/if_ether.h", + "netinet/in.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "poll.h", + "pthread.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "signal.h", + "spawn.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "sys/event.h", + "sys/file.h", + "sys/ioctl.h", + "sys/ipc.h", + "sys/kern_control.h", + "sys/mman.h", + "sys/mount.h", + "sys/proc_info.h", + "sys/ptrace.h", + "sys/quota.h", + "sys/resource.h", + "sys/sem.h", + "sys/shm.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/sys_domain.h", + "sys/sysctl.h", + "sys/time.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/utsname.h", + "sys/wait.h", + "sys/xattr.h", + "syslog.h", + "termios.h", + "time.h", + "unistd.h", + "util.h", + "utime.h", + "utmpx.h", + "wchar.h", + "xlocale.h", } - // Android doesn't actually have in_port_t but it's much easier if we - // provide one for us to test against - if android { - cfg.define("in_port_t", Some("uint16_t")); + if x86_64 { + headers! { cfg: "crt_externs.h" } } - cfg.header("errno.h") - .header("fcntl.h") - .header("limits.h") - .header("locale.h") - .header("stddef.h") - .header("stdint.h") - .header("stdio.h") - .header("stdlib.h") - .header("sys/stat.h") - .header("sys/types.h") - .header("time.h") - .header("wchar.h"); - - if windows { - cfg.header("winsock2.h"); // must be before windows.h - - cfg.header("direct.h"); - cfg.header("io.h"); - cfg.header("sys/utime.h"); - cfg.header("windows.h"); - cfg.header("process.h"); - cfg.header("ws2ipdef.h"); - cfg.header("signal.h"); - - if target.contains("gnu") { - cfg.header("ws2tcpip.h"); + cfg.skip_struct(move |ty| { + match ty { + // FIXME: actually a union + "sigval" => true, + + _ => false, } - } else { - cfg.flag("-Wno-deprecated-declarations"); + }); - cfg.header("ctype.h"); - cfg.header("dirent.h"); - if openbsd { - cfg.header("sys/socket.h"); + cfg.skip_const(move |name| { + match name { + // These OSX constants are removed in Sierra. + // https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html + "KERN_KDENABLE_BG_TRACE" | "KERN_KDDISABLE_BG_TRACE" => true, + _ => false, } - cfg.header("net/if.h"); - if !ios { - cfg.header("net/route.h"); - cfg.header("net/if_arp.h"); - } - cfg.header("netdb.h"); - cfg.header("netinet/in.h"); - cfg.header("netinet/ip.h"); - cfg.header("netinet/tcp.h"); - cfg.header("netinet/udp.h"); - cfg.header("resolv.h"); - cfg.header("pthread.h"); - cfg.header("dlfcn.h"); - cfg.header("signal.h"); - cfg.header("string.h"); - cfg.header("sys/file.h"); - cfg.header("sys/ioctl.h"); - cfg.header("sys/mman.h"); - cfg.header("sys/resource.h"); - cfg.header("sys/socket.h"); - if linux && !musl { - cfg.header("linux/if.h"); - cfg.header("sys/auxv.h"); - } - cfg.header("sys/time.h"); - cfg.header("sys/un.h"); - cfg.header("sys/wait.h"); - cfg.header("unistd.h"); - cfg.header("utime.h"); - cfg.header("pwd.h"); - cfg.header("grp.h"); - cfg.header("sys/utsname.h"); - if !solaris && !ios { - cfg.header("sys/ptrace.h"); - } - cfg.header("sys/mount.h"); - cfg.header("sys/uio.h"); - cfg.header("sched.h"); - cfg.header("termios.h"); - cfg.header("poll.h"); - cfg.header("syslog.h"); - cfg.header("semaphore.h"); - cfg.header("sys/statvfs.h"); - cfg.header("sys/times.h"); - } + }); - if android { - if !aarch64 && !x86_64 { - // time64_t is not define for aarch64 and x86_64 - // If included it will generate the error 'Your time_t is already 64-bit' - cfg.header("time64.h"); + cfg.skip_fn(move |name| { + // skip those that are manually verified + match name { + // FIXME: https://github.com/rust-lang/libc/issues/1272 + "execv" | "execve" | "execvp" => true, + + // close calls the close_nocancel system call + "close" => true, + + _ => false, } - cfg.header("arpa/inet.h"); - cfg.header("xlocale.h"); - cfg.header("utmp.h"); - cfg.header("ifaddrs.h"); - if i686 || x86_64 { - cfg.header("sys/reg.h"); + }); + + cfg.skip_field_type(move |struct_, field| { + match (struct_, field) { + // FIXME: actually a union + ("sigevent", "sigev_value") => true, + _ => false, } - } else if !windows { - cfg.header("glob.h"); - cfg.header("ifaddrs.h"); - cfg.header("langinfo.h"); + }); - if !openbsd && !freebsd && !dragonfly && !solaris { - cfg.header("sys/quota.h"); + cfg.volatile_item(|i| { + use ctest::VolatileItemKind::*; + match i { + StructField(ref n, ref f) if n == "aiocb" && f == "aio_buf" => { + true + } + _ => false, } + }); + + cfg.type_name(move |ty, is_struct, is_union| { + match ty { + // Just pass all these through, no need for a "struct" prefix + "FILE" | "DIR" | "Dl_info" => ty.to_string(), - if !musl && !x32 && !solaris { - cfg.header("sys/sysctl.h"); + // OSX calls this something else + "sighandler_t" => "sig_t".to_string(), + + t if is_union => format!("union {}", t), + t if t.ends_with("_t") => t.to_string(), + t if is_struct => format!("struct {}", t), + t => t.to_string(), } + }); - if !musl && !uclibc { - if !netbsd && !openbsd && !uclibc { - cfg.header("execinfo.h"); + cfg.field_name(move |struct_, field| { + match field { + s if s.ends_with("_nsec") && struct_.starts_with("stat") => { + s.replace("e_nsec", "espec.tv_nsec") } - - if openbsd { - cfg.header("utmp.h"); - } else { - cfg.header("utmpx.h"); + // FIXME: sigaction actually contains a union with two variants: + // a sa_sigaction with type: (*)(int, struct __siginfo *, void *) + // a sa_handler with type sig_t + "sa_sigaction" if struct_ == "sigaction" => { + "sa_handler".to_string() } + s => s.to_string(), } + }); + + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_openbsd(target: &str) { + assert!(target.contains("openbsd")); + + let mut cfg = ctest::TestGenerator::new(); + cfg.flag("-Wno-deprecated-declarations"); + + headers! { cfg: + "errno.h", + "fcntl.h", + "limits.h", + "locale.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "sys/stat.h", + "sys/types.h", + "time.h", + "wchar.h", + "ctype.h", + "dirent.h", + "sys/socket.h", + "net/if.h", + "net/route.h", + "net/if_arp.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "resolv.h", + "pthread.h", + "dlfcn.h", + "signal.h", + "string.h", + "sys/file.h", + "sys/ioctl.h", + "sys/mman.h", + "sys/resource.h", + "sys/socket.h", + "sys/time.h", + "sys/un.h", + "sys/wait.h", + "unistd.h", + "utime.h", + "pwd.h", + "grp.h", + "sys/utsname.h", + "sys/ptrace.h", + "sys/mount.h", + "sys/uio.h", + "sched.h", + "termios.h", + "poll.h", + "syslog.h", + "semaphore.h", + "sys/statvfs.h", + "sys/times.h", + "glob.h", + "ifaddrs.h", + "langinfo.h", + "sys/sysctl.h", + "utmp.h", + "sys/event.h", + "net/if_dl.h", + "util.h", + "ufs/ufs/quota.h", + "pthread_np.h", + "sys/syscall.h", } - if apple { - cfg.header("spawn.h"); - cfg.header("mach-o/dyld.h"); - cfg.header("mach/mach_time.h"); - cfg.header("malloc/malloc.h"); - cfg.header("util.h"); - cfg.header("xlocale.h"); - cfg.header("sys/xattr.h"); - if target.starts_with("x86") && !ios { - cfg.header("crt_externs.h"); - } - cfg.header("netinet/in.h"); - cfg.header("sys/ipc.h"); - cfg.header("sys/sem.h"); - cfg.header("sys/shm.h"); - - if !ios { - cfg.header("sys/sys_domain.h"); - cfg.header("net/if_utun.h"); - cfg.header("net/bpf.h"); - cfg.header("net/route.h"); - cfg.header("netinet/if_ether.h"); - cfg.header("sys/proc_info.h"); - cfg.header("sys/kern_control.h"); + cfg.skip_struct(move |ty| { + match ty { + // FIXME: actually a union + "sigval" => true, + + _ => false, } - } + }); - if bsdlike { - cfg.header("sys/event.h"); - cfg.header("net/if_dl.h"); - if freebsd { - cfg.header("net/bpf.h"); - cfg.header("libutil.h"); - } else { - cfg.header("util.h"); + cfg.skip_const(move |name| { + match name { + // Removed in OpenBSD 6.0 + "KERN_USERMOUNT" | "KERN_ARND" => true, + _ => false, } - } + }); - if linux || emscripten { - cfg.header("mntent.h"); - cfg.header("mqueue.h"); - cfg.header("ucontext.h"); - if !uclibc { - // optionally included in uclibc - cfg.header("sys/xattr.h"); - } - cfg.header("sys/ipc.h"); - cfg.header("sys/sem.h"); - cfg.header("sys/msg.h"); - cfg.header("sys/shm.h"); - cfg.header("sys/user.h"); - cfg.header("sys/timerfd.h"); - cfg.header("shadow.h"); - if !emscripten { - cfg.header("linux/input.h"); - cfg.header("linux/falloc.h"); - } - if x86_64 { - cfg.header("sys/io.h"); - } - if i686 || x86_64 { - cfg.header("sys/reg.h"); + cfg.skip_fn(move |name| { + match name { + "execv" | "execve" | "execvp" | "execvpe" => true, + + // typed 2nd arg + "gettimeofday" => true, + + // Removed in OpenBSD 6.5 + // https://marc.info/?l=openbsd-cvs&m=154723400730318 + "mincore" => true, + + _ => false, } - } + }); - if linux || android || emscripten { - cfg.header("malloc.h"); - cfg.header("net/ethernet.h"); - cfg.header("netpacket/packet.h"); - cfg.header("sched.h"); - cfg.header("sys/epoll.h"); - cfg.header("sys/eventfd.h"); - cfg.header("sys/prctl.h"); - cfg.header("sys/sendfile.h"); - cfg.header("sys/signalfd.h"); - cfg.header("sys/vfs.h"); - cfg.header("sys/syscall.h"); - cfg.header("sys/personality.h"); - cfg.header("sys/swap.h"); - cfg.header("pty.h"); - if !uclibc { - cfg.header("sys/sysinfo.h"); - } - cfg.header("sys/reboot.h"); - if !emscripten { - cfg.header("linux/sockios.h"); - cfg.header("linux/netlink.h"); - cfg.header("linux/genetlink.h"); - cfg.header("linux/netfilter_ipv4.h"); - cfg.header("linux/netfilter_ipv6.h"); - cfg.header("linux/fs.h"); - } - if !musl { - cfg.header("asm/mman.h"); - cfg.header("linux/magic.h"); - cfg.header("linux/reboot.h"); - cfg.header("linux/netfilter/nf_tables.h"); - - if !mips { - cfg.header("linux/quota.h"); - } + cfg.type_name(move |ty, is_struct, is_union| { + match ty { + // Just pass all these through, no need for a "struct" prefix + "FILE" | "DIR" | "Dl_info" => ty.to_string(), + + // OSX calls this something else + "sighandler_t" => "sig_t".to_string(), + + t if is_union => format!("union {}", t), + t if t.ends_with("_t") => t.to_string(), + t if is_struct => format!("struct {}", t), + t => t.to_string(), } + }); + + cfg.field_name(move |struct_, field| match field { + "st_birthtime" if struct_.starts_with("stat") => { + "__st_birthtime".to_string() + } + "st_birthtime_nsec" if struct_.starts_with("stat") => { + "__st_birthtimensec".to_string() + } + s if s.ends_with("_nsec") && struct_.starts_with("stat") => { + s.replace("e_nsec", ".tv_nsec") + } + "sa_sigaction" if struct_ == "sigaction" => "sa_handler".to_string(), + s => s.to_string(), + }); + + cfg.skip_field_type(move |struct_, field| { + // type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1 + (struct_ == "siginfo_t" && field == "si_addr") + }); + + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_windows(target: &str) { + assert!(target.contains("windows")); + let gnu = target.contains("gnu"); + + let mut cfg = ctest::TestGenerator::new(); + cfg.define("_WIN32_WINNT", Some("0x8000")); + + headers! { cfg: + "direct.h", + "errno.h", + "fcntl.h", + "io.h", + "limits.h", + "locale.h", + "process.h", + "signal.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "sys/stat.h", + "sys/types.h", + "sys/utime.h", + "time.h", + "wchar.h", } - if solaris { - cfg.header("sys/epoll.h"); + + if gnu { + headers! { cfg: "ws2tcpip.h" } + } else { + headers! { cfg: "Winsock2.h" }; } - if linux || android { - cfg.header("sys/fsuid.h"); - cfg.header("linux/module.h"); - cfg.header("linux/seccomp.h"); - cfg.header("linux/if_ether.h"); - cfg.header("linux/if_tun.h"); - cfg.header("linux/net_tstamp.h"); - // DCCP support - if !uclibc && !musl && !emscripten { - cfg.header("linux/dccp.h"); + cfg.type_name(move |ty, is_struct, is_union| { + match ty { + // Just pass all these through, no need for a "struct" prefix + "FILE" | "DIR" | "Dl_info" => ty.to_string(), + + // FIXME: these don't exist: + "time64_t" => "__time64_t".to_string(), + "ssize_t" => "SSIZE_T".to_string(), + + "sighandler_t" if !gnu => "_crt_signal_t".to_string(), + "sighandler_t" if gnu => "__p_sig_fn_t".to_string(), + + t if is_union => format!("union {}", t), + t if t.ends_with("_t") => t.to_string(), + + // Windows uppercase structs don't have `struct` in front: + t if is_struct => { + if ty.clone().chars().next().unwrap().is_uppercase() { + t.to_string() + } else if t == "stat" { + "struct __stat64".to_string() + } else if t == "utimbuf" { + "struct __utimbuf64".to_string() + } else { + // put `struct` in front of all structs: + format!("struct {}", t) + } + } + t => t.to_string(), + } + }); + + cfg.fn_cname(move |name, cname| cname.unwrap_or(name).to_string()); + + cfg.skip_type(move |name| match name { + "SSIZE_T" if !gnu => true, + "ssize_t" if !gnu => true, + _ => false, + }); + + cfg.skip_const(move |name| { + match name { + // FIXME: API error: + // SIG_ERR type is "void (*)(int)", not "int" + "SIG_ERR" => true, + _ => false, } + }); - if !musl || mips { - cfg.header("linux/memfd.h"); + // FIXME: All functions point to the wrong addresses? + cfg.skip_fn_ptrcheck(|_| true); + + cfg.skip_signededness(move |c| { + match c { + // windows-isms + n if n.starts_with("P") => true, + n if n.starts_with("H") => true, + n if n.starts_with("LP") => true, + "sighandler_t" if gnu => true, + _ => false, } - } + }); - if linux { - cfg.header("linux/random.h"); - cfg.header("elf.h"); - cfg.header("link.h"); - cfg.header("spawn.h"); - } + cfg.skip_fn(move |name| { + match name { + // FIXME: API error: + "execv" | "execve" | "execvp" | "execvpe" => true, - if freebsd { - cfg.header("mqueue.h"); - cfg.header("pthread_np.h"); - cfg.header("sched.h"); - cfg.header("ufs/ufs/quota.h"); - cfg.header("sys/extattr.h"); - cfg.header("sys/jail.h"); - cfg.header("sys/ipc.h"); - cfg.header("sys/msg.h"); - cfg.header("sys/shm.h"); - cfg.header("sys/procdesc.h"); - cfg.header("sys/rtprio.h"); - cfg.header("spawn.h"); - } + _ => false, + } + }); + + cfg.generate("../src/lib.rs", "main.rs"); +} - if netbsd { - cfg.header("mqueue.h"); - cfg.header("ufs/ufs/quota.h"); - cfg.header("ufs/ufs/quota1.h"); - cfg.header("sys/extattr.h"); - cfg.header("sys/ioctl_compat.h"); +fn test_redox(target: &str) { + assert!(target.contains("redox")); - // DCCP support - cfg.header("netinet/dccp.h"); + let mut cfg = ctest::TestGenerator::new(); + cfg.flag("-Wno-deprecated-declarations"); + + headers! { + cfg: + "ctype.h", + "dirent.h", + "dlfcn.h", + "errno.h", + "execinfo.h", + "fcntl.h", + "glob.h", + "grp.h", + "ifaddrs.h", + "langinfo.h", + "limits.h", + "locale.h", + "net/if.h", + "net/if_arp.h", + "net/route.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "poll.h", + "pthread.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "string.h", + "strings.h", + "sys/file.h", + "sys/ioctl.h", + "sys/mman.h", + "sys/mount.h", + "sys/ptrace.h", + "sys/quota.h", + "sys/resource.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/sysctl.h", + "sys/time.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/utsname.h", + "sys/wait.h", + "syslog.h", + "termios.h", + "time.h", + "unistd.h", + "utime.h", + "utmpx.h", + "wchar.h", } - if openbsd { - cfg.header("ufs/ufs/quota.h"); - cfg.header("pthread_np.h"); - cfg.header("sys/syscall.h"); - } + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_cloudabi(target: &str) { + assert!(target.contains("cloudabi")); - if dragonfly { - cfg.header("mqueue.h"); - cfg.header("ufs/ufs/quota.h"); - cfg.header("pthread_np.h"); - cfg.header("sys/rtprio.h"); + let mut cfg = ctest::TestGenerator::new(); + cfg.flag("-Wno-deprecated-declarations"); + + headers! { + cfg: + "execinfo.h", + "glob.h", + "ifaddrs.h", + "langinfo.h", + "sys/ptrace.h", + "sys/quota.h", + "sys/sysctl.h", + "utmpx.h", + "ctype.h", + "dirent.h", + "dlfcn.h", + "errno.h", + "fcntl.h", + "grp.h", + "limits.h", + "locale.h", + "net/if.h", + "net/if_arp.h", + "net/route.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "poll.h", + "pthread.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "signal.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "strings.h", + "sys/file.h", + "sys/ioctl.h", + "sys/mman.h", + "sys/mount.h", + "sys/resource.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/time.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/utsname.h", + "sys/wait.h", + "syslog.h", + "termios.h", + "time.h", + "unistd.h", + "utime.h", + "wchar.h", } - if solaris { - cfg.header("port.h"); - cfg.header("ucontext.h"); - cfg.header("sys/filio.h"); - cfg.header("sys/loadavg.h"); + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_solaris(target: &str) { + assert!(target.contains("solaris")); + + let mut cfg = ctest::TestGenerator::new(); + cfg.flag("-Wno-deprecated-declarations"); + + cfg.define("_XOPEN_SOURCE", Some("700")); + cfg.define("__EXTENSIONS__", None); + cfg.define("_LCONV_C99", None); + + headers! { + cfg: + "ctype.h", + "dirent.h", + "dlfcn.h", + "errno.h", + "execinfo.h", + "fcntl.h", + "glob.h", + "grp.h", + "ifaddrs.h", + "langinfo.h", + "limits.h", + "locale.h", + "net/if.h", + "net/if_arp.h", + "net/route.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "poll.h", + "port.h", + "pthread.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "signal.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "sys/epoll.h", + "sys/file.h", + "sys/filio.h", + "sys/ioctl.h", + "sys/loadavg.h", + "sys/mman.h", + "sys/mount.h", + "sys/resource.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/time.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/utsname.h", + "sys/wait.h", + "syslog.h", + "termios.h", + "time.h", + "ucontext.h", + "unistd.h", + "utime.h", + "utmpx.h", + "wchar.h", } - if linux || freebsd || dragonfly || netbsd || apple || emscripten { - if !uclibc { - cfg.header("aio.h"); + cfg.skip_const(move |name| match name { + "DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG" | "DT_LNK" + | "DT_SOCK" | "USRQUOTA" | "GRPQUOTA" | "PRIO_MIN" | "PRIO_MAX" => { + true } - } - if cloudabi || redox { - cfg.header("strings.h"); + _ => false, + }); + + cfg.skip_fn(move |name| { + // skip those that are manually verified + match name { + // const-ness only added recently + "dladdr" => true, + + // Definition of those functions as changed since unified headers + // from NDK r14b These changes imply some API breaking changes but + // are still ABI compatible. We can wait for the next major release + // to be compliant with the new API. + // + // FIXME: unskip these for next major release + "setpriority" | "personality" => true, + + // signal is defined with sighandler_t, so ignore + "signal" => true, + + "cfmakeraw" | "cfsetspeed" => true, + + // FIXME: mincore is defined with caddr_t on Solaris. + "mincore" => true, + + _ => false, + } + }); + + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_netbsd(target: &str) { + assert!(target.contains("netbsd")); + let rumprun = target.contains("rumprun"); + let mut cfg = ctest::TestGenerator::new(); + + cfg.flag("-Wno-deprecated-declarations"); + cfg.define("_NETBSD_SOURCE", Some("1")); + + headers! { + cfg: + "errno.h", + "fcntl.h", + "limits.h", + "locale.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "sys/stat.h", + "sys/types.h", + "time.h", + "wchar.h", + "aio.h", + "ctype.h", + "dirent.h", + "dlfcn.h", + "glob.h", + "grp.h", + "ifaddrs.h", + "langinfo.h", + "net/if.h", + "net/if_arp.h", + "net/if_dl.h", + "net/route.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "poll.h", + "pthread.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "signal.h", + "string.h", + "sys/extattr.h", + "sys/file.h", + "sys/ioctl.h", + "sys/ioctl_compat.h", + "sys/mman.h", + "sys/mount.h", + "sys/ptrace.h", + "sys/resource.h", + "sys/socket.h", + "sys/statvfs.h", + "sys/sysctl.h", + "sys/time.h", + "sys/times.h", + "sys/uio.h", + "sys/un.h", + "sys/utsname.h", + "sys/wait.h", + "syslog.h", + "termios.h", + "ufs/ufs/quota.h", + "ufs/ufs/quota1.h", + "unistd.h", + "util.h", + "utime.h", + "mqueue.h", + "netinet/dccp.h", + "sys/event.h", + "sys/quota.h", } cfg.type_name(move |ty, is_struct, is_union| { @@ -369,65 +804,235 @@ fn main() { | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" | "Elf64_Chdr" => ty.to_string(), - // Fixup a few types on windows that don't actually exist. - "time64_t" if windows => "__time64_t".to_string(), - "ssize_t" if windows => "SSIZE_T".to_string(), - // windows - "sighandler_t" if windows && !mingw => "_crt_signal_t".to_string(), - "sighandler_t" if windows && mingw => "__p_sig_fn_t".to_string(), // OSX calls this something else - "sighandler_t" if bsdlike => "sig_t".to_string(), + "sighandler_t" => "sig_t".to_string(), t if is_union => format!("union {}", t), t if t.ends_with("_t") => t.to_string(), - // Windows uppercase structs don't have `struct` in front, there's a - // few special cases for windows, and then otherwise put `struct` in - // front of everything. - t if is_struct => { - if windows && ty.chars().next().unwrap().is_uppercase() { - t.to_string() - } else if windows && t == "stat" { - "struct __stat64".to_string() - } else if windows && t == "utimbuf" { - "struct __utimbuf64".to_string() - } else { - format!("struct {}", t) - } - } + // put `struct` in front of all structs:. + t if is_struct => format!("struct {}", t), t => t.to_string(), } }); - let target2 = target.clone(); cfg.field_name(move |struct_, field| { match field { - "st_birthtime" if openbsd && struct_ == "stat" => { - "__st_birthtime".to_string() - } - "st_birthtime_nsec" if openbsd && struct_ == "stat" => { - "__st_birthtimensec".to_string() + // Our stat *_nsec fields normally don't actually exist but are part + // of a timeval struct + s if s.ends_with("_nsec") && struct_.starts_with("stat") => { + s.replace("e_nsec", ".tv_nsec") } + "u64" if struct_ == "epoll_event" => "data.u64".to_string(), + s => s.to_string(), + } + }); + + cfg.skip_type(move |ty| { + match ty { + // FIXME: sighandler_t is crazy across platforms + "sighandler_t" => true, + _ => false, + } + }); + + cfg.skip_struct(move |ty| { + match ty { + // This is actually a union, not a struct + "sigval" => true, + // These are tested as part of the linux_fcntl tests since there are + // header conflicts when including them with all the other structs. + "termios2" => true, + _ => false, + } + }); + + cfg.skip_signededness(move |c| { + match c { + "LARGE_INTEGER" | "float" | "double" => true, + // uuid_t is a struct, not an integer. + n if n.starts_with("pthread") => true, + // sem_t is a struct or pointer + "sem_t" => true, + _ => false, + } + }); + + cfg.skip_const(move |name| { + match name { + "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness + "SIGUNUSED" => true, // removed in glibc 2.26 + + // weird signed extension or something like that? + "MS_NOUSER" => true, + "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 + "BOTHER" => true, + + _ => false, + } + }); + + cfg.skip_fn(move |name| { + match name { + // FIXME: incorrect API + "execv" | + "execve" | + "execvp" | + "execvpe" | + "fexecve" => true, + + "getrlimit" | "getrlimit64" | // non-int in 1st arg + "setrlimit" | "setrlimit64" | // non-int in 1st arg + "prlimit" | "prlimit64" | // non-int in 2nd arg + + // These functions presumably exist on netbsd but don't look like + // they're implemented on rumprun yet, just let them slide for now. + // Some of them look like they have headers but then don't have + // corresponding actual definitions either... + "shm_open" | + "shm_unlink" | + "syscall" | + "mq_open" | + "mq_close" | + "mq_getattr" | + "mq_notify" | + "mq_receive" | + "mq_send" | + "mq_setattr" | + "mq_timedreceive" | + "mq_timedsend" | + "mq_unlink" | + "ptrace" | + "sigaltstack" if rumprun => true, + + _ => false, + } + }); + + cfg.skip_field_type(move |struct_, field| { + // This is a weird union, don't check the type. + (struct_ == "ifaddrs" && field == "ifa_ifu") || + // sighandler_t type is super weird + (struct_ == "sigaction" && field == "sa_sigaction") || + // sigval is actually a union, but we pretend it's a struct + (struct_ == "sigevent" && field == "sigev_value") || + // aio_buf is "volatile void*" and Rust doesn't understand volatile + (struct_ == "aiocb" && field == "aio_buf") + }); + + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_dragonflybsd(target: &str) { + assert!(target.contains("dragonfly")); + let mut cfg = ctest::TestGenerator::new(); + cfg.flag("-Wno-deprecated-declarations"); + + headers! { + cfg: + "aio.h", + "ctype.h", + "dirent.h", + "dlfcn.h", + "errno.h", + "execinfo.h", + "fcntl.h", + "glob.h", + "grp.h", + "ifaddrs.h", + "langinfo.h", + "limits.h", + "locale.h", + "mqueue.h", + "net/if.h", + "net/if_arp.h", + "net/if_dl.h", + "net/route.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "poll.h", + "pthread.h", + "pthread_np.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "signal.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "sys/event.h", + "sys/file.h", + "sys/ioctl.h", + "sys/mman.h", + "sys/mount.h", + "sys/ptrace.h", + "sys/resource.h", + "sys/rtprio.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/sysctl.h", + "sys/time.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/utsname.h", + "sys/wait.h", + "syslog.h", + "termios.h", + "time.h", + "ufs/ufs/quota.h", + "unistd.h", + "util.h", + "utime.h", + "utmpx.h", + "wchar.h", + } + + cfg.type_name(move |ty, is_struct, is_union| { + match ty { + // Just pass all these through, no need for a "struct" prefix + "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" + | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" + | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" + | "Elf64_Chdr" => ty.to_string(), + + // FIXME: OSX calls this something else + "sighandler_t" => "sig_t".to_string(), + + t if is_union => format!("union {}", t), + + t if t.ends_with("_t") => t.to_string(), + + // put `struct` in front of all structs:. + t if is_struct => format!("struct {}", t), + + t => t.to_string(), + } + }); + + cfg.field_name(move |struct_, field| { + match field { // Our stat *_nsec fields normally don't actually exist but are part // of a timeval struct s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - if target2.contains("apple") { - s.replace("_nsec", "spec.tv_nsec") - } else if target2.contains("android") { - s.to_string() - } else { - s.replace("e_nsec", ".tv_nsec") - } + s.replace("e_nsec", ".tv_nsec") } "u64" if struct_ == "epoll_event" => "data.u64".to_string(), "type_" - if (linux || freebsd || dragonfly) - && (struct_ == "input_event" - || struct_ == "input_mask" - || struct_ == "ff_effect" - || struct_ == "rtprio") => + if struct_ == "input_event" + || struct_ == "input_mask" + || struct_ == "ff_effect" + || struct_ == "rtprio" => { "type".to_string() } @@ -446,43 +1051,672 @@ fn main() { cfg.skip_struct(move |ty| { match ty { - "sockaddr_nl" => musl, + // This is actually a union, not a struct + "sigval" => true, - // On Linux, the type of `ut_tv` field of `struct utmpx` - // can be an anonymous struct, so an extra struct, - // which is absent in glibc, has to be defined. - "__timeval" if linux => true, + // FIXME: These are tested as part of the linux_fcntl tests since + // there are header conflicts when including them with all the other + // structs. + "termios2" => true, + + _ => false, + } + }); - // Fixed on feature=align with repr(packed(4)) - // Once repr_packed stabilizes we can fix this unconditionally - // and remove this check. - "kevent" | "shmid_ds" | "semid_ds" if apple && x86_64 => true, + cfg.skip_signededness(move |c| { + match c { + "LARGE_INTEGER" | "float" | "double" => true, + // uuid_t is a struct, not an integer. + "uuid_t" => true, + n if n.starts_with("pthread") => true, + // sem_t is a struct or pointer + "sem_t" => true, + // mqd_t is a pointer on DragonFly + "mqd_t" => true, + + _ => false, + } + }); + + cfg.skip_const(move |name| { + match name { + "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness + + // weird signed extension or something like that? + "MS_NOUSER" => true, + "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 + + // These are defined for Solaris 11, but the crate is tested on + // illumos, where they are currently not defined + "EADI" + | "PORT_SOURCE_POSTWAIT" + | "PORT_SOURCE_SIGNAL" + | "PTHREAD_STACK_MIN" => true, + + // These change all the time from release to release of linux + // distros, let's just not bother trying to verify them. They + // shouldn't be used in code anyway... + "AF_MAX" | "PF_MAX" => true, + + _ => false, + } + }); + + cfg.skip_fn(move |name| { + // skip those that are manually verified + match name { + "execv" | // crazy stuff with const/mut + "execve" | + "execvp" | + "execvpe" | + "fexecve" => true, + + "getrlimit" | "getrlimit64" | // non-int in 1st arg + "setrlimit" | "setrlimit64" | // non-int in 1st arg + "prlimit" | "prlimit64" | // non-int in 2nd arg + // typed 2nd arg on linux + "gettimeofday" => true, + + _ => false, + } + }); + + cfg.skip_field_type(move |struct_, field| { + // This is a weird union, don't check the type. + (struct_ == "ifaddrs" && field == "ifa_ifu") || + // sighandler_t type is super weird + (struct_ == "sigaction" && field == "sa_sigaction") || + // sigval is actually a union, but we pretend it's a struct + (struct_ == "sigevent" && field == "sigev_value") || + // aio_buf is "volatile void*" and Rust doesn't understand volatile + (struct_ == "aiocb" && field == "aio_buf") + }); + + cfg.skip_field(move |struct_, field| { + // this is actually a union on linux, so we can't represent it well and + // just insert some padding. + (struct_ == "siginfo_t" && field == "_pad") || + // sigev_notify_thread_id is actually part of a sigev_un union + (struct_ == "sigevent" && field == "sigev_notify_thread_id") + }); + + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_wasi(target: &str) { + assert!(target.contains("wasi")); + + let mut cfg = ctest::TestGenerator::new(); + cfg.define("_GNU_SOURCE", None); + + headers! { cfg: + "ctype.h", + "dirent.h", + "errno.h", + "fcntl.h", + "limits.h", + "locale.h", + "malloc.h", + "poll.h", + "sched.h", + "stdbool.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "sys/resource.h", + "sys/select.h", + "sys/socket.h", + "sys/stat.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/utsname.h", + "time.h", + "unistd.h", + "wasi/core.h", + "wasi/libc.h", + "wasi/libc-find-relpath.h", + "wchar.h", + } + + cfg.type_name(move |ty, is_struct, is_union| match ty { + "FILE" | "fd_set" | "DIR" => ty.to_string(), + t if is_union => format!("union {}", t), + t if t.starts_with("__wasi") && t.ends_with("_u") => { + format!("union {}", t) + } + t if t.starts_with("__wasi") && is_struct => format!("struct {}", t), + t if t.ends_with("_t") => t.to_string(), + t if is_struct => format!("struct {}", t), + t => t.to_string(), + }); + + cfg.field_name(move |_struct, field| { + match field { + // deal with fields as rust keywords + "type_" => "type".to_string(), + s => s.to_string(), + } + }); + // Looks like LLD doesn't merge duplicate imports, so if the Rust + // code imports from a module and the C code also imports from a + // module we end up with two imports of function pointers which + // import the same thing but have different function pointers + cfg.skip_fn_ptrcheck(|f| f.starts_with("__wasi")); + + // d_name is declared as a flexible array in WASI libc, so it + // doesn't support sizeof. + cfg.skip_field(|s, field| s == "dirent" && field == "d_name"); + + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_android(target: &str) { + assert!(target.contains("android")); + let target_pointer_width = match target { + t if t.contains("aarch64") || t.contains("x86_64") => 64, + t if t.contains("i686") || t.contains("arm") => 32, + t => panic!("unsupported target: {}", t), + }; + let x86 = target.contains("i686") || target.contains("x86_64"); + + let mut cfg = ctest::TestGenerator::new(); + cfg.define("_GNU_SOURCE", None); + + // FIXME: still necessary? + cfg.flag("-Wno-deprecated-declarations"); + + // Android doesn't actually have in_port_t but it's much easier if we + // provide one for us to test against + // FIXME: still necessary? + cfg.define("in_port_t", Some("uint16_t")); + + headers! { cfg: + "arpa/inet.h", + "asm/mman.h", + "ctype.h", + "dirent.h", + "dlfcn.h", + "errno.h", + "fcntl.h", + "grp.h", + "ifaddrs.h", + "limits.h", + "linux/dccp.h", + "linux/futex.h", + "linux/fs.h", + "linux/genetlink.h", + "linux/if_alg.h", + "linux/if_ether.h", + "linux/if_tun.h", + "linux/magic.h", + "linux/memfd.h", + "linux/module.h", + "linux/net_tstamp.h", + "linux/netfilter/nf_tables.h", + "linux/netfilter_ipv4.h", + "linux/netfilter_ipv6.h", + "linux/netlink.h", + "linux/quota.h", + "linux/reboot.h", + "linux/seccomp.h", + "linux/sockios.h", + "locale.h", + "malloc.h", + "net/ethernet.h", + "net/if.h", + "net/if_arp.h", + "net/route.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "netpacket/packet.h", + "poll.h", + "pthread.h", + "pty.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "signal.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "sys/epoll.h", + "sys/eventfd.h", + "sys/file.h", + "sys/fsuid.h", + "sys/inotify.h", + "sys/ioctl.h", + "sys/mman.h", + "sys/mount.h", + "sys/personality.h", + "sys/prctl.h", + "sys/ptrace.h", + "sys/reboot.h", + "sys/resource.h", + "sys/sendfile.h", + "sys/signalfd.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/swap.h", + "sys/syscall.h", + "sys/sysinfo.h", + "sys/time.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/utsname.h", + "sys/vfs.h", + "sys/wait.h", + "syslog.h", + "termios.h", + "time.h", + "unistd.h", + "utime.h", + "utmp.h", + "wchar.h", + "xlocale.h", + } + + if target_pointer_width == 32 { + // time64_t is not defined for 64-bit targets If included it will + // generate the error 'Your time_t is already 64-bit' + cfg.header("time64.h"); + } + if x86 { + cfg.header("sys/reg.h"); + } + + cfg.type_name(move |ty, is_struct, is_union| { + match ty { + // Just pass all these through, no need for a "struct" prefix + // FIXME: still required ? + "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" + | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" + | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" + | "Elf64_Chdr" => ty.to_string(), + + t if is_union => format!("union {}", t), + + t if t.ends_with("_t") => t.to_string(), + + // put `struct` in front of all structs:. + t if is_struct => format!("struct {}", t), + + t => t.to_string(), + } + }); + + cfg.field_name(move |struct_, field| { + match field { + // Our stat *_nsec fields normally don't actually exist but are part + // of a timeval struct + s if s.ends_with("_nsec") && struct_.starts_with("stat") => { + s.to_string() + } + // FIXME: still necessary? + "u64" if struct_ == "epoll_event" => "data.u64".to_string(), + s => s.to_string(), + } + }); + + cfg.skip_type(move |ty| { + match ty { + // sighandler_t is crazy across platforms + // FIXME: still necessary? + "sighandler_t" => true, + _ => false, + } + }); + + cfg.skip_struct(move |ty| { + match ty { // This is actually a union, not a struct + // FIXME: still necessary "sigval" => true, - // Linux kernel headers used on musl are too old to have this - // definition. Because it's tested on other Linux targets, skip it. - "input_mask" if musl => true, - // These structs have changed since unified headers in NDK r14b. // `st_atime` and `st_atime_nsec` have changed sign. // FIXME: unskip it for next major release - "stat" | "stat64" if android => true, + "stat" | "stat64" => true, // These are tested as part of the linux_fcntl tests since there are // header conflicts when including them with all the other structs. + // FIXME: still necessary "termios2" => true, - // Present on historical versions of iOS but missing in more recent - // SDKs - "bpf_hdr" | "proc_taskinfo" | "proc_taskallinfo" - | "proc_bsdinfo" | "proc_threadinfo" | "sockaddr_inarp" - | "sockaddr_ctl" | "arphdr" - if ios => + _ => false, + } + }); + + cfg.skip_signededness(move |c| { + match c { + // FIXME: still necessary? + "LARGE_INTEGER" | "float" | "double" => true, + // FIXME: still necessary? + n if n.starts_with("pthread") => true, + _ => false, + } + }); + + cfg.skip_const(move |name| { + match name { + // FIXME: still necessary? + "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness + // FIXME: still necessary? + "SIGUNUSED" => true, // removed in glibc 2.26 + + // weird signed extension or something like that? + // FIXME: still necessary? + "MS_NOUSER" => true, + // FIXME: still necessary? + "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 + + // Android uses old kernel headers + // These are constants used in getrandom syscall + // FIXME: still necessary? + "GRND_NONBLOCK" | "GRND_RANDOM" => true, + + // Defined by libattr not libc on linux (hard to test). + // See constant definition for more details. + // FIXME: still necessary? + "ENOATTR" => true, + + // FIXME: still necessary? + "BOTHER" => true, + + // MFD_HUGETLB is not available in some older libc versions on the CI builders. On the + // x86_64 and i686 builders it seems to be available for all targets, so at least test + // it there. + // FIXME: still necessary? + "MFD_HUGETLB" => true, + + // These change all the time from release to release of linux + // distros, let's just not bother trying to verify them. They + // shouldn't be used in code anyway... + // FIXME: still necessary? + "AF_MAX" | "PF_MAX" => true, + + _ => false, + } + }); + + cfg.skip_fn(move |name| { + // skip those that are manually verified + match name { + // FIXME: still necessary? + "execv" | // crazy stuff with const/mut + "execve" | + "execvp" | + "execvpe" | + "fexecve" => true, + + // typed 2nd arg on android + // FIXME: still necessary? + "gettimeofday" => true, + + // not declared in newer android toolchains + // FIXME: still necessary? + "getdtablesize" => true, + + // FIXME: still necessary? + "dlerror" => true, // const-ness is added + + // Apparently the NDK doesn't have this defined on android, but + // it's in a header file? + // FIXME: still necessary? + "endpwent" => true, + + // Apparently res_init exists on Android, but isn't defined in a header: + // https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html + // FIXME: still necessary? + "res_init" => true, + + // Definition of those functions as changed since unified headers from NDK r14b + // These changes imply some API breaking changes but are still ABI compatible. + // We can wait for the next major release to be compliant with the new API. + // FIXME: unskip these for next major release + "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" | + "setpriority" | "personality" => true, + // In Android 64 bits, these functions have been fixed since unified headers. + // Ignore these until next major version. + "bind" | "writev" | "readv" | "sendmsg" | "recvmsg" + if target_pointer_width == 64 => true, + + _ => false, + } + }); + + cfg.skip_static(move |name| { + match name { + // Internal constant, not declared in any headers. + // FIXME: still necessary + "__progname" => true, + _ => false, + } + }); + + // FIXME: still necessary? + cfg.skip_field_type(move |struct_, field| { + // This is a weird union, don't check the type. + (struct_ == "ifaddrs" && field == "ifa_ifu") || + // sighandler_t type is super weird + (struct_ == "sigaction" && field == "sa_sigaction") || + // sigval is actually a union, but we pretend it's a struct + (struct_ == "sigevent" && field == "sigev_value") || + // aio_buf is "volatile void*" and Rust doesn't understand volatile + (struct_ == "aiocb" && field == "aio_buf") + }); + + // FIXME: still necessary? + cfg.skip_field(move |struct_, field| { + // this is actually a union on linux, so we can't represent it well and + // just insert some padding. + (struct_ == "siginfo_t" && field == "_pad") || + // sigev_notify_thread_id is actually part of a sigev_un union + (struct_ == "sigevent" && field == "sigev_notify_thread_id") || + // signalfd had SIGSYS fields added in Linux 4.18, but no libc release has them yet. + (struct_ == "signalfd_siginfo" && (field == "ssi_addr_lsb" || + field == "_pad2" || + field == "ssi_syscall" || + field == "ssi_call_addr" || + field == "ssi_arch")) + }); + + // FIXME: remove + cfg.fn_cname(move |name, _cname| name.to_string()); + + cfg.generate("../src/lib.rs", "main.rs"); + + // On Android also generate another script for testing linux/fcntl + // declarations. These cannot be tested normally because including both + // `linux/fcntl.h` and `fcntl.h` fails. + // + // FIXME: is still necessary? + let mut cfg = ctest::TestGenerator::new(); + cfg.skip_type(|_| true) + .skip_fn(|_| true) + .skip_static(|_| true); + cfg.header("linux/fcntl.h"); + cfg.header("net/if.h"); + cfg.header("linux/if.h"); + cfg.header("linux/quota.h"); + cfg.header("asm/termbits.h"); + cfg.skip_const(move |name| match name { + "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false, + "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => { + false + } + "BOTHER" => false, + _ => true, + }); + cfg.skip_struct(|s| s != "termios2"); + cfg.type_name(move |ty, is_struct, is_union| match ty { + t if is_struct => format!("struct {}", t), + t if is_union => format!("union {}", t), + t => t.to_string(), + }); + cfg.generate("../src/lib.rs", "linux_fcntl.rs"); +} + +fn test_freebsd(target: &str) { + assert!(target.contains("freebsd")); + let x86 = target.contains("i686") || target.contains("x86_64"); + + let mut cfg = ctest::TestGenerator::new(); + // Required for `getline`: + cfg.define("_WITH_GETLINE", None); + + headers! { cfg: + "aio.h", + "arpa/inet.h", + "ctype.h", + "dirent.h", + "dlfcn.h", + "errno.h", + "fcntl.h", + "glob.h", + "grp.h", + "ifaddrs.h", + "langinfo.h", + "libutil.h", + "limits.h", + "locale.h", + "mqueue.h", + "net/bpf.h", + "net/if.h", + "net/if_arp.h", + "net/if_dl.h", + "net/route.h", + "netdb.h", + "netinet/ip.h", + "netinet/in.h", + "netinet/tcp.h", + "netinet/udp.h", + "poll.h", + "pthread.h", + "pthread_np.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "signal.h", + "spawn.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "sys/event.h", + "sys/extattr.h", + "sys/file.h", + "sys/ioctl.h", + "sys/ipc.h", + "sys/jail.h", + "sys/mman.h", + "sys/mount.h", + "sys/msg.h", + "sys/procdesc.h", + "sys/ptrace.h", + "sys/resource.h", + "sys/rtprio.h", + "sys/shm.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/sysctl.h", + "sys/time.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/utsname.h", + "sys/wait.h", + "syslog.h", + "termios.h", + "time.h", + "ufs/ufs/quota.h", + "unistd.h", + "utime.h", + "utmpx.h", + "wchar.h", + } + + cfg.type_name(move |ty, is_struct, is_union| { + match ty { + // Just pass all these through, no need for a "struct" prefix + // FIXME: still required? + "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" + | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" + | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" + | "Elf64_Chdr" => ty.to_string(), + + // FIXME: still required? + "sighandler_t" => "sig_t".to_string(), + + t if is_union => format!("union {}", t), + + t if t.ends_with("_t") => t.to_string(), + + // put `struct` in front of all structs:. + t if is_struct => format!("struct {}", t), + + t => t.to_string(), + } + }); + + cfg.field_name(move |struct_, field| { + match field { + // Our stat *_nsec fields normally don't actually exist but are part + // of a timeval struct + s if s.ends_with("_nsec") && struct_.starts_with("stat") => { + s.replace("e_nsec", ".tv_nsec") + } + // FIXME: still required? + "u64" if struct_ == "epoll_event" => "data.u64".to_string(), + // FIXME: still required? + "type_" + if struct_ == "input_event" + || struct_ == "input_mask" + || struct_ == "ff_effect" + || struct_ == "rtprio" => { - true + "type".to_string() } + s => s.to_string(), + } + }); + + cfg.skip_type(move |ty| { + match ty { + // sighandler_t is crazy across platforms + // FIXME: still required? + "sighandler_t" => true, + + _ => false, + } + }); + + cfg.skip_struct(move |ty| { + match ty { + // This is actually a union, not a struct + // FIXME: still required? + "sigval" => true, + + // These are tested as part of the linux_fcntl tests since there are + // header conflicts when including them with all the other structs. + // FIXME: still required? + "termios2" => true, _ => false, } @@ -490,103 +1724,839 @@ fn main() { cfg.skip_signededness(move |c| { match c { - "LARGE_INTEGER" - | "mach_timebase_info_data_t" - | "float" - | "double" => true, - // uuid_t is a struct, not an integer. - "uuid_t" if dragonfly => true, + // FIXME: still required? + "LARGE_INTEGER" | "float" | "double" => true, + // FIXME: still required? n if n.starts_with("pthread") => true, // sem_t is a struct or pointer - "sem_t" if openbsd || freebsd || dragonfly || netbsd => true, - // mqd_t is a pointer on FreeBSD and DragonFly - "mqd_t" if freebsd || dragonfly => true, - - // Just some typedefs on osx, no need to check their sign - "posix_spawnattr_t" | "posix_spawn_file_actions_t" => true, + // FIXME: still required? + "sem_t" => true, + // mqd_t is a pointer on FreeBSD + // FIXME: still required? + "mqd_t" => true, - // windows-isms - n if n.starts_with("P") => true, - n if n.starts_with("H") => true, - n if n.starts_with("LP") => true, - "__p_sig_fn_t" if mingw => true, _ => false, } }); cfg.skip_const(move |name| { match name { - // Apparently these don't exist in mingw headers? - "MEM_RESET_UNDO" - | "FILE_ATTRIBUTE_NO_SCRUB_DATA" - | "FILE_ATTRIBUTE_INTEGRITY_STREAM" - | "ERROR_NOTHING_TO_TERMINATE" - if mingw => - { - true + // FIXME: still required? + "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness + // FIXME: still required? + "SIGUNUSED" => true, // removed in glibc 2.26 + + // weird signed extension or something like that? + // FIXME: still required? + "MS_NOUSER" => true, + // FIXME: still required? + "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 + + // These constants were removed in FreeBSD 11 (svn r273250) but will + // still be accepted and ignored at runtime. + "MAP_RENAME" | "MAP_NORESERVE" => true, + + // These constants were removed in FreeBSD 11 (svn r262489), + // and they've never had any legitimate use outside of the + // base system anyway. + "CTL_MAXID" | "KERN_MAXID" | "HW_MAXID" | "NET_MAXID" + | "USER_MAXID" => true, + + // These constants were added in FreeBSD 11 + // FIXME: still required? + "EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY" + | "PD_CLOEXEC" | "PD_ALLOWED_AT_FORK" => true, + + // These constants were added in FreeBSD 12 + // FIXME: still required? + "SF_USER_READAHEAD" | "SO_REUSEPORT_LB" => true, + + // These constants are tested in a separate test program generated + // below because there are header conflicts if we try to include the + // headers that define them here. + // FIXME: still required? + "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true, + // FIXME: still required? + "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" + | "F_SEAL_WRITE" => true, + // FIXME: still required? + "BOTHER" => true, + + // MFD_HUGETLB is not available in some older libc versions on the + // CI builders. On the x86_64 and i686 builders it seems to be + // available for all targets, so at least test it there. + // FIXME: still required? + "MFD_HUGETLB" if !x86 => true, + + // These change all the time from release to release of linux + // distros, let's just not bother trying to verify them. They + // shouldn't be used in code anyway... + // FIXME: still required? + "AF_MAX" | "PF_MAX" => true, + + // FreeBSD 12 required, but CI has FreeBSD 11. + // FIXME: still required? + "IP_ORIGDSTADDR" + | "IP_RECVORIGDSTADDR" + | "IPV6_ORIGDSTADDR" + | "IPV6_RECVORIGDSTADDR" => true, + + _ => false, + } + }); + + cfg.skip_fn(move |name| { + // skip those that are manually verified + match name { + // FIXME: still required? + "execv" | // crazy stuff with const/mut + "execve" | + "execvp" | + "execvpe" | + "fexecve" => true, + + // FIXME: for some reason, our signature is wrong + "gettimeofday" => true, + + // The `uname` function in freebsd is now an inline wrapper that + // delegates to another, but the symbol still exists, so don't check + // the symbol. + // FIXME: still required? + "uname" => true, + + // FIXME: need to upgrade FreeBSD version; see https://github.com/rust-lang/libc/issues/938 + // FIXME: still required? + "setgrent" => true, + + // aio_waitcomplete's return type changed between FreeBSD 10 and 11. + // FIXME: still required? + "aio_waitcomplete" => true, + + // lio_listio confuses the checker, probably because one of its + // arguments is an array + // FIXME: still required? + "lio_listio" => true, + + // Definition of those functions as changed since unified headers from NDK r14b + // These changes imply some API breaking changes but are still ABI compatible. + // We can wait for the next major release to be compliant with the new API. + // FIXME: unskip these for next major release + // FIXME: still required ? + "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" | + + _ => false, + } + }); + + cfg.skip_field_type(move |struct_, field| { + // This is a weird union, don't check the type. + // FIXME: still required? + (struct_ == "ifaddrs" && field == "ifa_ifu") || + // FIXME: still required? + // sighandler_t type is super weird + (struct_ == "sigaction" && field == "sa_sigaction") || + // FIXME: still required? + // sigval is actually a union, but we pretend it's a struct + (struct_ == "sigevent" && field == "sigev_value") || + // aio_buf is "volatile void*" and Rust doesn't understand volatile + // FIXME: still required? + (struct_ == "aiocb" && field == "aio_buf") || + // stack_t.ss_sp's type changed from FreeBSD 10 to 11 in svn r294930 + // FIXME: still required? + (struct_ == "stack_t" && field == "ss_sp") + }); + + cfg.skip_field(move |struct_, field| { + // this is actually a union on linux, so we can't represent it well and + // just insert some padding. + // FIXME: still required? + (struct_ == "siginfo_t" && field == "_pad") || + // sigev_notify_thread_id is actually part of a sigev_un union + // FIXME: still required? + (struct_ == "sigevent" && field == "sigev_notify_thread_id") || + // signalfd had SIGSYS fields added in Linux 4.18, but no libc release has them yet. + // FIXME: still required? + (struct_ == "signalfd_siginfo" && (field == "ssi_addr_lsb" || + field == "_pad2" || + field == "ssi_syscall" || + field == "ssi_call_addr" || + field == "ssi_arch")) + }); + + // FIXME: remove + cfg.fn_cname(move |name, _cname| name.to_string()); + + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_emscripten(target: &str) { + assert!(target.contains("emscripten")); + + let mut cfg = ctest::TestGenerator::new(); + // FIXME: still necessary? + cfg.define("_GNU_SOURCE", None); + + // FIXME: still necessary? + cfg.flag("-Wno-deprecated-declarations"); + + headers! { cfg: + "aio.h", + "ctype.h", + "dirent.h", + "dlfcn.h", + "errno.h", + "fcntl.h", + "glob.h", + "grp.h", + "ifaddrs.h", + "langinfo.h", + "limits.h", + "locale.h", + "malloc.h", + "mntent.h", + "mqueue.h", + "net/ethernet.h", + "net/if.h", + "net/if_arp.h", + "net/route.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "netpacket/packet.h", + "poll.h", + "pthread.h", + "pty.h", + "pwd.h", + "resolv.h", + "sched.h", + "sched.h", + "semaphore.h", + "shadow.h", + "signal.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "sys/epoll.h", + "sys/eventfd.h", + "sys/file.h", + "sys/ioctl.h", + "sys/ipc.h", + "sys/mman.h", + "sys/mount.h", + "sys/msg.h", + "sys/personality.h", + "sys/prctl.h", + "sys/ptrace.h", + "sys/quota.h", + "sys/reboot.h", + "sys/resource.h", + "sys/sem.h", + "sys/sendfile.h", + "sys/shm.h", + "sys/signalfd.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/swap.h", + "sys/syscall.h", + "sys/sysctl.h", + "sys/sysinfo.h", + "sys/time.h", + "sys/timerfd.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/user.h", + "sys/utsname.h", + "sys/vfs.h", + "sys/wait.h", + "sys/xattr.h", + "syslog.h", + "termios.h", + "time.h", + "ucontext.h", + "unistd.h", + "utime.h", + "utmp.h", + "utmpx.h", + "wchar.h", + } + + cfg.type_name(move |ty, is_struct, is_union| { + match ty { + // Just pass all these through, no need for a "struct" prefix + // FIXME: is this necessary? + "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" + | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" + | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" + | "Elf64_Chdr" => ty.to_string(), + + t if is_union => format!("union {}", t), + + t if t.ends_with("_t") => t.to_string(), + + // put `struct` in front of all structs:. + t if is_struct => format!("struct {}", t), + + t => t.to_string(), + } + }); + + cfg.field_name(move |struct_, field| { + match field { + // Our stat *_nsec fields normally don't actually exist but are part + // of a timeval struct + s if s.ends_with("_nsec") && struct_.starts_with("stat") => { + s.replace("e_nsec", ".tv_nsec") } + // FIXME: is this necessary? + "u64" if struct_ == "epoll_event" => "data.u64".to_string(), + s => s.to_string(), + } + }); + cfg.skip_type(move |ty| { + match ty { + // sighandler_t is crazy across platforms + // FIXME: is this necessary? + "sighandler_t" => true, + + _ => false, + } + }); + + cfg.skip_struct(move |ty| { + match ty { + // FIXME: is this necessary? + "sockaddr_nl" => true, + + // This is actually a union, not a struct + // FIXME: is this necessary? + "sigval" => true, + + // Linux kernel headers used on musl are too old to have this + // definition. Because it's tested on other Linux targets, skip it. + // FIXME: is this necessary? + "input_mask" => true, + + // These are tested as part of the linux_fcntl tests since there are + // header conflicts when including them with all the other structs. + // FIXME: is this necessary? + "termios2" => true, + + _ => false, + } + }); + + cfg.skip_signededness(move |c| match c { + // FIXME: is this necessary? + "LARGE_INTEGER" | "float" | "double" => true, + // FIXME: is this necessary? + n if n.starts_with("pthread") => true, + _ => false, + }); + + cfg.skip_const(move |name| { + match name { + // FIXME: is this necessary? "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness + // FIXME: is this necessary? "SIGUNUSED" => true, // removed in glibc 2.26 // types on musl are defined a little differently - n if musl && n.contains("__SIZEOF_PTHREAD") => true, + // FIXME: is this necessary? + n if n.contains("__SIZEOF_PTHREAD") => true, // Skip constants not defined in MUSL but just passed down to the // kernel regardless + // FIXME: is this necessary? "RLIMIT_NLIMITS" | "TCP_COOKIE_TRANSACTIONS" | "RLIMIT_RTTIME" | "MSG_COPY" - if musl => + => { true } - // work around super old mips toolchain - "SCHED_IDLE" | "SHM_NORESERVE" => mips, // weird signed extension or something like that? + // FIXME: is this necessary? "MS_NOUSER" => true, + // FIXME: is this necessary? "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 - // These OSX constants are flagged as deprecated - "NOTE_EXIT_REPARENTED" | "NOTE_REAP" if apple => true, + // Musl uses old, patched kernel headers + // FIXME: is this necessary? + "FALLOC_FL_COLLAPSE_RANGE" + | "FALLOC_FL_ZERO_RANGE" + | "FALLOC_FL_INSERT_RANGE" + | "FALLOC_FL_UNSHARE_RANGE" + | "RENAME_NOREPLACE" + | "RENAME_EXCHANGE" + | "RENAME_WHITEOUT" + // ALG_SET_AEAD_* constants are available starting from kernel 3.19 + | "ALG_SET_AEAD_ASSOCLEN" + | "ALG_SET_AEAD_AUTHSIZE" + => + { + true + } + + // musl uses old kernel headers + // These are constants used in getrandom syscall + // FIXME: is this necessary? + "GRND_NONBLOCK" | "GRND_RANDOM" => true, - // These constants were removed in FreeBSD 11 (svn r273250) but will - // still be accepted and ignored at runtime. - "MAP_RENAME" | "MAP_NORESERVE" if freebsd => true, - // These constants were removed in FreeBSD 11 (svn r262489), - // and they've never had any legitimate use outside of the - // base system anyway. - "CTL_MAXID" | "KERN_MAXID" | "HW_MAXID" | "NET_MAXID" - | "USER_MAXID" - if freebsd => + // These constants are tested in a separate test program generated below because there + // are header conflicts if we try to include the headers that define them here. + // FIXME: is this necessary? + "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true, + // FIXME: is this necessary? + "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" + | "F_SEAL_WRITE" => true, + // FIXME: is this necessary? + "BOTHER" => true, + + // FIXME: is this necessary? + "MFD_CLOEXEC" | "MFD_ALLOW_SEALING" => true, + // MFD_HUGETLB is not available in some older libc versions on the CI builders. On the + // x86_64 and i686 builders it seems to be available for all targets, so at least test + // it there. + // FIXME: is this necessary? + "MFD_HUGETLB" => { true } - // These constants were added in FreeBSD 11 - "EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY" - | "PD_CLOEXEC" | "PD_ALLOWED_AT_FORK" - if freebsd => + // These are defined for Solaris 11, but the crate is tested on + // illumos, where they are currently not defined + // FIXME: is this necessary? + "EADI" + | "PORT_SOURCE_POSTWAIT" + | "PORT_SOURCE_SIGNAL" + | "PTHREAD_STACK_MIN" => true, + + // These change all the time from release to release of linux + // distros, let's just not bother trying to verify them. They + // shouldn't be used in code anyway... + // FIXME: is this necessary? + "AF_MAX" | "PF_MAX" => true, + + _ => false, + } + }); + + cfg.skip_fn(move |name| { + // skip those that are manually verified + match name { + // FIXME: is this necessary? + "execv" | // crazy stuff with const/mut + "execve" | + "execvp" | + "execvpe" | + "fexecve" => true, + + "getrlimit" | "getrlimit64" | // non-int in 1st arg + "setrlimit" | "setrlimit64" | // non-int in 1st arg + "prlimit" | "prlimit64" | // non-int in 2nd arg + + // int vs uint. Sorry musl, your prototype declarations are "correct" in the sense that + // they match the interface defined by Linux verbatim, but they conflict with other + // send*/recv* syscalls + // FIXME: is this necessary? + "sendmmsg" | "recvmmsg" => true, + + // FIXME: is this necessary? + "dladdr" => true, // const-ness only added recently + + // FIXME: is this necessary? + "lio_listio" => true, + + // Definition of those functions as changed since unified headers from NDK r14b + // These changes imply some API breaking changes but are still ABI compatible. + // We can wait for the next major release to be compliant with the new API. + // FIXME: unskip these for next major release + "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" | + + _ => false, + } + }); + + cfg.skip_field_type(move |struct_, field| { + // This is a weird union, don't check the type. + // FIXME: is this necessary? + (struct_ == "ifaddrs" && field == "ifa_ifu") || + // sighandler_t type is super weird + // FIXME: is this necessary? + (struct_ == "sigaction" && field == "sa_sigaction") || + // sigval is actually a union, but we pretend it's a struct + // FIXME: is this necessary? + (struct_ == "sigevent" && field == "sigev_value") || + // aio_buf is "volatile void*" and Rust doesn't understand volatile + // FIXME: is this necessary? + (struct_ == "aiocb" && field == "aio_buf") + }); + + cfg.skip_field(move |struct_, field| { + // this is actually a union on linux, so we can't represent it well and + // just insert some padding. + // FIXME: is this necessary? + (struct_ == "siginfo_t" && field == "_pad") || + // musl names this __dummy1 but it's still there + // FIXME: is this necessary? + (struct_ == "glob_t" && field == "gl_flags") || + // musl seems to define this as an *anonymous* bitfield + // FIXME: is this necessary? + (struct_ == "statvfs" && field == "__f_unused") || + // sigev_notify_thread_id is actually part of a sigev_un union + (struct_ == "sigevent" && field == "sigev_notify_thread_id") || + // signalfd had SIGSYS fields added in Linux 4.18, but no libc release has them yet. + (struct_ == "signalfd_siginfo" && (field == "ssi_addr_lsb" || + field == "_pad2" || + field == "ssi_syscall" || + field == "ssi_call_addr" || + field == "ssi_arch")) + }); + + // FIXME: remove + cfg.fn_cname(move |name, _cname| name.to_string()); + + cfg.generate("../src/lib.rs", "main.rs"); +} + +fn test_linux(target: &str) { + assert!(target.contains("linux")); + + // target_env + let gnu = target.contains("gnu"); + let musl = target.contains("musl"); + let uclibc = target.contains("uclibc"); + + match (gnu, musl, uclibc) { + (true, false, false) => (), + (false, true, false) => (), + (false, false, true) => (), + (_, _, _) => panic!( + "linux target lib is gnu: {}, musl: {}, uclibc: {}", + gnu, musl, uclibc + ), + } + + let mips = target.contains("mips"); + let i686 = target.contains("i686"); + let x86_64 = target.contains("x86_64"); + let x32 = target.ends_with("gnux32"); + + let mut cfg = ctest::TestGenerator::new(); + // FIXME: still necessary? + cfg.define("_GNU_SOURCE", None); + // This macro re-deifnes fscanf,scanf,sscanf to link to the symbols that are + // deprecated since glibc >= 2.29. This allows Rust binaries to link against + // glibc versions older than 2.29. + cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None); + + // FIXME: still necessary? + cfg.flag("-Wno-deprecated-declarations"); + + headers! { cfg: + "ctype.h", + "dirent.h", + "dlfcn.h", + "elf.h", + "fcntl.h", + "glob.h", + "grp.h", + "ifaddrs.h", + "langinfo.h", + "limits.h", + "link.h", + "locale.h", + "malloc.h", + "mntent.h", + "mqueue.h", + "net/ethernet.h", + "net/if.h", + "net/if_arp.h", + "net/route.h", + "netdb.h", + "netinet/in.h", + "netinet/ip.h", + "netinet/tcp.h", + "netinet/udp.h", + "netpacket/packet.h", + "poll.h", + "pthread.h", + "pty.h", + "pwd.h", + "resolv.h", + "sched.h", + "semaphore.h", + "shadow.h", + "signal.h", + "spawn.h", + "stddef.h", + "stdint.h", + "stdio.h", + "stdlib.h", + "string.h", + "sys/epoll.h", + "sys/eventfd.h", + "sys/file.h", + "sys/fsuid.h", + "sys/inotify.h", + "sys/ioctl.h", + "sys/ipc.h", + "sys/mman.h", + "sys/mount.h", + "sys/msg.h", + "sys/personality.h", + "sys/prctl.h", + "sys/ptrace.h", + "sys/quota.h", + "sys/reboot.h", + "sys/resource.h", + "sys/sem.h", + "sys/sendfile.h", + "sys/shm.h", + "sys/signalfd.h", + "sys/socket.h", + "sys/stat.h", + "sys/statvfs.h", + "sys/swap.h", + "sys/syscall.h", + "sys/time.h", + "sys/timerfd.h", + "sys/times.h", + "sys/types.h", + "sys/uio.h", + "sys/un.h", + "sys/user.h", + "sys/utsname.h", + "sys/vfs.h", + "sys/wait.h", + "syslog.h", + "termios.h", + "time.h", + "ucontext.h", + "unistd.h", + "utime.h", + "utmp.h", + "wchar.h", + "errno.h", + } + + // Include linux headers at the end: + headers! { + cfg: + "linux/falloc.h", + "linux/futex.h", + "linux/fs.h", + "linux/genetlink.h", + "linux/if_alg.h", + "linux/if_ether.h", + "linux/if_tun.h", + "linux/input.h", + "linux/module.h", + "linux/net_tstamp.h", + "linux/netfilter_ipv4.h", + "linux/netfilter_ipv6.h", + "linux/netlink.h", + "linux/random.h", + "linux/seccomp.h", + "linux/sockios.h", + } + + if x86_64 { + headers! { cfg: "sys/io.h" }; + } + if i686 || x86_64 { + headers! { cfg: "sys/reg.h" }; + } + + if !musl { + assert!(uclibc || gnu); + headers! { cfg: + "asm/mman.h", + "linux/if.h", + "linux/magic.h", + "linux/netfilter/nf_tables.h", + "linux/reboot.h", + "sys/auxv.h", + }; + + if !x32 { + assert!((gnu || uclibc) && !x32); + headers! { cfg: "sys/sysctl.h", } + } + if !uclibc { + assert!(gnu); + headers! { cfg: + "execinfo.h", + "utmpx.h", + } + } + if !mips { + assert!((gnu || uclibc) && !mips); + headers! { cfg: "linux/quota.h" }; + } + } + + // DCCP support + if !uclibc && !musl { + assert!(gnu); + headers! { cfg: "linux/dccp.h" }; + } + + if !musl || mips { + assert!(gnu || uclibc || (mips && musl)); + headers! { cfg: "linux/memfd.h" }; + } + + // note: aio.h must be included before sys/mount.h + if !uclibc { + assert!(gnu || musl); + // optionally included in uclibc + headers! { cfg: + "sys/xattr.h", + "sys/sysinfo.h", + "aio.h", + } + } + + cfg.type_name(move |ty, is_struct, is_union| { + match ty { + // Just pass all these through, no need for a "struct" prefix + "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" + | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" + | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" + | "Elf64_Chdr" => ty.to_string(), + + t if is_union => format!("union {}", t), + + t if t.ends_with("_t") => t.to_string(), + + // put `struct` in front of all structs:. + t if is_struct => format!("struct {}", t), + + t => t.to_string(), + } + }); + + cfg.field_name(move |struct_, field| { + match field { + // Our stat *_nsec fields normally don't actually exist but are part + // of a timeval struct + s if s.ends_with("_nsec") && struct_.starts_with("stat") => { + s.replace("e_nsec", ".tv_nsec") + } + // FIXME: is this necessary? + "u64" if struct_ == "epoll_event" => "data.u64".to_string(), + // FIXME: is this necessary? + "type_" + if struct_ == "input_event" + || struct_ == "input_mask" + || struct_ == "ff_effect" + || struct_ == "rtprio" => { - true + "type".to_string() } + s => s.to_string(), + } + }); - // These constants were added in FreeBSD 12 - "SF_USER_READAHEAD" | "SO_REUSEPORT_LB" if freebsd => true, + cfg.skip_type(move |ty| { + match ty { + // sighandler_t is crazy across platforms + // FIXME: is this necessary? + "sighandler_t" => true, - // These OSX constants are removed in Sierra. - // https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html - "KERN_KDENABLE_BG_TRACE" if apple => true, - "KERN_KDDISABLE_BG_TRACE" if apple => true, + // These cannot be tested when "resolv.h" is included and are tested + // below. + "Elf64_Phdr" | "Elf32_Phdr" => true, + + _ => false, + } + }); - // These constants were removed in OpenBSD 6 (https://git.io/v7gBO - // https://git.io/v7gBq) - "KERN_USERMOUNT" | "KERN_ARND" if openbsd => true, + cfg.skip_struct(move |ty| { + match ty { + // FIXME: is this necessary? + "sockaddr_nl" if musl => true, + + // These cannot be tested when "resolv.h" is included and are tested + // below. + "Elf64_Phdr" | "Elf32_Phdr" => true, + + // On Linux, the type of `ut_tv` field of `struct utmpx` + // can be an anonymous struct, so an extra struct, + // which is absent in glibc, has to be defined. + "__timeval" => true, + + // This is actually a union, not a struct + "sigval" => true, + + // Linux kernel headers used on musl are too old to have this + // definition. Because it's tested on other Linux targets, skip it. + // FIXME: is this necessary? + "input_mask" if musl => true, + + // These are tested as part of the linux_fcntl tests since there are + // header conflicts when including them with all the other structs. + // FIXME: is this necessary? + "termios2" => true, + + _ => false, + } + }); + + cfg.skip_signededness(move |c| match c { + // FIXME: is this necessary? + "LARGE_INTEGER" | "float" | "double" => true, + // FIXME: is this necessary? + n if n.starts_with("pthread") => true, + _ => false, + }); + + cfg.skip_const(move |name| { + match name { + // FIXME: is this necessary? + "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness + // FIXME: is this necessary? + "SIGUNUSED" => true, // removed in glibc 2.26 + + // types on musl are defined a little differently + // FIXME: is this necessary? + n if musl && n.contains("__SIZEOF_PTHREAD") => true, + + // Skip constants not defined in MUSL but just passed down to the + // kernel regardless + // FIXME: is this necessary? + "RLIMIT_NLIMITS" + | "TCP_COOKIE_TRANSACTIONS" + | "RLIMIT_RTTIME" + | "MSG_COPY" + if musl => + { + true + } + // work around super old mips toolchain + // FIXME: is this necessary? + "SCHED_IDLE" | "SHM_NORESERVE" => mips, + + // weird signed extension or something like that? + // FIXME: is this necessary? + "MS_NOUSER" => true, + // FIXME: is this necessary? + "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 // These are either unimplemented or optionally built into uClibc + // FIXME: is this necessary? "LC_CTYPE_MASK" | "LC_NUMERIC_MASK" | "LC_TIME_MASK" @@ -610,6 +2580,7 @@ fn main() { } // Musl uses old, patched kernel headers + // FIXME: is this necessary? "FALLOC_FL_COLLAPSE_RANGE" | "FALLOC_FL_ZERO_RANGE" | "FALLOC_FL_INSERT_RANGE" @@ -617,59 +2588,69 @@ fn main() { | "RENAME_NOREPLACE" | "RENAME_EXCHANGE" | "RENAME_WHITEOUT" + // ALG_SET_AEAD_* constants are available starting from kernel 3.19 + | "ALG_SET_AEAD_ASSOCLEN" + | "ALG_SET_AEAD_AUTHSIZE" if musl => { true } - // Both android and musl use old kernel headers + // musl uses old kernel headers // These are constants used in getrandom syscall - "GRND_NONBLOCK" | "GRND_RANDOM" if musl || android => true, + // FIXME: is this necessary? + "GRND_NONBLOCK" | "GRND_RANDOM" if musl => true, // Defined by libattr not libc on linux (hard to test). // See constant definition for more details. - "ENOATTR" if android || linux => true, + // FIXME: is this necessary? + "ENOATTR" => true, // On mips*-unknown-linux-gnu* CMSPAR cannot be included with the set of headers we // want to use here for testing. It's originally defined in asm/termbits.h, which is // also included by asm/termios.h, but not the standard termios.h. There's no way to // include both asm/termbits.h and termios.h and there's no way to include both // asm/termios.h and ioctl.h (+ some other headers) because of redeclared types. - "CMSPAR" if mips && linux && !musl => true, + // FIXME: is this necessary? + "CMSPAR" if mips && !musl => true, // On mips Linux targets, MADV_SOFT_OFFLINE is currently missing, though it's been added but CI has too old // of a Linux version. Since it exists on all other Linux targets, just ignore this for now and remove once // it's been fixed in CI. - "MADV_SOFT_OFFLINE" if mips && linux => true, + // FIXME: is this necessary? + "MADV_SOFT_OFFLINE" if mips => true, // These constants are tested in a separate test program generated below because there // are header conflicts if we try to include the headers that define them here. + // FIXME: is this necessary? "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true, + // FIXME: is this necessary? "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" - | "F_SEAL_WRITE" => true, + | "F_SEAL_WRITE" => true, + // FIXME: is this necessary? "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1" - if mips && linux => + if mips => { true } // Only on MIPS + // FIXME: is this necessary? "BOTHER" => true, + // FIXME: is this necessary? "MFD_CLOEXEC" | "MFD_ALLOW_SEALING" if !mips && musl => true, // MFD_HUGETLB is not available in some older libc versions on the CI builders. On the // x86_64 and i686 builders it seems to be available for all targets, so at least test // it there. - "MFD_HUGETLB" if !(x86_64 || i686) || musl || (x86_64 && android)=> true, - - "DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG" - | "DT_LNK" | "DT_SOCK" - if solaris => + // FIXME: is this necessary? + "MFD_HUGETLB" + if !(x86_64 || i686) || musl => { true } - "USRQUOTA" | "GRPQUOTA" if solaris => true, - "PRIO_MIN" | "PRIO_MAX" if solaris => true, - // These are defined for Solaris 11, but the crate is tested on illumos, where they are currently not defined + // These are defined for Solaris 11, but the crate is tested on + // illumos, where they are currently not defined + // FIXME: is this necessary? "EADI" | "PORT_SOURCE_POSTWAIT" | "PORT_SOURCE_SIGNAL" @@ -678,38 +2659,23 @@ fn main() { // These change all the time from release to release of linux // distros, let's just not bother trying to verify them. They // shouldn't be used in code anyway... + // FIXME: is this necessary? "AF_MAX" | "PF_MAX" => true, // These are not in a glibc release yet, only in kernel headers. - "AF_XDP" | "PF_XDP" | "SOL_XDP" if linux => true, - - // Present on historical versions of iOS, but now removed in more - // recent SDKs - "ARPOP_REQUEST" - | "ARPOP_REPLY" - | "ATF_COM" - | "ATF_PERM" - | "ATF_PUBL" - | "ATF_USETRAILERS" - | "AF_SYS_CONTROL" - | "SYSPROTO_EVENT" - | "PROC_PIDTASKALLINFO" - | "PROC_PIDTASKINFO" - | "PROC_PIDTHREADINFO" - | "UTUN_OPT_FLAGS" - | "UTUN_OPT_IFNAME" - | "BPF_ALIGNMENT" - | "SYSPROTO_CONTROL" - if ios => + // FIXME: is this necessary? + "AF_XDP" + | "PF_XDP" + | "SOL_XDP" + | "IPV6_FLOWINFO" + | "IPV6_FLOWLABEL_MGR" + | "IPV6_FLOWINFO_SEND" + | "IPV6_FLOWINFO_FLOWLABEL" + | "IPV6_FLOWINFO_PRIORITY" + => { true } - s if ios && s.starts_with("RTF_") => true, - s if ios && s.starts_with("RTM_") => true, - s if ios && s.starts_with("RTA_") => true, - s if ios && s.starts_with("RTAX_") => true, - s if ios && s.starts_with("RTV_") => true, - s if ios && s.starts_with("DLT_") => true, _ => false, } @@ -726,54 +2692,21 @@ fn main() { "getrlimit" | "getrlimit64" | // non-int in 1st arg "setrlimit" | "setrlimit64" | // non-int in 1st arg - "prlimit" | "prlimit64" | // non-int in 2nd arg - "strerror_r" if linux => true, // actually xpg-something-or-other + "prlimit" | "prlimit64" // non-int in 2nd arg + => true, // int vs uint. Sorry musl, your prototype declarations are "correct" in the sense that // they match the interface defined by Linux verbatim, but they conflict with other // send*/recv* syscalls + // FIXME: is this necessary? "sendmmsg" | "recvmmsg" if musl => true, - // typed 2nd arg on linux and android - "gettimeofday" if linux || android || freebsd || openbsd || dragonfly => true, - - // not declared in newer android toolchains - "getdtablesize" if android => true, - - "dlerror" if android => true, // const-ness is added - "dladdr" if musl || solaris => true, // const-ness only added recently - - // OSX has 'struct tm *const' which we can't actually represent in - // Rust, but is close enough to *mut - "timegm" if apple => true, - - // OSX's daemon is deprecated in 10.5 so we'll get a warning (which - // we turn into an error) so just ignore it. - "daemon" if apple => true, + // typed 2nd arg on linux + // FIXME: is this necessary? + "gettimeofday" => true, - // Deprecated on OSX - "sem_destroy" if apple => true, - "sem_init" if apple => true, - - // These functions presumably exist on netbsd but don't look like - // they're implemented on rumprun yet, just let them slide for now. - // Some of them look like they have headers but then don't have - // corresponding actual definitions either... - "shm_open" | - "shm_unlink" | - "syscall" | - "mq_open" | - "mq_close" | - "mq_getattr" | - "mq_notify" | - "mq_receive" | - "mq_send" | - "mq_setattr" | - "mq_timedreceive" | - "mq_timedsend" | - "mq_unlink" | - "ptrace" | - "sigaltstack" if rumprun => true, + // FIXME: is this necessary? + "dladdr" if musl => true, // const-ness only added recently // There seems to be a small error in EGLIBC's eventfd.h header. The // [underlying system call][1] always takes its first `count` @@ -789,29 +2722,11 @@ fn main() { // [1]: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/eventfd.c?id=refs/tags/v3.12.51#n397 // [2]: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty/view/head:/sysdeps/unix/sysv/linux/sys/eventfd.h // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34 - "eventfd" if linux => true, - - // The `uname` function in freebsd is now an inline wrapper that - // delegates to another, but the symbol still exists, so don't check - // the symbol. - "uname" if freebsd => true, + // FIXME: is this necessary? + "eventfd" => true, - // FIXME: need to upgrade FreeBSD version; see https://github.com/rust-lang/libc/issues/938 - "setgrent" if freebsd => true, - - // aio_waitcomplete's return type changed between FreeBSD 10 and 11. - "aio_waitcomplete" if freebsd => true, - - // lio_listio confuses the checker, probably because one of its - // arguments is an array - "lio_listio" if freebsd => true, "lio_listio" if musl => true, - // Apparently the NDK doesn't have this defined on android, but - // it's in a header file? - "endpwent" if android => true, - - // These are either unimplemented or optionally built into uClibc // or "sysinfo", where it's defined but the structs in linux/sysinfo.h and sys/sysinfo.h // clash so it can't be tested @@ -822,83 +2737,30 @@ fn main() { "sysinfo" | "newlocale" | "duplocale" | "freelocale" | "uselocale" | "nl_langinfo_l" | "wcslen" | "wcstombs" if uclibc => true, - // Apparently res_init exists on Android, but isn't defined in a header: - // https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html - "res_init" if android => true, - - // On macOS and iOS, res_init is available, but requires linking with libresolv: - // http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html - // See discussion for skipping here: - // https://github.com/rust-lang/libc/pull/585#discussion_r114561460 - "res_init" if apple => true, - - // On Mac we don't use the default `close()`, instead using their $NOCANCEL variants. - "close" if apple => true, - // Definition of those functions as changed since unified headers from NDK r14b // These changes imply some API breaking changes but are still ABI compatible. // We can wait for the next major release to be compliant with the new API. // FIXME: unskip these for next major release - "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" | - "setpriority" | "personality" if android || solaris => true, - // In Android 64 bits, these functions have been fixed since unified headers. - // Ignore these until next major version. - "bind" | "writev" | "readv" | "sendmsg" | "recvmsg" if android && (aarch64 || x86_64) => true, - - // signal is defined with sighandler_t, so ignore - "signal" if solaris => true, - - "cfmakeraw" | "cfsetspeed" if solaris => true, - - // FIXME: mincore is defined with caddr_t on Solaris. - "mincore" if solaris => true, - - // These were all included in historical versions of iOS but appear - // to be removed now - "system" | "ptrace" if ios => true, - - // Removed in OpenBSD 6.5 - // https://marc.info/?l=openbsd-cvs&m=154723400730318 - "mincore" if openbsd => true, - - _ => false, - } - }); - - cfg.skip_static(move |name| { - match name { - // Internal constant, not declared in any headers. - "__progname" if android => true, - _ => false, - } - }); - - cfg.skip_fn_ptrcheck(move |name| { - match name { - // dllimport weirdness? - _ if windows => true, + "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" => true, _ => false, } }); + // FIXME: is this necessary? cfg.skip_field_type(move |struct_, field| { // This is a weird union, don't check the type. (struct_ == "ifaddrs" && field == "ifa_ifu") || // sighandler_t type is super weird (struct_ == "sigaction" && field == "sa_sigaction") || // __timeval type is a patch which doesn't exist in glibc - (linux && struct_ == "utmpx" && field == "ut_tv") || + (struct_ == "utmpx" && field == "ut_tv") || // sigval is actually a union, but we pretend it's a struct (struct_ == "sigevent" && field == "sigev_value") || // aio_buf is "volatile void*" and Rust doesn't understand volatile (struct_ == "aiocb" && field == "aio_buf") || - // stack_t.ss_sp's type changed from FreeBSD 10 to 11 in svn r294930 - (freebsd && struct_ == "stack_t" && field == "ss_sp") || - // type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1 - (openbsd && struct_ == "siginfo_t" && field == "si_addr") || // this one is an anonymous union - (linux && struct_ == "ff_effect" && field == "u") + (struct_ == "ff_effect" && field == "u") }); cfg.skip_field(move |struct_, field| { @@ -919,57 +2781,70 @@ fn main() { field == "ssi_arch")) }); - cfg.fn_cname(move |name, cname| { - if windows { - cname.unwrap_or(name).to_string() - } else { - name.to_string() - } - }); + // FIXME: remove + cfg.fn_cname(move |name, _cname| name.to_string()); cfg.generate("../src/lib.rs", "main.rs"); - // On Linux or Android also generate another script for testing linux/fcntl declarations. + // On Linux also generate another script for testing linux/fcntl declarations. // These cannot be tested normally because including both `linux/fcntl.h` and `fcntl.h` // fails on a lot of platforms. let mut cfg = ctest::TestGenerator::new(); cfg.skip_type(|_| true) .skip_fn(|_| true) .skip_static(|_| true); - if android || linux { - // musl defines these directly in `fcntl.h` - if musl { - cfg.header("fcntl.h"); - } else { - cfg.header("linux/fcntl.h"); - } - if !musl { - cfg.header("net/if.h"); - cfg.header("linux/if.h"); - } - cfg.header("linux/quota.h"); - cfg.header("asm/termbits.h"); - cfg.skip_const(move |name| match name { - "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false, - "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" - | "F_SEAL_WRITE" => false, - "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1" - if mips && linux => - { - false - } - "BOTHER" => false, - _ => true, - }); - cfg.skip_struct(|s| s != "termios2"); - cfg.type_name(move |ty, is_struct, is_union| match ty { - t if is_struct => format!("struct {}", t), - t if is_union => format!("union {}", t), - t => t.to_string(), - }); + // musl defines these directly in `fcntl.h` + if musl { + cfg.header("fcntl.h"); } else { - cfg.skip_const(|_| true); - cfg.skip_struct(|_| true); + cfg.header("linux/fcntl.h"); } + if !musl { + cfg.header("net/if.h"); + cfg.header("linux/if.h"); + } + cfg.header("linux/quota.h"); + cfg.header("asm/termbits.h"); + cfg.skip_const(move |name| match name { + "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false, + "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => { + false + } + "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1" if mips => false, + "BOTHER" => false, + _ => true, + }); + cfg.skip_struct(|s| s != "termios2"); + cfg.type_name(move |ty, is_struct, is_union| match ty { + t if is_struct => format!("struct {}", t), + t if is_union => format!("union {}", t), + t => t.to_string(), + }); cfg.generate("../src/lib.rs", "linux_fcntl.rs"); + + // Test Elf64_Phdr and Elf32_Phdr + // These types have a field called `p_type`, but including + // "resolve.h" defines a `p_type` macro that expands to `__p_type` + // making the tests for these fails when both are included. + let mut cfg = ctest::TestGenerator::new(); + cfg.skip_fn(|_| true) + .skip_const(|_| true) + .skip_static(|_| true) + .type_name(move |ty, _is_struct, _is_union| { + ty.to_string() + }); + cfg.skip_struct(move |ty| { + match ty { + "Elf64_Phdr" | "Elf32_Phdr" => false, + _ => true, + } + }); + cfg.skip_type(move |ty| { + match ty { + "Elf64_Phdr" | "Elf32_Phdr" => false, + _ => true, + } + }); + cfg.header("elf.h"); + cfg.generate("../src/lib.rs", "linux_elf.rs"); } diff --git a/libc/libc-test/src/cmsg.c b/libc/libc-test/src/cmsg.c new file mode 100644 index 0000000..a8b1c37 --- /dev/null +++ b/libc/libc-test/src/cmsg.c @@ -0,0 +1,28 @@ +#include <sys/param.h> +#include <sys/socket.h> + +// Since the cmsg(3) macros are macros instead of functions, they aren't +// available to FFI. libc must reimplement them, which is error-prone. This +// file provides FFI access to the actual macros so they can be tested against +// the Rust reimplementations. + +struct cmsghdr *cmsg_firsthdr(struct msghdr *msgh) { + return CMSG_FIRSTHDR(msgh); +} + +struct cmsghdr *cmsg_nxthdr(struct msghdr *msgh, struct cmsghdr *cmsg) { + return CMSG_NXTHDR(msgh, cmsg); +} + +size_t cmsg_space(size_t length) { + return CMSG_SPACE(length); +} + +size_t cmsg_len(size_t length) { + return CMSG_LEN(length); +} + +unsigned char *cmsg_data(struct cmsghdr *cmsg) { + return CMSG_DATA(cmsg); +} + diff --git a/libc/libc-test/test/cmsg.rs b/libc/libc-test/test/cmsg.rs new file mode 100644 index 0000000..8304163 --- /dev/null +++ b/libc/libc-test/test/cmsg.rs @@ -0,0 +1,101 @@ +//! Compare libc's CMSG(3) family of functions against the actual C macros, for +//! various inputs. + +extern crate libc; + +#[cfg(unix)] +mod t { + + use libc::{self, c_uchar, c_uint, c_void, cmsghdr, msghdr}; + use std::mem; + + extern "C" { + pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr; + pub fn cmsg_nxthdr( + mhdr: *const msghdr, + cmsg: *const cmsghdr, + ) -> *mut cmsghdr; + pub fn cmsg_space(length: c_uint) -> usize; + pub fn cmsg_len(length: c_uint) -> usize; + pub fn cmsg_data(cmsg: *const cmsghdr) -> *mut c_uchar; + } + + #[test] + fn test_cmsg_data() { + for l in 0..128 { + let pcmsghdr = l as *const cmsghdr; + unsafe { + assert_eq!(libc::CMSG_DATA(pcmsghdr), cmsg_data(pcmsghdr)); + } + } + } + + #[test] + fn test_cmsg_firsthdr() { + let mut mhdr: msghdr = unsafe { mem::zeroed() }; + mhdr.msg_control = 0xdeadbeef as *mut c_void; + let pmhdr = &mhdr as *const msghdr; + for l in 0..128 { + mhdr.msg_controllen = l; + unsafe { + assert_eq!(libc::CMSG_FIRSTHDR(pmhdr), cmsg_firsthdr(pmhdr)); + } + } + } + + #[test] + fn test_cmsg_len() { + for l in 0..128 { + unsafe { + assert_eq!(libc::CMSG_LEN(l) as usize, cmsg_len(l)); + } + } + } + + // Skip on sparc64 + // https://github.com/rust-lang/libc/issues/1239 + #[cfg(not(target_arch = "sparc64"))] + #[test] + fn test_cmsg_nxthdr() { + use std::ptr; + + let mut buffer = [0u8; 256]; + let mut mhdr: msghdr = unsafe { mem::zeroed() }; + let pmhdr = &mhdr as *const msghdr; + for start_ofs in 0..64 { + let pcmsghdr = &mut buffer[start_ofs] as *mut u8 as *mut cmsghdr; + mhdr.msg_control = pcmsghdr as *mut c_void; + mhdr.msg_controllen = (160 - start_ofs) as _; + for cmsg_len in 0..64 { + for next_cmsg_len in 0..32 { + for i in buffer[start_ofs..].iter_mut() { + *i = 0; + } + unsafe { + (*pcmsghdr).cmsg_len = cmsg_len; + let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr); + let next = cmsg_nxthdr(pmhdr, pcmsghdr); + assert_eq!(libc_next, next); + + if libc_next != ptr::null_mut() { + (*libc_next).cmsg_len = next_cmsg_len; + let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr); + let next = cmsg_nxthdr(pmhdr, pcmsghdr); + assert_eq!(libc_next, next); + } + } + } + } + } + } + + #[test] + fn test_cmsg_space() { + unsafe { + for l in 0..128 { + assert_eq!(libc::CMSG_SPACE(l) as usize, cmsg_space(l)); + } + } + } + +} diff --git a/libc/libc-test/test/linux_fcntl.rs b/libc/libc-test/test/linux_fcntl.rs index 4c8ad52..a54636c 100644 --- a/libc/libc-test/test/linux_fcntl.rs +++ b/libc/libc-test/test/linux_fcntl.rs @@ -1,7 +1,10 @@ -#![allow(bad_style, improper_ctypes, unused)] +#![allow(bad_style, improper_ctypes, unused, deprecated)] extern crate libc; - use libc::*; +#[cfg(any(target_os = "linux", target_os = "android"))] include!(concat!(env!("OUT_DIR"), "/linux_fcntl.rs")); + +#[cfg(not(any(target_os = "linux", target_os = "android")))] +fn main() {} diff --git a/libc/libc-test/test/main.rs b/libc/libc-test/test/main.rs index 3d33610..62a587c 100644 --- a/libc/libc-test/test/main.rs +++ b/libc/libc-test/test/main.rs @@ -1,4 +1,4 @@ -#![allow(bad_style, improper_ctypes)] +#![allow(bad_style, improper_ctypes, deprecated)] extern crate libc; use libc::*; diff --git a/libc/rustfmt.toml b/libc/rustfmt.toml new file mode 100644 index 0000000..7ecc610 --- /dev/null +++ b/libc/rustfmt.toml @@ -0,0 +1,3 @@ +max_width = 79 +comment_width = 79 +error_on_line_overflow = true
\ No newline at end of file diff --git a/libc/src/cloudabi/mod.rs b/libc/src/cloudabi/mod.rs index df11de0..8191967 100644 --- a/libc/src/cloudabi/mod.rs +++ b/libc/src/cloudabi/mod.rs @@ -1,5 +1,3 @@ -use dox::Option; - pub type int8_t = i8; pub type int16_t = i16; pub type int32_t = i32; @@ -122,8 +120,18 @@ pub const PTHREAD_STACK_MIN: ::size_t = 1024; pub const SOCK_DGRAM: ::c_int = 128; pub const SOCK_STREAM: ::c_int = 130; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum FILE {} +impl ::Copy for FILE {} +impl ::Clone for FILE { + fn clone(&self) -> FILE { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos_t {} // TODO: fill this out with a struct +impl ::Copy for fpos_t {} +impl ::Clone for fpos_t { + fn clone(&self) -> fpos_t { *self } +} extern { pub fn isalnum(c: c_int) -> c_int; @@ -271,7 +279,7 @@ extern { ) -> ::c_int; pub fn pthread_key_create( key: *mut pthread_key_t, - dtor: Option<unsafe extern fn(*mut ::c_void)>, + dtor: ::Option<unsafe extern fn(*mut ::c_void)>, ) -> ::c_int; pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int; pub fn pthread_setspecific( @@ -306,13 +314,15 @@ cfg_if! { } cfg_if! { - if #[cfg(core_cvoid)] { - pub use core::ffi::c_void; + if #[cfg(libc_core_cvoid)] { + pub use ::ffi::c_void; } else { // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help // enable more optimization opportunities around it recognizing things // like malloc/free. #[repr(u8)] + #[allow(missing_copy_implementations)] + #[allow(missing_debug_implementations)] pub enum c_void { // Two dummy variants so the #[repr] attribute can be used. #[doc(hidden)] diff --git a/libc/src/dox.rs b/libc/src/dox.rs deleted file mode 100644 index 6296c6c..0000000 --- a/libc/src/dox.rs +++ /dev/null @@ -1,224 +0,0 @@ -pub use self::imp::*; - -#[cfg(not(cross_platform_docs))] -mod imp { - pub use core::clone::Clone; - pub use core::marker::Copy; - pub use core::mem; - pub use core::option::Option; -} - -#[cfg(cross_platform_docs)] -mod imp { - pub enum Option<T> { - Some(T), - None, - } - impl<T: Copy> Copy for Option<T> {} - impl<T: Clone> Clone for Option<T> { - fn clone(&self) -> Option<T> { - loop {} - } - } - - impl<T> Copy for *mut T {} - impl<T> Clone for *mut T { - fn clone(&self) -> *mut T { - loop {} - } - } - - impl<T> Copy for *const T {} - impl<T> Clone for *const T { - fn clone(&self) -> *const T { - loop {} - } - } - - pub trait Clone { - fn clone(&self) -> Self; - } - - #[lang = "copy"] - pub trait Copy {} - - #[lang = "freeze"] - pub trait Freeze {} - - #[lang = "sync"] - pub trait Sync {} - impl<T> Sync for T {} - - #[lang = "sized"] - pub trait Sized {} - - #[lang = "receiver"] - pub trait Receiver {} - impl<T: ?Sized> Receiver for &T {} - impl<T: ?Sized> Receiver for &mut T {} - - macro_rules! each_int { - ($mac:ident) => { - $mac!(u8); - $mac!(u16); - $mac!(u32); - $mac!(u64); - $mac!(usize); - each_signed_int!($mac); - }; - } - - macro_rules! each_signed_int { - ($mac:ident) => { - $mac!(i8); - $mac!(i16); - $mac!(i32); - $mac!(i64); - $mac!(isize); - }; - } - - #[lang = "div"] - pub trait Div<RHS = Self> { - type Output; - fn div(self, rhs: RHS) -> Self::Output; - } - - #[lang = "shl"] - pub trait Shl<RHS = Self> { - type Output; - fn shl(self, rhs: RHS) -> Self::Output; - } - - #[lang = "mul"] - pub trait Mul<RHS = Self> { - type Output; - fn mul(self, rhs: RHS) -> Self::Output; - } - - #[lang = "sub"] - pub trait Sub<RHS = Self> { - type Output; - fn sub(self, rhs: RHS) -> Self::Output; - } - - #[lang = "bitand"] - pub trait BitAnd<RHS = Self> { - type Output; - fn bitand(self, rhs: RHS) -> Self::Output; - } - - #[lang = "bitand_assign"] - pub trait BitAndAssign<RHS = Self> { - fn bitand_assign(&mut self, rhs: RHS); - } - - #[lang = "bitor"] - pub trait BitOr<RHS = Self> { - type Output; - fn bitor(self, rhs: RHS) -> Self::Output; - } - - #[lang = "bitor_assign"] - pub trait BitOrAssign<RHS = Self> { - fn bitor_assign(&mut self, rhs: RHS); - } - - #[lang = "bitxor"] - pub trait BitXor<RHS = Self> { - type Output; - fn bitxor(self, rhs: RHS) -> Self::Output; - } - - #[lang = "bitxor_assign"] - pub trait BitXorAssign<RHS = Self> { - fn bitxor_assign(&mut self, rhs: RHS); - } - - #[lang = "neg"] - pub trait Neg { - type Output; - fn neg(self) -> Self::Output; - } - - #[lang = "not"] - pub trait Not { - type Output; - fn not(self) -> Self::Output; - } - - #[lang = "add"] - pub trait Add<RHS = Self> { - type Output; - fn add(self, r: RHS) -> Self::Output; - } - - macro_rules! impl_traits { - ($($i:ident)*) => ($( - impl Div<$i> for $i { - type Output = $i; - fn div(self, rhs: $i) -> $i { self / rhs } - } - impl Shl<$i> for $i { - type Output = $i; - fn shl(self, rhs: $i) -> $i { self << rhs } - } - impl Mul for $i { - type Output = $i; - fn mul(self, rhs: $i) -> $i { self * rhs } - } - - impl Sub for $i { - type Output = $i; - fn sub(self, rhs: $i) -> $i { self - rhs } - } - impl BitAnd for $i { - type Output = $i; - fn bitand(self, rhs: $i) -> $i { self & rhs } - } - impl BitAndAssign for $i { - fn bitand_assign(&mut self, rhs: $i) { *self &= rhs; } - } - impl BitOr for $i { - type Output = $i; - fn bitor(self, rhs: $i) -> $i { self | rhs } - } - impl BitOrAssign for $i { - fn bitor_assign(&mut self, rhs: $i) { *self |= rhs; } - } - impl BitXor for $i { - type Output = $i; - fn bitxor(self, rhs: $i) -> $i { self ^ rhs } - } - impl BitXorAssign for $i { - fn bitxor_assign(&mut self, rhs: $i) { *self ^= rhs; } - } - impl Neg for $i { - type Output = $i; - fn neg(self) -> $i { -self } - } - impl Not for $i { - type Output = $i; - fn not(self) -> $i { !self } - } - impl Add<$i> for $i { - type Output = $i; - fn add(self, other: $i) -> $i { self + other } - } - impl Copy for $i {} - impl Clone for $i { - fn clone(&self) -> $i { loop {} } - } - )*) - } - each_int!(impl_traits); - - pub mod mem { - pub fn size_of_val<T>(_: &T) -> usize { - 4 - } - pub const fn size_of<T>() -> usize { - 4 - } - } -} diff --git a/libc/src/fuchsia/align.rs b/libc/src/fuchsia/align.rs new file mode 100644 index 0000000..bc97275 --- /dev/null +++ b/libc/src/fuchsia/align.rs @@ -0,0 +1,142 @@ +macro_rules! expand_align { + () => { + s! { + #[cfg_attr( + any( + target_pointer_width = "32", + target_arch = "x86_64" + ), + repr(align(4)))] + #[cfg_attr( + not(any( + target_pointer_width = "32", + target_arch = "x86_64" + )), + repr(align(8)))] + pub struct pthread_mutexattr_t { + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct pthread_rwlockattr_t { + size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], + } + + #[repr(align(4))] + pub struct pthread_condattr_t { + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + + s_no_extra_traits! { + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "arm", + target_arch = "x86_64")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "arm", + target_arch = "x86_64"))), + repr(align(8)))] + pub struct pthread_mutex_t { + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "arm", + target_arch = "x86_64")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "arm", + target_arch = "x86_64"))), + repr(align(8)))] + pub struct pthread_rwlock_t { + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + #[cfg_attr(target_arch = "x86", + repr(align(4)))] + #[cfg_attr(not(target_arch = "x86"), + repr(align(8)))] + pub struct pthread_cond_t { + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + } + + cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for pthread_cond_t { + fn eq(&self, other: &pthread_cond_t) -> bool { + self.size + .iter() + .zip(other.size.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_cond_t {} + impl ::fmt::Debug for pthread_cond_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_cond_t") + // FIXME: .field("size", &self.size) + .finish() + } + } + impl ::hash::Hash for pthread_cond_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.size.hash(state); + } + } + + impl PartialEq for pthread_mutex_t { + fn eq(&self, other: &pthread_mutex_t) -> bool { + self.size + .iter() + .zip(other.size.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_mutex_t {} + impl ::fmt::Debug for pthread_mutex_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_mutex_t") + // FIXME: .field("size", &self.size) + .finish() + } + } + impl ::hash::Hash for pthread_mutex_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.size.hash(state); + } + } + + impl PartialEq for pthread_rwlock_t { + fn eq(&self, other: &pthread_rwlock_t) -> bool { + self.size + .iter() + .zip(other.size.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_rwlock_t {} + impl ::fmt::Debug for pthread_rwlock_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_rwlock_t") + // FIXME: .field("size", &self.size) + .finish() + } + } + impl ::hash::Hash for pthread_rwlock_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.size.hash(state); + } + } + } + } + } +} diff --git a/libc/src/fuchsia/mod.rs b/libc/src/fuchsia/mod.rs index e785fab..cef48e5 100644 --- a/libc/src/fuchsia/mod.rs +++ b/libc/src/fuchsia/mod.rs @@ -3,8 +3,6 @@ //! More functions and definitions can be found in the more specific modules //! according to the platform in question. -use dox::{mem, Option}; - // PUB_TYPE pub type int8_t = i8; @@ -100,10 +98,30 @@ pub type c_ulong = u64; // FIXME: why are these uninhabited types? that seems... wrong? // Presumably these should be `()` or an `extern type` (when that stabilizes). +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum DIR {} +impl ::Copy for DIR {} +impl ::Clone for DIR { + fn clone(&self) -> DIR { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum locale_t {} +impl ::Copy for locale_t {} +impl ::Clone for locale_t { + fn clone(&self) -> locale_t { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos64_t {} // TODO: fill this out with a struct +impl ::Copy for fpos64_t {} +impl ::Clone for fpos64_t { + fn clone(&self) -> fpos64_t { *self } +} // PUB_STRUCT @@ -182,9 +200,6 @@ s! { pub ru_nivcsw: c_long, #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] __pad14: u32, - - #[cfg(any(target_env = "musl", target_os = "emscripten"))] - __reserved: [c_long; 16], } pub struct in_addr { @@ -292,7 +307,7 @@ s! { pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, pub sa_flags: ::c_int, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, } pub struct termios { @@ -314,23 +329,6 @@ s! { pub l_pid: ::pid_t, } - pub struct sysinfo { - pub uptime: ::c_ulong, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub __reserved: [::c_char; 256], - } - pub struct ucred { pub pid: ::pid_t, pub uid: ::uid_t, @@ -357,17 +355,6 @@ s! { pub sin6_scope_id: u32, } - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 108] - } - - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - __ss_align: ::size_t, - __ss_pad2: [u8; 128 - 2 * 8], - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -437,15 +424,6 @@ s! { pub u64: ::uint64_t, } - pub struct utsname { - pub sysname: [::c_char; 65], - pub nodename: [::c_char; 65], - pub release: [::c_char; 65], - pub version: [::c_char; 65], - pub machine: [::c_char; 65], - pub domainname: [::c_char; 65] - } - pub struct lconv { pub decimal_point: *mut ::c_char, pub thousands_sep: *mut ::c_char, @@ -482,22 +460,6 @@ s! { pub __pad: [::c_char; 56 - 3 * 8 /* 8 == sizeof(long) */], } - 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; 256], - } - - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - pub struct rlimit64 { pub rlim_cur: rlim64_t, pub rlim_max: rlim64_t, @@ -526,122 +488,6 @@ s! { pub ifa_data: *mut ::c_void } - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "arm", - target_arch = "x86_64")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "arm", - target_arch = "x86_64")))), - repr(align(8)))] - pub struct pthread_mutex_t { - #[cfg(all(not(feature = "align"), - any(target_arch = "arm", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "arm", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "arm", - target_arch = "x86_64")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "arm", - target_arch = "x86_64")))), - repr(align(8)))] - pub struct pthread_rwlock_t { - #[cfg(all(not(feature = "align"), - any(target_arch = "arm", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "arm", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCK_T], - } - - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "32", - target_arch = "x86_64", - all(target_arch = "aarch64", target_env = "musl"))), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(any(target_pointer_width = "32", - target_arch = "x86_64", - all(target_arch = "aarch64", target_env = "musl")))), - repr(align(8)))] - pub struct pthread_mutexattr_t { - #[cfg(all(not(features = "align"), - any(target_arch = "x86_64", - all(target_arch = "aarch64", target_env = "musl"))))] - __align: [::c_int; 0], - #[cfg(all(not(features = "align"), - not(any(target_arch = "x86_64", - all(target_arch = "aarch64", target_env = "musl")))))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[cfg_attr(all(feature = "align", - any(target_env = "musl", target_pointer_width = "32")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(target_env = "musl"), - target_pointer_width = "64"), - repr(align(8)))] - pub struct pthread_rwlockattr_t { - #[cfg(all(not(feature = "align"), target_env = "musl"))] - __align: [::c_int; 0], - #[cfg(all(not(feature = "align"), not(target_env = "musl")))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - #[cfg_attr(all(feature = "align", - target_env = "musl", - target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - target_env = "musl", - target_pointer_width = "64"), - repr(align(8)))] - #[cfg_attr(all(feature = "align", - not(target_env = "musl"), - target_arch = "x86"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(target_env = "musl"), - not(target_arch = "x86")), - repr(align(8)))] - pub struct pthread_cond_t { - #[cfg(all(not(feature = "align"), target_env = "musl"))] - __align: [*const ::c_void; 0], - #[cfg(not(any(feature = "align", target_env = "musl")))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_condattr_t { - #[cfg(not(feature = "align"))] - __align: [::c_int; 0], - size: [u8; __SIZEOF_PTHREAD_CONDATTR_T], - } - pub struct passwd { pub pw_name: *mut ::c_char, pub pw_passwd: *mut ::c_char, @@ -1075,6 +921,302 @@ s! { } } +s_no_extra_traits! { + pub struct sysinfo { + pub uptime: ::c_ulong, + pub loads: [::c_ulong; 3], + pub totalram: ::c_ulong, + pub freeram: ::c_ulong, + pub sharedram: ::c_ulong, + pub bufferram: ::c_ulong, + pub totalswap: ::c_ulong, + pub freeswap: ::c_ulong, + pub procs: ::c_ushort, + pub pad: ::c_ushort, + pub totalhigh: ::c_ulong, + pub freehigh: ::c_ulong, + pub mem_unit: ::c_uint, + pub __reserved: [::c_char; 256], + } + + pub struct sockaddr_un { + pub sun_family: sa_family_t, + pub sun_path: [::c_char; 108] + } + + pub struct sockaddr_storage { + pub ss_family: sa_family_t, + __ss_align: ::size_t, + __ss_pad2: [u8; 128 - 2 * 8], + } + + pub struct utsname { + pub sysname: [::c_char; 65], + pub nodename: [::c_char; 65], + pub release: [::c_char; 65], + pub version: [::c_char; 65], + pub machine: [::c_char; 65], + pub domainname: [::c_char; 65] + } + + 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; 256], + } + + pub struct dirent64 { + pub d_ino: ::ino64_t, + pub d_off: ::off64_t, + pub d_reclen: ::c_ushort, + pub d_type: ::c_uchar, + pub d_name: [::c_char; 256], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for sysinfo { + fn eq(&self, other: &sysinfo) -> bool { + self.uptime == other.uptime + && self.loads == other.loads + && self.totalram == other.totalram + && self.freeram == other.freeram + && self.sharedram == other.sharedram + && self.bufferram == other.bufferram + && self.totalswap == other.totalswap + && self.freeswap == other.freeswap + && self.procs == other.procs + && self.pad == other.pad + && self.totalhigh == other.totalhigh + && self.freehigh == other.freehigh + && self.mem_unit == other.mem_unit + && self + .__reserved + .iter() + .zip(other.__reserved.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sysinfo {} + impl ::fmt::Debug for sysinfo { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sysinfo") + .field("uptime", &self.uptime) + .field("loads", &self.loads) + .field("totalram", &self.totalram) + .field("freeram", &self.freeram) + .field("sharedram", &self.sharedram) + .field("bufferram", &self.bufferram) + .field("totalswap", &self.totalswap) + .field("freeswap", &self.freeswap) + .field("procs", &self.procs) + .field("pad", &self.pad) + .field("totalhigh", &self.totalhigh) + .field("freehigh", &self.freehigh) + .field("mem_unit", &self.mem_unit) + // FIXME: .field("__reserved", &self.__reserved) + .finish() + } + } + impl ::hash::Hash for sysinfo { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.uptime.hash(state); + self.loads.hash(state); + self.totalram.hash(state); + self.freeram.hash(state); + self.sharedram.hash(state); + self.bufferram.hash(state); + self.totalswap.hash(state); + self.freeswap.hash(state); + self.procs.hash(state); + self.pad.hash(state); + self.totalhigh.hash(state); + self.freehigh.hash(state); + self.mem_unit.hash(state); + self.__reserved.hash(state); + } + } + + impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_family == other.sun_family + && self + .sun_path + .iter() + .zip(other.sun_path.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr_un {} + impl ::fmt::Debug for sockaddr_un { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_un") + .field("sun_family", &self.sun_family) + // FIXME: .field("sun_path", &self.sun_path) + .finish() + } + } + impl ::hash::Hash for sockaddr_un { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sun_family.hash(state); + self.sun_path.hash(state); + } + } + + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.ss_family == other.ss_family + && self.__ss_align == other.__ss_align + && self + .__ss_pad2 + .iter() + .zip(other.__ss_pad2.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for sockaddr_storage {} + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("ss_family", &self.ss_family) + .field("__ss_align", &self.__ss_align) + // FIXME: .field("__ss_pad2", &self.__ss_pad2) + .finish() + } + } + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ss_family.hash(state); + self.__ss_align.hash(state); + self.__ss_pad2.hash(state); + } + } + + impl PartialEq for utsname { + fn eq(&self, other: &utsname) -> bool { + self.sysname + .iter() + .zip(other.sysname.iter()) + .all(|(a,b)| a == b) + && self + .nodename + .iter() + .zip(other.nodename.iter()) + .all(|(a,b)| a == b) + && self + .release + .iter() + .zip(other.release.iter()) + .all(|(a,b)| a == b) + && self + .version + .iter() + .zip(other.version.iter()) + .all(|(a,b)| a == b) + && self + .machine + .iter() + .zip(other.machine.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for utsname {} + impl ::fmt::Debug for utsname { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utsname") + // FIXME: .field("sysname", &self.sysname) + // FIXME: .field("nodename", &self.nodename) + // FIXME: .field("release", &self.release) + // FIXME: .field("version", &self.version) + // FIXME: .field("machine", &self.machine) + .finish() + } + } + impl ::hash::Hash for utsname { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sysname.hash(state); + self.nodename.hash(state); + self.release.hash(state); + self.version.hash(state); + self.machine.hash(state); + } + } + + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent {} + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for dirent64 { + fn eq(&self, other: &dirent64) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent64 {} + impl ::fmt::Debug for dirent64 { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent64") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent64 { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + } +} + // PUB_CONST pub const INT_MIN: c_int = -2147483648; @@ -1701,7 +1843,7 @@ pub const WEXITED: ::c_int = 0x00000004; pub const WCONTINUED: ::c_int = 0x00000008; pub const WNOWAIT: ::c_int = 0x01000000; -// Options set using PTRACE_SETOPTIONS. +// ::Options set using PTRACE_SETOPTIONS. pub const PTRACE_O_TRACESYSGOOD: ::c_int = 0x00000001; pub const PTRACE_O_TRACEFORK: ::c_int = 0x00000002; pub const PTRACE_O_TRACEVFORK: ::c_int = 0x00000004; @@ -2920,20 +3062,20 @@ cfg_if! { f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; (*set).fds_bits[fd / size] &= !(1 << (fd % size)); return } pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 } pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; (*set).fds_bits[fd / size] |= 1 << (fd % size); return } @@ -2987,21 +3129,23 @@ f! { } pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc + let size_in_bits + = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); cpuset.bits[idx] |= 1 << offset; () } pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc + let size_in_bits + = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); cpuset.bits[idx] &= !(1 << offset); () } pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); + let size_in_bits = 8 * ::mem::size_of_val(&cpuset.bits[0]); let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); 0 != (cpuset.bits[idx] & (1 << offset)) } @@ -3042,8 +3186,18 @@ f! { #[link(name = "fdio")] extern {} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum FILE {} +impl ::Copy for FILE {} +impl ::Clone for FILE { + fn clone(&self) -> FILE { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos_t {} // TODO: fill this out with a struct +impl ::Copy for fpos_t {} +impl ::Clone for fpos_t { + fn clone(&self) -> fpos_t { *self } +} extern { pub fn isalnum(c: c_int) -> c_int; @@ -3371,7 +3525,7 @@ extern { pub fn pthread_detach(thread: ::pthread_t) -> ::c_int; pub fn sched_yield() -> ::c_int; pub fn pthread_key_create(key: *mut pthread_key_t, - dtor: Option<unsafe extern fn(*mut ::c_void)>) + dtor: ::Option<unsafe extern fn(*mut ::c_void)>) -> ::c_int; pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int; pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void; @@ -3876,7 +4030,7 @@ extern { pub fn glob(pattern: *const c_char, flags: ::c_int, - errfunc: Option<extern fn(epath: *const c_char, + errfunc: ::Option<extern fn(epath: *const c_char, errno: ::c_int) -> ::c_int>, pglob: *mut ::glob_t) -> ::c_int; pub fn globfree(pglob: *mut ::glob_t); @@ -4014,7 +4168,7 @@ extern { offset: *mut off_t, count: ::size_t) -> ::ssize_t; pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int; - pub fn getgrgid_r(uid: ::uid_t, + pub fn getgrgid_r(gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, @@ -4049,9 +4203,9 @@ extern { result: *mut *mut passwd) -> ::c_int; pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork(prepare: Option<unsafe extern fn()>, - parent: Option<unsafe extern fn()>, - child: Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; pub fn getgrgid(gid: ::gid_t) -> *mut ::group; pub fn getgrouplist(user: *const ::c_char, group: ::gid_t, @@ -4068,7 +4222,7 @@ extern { f: extern fn(*mut ::c_void) -> *mut ::c_void, value: *mut ::c_void) -> ::c_int; pub fn dl_iterate_phdr( - callback: Option<unsafe extern fn( + callback: ::Option<unsafe extern fn( info: *mut ::dl_phdr_info, size: ::size_t, data: *mut ::c_void @@ -4090,13 +4244,26 @@ cfg_if! { } cfg_if! { - if #[cfg(core_cvoid)] { - pub use core::ffi::c_void; + if #[cfg(libc_align)] { + #[macro_use] + mod align; + } else { + #[macro_use] + mod no_align; + } +} +expand_align!(); + +cfg_if! { + if #[cfg(libc_core_cvoid)] { + pub use ::ffi::c_void; } else { // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help // enable more optimization opportunities around it recognizing things // like malloc/free. #[repr(u8)] + #[allow(missing_copy_implementations)] + #[allow(missing_debug_implementations)] pub enum c_void { // Two dummy variants so the #[repr] attribute can be used. #[doc(hidden)] diff --git a/libc/src/fuchsia/no_align.rs b/libc/src/fuchsia/no_align.rs new file mode 100644 index 0000000..437da97 --- /dev/null +++ b/libc/src/fuchsia/no_align.rs @@ -0,0 +1,129 @@ +macro_rules! expand_align { + () => { + s! { + pub struct pthread_mutexattr_t { + #[cfg(target_arch = "x86_64")] + __align: [::c_int; 0], + #[cfg(not(target_arch = "x86_64"))] + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + pub struct pthread_rwlockattr_t { + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], + } + + pub struct pthread_condattr_t { + __align: [::c_int; 0], + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + + s_no_extra_traits! { + pub struct pthread_mutex_t { + #[cfg(any(target_arch = "arm", + all(target_arch = "x86_64", + target_pointer_width = "32")))] + __align: [::c_long; 0], + #[cfg(not(any(target_arch = "arm", + all(target_arch = "x86_64", + target_pointer_width = "32"))))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + pub struct pthread_rwlock_t { + __align: [::c_long; 0], + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + + pub struct pthread_cond_t { + __align: [*const ::c_void; 0], + #[cfg(not(target_env = "musl"))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + } + + cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for pthread_cond_t { + fn eq(&self, other: &pthread_cond_t) -> bool { + // Ignore __align field + self.size + .iter() + .zip(other.size.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_cond_t {} + impl ::fmt::Debug for pthread_cond_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_cond_t") + // Ignore __align field + // FIXME: .field("size", &self.size) + .finish() + } + } + impl ::hash::Hash for pthread_cond_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + // Ignore __align field + self.size.hash(state); + } + } + + impl PartialEq for pthread_mutex_t { + fn eq(&self, other: &pthread_mutex_t) -> bool { + // Ignore __align field + self.size + .iter() + .zip(other.size.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_mutex_t {} + impl ::fmt::Debug for pthread_mutex_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_mutex_t") + // Ignore __align field + // FIXME: .field("size", &self.size) + .finish() + } + } + impl ::hash::Hash for pthread_mutex_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + // Ignore __align field + self.size.hash(state); + } + } + + impl PartialEq for pthread_rwlock_t { + fn eq(&self, other: &pthread_rwlock_t) -> bool { + // Ignore __align field + self.size + .iter() + .zip(other.size.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_rwlock_t {} + impl ::fmt::Debug for pthread_rwlock_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_rwlock_t") + // Ignore __align field + // FIXME: .field("size", &self.size) + .finish() + } + } + impl ::hash::Hash for pthread_rwlock_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + // Ignore __align field + self.size.hash(state); + } + } + } + } + } +} diff --git a/libc/src/fuchsia/x86_64.rs b/libc/src/fuchsia/x86_64.rs index 2e4eccc..eb22099 100644 --- a/libc/src/fuchsia/x86_64.rs +++ b/libc/src/fuchsia/x86_64.rs @@ -51,15 +51,6 @@ s! { __private: [u64; 32], } - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 512], - } - pub struct ipc_perm { pub __ipc_perm_key: ::key_t, pub uid: ::uid_t, @@ -73,6 +64,59 @@ s! { } } +s_no_extra_traits! { + pub struct ucontext_t { + pub uc_flags: ::c_ulong, + pub uc_link: *mut ucontext_t, + pub uc_stack: ::stack_t, + pub uc_mcontext: mcontext_t, + pub uc_sigmask: ::sigset_t, + __private: [u8; 512], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for ucontext_t { + fn eq(&self, other: &ucontext_t) -> bool { + self.uc_flags == other.uc_flags + && self.uc_link == other.uc_link + && self.uc_stack == other.uc_stack + && self.uc_mcontext == other.uc_mcontext + && self.uc_sigmask == other.uc_sigmask + && self + .__private + .iter() + .zip(other.__private.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for ucontext_t {} + impl ::fmt::Debug for ucontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ucontext_t") + .field("uc_flags", &self.uc_flags) + .field("uc_link", &self.uc_link) + .field("uc_stack", &self.uc_stack) + .field("uc_mcontext", &self.uc_mcontext) + .field("uc_sigmask", &self.uc_sigmask) + // FIXME: .field("__private", &self.__private) + .finish() + } + } + impl ::hash::Hash for ucontext_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + self.__private.hash(state); + } + } + } +} + // Syscall table pub const SYS_read: ::c_long = 0; diff --git a/libc/src/hermit/aarch64.rs b/libc/src/hermit/aarch64.rs new file mode 100644 index 0000000..1a92e3b --- /dev/null +++ b/libc/src/hermit/aarch64.rs @@ -0,0 +1,2 @@ +pub type c_char = u8; +pub type wchar_t = u32; diff --git a/libc/src/hermit/mod.rs b/libc/src/hermit/mod.rs new file mode 100644 index 0000000..3e15175 --- /dev/null +++ b/libc/src/hermit/mod.rs @@ -0,0 +1,83 @@ +// Copyright 2018 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// libc port for HermitCore (https://hermitcore.org) +// +// Ported by Colin Fink <colin.finck@rwth-aachen.de> +// and Stefan Lankes <slankes@eonerc.rwth-aachen.de> + +pub type int8_t = i8; +pub type int16_t = i16; +pub type int32_t = i32; +pub type int64_t = i64; +pub type uint8_t = u8; +pub type uint16_t = u16; +pub type uint32_t = u32; +pub type uint64_t = u64; + +pub type c_schar = i8; +pub type c_uchar = u8; +pub type c_short = i16; +pub type c_ushort = u16; +pub type c_int = i32; +pub type c_uint = u32; +pub type c_float = f32; +pub type c_double = f64; +pub type c_longlong = i64; +pub type c_ulonglong = u64; +pub type intmax_t = i64; +pub type uintmax_t = u64; + +pub type size_t = usize; +pub type ptrdiff_t = isize; +pub type intptr_t = isize; +pub type uintptr_t = usize; +pub type ssize_t = isize; + +pub type c_long = i64; +pub type c_ulong = u64; + +pub type wint_t = u32; +pub type wctype_t = i64; + +pub type regoff_t = size_t; +pub type off_t = c_long; + +cfg_if! { + if #[cfg(target_arch = "aarch64")] { + mod aarch64; + pub use self::aarch64::*; + } else if #[cfg(target_arch = "x86_64")] { + mod x86_64; + pub use self::x86_64::*; + } else { + // Unknown target_arch + } +} + +cfg_if! { + if #[cfg(libc_core_cvoid)] { + pub use ::ffi::c_void; + } else { + // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help + // enable more optimization opportunities around it recognizing things + // like malloc/free. + #[repr(u8)] + #[allow(missing_copy_implementations)] + #[allow(missing_debug_implementations)] + pub enum c_void { + // Two dummy variants so the #[repr] attribute can be used. + #[doc(hidden)] + __variant1, + #[doc(hidden)] + __variant2, + } + } +} diff --git a/libc/src/hermit/x86_64.rs b/libc/src/hermit/x86_64.rs new file mode 100644 index 0000000..76ec3ce --- /dev/null +++ b/libc/src/hermit/x86_64.rs @@ -0,0 +1,2 @@ +pub type c_char = i8; +pub type wchar_t = i32; diff --git a/libc/src/lib.rs b/libc/src/lib.rs index 03e7804..baf6324 100644 --- a/libc/src/lib.rs +++ b/libc/src/lib.rs @@ -7,180 +7,91 @@ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. - -//! Crate docs - -#![allow(bad_style, overflowing_literals, improper_ctypes)] -#![crate_type = "rlib"] +//! libc - Raw FFI bindings to platforms' system libraries +//! +//! [Documentation for other platforms][pd]. +//! +//! [pd]: https://rust-lang.github.io/libc/#platform-specific-documentation #![crate_name = "libc"] -#![cfg_attr(cross_platform_docs, feature(no_core, lang_items, const_fn))] -#![cfg_attr(cross_platform_docs, no_core)] -#![doc( - html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", - html_favicon_url = "https://doc.rust-lang.org/favicon.ico" -)] -#![cfg_attr( - all(target_os = "linux", target_arch = "x86_64"), - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-linux-gnu" - ) -)] -#![cfg_attr( - all(target_os = "linux", target_arch = "x86"), - doc( - html_root_url = "https://rust-lang.github.io/libc/i686-unknown-linux-gnu" - ) -)] -#![cfg_attr( - all(target_os = "linux", target_arch = "arm"), - doc( - html_root_url = "https://rust-lang.github.io/libc/arm-unknown-linux-gnueabihf" - ) -)] -#![cfg_attr( - all(target_os = "linux", target_arch = "mips"), - doc( - html_root_url = "https://rust-lang.github.io/libc/mips-unknown-linux-gnu" - ) -)] -#![cfg_attr( - all(target_os = "linux", target_arch = "aarch64"), - doc( - html_root_url = "https://rust-lang.github.io/libc/aarch64-unknown-linux-gnu" - ) -)] -#![cfg_attr( - all(target_os = "linux", target_env = "musl"), - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-linux-musl" - ) -)] -#![cfg_attr( - all(target_os = "macos", target_arch = "x86_64"), - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-apple-darwin" - ) -)] -#![cfg_attr( - all(target_os = "macos", target_arch = "x86"), - doc(html_root_url = "https://rust-lang.github.io/libc/i686-apple-darwin") -)] -#![cfg_attr( - all(windows, target_arch = "x86_64", target_env = "gnu"), - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-pc-windows-gnu" - ) -)] -#![cfg_attr( - all(windows, target_arch = "x86", target_env = "gnu"), - doc( - html_root_url = "https://rust-lang.github.io/libc/i686-pc-windows-gnu" - ) -)] -#![cfg_attr( - all(windows, target_arch = "x86_64", target_env = "msvc"), - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-pc-windows-msvc" - ) -)] -#![cfg_attr( - all(windows, target_arch = "x86", target_env = "msvc"), - doc( - html_root_url = "https://rust-lang.github.io/libc/i686-pc-windows-msvc" - ) -)] -#![cfg_attr( - target_os = "android", - doc( - html_root_url = "https://rust-lang.github.io/libc/arm-linux-androideabi" - ) -)] -#![cfg_attr( - target_os = "freebsd", - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-freebsd" - ) -)] -#![cfg_attr( - target_os = "openbsd", - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-openbsd" - ) -)] -#![cfg_attr( - target_os = "bitrig", - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-bitrig" - ) -)] -#![cfg_attr( - target_os = "netbsd", - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-netbsd" - ) -)] -#![cfg_attr( - target_os = "dragonfly", - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-dragonfly" - ) -)] -#![cfg_attr( - target_os = "solaris", - doc( - html_root_url = "https://rust-lang.github.io/libc/x86_64-sun-solaris" - ) -)] -#![cfg_attr( - all(target_os = "emscripten", target_arch = "asmjs"), - doc( - html_root_url = "https://rust-lang.github.io/libc/asmjs-unknown-emscripten" - ) -)] -#![cfg_attr( - all(target_os = "emscripten", target_arch = "wasm32"), - doc( - html_root_url = "https://rust-lang.github.io/libc/wasm32-unknown-emscripten" - ) -)] +#![crate_type = "rlib"] +#![cfg_attr(not(feature = "rustc-dep-of-std"), deny(warnings))] +#![allow(bad_style, overflowing_literals, improper_ctypes, unknown_lints)] +// Attributes needed when building as part of the standard library #![cfg_attr( - all(target_os = "linux", target_arch = "sparc64"), - doc( - html_root_url = "https://rust-lang.github.io/libc/sparc64-unknown-linux-gnu" - ) + feature = "rustc-dep-of-std", + feature(cfg_target_vendor, link_cfg, no_core) )] -// Attributes needed when building as part of the standard library -#![cfg_attr(feature = "rustc-dep-of-std", feature(cfg_target_vendor))] -#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, repr_packed))] -#![cfg_attr(feature = "rustc-dep-of-std", feature(no_core))] +// Enable extra lints: +#![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))] +#![deny(missing_copy_implementations, safe_packed_borrows)] +#![no_std] #![cfg_attr(feature = "rustc-dep-of-std", no_core)] -#![cfg_attr(feature = "rustc-dep-of-std", allow(warnings))] -#![cfg_attr(not(any(feature = "use_std", feature = "rustc-dep-of-std")), no_std)] - -#[cfg(all(not(cross_platform_docs), feature = "use_std"))] -extern crate std as core; - -#[cfg(feature = "rustc-dep-of-std")] -extern crate rustc_std_workspace_core as core; -#[cfg(feature = "rustc-dep-of-std")] -#[allow(unused_imports)] -use core::iter; -#[cfg(feature = "rustc-dep-of-std")] -#[allow(unused_imports)] -use core::option; +#![cfg_attr(target_os = "redox", feature(static_nobundle))] #[macro_use] mod macros; -mod dox; +cfg_if! { + if #[cfg(feature = "rustc-dep-of-std")] { + extern crate rustc_std_workspace_core as core; + #[allow(unused_imports)] + use core::iter; + #[allow(unused_imports)] + use core::option; + } +} + +cfg_if! { + if #[cfg(libc_priv_mod_use)] { + #[cfg(libc_core_cvoid)] + #[allow(unused_imports)] + use core::ffi; + #[allow(unused_imports)] + use core::fmt; + #[allow(unused_imports)] + use core::hash; + #[allow(unused_imports)] + use core::num; + #[allow(unused_imports)] + use core::mem; + #[doc(hidden)] + #[allow(unused_imports)] + use core::clone::Clone; + #[doc(hidden)] + #[allow(unused_imports)] + use core::marker::Copy; + #[doc(hidden)] + #[allow(unused_imports)] + use core::option::Option; + } else { + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::fmt; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::hash; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::num; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::mem; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::clone::Clone; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::marker::Copy; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::option::Option; + } +} cfg_if! { if #[cfg(windows)] { mod windows; pub use windows::*; - } else if #[cfg(target_os = "redox")] { - mod redox; - pub use redox::*; } else if #[cfg(target_os = "cloudabi")] { mod cloudabi; pub use cloudabi::*; @@ -193,10 +104,16 @@ cfg_if! { } else if #[cfg(unix)] { mod unix; pub use unix::*; - } else if #[cfg(target_env = "sgx")] { + } else if #[cfg(target_os = "hermit")] { + mod hermit; + pub use hermit::*; + } else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] { mod sgx; pub use sgx::*; - } else { + } else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] { + mod wasi; + pub use wasi::*; + } else { // non-supported targets: empty... } } diff --git a/libc/src/macros.rs b/libc/src/macros.rs index 7720578..c48ae8b 100644 --- a/libc/src/macros.rs +++ b/libc/src/macros.rs @@ -6,46 +6,116 @@ /// /// This allows you to conveniently provide a long list #[cfg]'d blocks of code /// without having to rewrite each clause multiple times. +#[allow(unused_macros)] macro_rules! cfg_if { + // match if/else chains with a final `else` ($( if #[cfg($($meta:meta),*)] { $($it:item)* } ) else * else { $($it2:item)* }) => { - __cfg_if_items! { + cfg_if! { + @__items () ; $( ( ($($meta),*) ($($it)*) ), )* ( () ($($it2)*) ), } - } -} + }; -macro_rules! __cfg_if_items { - (($($not:meta,)*) ; ) => {}; - (($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => { - __cfg_if_apply! { cfg(all(not(any($($not),*)), $($m,)*)), $($it)* } - __cfg_if_items! { ($($not,)* $($m,)*) ; $($rest)* } - } -} + // match if/else chains lacking a final `else` + ( + if #[cfg($($i_met:meta),*)] { $($i_it:item)* } + $( + else if #[cfg($($e_met:meta),*)] { $($e_it:item)* } + )* + ) => { + cfg_if! { + @__items + () ; + ( ($($i_met),*) ($($i_it)*) ), + $( ( ($($e_met),*) ($($e_it)*) ), )* + ( () () ), + } + }; + + // Internal and recursive macro to emit all the items + // + // Collects all the negated cfgs in a list at the beginning and after the + // semicolon is all the remaining items + (@__items ($($not:meta,)*) ; ) => {}; + (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), + $($rest:tt)*) => { + // Emit all items within one block, applying an approprate #[cfg]. The + // #[cfg] will require all `$m` matchers specified and must also negate + // all previous matchers. + cfg_if! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* } -macro_rules! __cfg_if_apply { - ($m:meta, $($it:item)*) => { + // Recurse to emit all other items in `$rest`, and when we do so add all + // our `$m` matchers to the list of `$not` matchers as future emissions + // will have to negate everything we just matched as well. + cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* } + }; + + // Internal macro to Apply a cfg attribute to a list of items + (@__apply $m:meta, $($it:item)*) => { $(#[$m] $it)* - } + }; } +#[allow(unused_macros)] macro_rules! s { ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($( + s!(it: $(#[$attr])* pub $t $i { $($field)* }); + )*); + (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => ( + compile_error!("unions cannot derive extra traits, use s_no_extra_traits instead"); + ); + (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( __item! { #[repr(C)] + #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] $(#[$attr])* - pub $t $i { $($field)* } + pub struct $i { $($field)* } } - impl ::dox::Copy for $i {} - impl ::dox::Clone for $i { + impl ::Copy for $i {} + impl ::Clone for $i { fn clone(&self) -> $i { *self } } - )*) + ); +} + +#[allow(unused_macros)] +macro_rules! s_no_extra_traits { + ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($( + s_no_extra_traits!(it: $(#[$attr])* pub $t $i { $($field)* }); + )*); + (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => ( + cfg_if! { + if #[cfg(libc_union)] { + __item! { + #[repr(C)] + $(#[$attr])* + pub union $i { $($field)* } + } + + impl ::Copy for $i {} + impl ::Clone for $i { + fn clone(&self) -> $i { *self } + } + } + } + ); + (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( + __item! { + #[repr(C)] + $(#[$attr])* + pub struct $i { $($field)* } + } + impl ::Copy for $i {} + impl ::Clone for $i { + fn clone(&self) -> $i { *self } + } + ); } #[allow(unused_macros)] @@ -54,19 +124,13 @@ macro_rules! f { $($body:stmt);* })*) => ($( #[inline] - #[cfg(not(cross_platform_docs))] pub unsafe extern fn $i($($arg: $argty),*) -> $ret { $($body);* } - - #[cfg(cross_platform_docs)] - #[allow(dead_code)] - pub unsafe extern fn $i($($arg: $argty),*) -> $ret { - loop {} - } )*) } +#[allow(unused_macros)] macro_rules! __item { ($i:item) => { $i @@ -75,13 +139,15 @@ macro_rules! __item { #[allow(unused_macros)] macro_rules! align_const { - ($($(#[$attr:meta])* pub const $name:ident : $t1:ty = $t2:ident { $($field:tt)* };)*) => ($( - #[cfg(feature = "align")] + ($($(#[$attr:meta])* + pub const $name:ident : $t1:ty + = $t2:ident { $($field:tt)* };)*) => ($( + #[cfg(libc_align)] $(#[$attr])* pub const $name : $t1 = $t2 { $($field)* }; - #[cfg(not(feature = "align"))] + #[cfg(not(libc_align))] $(#[$attr])* pub const $name : $t1 = $t2 { $($field)* diff --git a/libc/src/redox/mod.rs b/libc/src/redox/mod.rs deleted file mode 100644 index 8dabd90..0000000 --- a/libc/src/redox/mod.rs +++ /dev/null @@ -1,394 +0,0 @@ -pub type int8_t = i8; -pub type int16_t = i16; -pub type int32_t = i32; -pub type int64_t = i64; -pub type uint8_t = u8; -pub type uint16_t = u16; -pub type uint32_t = u32; -pub type uint64_t = u64; - -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type size_t = usize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type ssize_t = isize; - -pub type c_char = i8; -pub type c_long = i64; -pub type c_ulong = u64; - -pub type wchar_t = i32; -pub type wint_t = u32; -pub type wctype_t = i64; - -pub type regoff_t = size_t; -pub type off_t = c_long; -pub type mode_t = c_int; -pub type time_t = c_long; -pub type pid_t = c_int; -pub type id_t = c_uint; -pub type gid_t = c_int; -pub type uid_t = c_int; -pub type dev_t = c_long; -pub type ino_t = c_ulong; -pub type nlink_t = c_ulong; -pub type blksize_t = c_long; -pub type blkcnt_t = c_ulong; - -pub type fsblkcnt_t = c_ulong; -pub type fsfilcnt_t = c_ulong; - -pub type useconds_t = c_uint; -pub type suseconds_t = c_int; - -pub type clock_t = c_long; -pub type clockid_t = c_int; -pub type timer_t = *mut c_void; - -pub type nfds_t = c_ulong; - -s! { - pub struct fd_set { - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], - } - - pub struct pollfd { - pub fd: ::c_int, - pub events: ::c_short, - pub revents: ::c_short, - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - - pub st_atime: ::timespec, - pub st_mtime: ::timespec, - pub st_ctime: ::timespec, - - _pad: [c_char; 24], - } - - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } -} - -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; - -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; - -pub const FD_SETSIZE: usize = 1024; - -pub const MAP_SHARED: ::c_int = 1; -pub const MAP_PRIVATE: ::c_int = 2; -pub const MAP_ANONYMOUS: ::c_int = 4; -pub const MAP_ANON: ::c_int = MAP_ANONYMOUS; - -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -pub const POLLIN: ::c_short = 0x001; -pub const POLLPRI: ::c_short = 0x002; -pub const POLLOUT: ::c_short = 0x004; -pub const POLLERR: ::c_short = 0x008; -pub const POLLHUP: ::c_short = 0x010; -pub const POLLNVAL: ::c_short = 0x020; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_EXEC: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_READ: ::c_int = 4; - -pub const S_ISUID: ::c_int = 0x800; -pub const S_ISGID: ::c_int = 0x400; -pub const S_ISVTX: ::c_int = 0x200; - -pub const S_IFIFO: mode_t = 0x1000; -pub const S_IFCHR: mode_t = 0x2000; -pub const S_IFBLK: mode_t = 0x6000; -pub const S_IFDIR: mode_t = 0x4000; -pub const S_IFREG: mode_t = 0x8000; -pub const S_IFLNK: mode_t = 0xA000; -pub const S_IFSOCK: mode_t = 0xC000; -pub const S_IFMT: mode_t = 0xF000; -pub const S_IEXEC: mode_t = 0x40; -pub const S_IWRITE: mode_t = 0x80; -pub const S_IREAD: mode_t = 0x100; -pub const S_IRWXU: mode_t = 0x1C0; -pub const S_IXUSR: mode_t = 0x40; -pub const S_IWUSR: mode_t = 0x80; -pub const S_IRUSR: mode_t = 0x100; -pub const S_IRWXG: mode_t = 0x38; -pub const S_IXGRP: mode_t = 0x8; -pub const S_IWGRP: mode_t = 0x10; -pub const S_IRGRP: mode_t = 0x20; -pub const S_IRWXO: mode_t = 0x7; -pub const S_IXOTH: mode_t = 0x1; -pub const S_IWOTH: mode_t = 0x2; -pub const S_IROTH: mode_t = 0x4; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; - -pub const FD_CLOEXEC: ::c_int = 0x0100_0000; - -pub const O_RDONLY: ::c_int = 0x0001_0000; -pub const O_WRONLY: ::c_int = 0x0002_0000; -pub const O_RDWR: ::c_int = 0x0003_0000; -pub const O_NONBLOCK: ::c_int = 0x0004_0000; -pub const O_APPEND: ::c_int = 0x0008_0000; -pub const O_SHLOCK: ::c_int = 0x0010_0000; -pub const O_EXLOCK: ::c_int = 0x0020_0000; -pub const O_ASYNC: ::c_int = 0x0040_0000; -pub const O_FSYNC: ::c_int = 0x0080_0000; -pub const O_CLOEXEC: ::c_int = 0x0100_0000; -pub const O_CREAT: ::c_int = 0x0200_0000; -pub const O_TRUNC: ::c_int = 0x0400_0000; -pub const O_EXCL: ::c_int = 0x0800_0000; -pub const O_DIRECTORY: ::c_int = 0x1000_0000; -pub const O_STAT: ::c_int = 0x2000_0000; -pub const O_SYMLINK: ::c_int = 0x4000_0000; -pub const O_NOFOLLOW: ::c_int = 0x8000_0000; -pub const O_ACCMODE: ::c_int = O_RDONLY | O_WRONLY | O_RDWR; - -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGTRAP: ::c_int = 5; -pub const SIGABRT: ::c_int = 6; -pub const SIGBUS: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGUSR1: ::c_int = 10; -pub const SIGSEGV: ::c_int = 11; -pub const SIGUSR2: ::c_int = 12; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGCHLD: ::c_int = 17; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGURG: ::c_int = 23; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGIO: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIGSYS: ::c_int = 31; - -pub enum FILE {} -pub enum fpos_t {} // TODO: fill this out with a struct - -// intentionally not public, only used for fd_set -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - const ULONG_SIZE: usize = 32; - } else if #[cfg(target_pointer_width = "64")] { - const ULONG_SIZE: usize = 64; - } else { - // Unknown target_pointer_width - } -} - -extern { - pub fn isalnum(c: c_int) -> c_int; - pub fn isalpha(c: c_int) -> c_int; - pub fn iscntrl(c: c_int) -> c_int; - pub fn isdigit(c: c_int) -> c_int; - pub fn isgraph(c: c_int) -> c_int; - pub fn islower(c: c_int) -> c_int; - pub fn isprint(c: c_int) -> c_int; - pub fn ispunct(c: c_int) -> c_int; - pub fn isspace(c: c_int) -> c_int; - pub fn isupper(c: c_int) -> c_int; - pub fn isxdigit(c: c_int) -> c_int; - pub fn tolower(c: c_int) -> c_int; - pub fn toupper(c: c_int) -> c_int; - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - pub fn freopen(filename: *const c_char, mode: *const c_char, - file: *mut FILE) -> *mut FILE; - pub fn fflush(file: *mut FILE) -> c_int; - pub fn fclose(file: *mut FILE) -> c_int; - pub fn remove(filename: *const c_char) -> c_int; - pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; - pub fn tmpfile() -> *mut FILE; - pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, - size: size_t) -> c_int; - pub fn setbuf(stream: *mut FILE, buf: *mut c_char); - pub fn getchar() -> c_int; - pub fn putchar(c: c_int) -> c_int; - pub fn fgetc(stream: *mut FILE) -> c_int; - pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; - pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; - pub fn puts(s: *const c_char) -> c_int; - pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, - stream: *mut FILE) -> size_t; - pub fn fwrite(ptr: *const c_void, size: size_t, nobj: size_t, - stream: *mut FILE) -> size_t; - pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; - pub fn ftell(stream: *mut FILE) -> c_long; - pub fn rewind(stream: *mut FILE); - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; - pub fn feof(stream: *mut FILE) -> c_int; - pub fn ferror(stream: *mut FILE) -> c_int; - pub fn perror(s: *const c_char); - pub fn atoi(s: *const c_char) -> c_int; - pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; - pub fn strtol(s: *const c_char, endp: *mut *mut c_char, - base: c_int) -> c_long; - pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, - base: c_int) -> c_ulong; - pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; - pub fn malloc(size: size_t) -> *mut c_void; - pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; - pub fn free(p: *mut c_void); - pub fn abort() -> !; - pub fn exit(status: c_int) -> !; - pub fn _exit(status: c_int) -> !; - pub fn atexit(cb: extern fn()) -> c_int; - pub fn system(s: *const c_char) -> c_int; - pub fn getenv(s: *const c_char) -> *mut c_char; - - pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; - pub fn strncpy(dst: *mut c_char, src: *const c_char, - n: size_t) -> *mut c_char; - pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; - pub fn strncat(s: *mut c_char, ct: *const c_char, - n: size_t) -> *mut c_char; - pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strncmp(cs: *const c_char, ct: *const c_char, - n: size_t) -> c_int; - pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strdup(cs: *const c_char) -> *mut c_char; - pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; - pub fn strncasecmp(s1: *const c_char, s2: *const c_char, - n: size_t) -> c_int; - pub fn strlen(cs: *const c_char) -> size_t; - pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; - pub fn strerror(n: c_int) -> *mut c_char; - pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; - pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; - pub fn wcslen(buf: *const wchar_t) -> size_t; - pub fn wcstombs(dest: *mut c_char, src: *const wchar_t, - n: size_t) -> ::size_t; - - pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memcpy(dest: *mut c_void, src: *const c_void, - n: size_t) -> *mut c_void; - pub fn memmove(dest: *mut c_void, src: *const c_void, - n: size_t) -> *mut c_void; - pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; - - pub fn abs(i: c_int) -> c_int; - pub fn atof(s: *const c_char) -> c_double; - pub fn labs(i: c_long) -> c_long; - pub fn rand() -> c_int; - pub fn srand(seed: c_uint); - - pub fn chown(path: *const c_char, uid: uid_t, gid: gid_t) -> ::c_int; - pub fn close(fd: ::c_int) -> ::c_int; - pub fn fchown(fd: ::c_int, uid: ::uid_t, gid: ::gid_t) -> ::c_int; - pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int; - pub fn fstat(fd: ::c_int, buf: *mut stat) -> ::c_int; - pub fn fsync(fd: ::c_int) -> ::c_int; - pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int; - pub fn getpid() -> pid_t; - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; - pub fn mmap(addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - flags: ::c_int, - fd: ::c_int, - offset: off_t) - -> *mut ::c_void; - pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) - -> ::c_int; - pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int; - pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int; - pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) -> ::ssize_t; - pub fn setenv(name: *const c_char, val: *const c_char, overwrite: ::c_int) - -> ::c_int; - pub fn unsetenv(name: *const c_char) -> ::c_int; - pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t) - -> ::ssize_t; -} - -#[link(name = "c")] -#[link(name = "m")] -extern {} - -pub use self::net::*; - -mod net; - -cfg_if! { - if #[cfg(core_cvoid)] { - pub use core::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} diff --git a/libc/src/redox/net.rs b/libc/src/redox/net.rs deleted file mode 100644 index fcbb181..0000000 --- a/libc/src/redox/net.rs +++ /dev/null @@ -1,124 +0,0 @@ -pub type in_addr_t = u32; -pub type in_port_t = u16; - -pub type socklen_t = u32; -pub type sa_family_t = u16; - -s! { - pub struct in_addr { - pub s_addr: in_addr_t, - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct in6_addr { - pub s6_addr: [u8; 16], - #[cfg(not(feature = "align"))] - __align: [u32; 0], - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct ipv6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: ::c_uint, - } - - pub struct linger { - pub l_onoff: ::c_int, - pub l_linger: ::c_int, - } - - pub struct sockaddr { - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_family: sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [u8; 8], - } - - pub struct sockaddr_in6 { - pub sin6_family: sa_family_t, - pub sin6_port: in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - pub __ss_padding: [u8; 26], - } -} - -pub const AF_INET: ::c_int = 2; -pub const AF_INET6: ::c_int = 23; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const IPPROTO_TCP: ::c_int = 6; -pub const IPPROTO_IP: ::c_int = 0; -pub const IPPROTO_IPV6: ::c_int = 41; - -pub const TCP_KEEPIDLE: ::c_int = 4; -pub const TCP_NODELAY: ::c_int = 8193; - -pub const IP_TTL: ::c_int = 8; -pub const IP_MULTICAST_LOOP: ::c_int = 9; -pub const IP_MULTICAST_TTL: ::c_int = 10; -pub const IP_ADD_MEMBERSHIP: ::c_int = 11; -pub const IP_DROP_MEMBERSHIP: ::c_int = 12; - -pub const IPV6_MULTICAST_LOOP: ::c_int = 19; -pub const IPV6_ADD_MEMBERSHIP: ::c_int = 20; -pub const IPV6_DROP_MEMBERSHIP: ::c_int = 21; -pub const IPV6_V6ONLY: ::c_int = 26; - -pub const SOL_SOCKET: ::c_int = 65535; - -pub const SO_REUSEADDR: ::c_int = 4; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_KEEPALIVE: ::c_int = 8; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_LINGER: ::c_int = 128; -pub const SO_SNDBUF: ::c_int = 4097; -pub const SO_RCVBUF: ::c_int = 4098; -pub const SO_ERROR: ::c_int = 4105; - -extern { - pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int; - pub fn bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t) -> ::c_int; - pub fn connect(socket: ::c_int, address: *const sockaddr, - len: socklen_t) -> ::c_int; - pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; - pub fn getsockname(socket: ::c_int, address: *mut sockaddr, - address_len: *mut socklen_t) -> ::c_int; - pub fn getsockopt(sockfd: ::c_int, - level: ::c_int, - optname: ::c_int, - optval: *mut ::c_void, - optlen: *mut ::socklen_t) -> ::c_int; - pub fn setsockopt(socket: ::c_int, level: ::c_int, name: ::c_int, - value: *const ::c_void, - option_len: socklen_t) -> ::c_int; - pub fn getpeername(socket: ::c_int, address: *mut sockaddr, - address_len: *mut socklen_t) -> ::c_int; - pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t, - flags: ::c_int, addr: *const sockaddr, - addrlen: socklen_t) -> ::ssize_t; - pub fn send(socket: ::c_int, buf: *const ::c_void, len: ::size_t, - flags: ::c_int) -> ::ssize_t; - pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, - flags: ::c_int, addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t) -> ::ssize_t; - pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, - flags: ::c_int) -> ::ssize_t; -} diff --git a/libc/src/sgx.rs b/libc/src/sgx.rs index 0451333..8a69ad3 100644 --- a/libc/src/sgx.rs +++ b/libc/src/sgx.rs @@ -36,13 +36,15 @@ pub const INT_MIN: c_int = -2147483648; pub const INT_MAX: c_int = 2147483647; cfg_if! { - if #[cfg(core_cvoid)] { - pub use core::ffi::c_void; + if #[cfg(libc_core_cvoid)] { + pub use ::ffi::c_void; } else { // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help // enable more optimization opportunities around it recognizing things // like malloc/free. #[repr(u8)] + #[allow(missing_copy_implementations)] + #[allow(missing_debug_implementations)] pub enum c_void { // Two dummy variants so the #[repr] attribute can be used. #[doc(hidden)] diff --git a/libc/src/switch.rs b/libc/src/switch.rs index e2d9b49..06fa203 100644 --- a/libc/src/switch.rs +++ b/libc/src/switch.rs @@ -38,13 +38,15 @@ pub const INT_MIN: c_int = -2147483648; pub const INT_MAX: c_int = 2147483647; cfg_if! { - if #[cfg(core_cvoid)] { - pub use core::ffi::c_void; + if #[cfg(libc_core_cvoid)] { + pub use ::ffi::c_void; } else { // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help // enable more optimization opportunities around it recognizing things // like malloc/free. #[repr(u8)] + #[allow(missing_copy_implementations)] + #[allow(missing_debug_implementations)] pub enum c_void { // Two dummy variants so the #[repr] attribute can be used. #[doc(hidden)] diff --git a/libc/src/unix/align.rs b/libc/src/unix/align.rs new file mode 100644 index 0000000..4fdba9a --- /dev/null +++ b/libc/src/unix/align.rs @@ -0,0 +1,6 @@ +s! { + #[repr(align(4))] + pub struct in6_addr { + pub s6_addr: [u8; 16], + } +} diff --git a/libc/src/unix/bsd/apple/b32.rs b/libc/src/unix/bsd/apple/b32.rs index 907ab02..13b1a0b 100644 --- a/libc/src/unix/bsd/apple/b32.rs +++ b/libc/src/unix/bsd/apple/b32.rs @@ -5,11 +5,6 @@ pub type c_ulong = u32; pub type boolean_t = ::c_int; s! { - pub struct pthread_attr_t { - __sig: c_long, - __opaque: [::c_char; 36] - } - pub struct if_data { pub ifi_type: ::c_uchar, pub ifi_typelen: ::c_uchar, @@ -50,6 +45,42 @@ s! { } } +s_no_extra_traits!{ + pub struct pthread_attr_t { + __sig: c_long, + __opaque: [::c_char; 36] + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for pthread_attr_t { + fn eq(&self, other: &pthread_attr_t) -> bool { + self.__sig == other.__sig + && self.__opaque + .iter() + .zip(other.__opaque.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_attr_t {} + impl ::fmt::Debug for pthread_attr_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_attr_t") + .field("__sig", &self.__sig) + // FIXME: .field("__opaque", &self.__opaque) + .finish() + } + } + impl ::hash::Hash for pthread_attr_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } + } + } +} + pub const __PTHREAD_MUTEX_SIZE__: usize = 40; pub const __PTHREAD_COND_SIZE__: usize = 24; pub const __PTHREAD_CONDATTR_SIZE__: usize = 4; diff --git a/libc/src/unix/bsd/apple/b64.rs b/libc/src/unix/bsd/apple/b64.rs index 8e8c87d..50b48fa 100644 --- a/libc/src/unix/bsd/apple/b64.rs +++ b/libc/src/unix/bsd/apple/b64.rs @@ -5,11 +5,6 @@ pub type c_ulong = u64; pub type boolean_t = ::c_uint; s! { - pub struct pthread_attr_t { - __sig: c_long, - __opaque: [::c_char; 56] - } - pub struct timeval32 { pub tv_sec: i32, pub tv_usec: i32, @@ -55,6 +50,42 @@ s! { } } +s_no_extra_traits!{ + pub struct pthread_attr_t { + __sig: c_long, + __opaque: [::c_char; 56] + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for pthread_attr_t { + fn eq(&self, other: &pthread_attr_t) -> bool { + self.__sig == other.__sig + && self.__opaque + .iter() + .zip(other.__opaque.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_attr_t {} + impl ::fmt::Debug for pthread_attr_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_attr_t") + .field("__sig", &self.__sig) + // FIXME: .field("__opaque", &self.__opaque) + .finish() + } + } + impl ::hash::Hash for pthread_attr_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } + } + } +} + pub const __PTHREAD_MUTEX_SIZE__: usize = 56; pub const __PTHREAD_COND_SIZE__: usize = 40; pub const __PTHREAD_CONDATTR_SIZE__: usize = 8; diff --git a/libc/src/unix/bsd/apple/mod.rs b/libc/src/unix/bsd/apple/mod.rs index 837efff..9483e90 100644 --- a/libc/src/unix/bsd/apple/mod.rs +++ b/libc/src/unix/bsd/apple/mod.rs @@ -1,8 +1,6 @@ //! Apple (ios/darwin)-specific definitions //! //! This covers *-apple-* triples currently -use dox::mem; - pub type c_char = i8; pub type clock_t = c_ulong; pub type time_t = c_long; @@ -33,10 +31,21 @@ pub type posix_spawnattr_t = *mut ::c_void; pub type posix_spawn_file_actions_t = *mut ::c_void; pub type key_t = ::c_int; pub type shmatt_t = ::c_ushort; +pub type vm_size_t = ::uintptr_t; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} s! { + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + pub struct aiocb { pub aio_fildes: ::c_int, pub aio_offset: ::off_t, @@ -47,17 +56,6 @@ s! { pub aio_lio_opcode: ::c_int } - pub struct utmpx { - pub ut_user: [::c_char; _UTX_USERSIZE], - pub ut_id: [::c_char; _UTX_IDSIZE], - pub ut_line: [::c_char; _UTX_LINESIZE], - pub ut_pid: ::pid_t, - pub ut_type: ::c_short, - pub ut_tv: ::timeval, - pub ut_host: [::c_char; _UTX_HOSTSIZE], - ut_pad: [::uint32_t; 16], - } - pub struct glob_t { pub gl_pathc: ::size_t, __unused1: ::c_int, @@ -74,14 +72,6 @@ s! { __unused8: *mut ::c_void, } - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_align: i64, - __ss_pad2: [u8; 112], - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -123,40 +113,16 @@ s! { pub st_qspare: [::int64_t; 2], } - pub struct dirent { - pub d_ino: u64, - pub d_seekoff: u64, - pub d_reclen: u16, - pub d_namlen: u16, - pub d_type: u8, - pub d_name: [::c_char; 1024], - } - - pub struct pthread_mutex_t { - __sig: ::c_long, - __opaque: [u8; __PTHREAD_MUTEX_SIZE__], - } - pub struct pthread_mutexattr_t { __sig: ::c_long, __opaque: [u8; 8], } - pub struct pthread_cond_t { - __sig: ::c_long, - __opaque: [u8; __PTHREAD_COND_SIZE__], - } - pub struct pthread_condattr_t { __sig: ::c_long, __opaque: [u8; __PTHREAD_CONDATTR_SIZE__], } - pub struct pthread_rwlock_t { - __sig: ::c_long, - __opaque: [u8; __PTHREAD_RWLOCK_SIZE__], - } - pub struct pthread_rwlockattr_t { __sig: ::c_long, __opaque: [u8; __PTHREAD_RWLOCKATTR_SIZE__], @@ -174,6 +140,7 @@ s! { } pub struct sigaction { + // FIXME: this field is actually a union pub sa_sigaction: ::sighandler_t, pub sa_mask: sigset_t, pub sa_flags: ::c_int, @@ -227,35 +194,6 @@ s! { pub sin_zero: [::c_char; 8], } - pub struct statfs { - pub f_bsize: ::uint32_t, - pub f_iosize: ::int32_t, - pub f_blocks: ::uint64_t, - pub f_bfree: ::uint64_t, - pub f_bavail: ::uint64_t, - pub f_files: ::uint64_t, - pub f_ffree: ::uint64_t, - pub f_fsid: ::fsid_t, - pub f_owner: ::uid_t, - pub f_type: ::uint32_t, - pub f_flags: ::uint32_t, - pub f_fssubtype: ::uint32_t, - pub f_fstypename: [::c_char; 16], - pub f_mntonname: [::c_char; 1024], - pub f_mntfromname: [::c_char; 1024], - pub f_reserved: [::uint32_t; 8], - } - - #[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))] - pub struct kevent { - pub ident: ::uintptr_t, - pub filter: ::int16_t, - pub flags: ::uint16_t, - pub fflags: ::uint32_t, - pub data: ::intptr_t, - pub udata: *mut ::c_void, - } - pub struct kevent64_s { pub ident: ::uint64_t, pub filter: ::int16_t, @@ -400,20 +338,6 @@ s! { pub ptinfo: proc_taskinfo, } - pub struct proc_threadinfo { - pub pth_user_time: u64, - pub pth_system_time: u64, - pub pth_cpu_usage: i32, - pub pth_policy: i32, - pub pth_run_state: i32, - pub pth_flags: i32, - pub pth_sleep_time: i32, - pub pth_curpri: i32, - pub pth_priority: i32, - pub pth_maxpriority: i32, - pub pth_name: [::c_char; MAXTHREADNAMESIZE], - } - pub struct xsw_usage { pub xsu_total: u64, pub xsu_avail: u64, @@ -544,7 +468,33 @@ s! { pub sem_flg: ::c_short, } - #[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))] + // sys/shm.h + + pub struct arphdr { + pub ar_hrd: u16, + pub ar_pro: u16, + pub ar_hln: u8, + pub ar_pln: u8, + pub ar_op: u16, + } + + pub struct in_addr { + pub s_addr: ::in_addr_t, + } +} + +s_no_extra_traits!{ + #[cfg_attr(libc_packedN, repr(packed(4)))] + pub struct kevent { + pub ident: ::uintptr_t, + pub filter: ::int16_t, + pub flags: ::uint16_t, + pub fflags: ::uint32_t, + pub data: ::intptr_t, + pub udata: *mut ::c_void, + } + + #[cfg_attr(libc_packedN, repr(packed(4)))] pub struct semid_ds { // Note the manpage shows different types than the system header. pub sem_perm: ipc_perm, @@ -557,15 +507,7 @@ s! { pub sem_pad3: [::int32_t; 4], } - pub union semun { - pub val: ::c_int, - pub buf: *mut semid_ds, - pub array: *mut ::c_ushort, - } - - // sys/shm.h - - #[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))] + #[cfg_attr(libc_packedN, repr(packed(4)))] pub struct shmid_ds { pub shm_perm: ipc_perm, pub shm_segsz: ::size_t, @@ -577,15 +519,630 @@ s! { pub shm_ctime: ::time_t, // FIXME: 64-bit wrong align => wrong offset // FIXME: 64-bit wrong align => wrong offset: pub shm_internal: *mut ::c_void, + } + pub struct proc_threadinfo { + pub pth_user_time: u64, + pub pth_system_time: u64, + pub pth_cpu_usage: i32, + pub pth_policy: i32, + pub pth_run_state: i32, + pub pth_flags: i32, + pub pth_sleep_time: i32, + pub pth_curpri: i32, + pub pth_priority: i32, + pub pth_maxpriority: i32, + pub pth_name: [::c_char; MAXTHREADNAMESIZE], } - pub struct arphdr { - pub ar_hrd: u16, - pub ar_pro: u16, - pub ar_hln: u8, - pub ar_pln: u8, - pub ar_op: u16, + pub struct statfs { + pub f_bsize: ::uint32_t, + pub f_iosize: ::int32_t, + pub f_blocks: ::uint64_t, + pub f_bfree: ::uint64_t, + pub f_bavail: ::uint64_t, + pub f_files: ::uint64_t, + pub f_ffree: ::uint64_t, + pub f_fsid: ::fsid_t, + pub f_owner: ::uid_t, + pub f_type: ::uint32_t, + pub f_flags: ::uint32_t, + pub f_fssubtype: ::uint32_t, + pub f_fstypename: [::c_char; 16], + pub f_mntonname: [::c_char; 1024], + pub f_mntfromname: [::c_char; 1024], + pub f_reserved: [::uint32_t; 8], + } + + pub struct dirent { + pub d_ino: u64, + pub d_seekoff: u64, + pub d_reclen: u16, + pub d_namlen: u16, + pub d_type: u8, + pub d_name: [::c_char; 1024], + } + + pub struct pthread_rwlock_t { + __sig: ::c_long, + __opaque: [u8; __PTHREAD_RWLOCK_SIZE__], + } + + pub struct pthread_mutex_t { + __sig: ::c_long, + __opaque: [u8; __PTHREAD_MUTEX_SIZE__], + } + + pub struct pthread_cond_t { + __sig: ::c_long, + __opaque: [u8; __PTHREAD_COND_SIZE__], + } + + pub struct sockaddr_storage { + pub ss_len: u8, + pub ss_family: ::sa_family_t, + __ss_pad1: [u8; 6], + __ss_align: i64, + __ss_pad2: [u8; 112], + } + + pub struct utmpx { + pub ut_user: [::c_char; _UTX_USERSIZE], + pub ut_id: [::c_char; _UTX_IDSIZE], + pub ut_line: [::c_char; _UTX_LINESIZE], + pub ut_pid: ::pid_t, + pub ut_type: ::c_short, + pub ut_tv: ::timeval, + pub ut_host: [::c_char; _UTX_HOSTSIZE], + ut_pad: [::uint32_t; 16], + } +} + +cfg_if! { + if #[cfg(libc_union)] { + s_no_extra_traits! { + pub union semun { + pub val: ::c_int, + pub buf: *mut semid_ds, + pub array: *mut ::c_ushort, + } + } + + cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for semun { + fn eq(&self, other: &semun) -> bool { + unsafe { self.val == other.val } + } + } + impl Eq for semun {} + impl ::fmt::Debug for semun { + fn fmt(&self, f: &mut ::fmt::Formatter) + -> ::fmt::Result { + f.debug_struct("semun") + .field("val", unsafe { &self.val }) + .finish() + } + } + impl ::hash::Hash for semun { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + unsafe { self.val.hash(state) }; + } + } + } + } + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for kevent { + fn eq(&self, other: &kevent) -> bool { + self.ident == other.ident + && self.filter == other.filter + && self.flags == other.flags + && self.fflags == other.fflags + && self.data == other.data + && self.udata == other.udata + } + } + impl Eq for kevent {} + impl ::fmt::Debug for kevent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let ident = self.ident; + let filter = self.filter; + let flags = self.flags; + let fflags = self.fflags; + let data = self.data; + let udata = self.udata; + f.debug_struct("kevent") + .field("ident", &ident) + .field("filter", &filter) + .field("flags", &flags) + .field("fflags", &fflags) + .field("data", &data) + .field("udata", &udata) + .finish() + } + } + impl ::hash::Hash for kevent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + let ident = self.ident; + let filter = self.filter; + let flags = self.flags; + let fflags = self.fflags; + let data = self.data; + let udata = self.udata; + ident.hash(state); + filter.hash(state); + flags.hash(state); + fflags.hash(state); + data.hash(state); + udata.hash(state); + } + } + + impl PartialEq for semid_ds { + fn eq(&self, other: &semid_ds) -> bool { + let sem_perm = self.sem_perm; + let sem_pad3 = self.sem_pad3; + let other_sem_perm = other.sem_perm; + let other_sem_pad3 = other.sem_pad3; + sem_perm == other_sem_perm + && self.sem_base == other.sem_base + && self.sem_nsems == other.sem_nsems + && self.sem_otime == other.sem_otime + && self.sem_pad1 == other.sem_pad1 + && self.sem_ctime == other.sem_ctime + && self.sem_pad2 == other.sem_pad2 + && sem_pad3 == other_sem_pad3 + } + } + impl Eq for semid_ds {} + impl ::fmt::Debug for semid_ds { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let sem_perm = self.sem_perm; + let sem_base = self.sem_base; + let sem_nsems = self.sem_nsems; + let sem_otime = self.sem_otime; + let sem_pad1 = self.sem_pad1; + let sem_ctime = self.sem_ctime; + let sem_pad2 = self.sem_pad2; + let sem_pad3 = self.sem_pad3; + f.debug_struct("semid_ds") + .field("sem_perm", &sem_perm) + .field("sem_base", &sem_base) + .field("sem_nsems", &sem_nsems) + .field("sem_otime", &sem_otime) + .field("sem_pad1", &sem_pad1) + .field("sem_ctime", &sem_ctime) + .field("sem_pad2", &sem_pad2) + .field("sem_pad3", &sem_pad3) + .finish() + } + } + impl ::hash::Hash for semid_ds { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + let sem_perm = self.sem_perm; + let sem_base = self.sem_base; + let sem_nsems = self.sem_nsems; + let sem_otime = self.sem_otime; + let sem_pad1 = self.sem_pad1; + let sem_ctime = self.sem_ctime; + let sem_pad2 = self.sem_pad2; + let sem_pad3 = self.sem_pad3; + sem_perm.hash(state); + sem_base.hash(state); + sem_nsems.hash(state); + sem_otime.hash(state); + sem_pad1.hash(state); + sem_ctime.hash(state); + sem_pad2.hash(state); + sem_pad3.hash(state); + } + } + + impl PartialEq for shmid_ds { + fn eq(&self, other: &shmid_ds) -> bool { + let shm_perm = self.shm_perm; + let other_shm_perm = other.shm_perm; + shm_perm == other_shm_perm + && self.shm_segsz == other.shm_segsz + && self.shm_lpid == other.shm_lpid + && self.shm_cpid == other.shm_cpid + && self.shm_nattch == other.shm_nattch + && self.shm_atime == other.shm_atime + && self.shm_dtime == other.shm_dtime + && self.shm_ctime == other.shm_ctime + && self.shm_internal == other.shm_internal + } + } + impl Eq for shmid_ds {} + impl ::fmt::Debug for shmid_ds { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let shm_perm = self.shm_perm; + let shm_segsz = self.shm_segsz; + let shm_lpid = self.shm_lpid; + let shm_cpid = self.shm_cpid; + let shm_nattch = self.shm_nattch; + let shm_atime = self.shm_atime; + let shm_dtime = self.shm_dtime; + let shm_ctime = self.shm_ctime; + let shm_internal = self.shm_internal; + f.debug_struct("shmid_ds") + .field("shm_perm", &shm_perm) + .field("shm_segsz", &shm_segsz) + .field("shm_lpid", &shm_lpid) + .field("shm_cpid", &shm_cpid) + .field("shm_nattch", &shm_nattch) + .field("shm_atime", &shm_atime) + .field("shm_dtime", &shm_dtime) + .field("shm_ctime", &shm_ctime) + .field("shm_internal", &shm_internal) + .finish() + } + } + impl ::hash::Hash for shmid_ds { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + let shm_perm = self.shm_perm; + let shm_segsz = self.shm_segsz; + let shm_lpid = self.shm_lpid; + let shm_cpid = self.shm_cpid; + let shm_nattch = self.shm_nattch; + let shm_atime = self.shm_atime; + let shm_dtime = self.shm_dtime; + let shm_ctime = self.shm_ctime; + let shm_internal = self.shm_internal; + shm_perm.hash(state); + shm_segsz.hash(state); + shm_lpid.hash(state); + shm_cpid.hash(state); + shm_nattch.hash(state); + shm_atime.hash(state); + shm_dtime.hash(state); + shm_ctime.hash(state); + shm_internal.hash(state); + } + } + + impl PartialEq for proc_threadinfo { + fn eq(&self, other: &proc_threadinfo) -> bool { + self.pth_user_time == other.pth_user_time + && self.pth_system_time == other.pth_system_time + && self.pth_cpu_usage == other.pth_cpu_usage + && self.pth_policy == other.pth_policy + && self.pth_run_state == other.pth_run_state + && self.pth_flags == other.pth_flags + && self.pth_sleep_time == other.pth_sleep_time + && self.pth_curpri == other.pth_curpri + && self.pth_priority == other.pth_priority + && self.pth_maxpriority == other.pth_maxpriority + && self.pth_name + .iter() + .zip(other.pth_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for proc_threadinfo {} + impl ::fmt::Debug for proc_threadinfo { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("proc_threadinfo") + .field("pth_user_time", &self.pth_user_time) + .field("pth_system_time", &self.pth_system_time) + .field("pth_cpu_usage", &self.pth_cpu_usage) + .field("pth_policy", &self.pth_policy) + .field("pth_run_state", &self.pth_run_state) + .field("pth_flags", &self.pth_flags) + .field("pth_sleep_time", &self.pth_sleep_time) + .field("pth_curpri", &self.pth_curpri) + .field("pth_priority", &self.pth_priority) + .field("pth_maxpriority", &self.pth_maxpriority) + // FIXME: .field("pth_name", &self.pth_name) + .finish() + } + } + impl ::hash::Hash for proc_threadinfo { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.pth_user_time.hash(state); + self.pth_system_time.hash(state); + self.pth_cpu_usage.hash(state); + self.pth_policy.hash(state); + self.pth_run_state.hash(state); + self.pth_flags.hash(state); + self.pth_sleep_time.hash(state); + self.pth_curpri.hash(state); + self.pth_priority.hash(state); + self.pth_maxpriority.hash(state); + self.pth_name.hash(state); + } + } + + impl PartialEq for statfs { + fn eq(&self, other: &statfs) -> bool { + self.f_bsize == other.f_bsize + && self.f_iosize == other.f_iosize + && self.f_blocks == other.f_blocks + && self.f_bfree == other.f_bfree + && self.f_bavail == other.f_bavail + && self.f_files == other.f_files + && self.f_ffree == other.f_ffree + && self.f_fsid == other.f_fsid + && self.f_owner == other.f_owner + && self.f_flags == other.f_flags + && self.f_fssubtype == other.f_fssubtype + && self.f_fstypename == other.f_fstypename + && self.f_type == other.f_type + && self + .f_mntonname + .iter() + .zip(other.f_mntonname.iter()) + .all(|(a,b)| a == b) + && self + .f_mntfromname + .iter() + .zip(other.f_mntfromname.iter()) + .all(|(a,b)| a == b) + && self.f_reserved == other.f_reserved + } + } + + impl Eq for statfs {} + impl ::fmt::Debug for statfs { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("statfs") + .field("f_bsize", &self.f_bsize) + .field("f_iosize", &self.f_iosize) + .field("f_blocks", &self.f_blocks) + .field("f_bfree", &self.f_bfree) + .field("f_bavail", &self.f_bavail) + .field("f_files", &self.f_files) + .field("f_ffree", &self.f_ffree) + .field("f_fsid", &self.f_fsid) + .field("f_owner", &self.f_owner) + .field("f_flags", &self.f_flags) + .field("f_fssubtype", &self.f_fssubtype) + .field("f_fstypename", &self.f_fstypename) + .field("f_type", &self.f_type) + // FIXME: .field("f_mntonname", &self.f_mntonname) + // FIXME: .field("f_mntfromname", &self.f_mntfromname) + .field("f_reserved", &self.f_reserved) + .finish() + } + } + + impl ::hash::Hash for statfs { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.f_bsize.hash(state); + self.f_iosize.hash(state); + self.f_blocks.hash(state); + self.f_bfree.hash(state); + self.f_bavail.hash(state); + self.f_files.hash(state); + self.f_ffree.hash(state); + self.f_fsid.hash(state); + self.f_owner.hash(state); + self.f_flags.hash(state); + self.f_fssubtype.hash(state); + self.f_fstypename.hash(state); + self.f_type.hash(state); + self.f_mntonname.hash(state); + self.f_mntfromname.hash(state); + self.f_reserved.hash(state); + } + } + + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_ino == other.d_ino + && self.d_seekoff == other.d_seekoff + && self.d_reclen == other.d_reclen + && self.d_namlen == other.d_namlen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent {} + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_ino", &self.d_ino) + .field("d_seekoff", &self.d_seekoff) + .field("d_reclen", &self.d_reclen) + .field("d_namlen", &self.d_namlen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_seekoff.hash(state); + self.d_reclen.hash(state); + self.d_namlen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + impl PartialEq for pthread_rwlock_t { + fn eq(&self, other: &pthread_rwlock_t) -> bool { + self.__sig == other.__sig + && self. + __opaque + .iter() + .zip(other.__opaque.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_rwlock_t {} + impl ::fmt::Debug for pthread_rwlock_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_rwlock_t") + .field("__sig", &self.__sig) + // FIXME: .field("__opaque", &self.__opaque) + .finish() + } + } + impl ::hash::Hash for pthread_rwlock_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } + } + + impl PartialEq for pthread_mutex_t { + fn eq(&self, other: &pthread_mutex_t) -> bool { + self.__sig == other.__sig + && self. + __opaque + .iter() + .zip(other.__opaque.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for pthread_mutex_t {} + + impl ::fmt::Debug for pthread_mutex_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_mutex_t") + .field("__sig", &self.__sig) + // FIXME: .field("__opaque", &self.__opaque) + .finish() + } + } + + impl ::hash::Hash for pthread_mutex_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } + } + + impl PartialEq for pthread_cond_t { + fn eq(&self, other: &pthread_cond_t) -> bool { + self.__sig == other.__sig + && self. + __opaque + .iter() + .zip(other.__opaque.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for pthread_cond_t {} + + impl ::fmt::Debug for pthread_cond_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_cond_t") + .field("__sig", &self.__sig) + // FIXME: .field("__opaque", &self.__opaque) + .finish() + } + } + + impl ::hash::Hash for pthread_cond_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } + } + + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.ss_len == other.ss_len + && self.ss_family == other.ss_family + && self + .__ss_pad1 + .iter() + .zip(other.__ss_pad1.iter()) + .all(|(a, b)| a == b) + && self.__ss_align == other.__ss_align + && self + .__ss_pad2 + .iter() + .zip(other.__ss_pad2.iter()) + .all(|(a, b)| a == b) + } + } + + impl Eq for sockaddr_storage {} + + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("ss_len", &self.ss_len) + .field("ss_family", &self.ss_family) + .field("__ss_pad1", &self.__ss_pad1) + .field("__ss_align", &self.__ss_align) + // FIXME: .field("__ss_pad2", &self.__ss_pad2) + .finish() + } + } + + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ss_len.hash(state); + self.ss_family.hash(state); + self.__ss_pad1.hash(state); + self.__ss_align.hash(state); + self.__ss_pad2.hash(state); + } + } + + impl PartialEq for utmpx { + fn eq(&self, other: &utmpx) -> bool { + self.ut_user + .iter() + .zip(other.ut_user.iter()) + .all(|(a,b)| a == b) + && self.ut_id == other.ut_id + && self.ut_line == other.ut_line + && self.ut_pid == other.ut_pid + && self.ut_type == other.ut_type + && self.ut_tv == other.ut_tv + && self + .ut_host + .iter() + .zip(other.ut_host.iter()) + .all(|(a,b)| a == b) + && self.ut_pad == other.ut_pad + } + } + + impl Eq for utmpx {} + + impl ::fmt::Debug for utmpx { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utmpx") + // FIXME: .field("ut_user", &self.ut_user) + .field("ut_id", &self.ut_id) + .field("ut_line", &self.ut_line) + .field("ut_pid", &self.ut_pid) + .field("ut_type", &self.ut_type) + .field("ut_tv", &self.ut_tv) + // FIXME: .field("ut_host", &self.ut_host) + .field("ut_pad", &self.ut_pad) + .finish() + } + } + + impl ::hash::Hash for utmpx { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ut_user.hash(state); + self.ut_id.hash(state); + self.ut_line.hash(state); + self.ut_pid.hash(state); + self.ut_type.hash(state); + self.ut_tv.hash(state); + self.ut_host.hash(state); + self.ut_pad.hash(state); + } + } } } @@ -1862,12 +2419,14 @@ pub const NOTE_NONE: ::uint32_t = 0x00000080; pub const NOTE_EXIT: ::uint32_t = 0x80000000; pub const NOTE_FORK: ::uint32_t = 0x40000000; pub const NOTE_EXEC: ::uint32_t = 0x20000000; +#[deprecated(since="0.2.49", note="Deprecated since MacOSX 10.9")] pub const NOTE_REAP: ::uint32_t = 0x10000000; pub const NOTE_SIGNAL: ::uint32_t = 0x08000000; pub const NOTE_EXITSTATUS: ::uint32_t = 0x04000000; pub const NOTE_EXIT_DETAIL: ::uint32_t = 0x02000000; pub const NOTE_PDATAMASK: ::uint32_t = 0x000fffff; pub const NOTE_PCTRLMASK: ::uint32_t = 0xfff00000; +#[deprecated(since="0.2.49", note="Deprecated since MacOSX 10.9")] pub const NOTE_EXIT_REPARENTED: ::uint32_t = 0x00080000; pub const NOTE_EXIT_DETAIL_MASK: ::uint32_t = 0x00070000; pub const NOTE_EXIT_DECRYPTFAIL: ::uint32_t = 0x00010000; @@ -2073,7 +2632,9 @@ pub const KERN_KDSETRTCDEC: ::c_int = 15; pub const KERN_KDGETENTROPY: ::c_int = 16; pub const KERN_KDWRITETR: ::c_int = 17; pub const KERN_KDWRITEMAP: ::c_int = 18; +#[deprecated(since = "0.2.49", note ="Removed in MacOSX 10.12")] pub const KERN_KDENABLE_BG_TRACE: ::c_int = 19; +#[deprecated(since = "0.2.49", note ="Removed in MacOSX 10.12")] pub const KERN_KDDISABLE_BG_TRACE: ::c_int = 20; pub const KERN_KDREADCURTHRMAP: ::c_int = 21; pub const KERN_KDSET_TYPEFILTER: ::c_int = 22; @@ -2384,9 +2945,18 @@ pub const SF_IMMUTABLE: ::c_uint = 0x00020000; pub const SF_APPEND: ::c_uint = 0x00040000; pub const UF_HIDDEN: ::c_uint = 0x00008000; -fn __DARWIN_ALIGN32(p: usize) -> usize { - const __DARWIN_ALIGNBYTES32: usize = mem::size_of::<u32>() - 1; - p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 +cfg_if! { + if #[cfg(libc_const_size_of)] { + fn __DARWIN_ALIGN32(p: usize) -> usize { + const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1; + p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 + } + } else { + fn __DARWIN_ALIGN32(p: usize) -> usize { + let __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1; + p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 + } + } } f! { @@ -2396,11 +2966,10 @@ f! { return ::CMSG_FIRSTHDR(mhdr); }; let cmsg_len = (*cmsg).cmsg_len as usize; - let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len as usize) - + __DARWIN_ALIGN32(mem::size_of::<::cmsghdr>()); + let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len as usize); let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next > max { + if next + __DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) > max { 0 as *mut ::cmsghdr } else { next as *mut ::cmsghdr @@ -2409,17 +2978,17 @@ f! { pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { (cmsg as *mut ::c_uchar) - .offset(__DARWIN_ALIGN32(mem::size_of::<::cmsghdr>()) as isize) + .offset(__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) as isize) } pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (__DARWIN_ALIGN32(mem::size_of::<::cmsghdr>()) + (__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) + __DARWIN_ALIGN32(length as usize)) as ::c_uint } pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - __DARWIN_ALIGN32(mem::size_of::<::cmsghdr>() + length as usize) + (__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) + length as usize) as ::c_uint } @@ -2445,6 +3014,16 @@ f! { } extern { + #[deprecated(since="0.2.49", note="Deprecated in MacOSX 10.5")] + #[link_name = "daemon$1050"] + pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; + #[deprecated(since="0.2.49", note="Deprecated in MacOSX 10.10")] + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + #[deprecated(since="0.2.49", note="Deprecated in MacOSX 10.10")] + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int; pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int; pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int; @@ -2589,6 +3168,7 @@ extern { name: *mut ::c_char, termp: *mut termios, winp: *mut ::winsize) -> ::pid_t; + pub fn login_tty(fd: ::c_int) -> ::c_int; pub fn duplocale(base: ::locale_t) -> ::locale_t; pub fn freelocale(loc: ::locale_t) -> ::c_int; pub fn localeconv_l(loc: ::locale_t) -> *mut lconv; diff --git a/libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 992d008..e91b351 100644 --- a/libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -1,3 +1,4 @@ +pub type c_char = i8; pub type clock_t = u64; pub type ino_t = u64; pub type lwpid_t = i32; @@ -15,34 +16,22 @@ pub type uuid_t = ::uuid; pub type fsblkcnt_t = u64; pub type fsfilcnt_t = u64; +pub type mqd_t = ::c_int; pub type sem_t = *mut sem; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum sem {} +impl ::Copy for sem {} +impl ::Clone for sem { + fn clone(&self) -> sem { *self } +} s! { - pub struct exit_status { pub e_termination: u16, pub e_exit: u16 } - pub struct utmpx { - pub ut_name: [::c_char; 32], - pub ut_id: [::c_char; 4], - - pub ut_line: [::c_char; 32], - pub ut_host: [::c_char; 256], - - pub ut_unused: [u8; 16], - pub ut_session: u16, - pub ut_type: u16, - pub ut_pid: ::pid_t, - ut_exit: exit_status, - ut_ss: ::sockaddr_storage, - pub ut_tv: ::timeval, - pub ut_unused2: [u8; 16], - } - pub struct aiocb { pub aio_fildes: ::c_int, pub aio_offset: ::off_t, @@ -55,15 +44,6 @@ s! { _aio_err: ::c_int } - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_namlen: u16, - pub d_type: u8, - __unused1: u8, - __unused2: u32, - pub d_name: [::c_char; 256], - } - pub struct uuid { pub time_low: u32, pub time_mid: u16, @@ -115,27 +95,6 @@ s! { pub f_uid_uuid: ::uuid_t, } - pub struct statfs { - pub f_bsize: ::c_long, - pub f_iosize: ::c_long, - pub f_blocks: ::c_long, - pub f_bfree: ::c_long, - pub f_bavail: ::c_long, - pub f_files: ::c_long, - pub f_ffree: ::c_long, - pub f_fsid: ::fsid_t, - pub f_owner: ::uid_t, - pub f_type: ::int32_t, - pub f_flags: ::int32_t, - pub f_syncwrites: ::c_long, - pub f_asyncwrites: ::c_long, - pub f_fstypename: [::c_char; 16], - pub f_mntonname: [::c_char; 90], - pub f_syncreads: ::c_long, - pub f_asyncreads: ::c_long, - pub f_mntfromname: [::c_char; 90], - } - pub struct stat { pub st_ino: ::ino_t, pub st_nlink: ::nlink_t, @@ -218,6 +177,230 @@ s! { } } +s_no_extra_traits! { + pub struct utmpx { + pub ut_name: [::c_char; 32], + pub ut_id: [::c_char; 4], + + pub ut_line: [::c_char; 32], + pub ut_host: [::c_char; 256], + + pub ut_unused: [u8; 16], + pub ut_session: u16, + pub ut_type: u16, + pub ut_pid: ::pid_t, + ut_exit: exit_status, + ut_ss: ::sockaddr_storage, + pub ut_tv: ::timeval, + pub ut_unused2: [u8; 16], + } + + pub struct dirent { + pub d_fileno: ::ino_t, + pub d_namlen: u16, + pub d_type: u8, + __unused1: u8, + __unused2: u32, + pub d_name: [::c_char; 256], + } + + pub struct statfs { + pub f_bsize: ::c_long, + pub f_iosize: ::c_long, + pub f_blocks: ::c_long, + pub f_bfree: ::c_long, + pub f_bavail: ::c_long, + pub f_files: ::c_long, + pub f_ffree: ::c_long, + pub f_fsid: ::fsid_t, + pub f_owner: ::uid_t, + pub f_type: ::int32_t, + pub f_flags: ::int32_t, + pub f_syncwrites: ::c_long, + pub f_asyncwrites: ::c_long, + pub f_fstypename: [::c_char; 16], + pub f_mntonname: [::c_char; 90], + pub f_syncreads: ::c_long, + pub f_asyncreads: ::c_long, + pub f_mntfromname: [::c_char; 90], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for utmpx { + fn eq(&self, other: &utmpx) -> bool { + self.ut_name == other.ut_name + && self.ut_id == other.ut_id + && self.ut_line == other.ut_line + && self + .ut_host + .iter() + .zip(other.ut_host.iter()) + .all(|(a,b)| a == b) + && self.ut_unused == other.ut_unused + && self.ut_session == other.ut_session + && self.ut_type == other.ut_type + && self.ut_pid == other.ut_pid + && self.ut_exit == other.ut_exit + && self.ut_ss == other.ut_ss + && self.ut_tv == other.ut_tv + && self.ut_unused2 == other.ut_unused2 + } + } + impl Eq for utmpx {} + impl ::fmt::Debug for utmpx { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utmpx") + .field("ut_name", &self.ut_name) + .field("ut_id", &self.ut_id) + .field("ut_line", &self.ut_line) + // FIXME: .field("ut_host", &self.ut_host) + .field("ut_unused", &self.ut_unused) + .field("ut_session", &self.ut_session) + .field("ut_type", &self.ut_type) + .field("ut_pid", &self.ut_pid) + .field("ut_exit", &self.ut_exit) + .field("ut_ss", &self.ut_ss) + .field("ut_tv", &self.ut_tv) + .field("ut_unused2", &self.ut_unused2) + .finish() + } + } + impl ::hash::Hash for utmpx { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ut_name.hash(state); + self.ut_id.hash(state); + self.ut_line.hash(state); + self.ut_host.hash(state); + self.ut_unused.hash(state); + self.ut_session.hash(state); + self.ut_type.hash(state); + self.ut_pid.hash(state); + self.ut_exit.hash(state); + self.ut_ss.hash(state); + self.ut_tv.hash(state); + self.ut_unused2.hash(state); + } + } + + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_fileno == other.d_fileno + && self.d_namlen == other.d_namlen + && self.d_type == other.d_type + // Ignore __unused1 + // Ignore __unused2 + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent {} + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_fileno", &self.d_fileno) + .field("d_namlen", &self.d_namlen) + .field("d_type", &self.d_type) + // Ignore __unused1 + // Ignore __unused2 + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_fileno.hash(state); + self.d_namlen.hash(state); + self.d_type.hash(state); + // Ignore __unused1 + // Ignore __unused2 + self.d_name.hash(state); + } + } + + impl PartialEq for statfs { + fn eq(&self, other: &statfs) -> bool { + self.f_bsize == other.f_bsize + && self.f_iosize == other.f_iosize + && self.f_blocks == other.f_blocks + && self.f_bfree == other.f_bfree + && self.f_bavail == other.f_bavail + && self.f_files == other.f_files + && self.f_ffree == other.f_ffree + && self.f_fsid == other.f_fsid + && self.f_owner == other.f_owner + && self.f_type == other.f_type + && self.f_flags == other.f_flags + && self.f_syncwrites == other.f_syncwrites + && self.f_asyncwrites == other.f_asyncwrites + && self.f_fstypename == other.f_fstypename + && self + .f_mntonname + .iter() + .zip(other.f_mntonname.iter()) + .all(|(a,b)| a == b) + && self.f_syncreads == other.f_syncreads + && self.f_asyncreads == other.f_asyncreads + && self + .f_mntfromname + .iter() + .zip(other.f_mntfromname.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for statfs {} + impl ::fmt::Debug for statfs { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("statfs") + .field("f_bsize", &self.f_bsize) + .field("f_iosize", &self.f_iosize) + .field("f_blocks", &self.f_blocks) + .field("f_bfree", &self.f_bfree) + .field("f_bavail", &self.f_bavail) + .field("f_files", &self.f_files) + .field("f_ffree", &self.f_ffree) + .field("f_fsid", &self.f_fsid) + .field("f_owner", &self.f_owner) + .field("f_type", &self.f_type) + .field("f_flags", &self.f_flags) + .field("f_syncwrites", &self.f_syncwrites) + .field("f_asyncwrites", &self.f_asyncwrites) + // FIXME: .field("f_mntonname", &self.f_mntonname) + .field("f_syncreads", &self.f_syncreads) + .field("f_asyncreads", &self.f_asyncreads) + // FIXME: .field("f_mntfromname", &self.f_mntfromname) + .finish() + } + } + impl ::hash::Hash for statfs { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.f_bsize.hash(state); + self.f_iosize.hash(state); + self.f_blocks.hash(state); + self.f_bfree.hash(state); + self.f_bavail.hash(state); + self.f_files.hash(state); + self.f_ffree.hash(state); + self.f_fsid.hash(state); + self.f_owner.hash(state); + self.f_type.hash(state); + self.f_flags.hash(state); + self.f_syncwrites.hash(state); + self.f_asyncwrites.hash(state); + self.f_fstypename.hash(state); + self.f_mntonname.hash(state); + self.f_syncreads.hash(state); + self.f_asyncreads.hash(state); + self.f_mntfromname.hash(state); + } + } + } +} + pub const RAND_MAX: ::c_int = 0x7fff_ffff; pub const PTHREAD_STACK_MIN: ::size_t = 16384; pub const SIGSTKSZ: ::size_t = 40960; @@ -795,29 +978,32 @@ fn _CMSG_ALIGN(n: usize) -> usize { f! { pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { (cmsg as *mut ::c_uchar) - .offset(_CMSG_ALIGN(mem::size_of::<::cmsghdr>()) as isize) + .offset(_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) } pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - _CMSG_ALIGN(mem::size_of::<::cmsghdr>()) + length as usize + (_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + length as usize) + as ::c_uint } pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) -> *mut ::cmsghdr { - let next = cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len) - + _CMSG_ALIGN(mem::size_of::<::cmsghdr>()); + let next = cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize) + + _CMSG_ALIGN(::mem::size_of::<::cmsghdr>()); let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; if next <= max { - (cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len)) as *mut ::cmsghdr + (cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize)) + as *mut ::cmsghdr } else { 0 as *mut ::cmsghdr } } pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - _CMSG_ALIGN(mem::size_of::<::cmsghdr>()) + _CMSG_ALIGN(length as usize) + (_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + + _CMSG_ALIGN(length as usize)) as ::c_uint } } diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs b/libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs index d33b475..996abc5 100644 --- a/libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs +++ b/libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs @@ -1,5 +1,4 @@ -use dox::mem; - +pub type c_char = u8; pub type c_long = i64; pub type c_ulong = u64; pub type time_t = i64; @@ -32,6 +31,14 @@ s! { } // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_longlong>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_longlong>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} + pub const MAP_32BIT: ::c_int = 0x00080000; diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/arm.rs b/libc/src/unix/bsd/freebsdlike/freebsd/arm.rs new file mode 100644 index 0000000..945aca9 --- /dev/null +++ b/libc/src/unix/bsd/freebsdlike/freebsd/arm.rs @@ -0,0 +1,47 @@ +pub type c_char = u8; +pub type c_long = i32; +pub type c_ulong = u32; +pub type time_t = i64; +pub type suseconds_t = i32; + +s! { + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::dev_t, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + pub st_atime_pad: ::c_long, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + pub st_mtime_pad: ::c_long, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + pub st_ctime_pad: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::blkcnt_t, + pub st_blksize: ::blksize_t, + pub st_flags: ::fflags_t, + pub st_gen: ::uint32_t, + pub st_lspare: ::int32_t, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + pub st_birthtime_pad: ::c_long, + } +} + +// should be pub(crate), but that requires Rust 1.18.0 +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 4 - 1; + } +} +pub const MAP_32BIT: ::c_int = 0x00080000; diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/mod.rs b/libc/src/unix/bsd/freebsdlike/freebsd/mod.rs index 91eab30..3ce96e8 100644 --- a/libc/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/libc/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -1,5 +1,3 @@ -use dox::mem; - pub type fflags_t = u32; pub type clock_t = i32; pub type ino_t = u32; @@ -17,21 +15,11 @@ pub type key_t = ::c_long; pub type msglen_t = ::c_ulong; pub type msgqnum_t = ::c_ulong; +pub type mqd_t = *mut ::c_void; pub type posix_spawnattr_t = *mut ::c_void; pub type posix_spawn_file_actions_t = *mut ::c_void; s! { - pub struct utmpx { - pub ut_type: ::c_short, - pub ut_tv: ::timeval, - pub ut_id: [::c_char; 8], - pub ut_pid: ::pid_t, - pub ut_user: [::c_char; 32], - pub ut_line: [::c_char; 16], - pub ut_host: [::c_char; 128], - pub __ut_spare: [::c_char; 64], - } - pub struct aiocb { pub aio_fildes: ::c_int, pub aio_offset: ::off_t, @@ -48,14 +36,6 @@ s! { pub aio_sigevent: sigevent } - pub struct dirent { - pub d_fileno: u32, - pub d_reclen: u16, - pub d_type: u8, - pub d_namlen: u8, - pub d_name: [::c_char; 256], - } - pub struct jail { pub version: u32, pub path: *mut ::c_char, @@ -101,31 +81,6 @@ s! { pub f_namemax: ::c_ulong, } - pub struct statfs { - pub f_version: ::uint32_t, - pub f_type: ::uint32_t, - pub f_flags: ::uint64_t, - pub f_bsize: ::uint64_t, - pub f_iosize: ::uint64_t, - pub f_blocks: ::uint64_t, - pub f_bfree: ::uint64_t, - pub f_bavail: ::int64_t, - pub f_files: ::uint64_t, - pub f_ffree: ::int64_t, - pub f_syncwrites: ::uint64_t, - pub f_asyncwrites: ::uint64_t, - pub f_syncreads: ::uint64_t, - pub f_asyncreads: ::uint64_t, - f_spare: [::uint64_t; 10], - pub f_namemax: ::uint32_t, - pub f_owner: ::uid_t, - pub f_fsid: ::fsid_t, - f_charspare: [::c_char; 80], - pub f_fstypename: [::c_char; 16], - pub f_mntfromname: [::c_char; 88], - pub f_mntonname: [::c_char; 88], - } - // internal structure has changed over time pub struct _sem { data: [u32; 4], @@ -174,6 +129,63 @@ s! { __cr_unused1: *mut ::c_void, } + pub struct stack_t { + pub ss_sp: *mut ::c_void, + pub ss_size: ::size_t, + pub ss_flags: ::c_int, + } + + pub struct mmsghdr { + pub msg_hdr: ::msghdr, + pub msg_len: ::ssize_t, + } +} + +s_no_extra_traits! { + pub struct utmpx { + pub ut_type: ::c_short, + pub ut_tv: ::timeval, + pub ut_id: [::c_char; 8], + pub ut_pid: ::pid_t, + pub ut_user: [::c_char; 32], + pub ut_line: [::c_char; 16], + pub ut_host: [::c_char; 128], + pub __ut_spare: [::c_char; 64], + } + + pub struct dirent { + pub d_fileno: u32, + pub d_reclen: u16, + pub d_type: u8, + pub d_namlen: u8, + pub d_name: [::c_char; 256], + } + + pub struct statfs { + pub f_version: ::uint32_t, + pub f_type: ::uint32_t, + pub f_flags: ::uint64_t, + pub f_bsize: ::uint64_t, + pub f_iosize: ::uint64_t, + pub f_blocks: ::uint64_t, + pub f_bfree: ::uint64_t, + pub f_bavail: ::int64_t, + pub f_files: ::uint64_t, + pub f_ffree: ::int64_t, + pub f_syncwrites: ::uint64_t, + pub f_asyncwrites: ::uint64_t, + pub f_syncreads: ::uint64_t, + pub f_asyncreads: ::uint64_t, + f_spare: [::uint64_t; 10], + pub f_namemax: ::uint32_t, + pub f_owner: ::uid_t, + pub f_fsid: ::fsid_t, + f_charspare: [::c_char; 80], + pub f_fstypename: [::c_char; 16], + pub f_mntfromname: [::c_char; 88], + pub f_mntonname: [::c_char; 88], + } + pub struct sockaddr_dl { pub sdl_len: ::c_uchar, pub sdl_family: ::c_uchar, @@ -184,11 +196,227 @@ s! { pub sdl_slen: ::c_uchar, pub sdl_data: [::c_char; 46], } +} - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for utmpx { + fn eq(&self, other: &utmpx) -> bool { + self.ut_type == other.ut_type + && self.ut_tv == other.ut_tv + && self.ut_id == other.ut_id + && self.ut_pid == other.ut_pid + && self.ut_user == other.ut_user + && self.ut_line == other.ut_line + && self + .ut_host + .iter() + .zip(other.ut_host.iter()) + .all(|(a,b)| a == b) + && self + .__ut_spare + .iter() + .zip(other.__ut_spare.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for utmpx {} + impl ::fmt::Debug for utmpx { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utmpx") + .field("ut_type", &self.ut_type) + .field("ut_tv", &self.ut_tv) + .field("ut_id", &self.ut_id) + .field("ut_pid", &self.ut_pid) + .field("ut_user", &self.ut_user) + .field("ut_line", &self.ut_line) + // FIXME: .field("ut_host", &self.ut_host) + // FIXME: .field("__ut_spare", &self.__ut_spare) + .finish() + } + } + impl ::hash::Hash for utmpx { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ut_type.hash(state); + self.ut_tv.hash(state); + self.ut_id.hash(state); + self.ut_pid.hash(state); + self.ut_user.hash(state); + self.ut_line.hash(state); + self.ut_host.hash(state); + self.__ut_spare.hash(state); + } + } + + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_fileno == other.d_fileno + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self.d_namlen == other.d_namlen + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent {} + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_fileno", &self.d_fileno) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + .field("d_namlen", &self.d_namlen) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_fileno.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_namlen.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for statfs { + fn eq(&self, other: &statfs) -> bool { + self.f_version == other.f_version + && self.f_type == other.f_type + && self.f_flags == other.f_flags + && self.f_bsize == other.f_bsize + && self.f_iosize == other.f_iosize + && self.f_blocks == other.f_blocks + && self.f_bfree == other.f_bfree + && self.f_bavail == other.f_bavail + && self.f_files == other.f_files + && self.f_ffree == other.f_ffree + && self.f_syncwrites == other.f_syncwrites + && self.f_asyncwrites == other.f_asyncwrites + && self.f_syncreads == other.f_syncreads + && self.f_asyncreads == other.f_asyncreads + && self.f_spare == other.f_spare + && self.f_namemax == other.f_namemax + && self.f_owner == other.f_owner + && self.f_fsid == other.f_fsid + && self + .f_charspare + .iter() + .zip(other.f_charspare.iter()) + .all(|(a,b)| a == b) + && self.f_fstypename == other.f_fstypename + && self + .f_mntfromname + .iter() + .zip(other.f_mntfromname.iter()) + .all(|(a,b)| a == b) + && self + .f_mntonname + .iter() + .zip(other.f_mntonname.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for statfs {} + impl ::fmt::Debug for statfs { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("statfs") + .field("f_bsize", &self.f_bsize) + .field("f_iosize", &self.f_iosize) + .field("f_blocks", &self.f_blocks) + .field("f_bfree", &self.f_bfree) + .field("f_bavail", &self.f_bavail) + .field("f_files", &self.f_files) + .field("f_ffree", &self.f_ffree) + .field("f_syncwrites", &self.f_syncwrites) + .field("f_asyncwrites", &self.f_asyncwrites) + .field("f_syncreads", &self.f_syncreads) + .field("f_asyncreads", &self.f_asyncreads) + .field("f_spare", &self.f_spare) + .field("f_namemax", &self.f_namemax) + .field("f_owner", &self.f_owner) + .field("f_fsid", &self.f_fsid) + // FIXME: .field("f_charspare", &self.f_charspare) + .field("f_fstypename", &self.f_fstypename) + // FIXME: .field("f_mntfromname", &self.f_mntfromname) + // FIXME: .field("f_mntonname", &self.f_mntonname) + .finish() + } + } + impl ::hash::Hash for statfs { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.f_version.hash(state); + self.f_type.hash(state); + self.f_flags.hash(state); + self.f_bsize.hash(state); + self.f_iosize.hash(state); + self.f_blocks.hash(state); + self.f_bfree.hash(state); + self.f_bavail.hash(state); + self.f_files.hash(state); + self.f_ffree.hash(state); + self.f_syncwrites.hash(state); + self.f_asyncwrites.hash(state); + self.f_syncreads.hash(state); + self.f_asyncreads.hash(state); + self.f_spare.hash(state); + self.f_namemax.hash(state); + self.f_owner.hash(state); + self.f_fsid.hash(state); + self.f_charspare.hash(state); + self.f_fstypename.hash(state); + self.f_mntfromname.hash(state); + self.f_mntonname.hash(state); + } + } + + impl PartialEq for sockaddr_dl { + fn eq(&self, other: &sockaddr_dl) -> bool { + self.sdl_len == other.sdl_len + && self.sdl_family == other.sdl_family + && self.sdl_index == other.sdl_index + && self.sdl_type == other.sdl_type + && self.sdl_nlen == other.sdl_nlen + && self.sdl_alen == other.sdl_alen + && self.sdl_slen == other.sdl_slen + && self + .sdl_data + .iter() + .zip(other.sdl_data.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr_dl {} + impl ::fmt::Debug for sockaddr_dl { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_dl") + .field("sdl_len", &self.sdl_len) + .field("sdl_family", &self.sdl_family) + .field("sdl_index", &self.sdl_index) + .field("sdl_type", &self.sdl_type) + .field("sdl_nlen", &self.sdl_nlen) + .field("sdl_alen", &self.sdl_alen) + .field("sdl_slen", &self.sdl_slen) + // FIXME: .field("sdl_data", &self.sdl_data) + .finish() + } + } + impl ::hash::Hash for sockaddr_dl { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sdl_len.hash(state); + self.sdl_family.hash(state); + self.sdl_index.hash(state); + self.sdl_type.hash(state); + self.sdl_nlen.hash(state); + self.sdl_alen.hash(state); + self.sdl_slen.hash(state); + self.sdl_data.hash(state); + } + } } } @@ -824,8 +1052,16 @@ pub const TCP_PCAP_OUT: ::c_int = 2048; pub const TCP_PCAP_IN: ::c_int = 4096; pub const IP_BINDANY: ::c_int = 24; +pub const IP_BINDMULTI: ::c_int = 25; +pub const IP_RSS_LISTEN_BUCKET: ::c_int = 26; +pub const IP_ORIGDSTADDR : ::c_int = 27; +pub const IP_RECVORIGDSTADDR : ::c_int = IP_ORIGDSTADDR; + pub const IP_RECVTOS: ::c_int = 68; +pub const IPV6_ORIGDSTADDR: ::c_int = 72; +pub const IPV6_RECVORIGDSTADDR: ::c_int = IPV6_ORIGDSTADDR; + pub const PF_SLOW: ::c_int = AF_SLOW; pub const PF_SCLUSTER: ::c_int = AF_SCLUSTER; pub const PF_ARP: ::c_int = AF_ARP; @@ -977,11 +1213,11 @@ fn _ALIGN(p: usize) -> usize { f! { pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { (cmsg as *mut ::c_uchar) - .offset(_ALIGN(mem::size_of::<::cmsghdr>()) as isize) + .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) } pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - _ALIGN(mem::size_of::<::cmsghdr>()) as ::c_uint + length + _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length } pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) @@ -991,7 +1227,7 @@ f! { return ::CMSG_FIRSTHDR(mhdr); }; let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) - + _ALIGN(mem::size_of::<::cmsghdr>()); + + _ALIGN(::mem::size_of::<::cmsghdr>()); let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; if next > max { @@ -1003,7 +1239,7 @@ f! { } pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (_ALIGN(mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) + (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) as ::c_uint } @@ -1097,6 +1333,7 @@ extern { pub fn aio_waitcomplete(iocbp: *mut *mut aiocb, timeout: *mut ::timespec) -> ::ssize_t; + pub fn mq_getfd_np(mqd: ::mqd_t) -> ::c_int; pub fn freelocale(loc: ::locale_t) -> ::c_int; pub fn waitid(idtype: idtype_t, id: ::id_t, infop: *mut ::siginfo_t, @@ -1199,6 +1436,11 @@ extern { pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int; pub fn __xuname(nmln: ::c_int, buf: *mut ::c_void) -> ::c_int; + + pub fn sendmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::size_t, + flags: ::c_int) -> ::ssize_t; + pub fn recvmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::size_t, + flags: ::c_int, timeout: *const ::timespec) -> ::ssize_t; } #[link(name = "util")] @@ -1219,6 +1461,12 @@ cfg_if! { } else if #[cfg(target_arch = "aarch64")] { mod aarch64; pub use self::aarch64::*; + } else if #[cfg(target_arch = "arm")] { + mod arm; + pub use self::arm::*; + } else if #[cfg(target_arch = "powerpc64")] { + mod powerpc64; + pub use self::powerpc64::*; } else { // Unknown target_arch } diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs b/libc/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs new file mode 100644 index 0000000..9d893b6 --- /dev/null +++ b/libc/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs @@ -0,0 +1,44 @@ +pub type c_char = u8; +pub type c_long = i64; +pub type c_ulong = u64; +pub type time_t = i64; +pub type suseconds_t = i64; + +s! { + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::dev_t, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::blkcnt_t, + pub st_blksize: ::blksize_t, + pub st_flags: ::fflags_t, + pub st_gen: ::uint32_t, + pub st_lspare: ::int32_t, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + } +} + +// should be pub(crate), but that requires Rust 1.18.0 +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} + +pub const MAP_32BIT: ::c_int = 0x00080000; diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/x86.rs b/libc/src/unix/bsd/freebsdlike/freebsd/x86.rs index a5495aa..845124d 100644 --- a/libc/src/unix/bsd/freebsdlike/freebsd/x86.rs +++ b/libc/src/unix/bsd/freebsdlike/freebsd/x86.rs @@ -1,5 +1,4 @@ -use dox::mem; - +pub type c_char = i8; pub type c_long = i32; pub type c_ulong = u32; pub type time_t = i32; @@ -33,5 +32,12 @@ s! { } // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_long>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/x86_64.rs b/libc/src/unix/bsd/freebsdlike/freebsd/x86_64.rs index 711feb7..323d1ab 100644 --- a/libc/src/unix/bsd/freebsdlike/freebsd/x86_64.rs +++ b/libc/src/unix/bsd/freebsdlike/freebsd/x86_64.rs @@ -1,5 +1,4 @@ -use dox::mem; - +pub type c_char = i8; pub type c_long = i64; pub type c_ulong = u64; pub type time_t = i64; @@ -32,6 +31,13 @@ s! { } // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_long>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} pub const MAP_32BIT: ::c_int = 0x00080000; diff --git a/libc/src/unix/bsd/freebsdlike/mod.rs b/libc/src/unix/bsd/freebsdlike/mod.rs index 22c11b3..7a82a45 100644 --- a/libc/src/unix/bsd/freebsdlike/mod.rs +++ b/libc/src/unix/bsd/freebsdlike/mod.rs @@ -1,9 +1,7 @@ -pub type c_char = i8; pub type dev_t = u32; pub type mode_t = u16; pub type pthread_attr_t = *mut ::c_void; pub type rlim_t = i64; -pub type mqd_t = *mut ::c_void; pub type pthread_mutex_t = *mut ::c_void; pub type pthread_mutexattr_t = *mut ::c_void; pub type pthread_cond_t = *mut ::c_void; @@ -15,10 +13,25 @@ pub type tcflag_t = ::c_uint; pub type speed_t = ::c_uint; pub type nl_item = ::c_int; pub type id_t = i64; +pub type vm_size_t = ::uintptr_t; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} s! { + pub struct in_addr { + pub s_addr: ::in_addr_t, + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + pub struct glob_t { pub gl_pathc: ::size_t, pub gl_matchc: ::size_t, @@ -42,14 +55,6 @@ s! { pub udata: *mut ::c_void, } - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_align: i64, - __ss_pad2: [u8; 112], - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -183,6 +188,55 @@ s! { } } +s_no_extra_traits! { + pub struct sockaddr_storage { + pub ss_len: u8, + pub ss_family: ::sa_family_t, + __ss_pad1: [u8; 6], + __ss_align: i64, + __ss_pad2: [u8; 112], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.ss_len == other.ss_len + && self.ss_family == other.ss_family + && self.__ss_pad1 == other.__ss_pad1 + && self.__ss_align == other.__ss_align + && self + .__ss_pad2 + .iter() + .zip(other.__ss_pad2.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for sockaddr_storage {} + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("ss_len", &self.ss_len) + .field("ss_family", &self.ss_family) + .field("__ss_pad1", &self.__ss_pad1) + .field("__ss_align", &self.__ss_align) + // FIXME: .field("__ss_pad2", &self.__ss_pad2) + .finish() + } + } + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ss_len.hash(state); + self.ss_family.hash(state); + self.__ss_pad1.hash(state); + self.__ss_align.hash(state); + self.__ss_pad2.hash(state); + } + } + } +} + pub const AIO_LISTIO_MAX: ::c_int = 16; pub const AIO_CANCELED: ::c_int = 1; pub const AIO_NOTCANCELED: ::c_int = 2; @@ -1034,6 +1088,14 @@ f! { } extern { + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; + + pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; + pub fn accept4(s: ::c_int, addr: *mut ::sockaddr, addrlen: *mut ::socklen_t, flags: ::c_int) -> ::c_int; pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int; @@ -1237,6 +1299,7 @@ extern { name: *mut ::c_char, termp: *mut termios, winp: *mut ::winsize) -> ::pid_t; + pub fn login_tty(fd: ::c_int) -> ::c_int; } cfg_if! { diff --git a/libc/src/unix/bsd/mod.rs b/libc/src/unix/bsd/mod.rs index 12f6e14..03c987d 100644 --- a/libc/src/unix/bsd/mod.rs +++ b/libc/src/unix/bsd/mod.rs @@ -1,5 +1,3 @@ -use dox::{mem, Option}; - pub type wchar_t = i32; pub type off_t = i64; pub type useconds_t = u32; @@ -25,12 +23,6 @@ s! { pub sin6_scope_id: u32, } - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [c_char; 104] - } - pub struct passwd { pub pw_name: *mut ::c_char, pub pw_passwd: *mut ::c_char, @@ -85,6 +77,39 @@ s! { pub tm_zone: *mut ::c_char, } + pub struct msghdr { + pub msg_name: *mut ::c_void, + pub msg_namelen: ::socklen_t, + pub msg_iov: *mut ::iovec, + pub msg_iovlen: ::c_int, + pub msg_control: *mut ::c_void, + pub msg_controllen: ::socklen_t, + pub msg_flags: ::c_int, + } + + pub struct cmsghdr { + pub cmsg_len: ::socklen_t, + pub cmsg_level: ::c_int, + pub cmsg_type: ::c_int, + } + + pub struct fsid_t { + __fsid_val: [::int32_t; 2], + } + + pub struct if_nameindex { + pub if_index: ::c_uint, + pub if_name: *mut ::c_char, + } +} + +s_no_extra_traits!{ + pub struct sockaddr_un { + pub sun_len: u8, + pub sun_family: sa_family_t, + pub sun_path: [c_char; 104] + } + pub struct utsname { #[cfg(not(target_os = "dragonfly"))] pub sysname: [::c_char; 256], @@ -108,29 +133,94 @@ s! { pub machine: [::c_char; 32], } - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - pub msg_flags: ::c_int, - } +} - pub struct cmsghdr { - pub cmsg_len: ::socklen_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_len == other.sun_len + && self.sun_family == other.sun_family + && self + .sun_path + .iter() + .zip(other.sun_path.iter()) + .all(|(a,b)| a == b) + } + } - pub struct fsid_t { - __fsid_val: [::int32_t; 2], - } + impl Eq for sockaddr_un {} - pub struct if_nameindex { - pub if_index: ::c_uint, - pub if_name: *mut ::c_char, + impl ::fmt::Debug for sockaddr_un { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_un") + .field("sun_len", &self.sun_len) + .field("sun_family", &self.sun_family) + // FIXME: .field("sun_path", &self.sun_path) + .finish() + } + } + + impl ::hash::Hash for sockaddr_un { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sun_len.hash(state); + self.sun_family.hash(state); + self.sun_path.hash(state); + } + } + + impl PartialEq for utsname { + fn eq(&self, other: &utsname) -> bool { + self.sysname + .iter() + .zip(other.sysname.iter()) + .all(|(a,b)| a == b) + && self + .nodename + .iter() + .zip(other.nodename.iter()) + .all(|(a,b)| a == b) + && self + .release + .iter() + .zip(other.release.iter()) + .all(|(a,b)| a == b) + && self + .version + .iter() + .zip(other.version.iter()) + .all(|(a,b)| a == b) + && self + .machine + .iter() + .zip(other.machine.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for utsname {} + + impl ::fmt::Debug for utsname { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utsname") + // FIXME: .field("sysname", &self.sysname) + // FIXME: .field("nodename", &self.nodename) + // FIXME: .field("release", &self.release) + // FIXME: .field("version", &self.version) + // FIXME: .field("machine", &self.machine) + .finish() + } + } + + impl ::hash::Hash for utsname { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sysname.hash(state); + self.nodename.hash(state); + self.release.hash(state); + self.version.hash(state); + self.machine.hash(state); + } + } } } @@ -343,7 +433,7 @@ pub const POLLWRBAND: ::c_short = 0x100; f! { pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr { - if (*mhdr).msg_controllen as usize >= mem::size_of::<::cmsghdr>() { + if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() { (*mhdr).msg_control as *mut ::cmsghdr } else { 0 as *mut ::cmsghdr @@ -351,20 +441,20 @@ f! { } pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); return } pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 } pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; (*set).fds_bits[fd / bits] |= 1 << (fd % bits); return @@ -435,7 +525,7 @@ extern { #[cfg_attr(target_os = "freebsd", link_name = "glob@FBSD_1.0")] pub fn glob(pattern: *const ::c_char, flags: ::c_int, - errfunc: Option<extern fn(epath: *const ::c_char, + errfunc: ::Option<extern fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, pglob: *mut ::glob_t) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] @@ -504,7 +594,7 @@ extern { pub fn sync(); #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r(uid: ::uid_t, + pub fn getgrgid_r(gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, @@ -533,7 +623,6 @@ extern { pub fn pthread_cancel(thread: ::pthread_t) -> ::c_int; pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")] pub fn getpwnam_r(name: *const ::c_char, @@ -553,9 +642,9 @@ extern { #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork(prepare: Option<unsafe extern fn()>, - parent: Option<unsafe extern fn()>, - child: Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; pub fn getgrgid(gid: ::gid_t) -> *mut ::group; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "popen$UNIX2003")] @@ -574,8 +663,7 @@ cfg_if! { if #[cfg(any(target_os = "macos", target_os = "ios"))] { mod apple; pub use self::apple::*; - } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd", - target_os = "bitrig"))] { + } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] { mod netbsdlike; pub use self::netbsdlike::*; } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { diff --git a/libc/src/unix/bsd/netbsdlike/mod.rs b/libc/src/unix/bsd/netbsdlike/mod.rs index 291c081..29b4dd7 100644 --- a/libc/src/unix/bsd/netbsdlike/mod.rs +++ b/libc/src/unix/bsd/netbsdlike/mod.rs @@ -1,5 +1,3 @@ -use dox::mem; - pub type time_t = i64; pub type mode_t = u32; pub type nlink_t = ::uint32_t; @@ -13,8 +11,18 @@ pub type clockid_t = ::c_int; pub type id_t = ::uint32_t; pub type sem_t = *mut sem; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum sem {} +impl ::Copy for sem {} +impl ::Clone for sem { + fn clone(&self) -> sem { *self } +} s! { pub struct sigaction { @@ -29,14 +37,6 @@ s! { pub ss_flags: ::c_int, } - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [::int8_t; 8], - } - pub struct in6_pktinfo { pub ipi6_addr: ::in6_addr, pub ipi6_ifindex: ::c_uint, @@ -595,58 +595,15 @@ pub const SF_APPEND: ::c_ulong = 0x00040000; pub const TIMER_ABSTIME: ::c_int = 1; -fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES -} - -f! { - pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { - (cmsg as *mut ::c_uchar) - .offset(_ALIGN(mem::size_of::<::cmsghdr>()) as isize) - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - _ALIGN(mem::size_of::<::cmsghdr>()) as ::c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) - -> *mut ::cmsghdr - { - if cmsg.is_null() { - return ::CMSG_FIRSTHDR(mhdr); - }; - let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) - + _ALIGN(mem::size_of::<::cmsghdr>()); - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next > max { - 0 as *mut ::cmsghdr - } else { - (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) - as *mut ::cmsghdr - } - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (_ALIGN(mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) - as ::c_uint - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - status >> 8 - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - (status & 0o177) != 0o177 && (status & 0o177) != 0 - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0o177) == 0o177 - } -} - #[link(name = "util")] extern { + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; + + pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_char) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__clock_getres50")] @@ -686,6 +643,7 @@ extern { name: *mut ::c_char, termp: *mut termios, winp: *mut ::winsize) -> ::pid_t; + pub fn login_tty(fd: ::c_int) -> ::c_int; pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int; pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int; @@ -718,7 +676,7 @@ cfg_if! { if #[cfg(target_os = "netbsd")] { mod netbsd; pub use self::netbsd::*; - } else if #[cfg(any(target_os = "openbsd", target_os = "bitrig"))] { + } else if #[cfg(target_os = "openbsd")] { mod openbsdlike; pub use self::openbsdlike::*; } else { diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs b/libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs index cda75bc..58c4cf7 100644 --- a/libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs +++ b/libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs @@ -1,5 +1,3 @@ -use dox::mem; - use PT_FIRSTMACH; pub type c_long = i64; @@ -8,8 +6,15 @@ pub type c_char = u8; pub type __cpu_simple_lock_nv_t = ::c_uchar; // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_int>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 4 - 1; + } +} pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 0; pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 1; diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/arm.rs b/libc/src/unix/bsd/netbsdlike/netbsd/arm.rs index 71c2cb7..4bf3ccd 100644 --- a/libc/src/unix/bsd/netbsdlike/netbsd/arm.rs +++ b/libc/src/unix/bsd/netbsdlike/netbsd/arm.rs @@ -1,5 +1,3 @@ -use dox::mem; - use PT_FIRSTMACH; pub type c_long = i32; @@ -8,8 +6,15 @@ pub type c_char = u8; pub type __cpu_simple_lock_nv_t = ::c_int; // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_longlong>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_longlong>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 2; diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/mod.rs b/libc/src/unix/bsd/netbsdlike/netbsd/mod.rs index d3acfb9..ad53c19 100644 --- a/libc/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/libc/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1,5 +1,3 @@ -use dox::mem; - pub type clock_t = ::c_uint; pub type suseconds_t = ::c_int; pub type dev_t = u64; @@ -9,6 +7,7 @@ pub type fsfilcnt_t = ::uint64_t; pub type idtype_t = ::c_int; pub type mqd_t = ::c_int; type __pthread_spin_t = __cpu_simple_lock_nv_t; +pub type vm_size_t = ::uintptr_t; s! { pub struct aiocb { @@ -24,14 +23,6 @@ s! { _retval: ::ssize_t } - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_reclen: u16, - pub d_namlen: u16, - pub d_type: u8, - pub d_name: [::c_char; 512], - } - pub struct glob_t { pub gl_pathc: ::size_t, pub gl_matchc: ::size_t, @@ -91,41 +82,7 @@ s! { pub st_spare: [::uint32_t; 2], } - pub struct statvfs { - pub f_flag: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_iosize: ::c_ulong, - - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_bresvd: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fresvd: ::fsfilcnt_t, - - pub f_syncreads: ::uint64_t, - pub f_syncwrites: ::uint64_t, - - pub f_asyncreads: ::uint64_t, - pub f_asyncwrites: ::uint64_t, - - pub f_fsidx: ::fsid_t, - pub f_fsid: ::c_ulong, - pub f_namemax: ::c_ulong, - pub f_owner: ::uid_t, - - pub f_spare: [::uint32_t; 4], - - pub f_fstypename: [::c_char; 32], - pub f_mntonname: [::c_char; 1024], - pub f_mntfromname: [::c_char; 1024], - } - - pub struct addrinfo { + pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, pub ai_socktype: ::c_int, @@ -136,14 +93,6 @@ s! { pub ai_next: *mut ::addrinfo, } - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_pad2: i64, - __ss_pad3: [u8; 112], - } - pub struct siginfo_t { pub si_signo: ::c_int, pub si_code: ::c_int, @@ -319,6 +268,13 @@ s! { pub sdl_data: [::c_char; 12], } + pub struct mmsghdr { + pub msg_hdr: ::msghdr, + pub msg_len: ::c_uint, + } +} + +s_no_extra_traits! { pub struct in_pktinfo { pub ipi_addr: ::in_addr, pub ipi_ifindex: ::c_uint, @@ -332,6 +288,377 @@ s! { pub ar_pln: u8, pub ar_op: u16, } + + #[repr(packed)] + pub struct in_addr { + pub s_addr: ::in_addr_t, + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + + pub struct sockaddr_in { + pub sin_len: u8, + pub sin_family: ::sa_family_t, + pub sin_port: ::in_port_t, + pub sin_addr: ::in_addr, + pub sin_zero: [::int8_t; 8], + } + + pub struct dirent { + pub d_fileno: ::ino_t, + pub d_reclen: u16, + pub d_namlen: u16, + pub d_type: u8, + pub d_name: [::c_char; 512], + } + + pub struct statvfs { + pub f_flag: ::c_ulong, + pub f_bsize: ::c_ulong, + pub f_frsize: ::c_ulong, + pub f_iosize: ::c_ulong, + + pub f_blocks: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_bavail: ::fsblkcnt_t, + pub f_bresvd: ::fsblkcnt_t, + + pub f_files: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + pub f_favail: ::fsfilcnt_t, + pub f_fresvd: ::fsfilcnt_t, + + pub f_syncreads: ::uint64_t, + pub f_syncwrites: ::uint64_t, + + pub f_asyncreads: ::uint64_t, + pub f_asyncwrites: ::uint64_t, + + pub f_fsidx: ::fsid_t, + pub f_fsid: ::c_ulong, + pub f_namemax: ::c_ulong, + pub f_owner: ::uid_t, + + pub f_spare: [::uint32_t; 4], + + pub f_fstypename: [::c_char; 32], + pub f_mntonname: [::c_char; 1024], + pub f_mntfromname: [::c_char; 1024], + } + + pub struct sockaddr_storage { + pub ss_len: u8, + pub ss_family: ::sa_family_t, + __ss_pad1: [u8; 6], + __ss_pad2: i64, + __ss_pad3: [u8; 112], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for in_pktinfo { + fn eq(&self, other: &in_pktinfo) -> bool { + self.ipi_addr == other.ipi_addr + && self.ipi_ifindex == other.ipi_ifindex + } + } + impl Eq for in_pktinfo {} + impl ::fmt::Debug for in_pktinfo { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("in_pktinfo") + .field("ipi_addr", &self.ipi_addr) + .field("ipi_ifindex", &self.ipi_ifindex) + .finish() + } + } + impl ::hash::Hash for in_pktinfo { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ipi_addr.hash(state); + self.ipi_ifindex.hash(state); + } + } + + impl PartialEq for arphdr { + fn eq(&self, other: &arphdr) -> bool { + self.ar_hrd == other.ar_hrd + && self.ar_pro == other.ar_pro + && self.ar_hln == other.ar_hln + && self.ar_pln == other.ar_pln + && self.ar_op == other.ar_op + } + } + impl Eq for arphdr {} + impl ::fmt::Debug for arphdr { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let ar_hrd = self.ar_hrd; + let ar_pro = self.ar_pro; + let ar_op = self.ar_op; + f.debug_struct("arphdr") + .field("ar_hrd", &ar_hrd) + .field("ar_pro", &ar_pro) + .field("ar_hln", &self.ar_hln) + .field("ar_pln", &self.ar_pln) + .field("ar_op", &ar_op) + .finish() + } + } + impl ::hash::Hash for arphdr { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + let ar_hrd = self.ar_hrd; + let ar_pro = self.ar_pro; + let ar_op = self.ar_op; + ar_hrd.hash(state); + ar_pro.hash(state); + self.ar_hln.hash(state); + self.ar_pln.hash(state); + ar_op.hash(state); + } + } + + impl PartialEq for in_addr { + fn eq(&self, other: &in_addr) -> bool { + self.s_addr == other.s_addr + } + } + impl Eq for in_addr {} + impl ::fmt::Debug for in_addr { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let s_addr = self.s_addr; + f.debug_struct("in_addr") + .field("s_addr", &s_addr) + .finish() + } + } + impl ::hash::Hash for in_addr { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + let s_addr = self.s_addr; + s_addr.hash(state); + } + } + + impl PartialEq for ip_mreq { + fn eq(&self, other: &ip_mreq) -> bool { + self.imr_multiaddr == other.imr_multiaddr + && self.imr_interface == other.imr_interface + } + } + impl Eq for ip_mreq {} + impl ::fmt::Debug for ip_mreq { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ip_mreq") + .field("imr_multiaddr", &self.imr_multiaddr) + .field("imr_interface", &self.imr_interface) + .finish() + } + } + impl ::hash::Hash for ip_mreq { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.imr_multiaddr.hash(state); + self.imr_interface.hash(state); + } + } + + impl PartialEq for sockaddr_in { + fn eq(&self, other: &sockaddr_in) -> bool { + self.sin_len == other.sin_len + && self.sin_family == other.sin_family + && self.sin_port == other.sin_port + && self.sin_addr == other.sin_addr + && self.sin_zero == other.sin_zero + } + } + impl Eq for sockaddr_in {} + impl ::fmt::Debug for sockaddr_in { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_in") + .field("sin_len", &self.sin_len) + .field("sin_family", &self.sin_family) + .field("sin_port", &self.sin_port) + .field("sin_addr", &self.sin_addr) + .field("sin_zero", &self.sin_zero) + .finish() + } + } + impl ::hash::Hash for sockaddr_in { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sin_len.hash(state); + self.sin_family.hash(state); + self.sin_port.hash(state); + self.sin_addr.hash(state); + self.sin_zero.hash(state); + } + } + + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_fileno == other.d_fileno + && self.d_reclen == other.d_reclen + && self.d_namlen == other.d_namlen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent {} + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_fileno", &self.d_fileno) + .field("d_reclen", &self.d_reclen) + .field("d_namlen", &self.d_namlen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_fileno.hash(state); + self.d_reclen.hash(state); + self.d_namlen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for statvfs { + fn eq(&self, other: &statvfs) -> bool { + self.f_flag == other.f_flag + && self.f_bsize == other.f_bsize + && self.f_frsize == other.f_frsize + && self.f_iosize == other.f_iosize + && self.f_blocks == other.f_blocks + && self.f_bfree == other.f_bfree + && self.f_bavail == other.f_bavail + && self.f_bresvd == other.f_bresvd + && self.f_files == other.f_files + && self.f_ffree == other.f_ffree + && self.f_favail == other.f_favail + && self.f_fresvd == other.f_fresvd + && self.f_syncreads == other.f_syncreads + && self.f_syncwrites == other.f_syncwrites + && self.f_asyncreads == other.f_asyncreads + && self.f_asyncwrites == other.f_asyncwrites + && self.f_fsidx == other.f_fsidx + && self.f_fsid == other.f_fsid + && self.f_namemax == other.f_namemax + && self.f_owner == other.f_owner + && self.f_spare == other.f_spare + && self.f_fstypename == other.f_fstypename + && self + .f_mntonname + .iter() + .zip(other.f_mntonname.iter()) + .all(|(a,b)| a == b) + && self + .f_mntfromname + .iter() + .zip(other.f_mntfromname.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for statvfs {} + impl ::fmt::Debug for statvfs { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("statvfs") + .field("f_flag", &self.f_flag) + .field("f_bsize", &self.f_bsize) + .field("f_frsize", &self.f_frsize) + .field("f_iosize", &self.f_iosize) + .field("f_blocks", &self.f_blocks) + .field("f_bfree", &self.f_bfree) + .field("f_bavail", &self.f_bavail) + .field("f_bresvd", &self.f_bresvd) + .field("f_files", &self.f_files) + .field("f_ffree", &self.f_ffree) + .field("f_favail", &self.f_favail) + .field("f_fresvd", &self.f_fresvd) + .field("f_syncreads", &self.f_syncreads) + .field("f_syncwrites", &self.f_syncwrites) + .field("f_asyncreads", &self.f_asyncreads) + .field("f_asyncwrites", &self.f_asyncwrites) + .field("f_fsidx", &self.f_fsidx) + .field("f_fsid", &self.f_fsid) + .field("f_namemax", &self.f_namemax) + .field("f_owner", &self.f_owner) + .field("f_spare", &self.f_spare) + .field("f_fstypename", &self.f_fstypename) + // FIXME: .field("f_mntonname", &self.f_mntonname) + // FIXME: .field("f_mntfromname", &self.f_mntfromname) + .finish() + } + } + impl ::hash::Hash for statvfs { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.f_flag.hash(state); + self.f_bsize.hash(state); + self.f_frsize.hash(state); + self.f_iosize.hash(state); + self.f_blocks.hash(state); + self.f_bfree.hash(state); + self.f_bavail.hash(state); + self.f_bresvd.hash(state); + self.f_files.hash(state); + self.f_ffree.hash(state); + self.f_favail.hash(state); + self.f_fresvd.hash(state); + self.f_syncreads.hash(state); + self.f_syncwrites.hash(state); + self.f_asyncreads.hash(state); + self.f_asyncwrites.hash(state); + self.f_fsidx.hash(state); + self.f_fsid.hash(state); + self.f_namemax.hash(state); + self.f_owner.hash(state); + self.f_spare.hash(state); + self.f_fstypename.hash(state); + self.f_mntonname.hash(state); + self.f_mntfromname.hash(state); + } + } + + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.ss_len == other.ss_len + && self.ss_family == other.ss_family + && self.__ss_pad1 == other.__ss_pad1 + && self.__ss_pad2 == other.__ss_pad2 + && self + .__ss_pad3 + .iter() + .zip(other.__ss_pad3.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr_storage {} + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("ss_len", &self.ss_len) + .field("ss_family", &self.ss_family) + .field("__ss_pad1", &self.__ss_pad1) + .field("__ss_pad2", &self.__ss_pad2) + // FIXME: .field("__ss_pad3", &self.__ss_pad3) + .finish() + } + } + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ss_len.hash(state); + self.ss_family.hash(state); + self.__ss_pad1.hash(state); + self.__ss_pad2.hash(state); + self.__ss_pad3.hash(state); + } + } + } } pub const AT_FDCWD: ::c_int = -100; @@ -708,21 +1035,32 @@ pub const FD_SETSIZE: usize = 0x100; pub const ST_NOSUID: ::c_ulong = 8; -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - ptm_magic: 0x33330003, - ptm_errorcheck: 0, - #[cfg(any(target_arch = "sparc", target_arch = "sparc64", - target_arch = "x86", target_arch = "x86_64"))] - ptm_pad1: [0; 3], - ptm_unused: 0, - #[cfg(any(target_arch = "sparc", target_arch = "sparc64", - target_arch = "x86", target_arch = "x86_64"))] - ptm_pad2: [0; 3], - ptm_waiters: 0 as *mut _, - ptm_owner: 0, - ptm_recursed: 0, - ptm_spare2: 0 as *mut _, -}; +cfg_if! { + if #[cfg(any(target_arch = "sparc", target_arch = "sparc64", + target_arch = "x86", target_arch = "x86_64"))] { + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + ptm_magic: 0x33330003, + ptm_errorcheck: 0, + ptm_pad1: [0; 3], + ptm_unused: 0, + ptm_pad2: [0; 3], + ptm_waiters: 0 as *mut _, + ptm_owner: 0, + ptm_recursed: 0, + ptm_spare2: 0 as *mut _, + }; + } else { + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + ptm_magic: 0x33330003, + ptm_errorcheck: 0, + ptm_unused: 0, + ptm_waiters: 0 as *mut _, + ptm_owner: 0, + ptm_recursed: 0, + ptm_spare2: 0 as *mut _, + }; + } +} pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { ptc_magic: 0x55550005, @@ -1018,10 +1356,58 @@ pub const SF_SNAPSHOT: ::c_ulong = 0x00200000; pub const SF_LOG: ::c_ulong = 0x00400000; pub const SF_SNAPINVAL: ::c_ulong = 0x00800000; -// dirfd() is a macro on netbsd to access -// the first field of the struct where dirp points to: -// http://cvsweb.netbsd.org/bsdweb.cgi/src/include/dirent.h?rev=1.36 +fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES +} + f! { + pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { + (cmsg as *mut ::c_uchar) + .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) + } + + pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { + _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length + } + + pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) + -> *mut ::cmsghdr + { + if cmsg.is_null() { + return ::CMSG_FIRSTHDR(mhdr); + }; + let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + + _ALIGN(::mem::size_of::<::cmsghdr>()); + let max = (*mhdr).msg_control as usize + + (*mhdr).msg_controllen as usize; + if next > max { + 0 as *mut ::cmsghdr + } else { + (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) + as *mut ::cmsghdr + } + } + + pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) + as ::c_uint + } + + pub fn WSTOPSIG(status: ::c_int) -> ::c_int { + status >> 8 + } + + pub fn WIFSIGNALED(status: ::c_int) -> bool { + (status & 0o177) != 0o177 && (status & 0o177) != 0 + } + + pub fn WIFSTOPPED(status: ::c_int) -> bool { + (status & 0o177) == 0o177 + } + + // dirfd() is a macro on netbsd to access + // the first field of the struct where dirp points to: + // http://cvsweb.netbsd.org/bsdweb.cgi/src/include/dirent.h?rev=1.36 pub fn dirfd(dirp: *mut ::DIR) -> ::c_int { *(dirp as *const ::c_int) } @@ -1036,7 +1422,7 @@ f! { } else { 0 }; - mem::size_of::<sockcred>() + mem::size_of::<::gid_t>() * ngrps + ::mem::size_of::<sockcred>() + ::mem::size_of::<::gid_t>() * ngrps } } @@ -1199,6 +1585,11 @@ extern { pub fn settimeofday(tv: *const ::timeval, tz: *const ::c_void) -> ::c_int; pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int; + + pub fn sendmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::c_uint, + flags: ::c_int) -> ::c_int; + pub fn recvmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::c_uint, + flags: ::c_int, timeout: *mut ::timespec) -> ::c_int; } #[link(name = "util")] diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs b/libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs index 3c682c3..e12fd5e 100644 --- a/libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs +++ b/libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs @@ -1,5 +1,3 @@ -use dox::mem; - use PT_FIRSTMACH; pub type c_long = i32; @@ -8,8 +6,15 @@ pub type c_char = u8; pub type __cpu_simple_lock_nv_t = ::c_int; // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_double>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_double>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} pub const PT_STEP: ::c_int = PT_FIRSTMACH + 0; pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/x86.rs b/libc/src/unix/bsd/netbsdlike/netbsd/x86.rs index 4da9968..daa89a1 100644 --- a/libc/src/unix/bsd/netbsdlike/netbsd/x86.rs +++ b/libc/src/unix/bsd/netbsdlike/netbsd/x86.rs @@ -1,10 +1,15 @@ -use dox::mem; - pub type c_long = i32; pub type c_ulong = u32; pub type c_char = i8; pub type __cpu_simple_lock_nv_t = ::c_uchar; // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_int>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 4 - 1; + } +} diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs b/libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs index af1b8f8..0860d4f 100644 --- a/libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs +++ b/libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs @@ -1,5 +1,3 @@ -use dox::mem; - use PT_FIRSTMACH; pub type c_long = i64; @@ -8,8 +6,15 @@ pub type c_char = i8; pub type __cpu_simple_lock_nv_t = ::c_uchar; // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_long>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} pub const PT_STEP: ::c_int = PT_FIRSTMACH + 0; pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; diff --git a/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/mod.rs b/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/mod.rs deleted file mode 100644 index e5f0219..0000000 --- a/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/mod.rs +++ /dev/null @@ -1,113 +0,0 @@ -pub type c_char = i8; - -s! { - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } -} - -pub const LC_COLLATE_MASK: ::c_int = (1 << 0); -pub const LC_CTYPE_MASK: ::c_int = (1 << 1); -pub const LC_MESSAGES_MASK: ::c_int = (1 << 2); -pub const LC_MONETARY_MASK: ::c_int = (1 << 3); -pub const LC_NUMERIC_MASK: ::c_int = (1 << 4); -pub const LC_TIME_MASK: ::c_int = (1 << 5); -pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK - | LC_CTYPE_MASK - | LC_MESSAGES_MASK - | LC_MONETARY_MASK - | LC_NUMERIC_MASK - | LC_TIME_MASK; - -pub const ERA: ::nl_item = 52; -pub const ERA_D_FMT: ::nl_item = 53; -pub const ERA_D_T_FMT: ::nl_item = 54; -pub const ERA_T_FMT: ::nl_item = 55; -pub const ALT_DIGITS: ::nl_item = 56; - -pub const D_MD_ORDER: ::nl_item = 57; - -pub const ALTMON_1: ::nl_item = 58; -pub const ALTMON_2: ::nl_item = 59; -pub const ALTMON_3: ::nl_item = 60; -pub const ALTMON_4: ::nl_item = 61; -pub const ALTMON_5: ::nl_item = 62; -pub const ALTMON_6: ::nl_item = 63; -pub const ALTMON_7: ::nl_item = 64; -pub const ALTMON_8: ::nl_item = 65; -pub const ALTMON_9: ::nl_item = 66; -pub const ALTMON_10: ::nl_item = 67; -pub const ALTMON_11: ::nl_item = 68; -pub const ALTMON_12: ::nl_item = 69; - -pub const KERN_RND: ::c_int = 31; - -// https://github.com/bitrig/bitrig/blob/master/sys/net/if.h#L187 -pub const IFF_UP: ::c_int = 0x1; // interface is up -pub const IFF_BROADCAST: ::c_int = 0x2; // broadcast address valid -pub const IFF_DEBUG: ::c_int = 0x4; // turn on debugging -pub const IFF_LOOPBACK: ::c_int = 0x8; // is a loopback net -pub const IFF_POINTOPOINT: ::c_int = 0x10; // interface is point-to-point link -pub const IFF_NOTRAILERS: ::c_int = 0x20; // avoid use of trailers -pub const IFF_RUNNING: ::c_int = 0x40; // resources allocated -pub const IFF_NOARP: ::c_int = 0x80; // no address resolution protocol -pub const IFF_PROMISC: ::c_int = 0x100; // receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x200; // receive all multicast packets -pub const IFF_OACTIVE: ::c_int = 0x400; // transmission in progress -pub const IFF_SIMPLEX: ::c_int = 0x800; // can't hear own transmissions -pub const IFF_LINK0: ::c_int = 0x1000; // per link layer defined bit -pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit -pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit -pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast - -pub const SIGSTKSZ : ::size_t = 40960; - -pub const PT_FIRSTMACH: ::c_int = 32; - -extern { - pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) -> *mut ::c_char; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn freelocale(loc: ::locale_t) -> ::c_int; - pub fn newlocale(mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t) -> ::locale_t; - pub fn uselocale(loc: ::locale_t) -> ::locale_t; - pub fn pledge(promises: *const ::c_char, - paths: *mut *const ::c_char) -> ::c_int; - pub fn querylocale(mask: ::c_int, loc: ::locale_t) -> *const ::c_char; -} - -cfg_if! { - if #[cfg(target_arch = "x86")] { - mod x86; - pub use self::x86::*; - } else if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/x86.rs b/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/x86.rs deleted file mode 100644 index 9b0b338..0000000 --- a/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/x86.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/x86_64.rs b/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/x86_64.rs deleted file mode 100644 index d3971aa..0000000 --- a/libc/src/unix/bsd/netbsdlike/openbsdlike/bitrig/x86_64.rs +++ /dev/null @@ -1,10 +0,0 @@ -use PT_FIRSTMACH; - -pub type c_long = i64; -pub type c_ulong = u64; - -pub const PT_STEP: ::c_int = PT_FIRSTMACH + 0; -pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; -pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 2; -pub const PT_GETFPREGS: ::c_int = PT_FIRSTMACH + 3; -pub const PT_SETFPREGS: ::c_int = PT_FIRSTMACH + 4; diff --git a/libc/src/unix/bsd/netbsdlike/openbsdlike/mod.rs b/libc/src/unix/bsd/netbsdlike/openbsdlike/mod.rs index 1c2e47d..223064b 100644 --- a/libc/src/unix/bsd/netbsdlike/openbsdlike/mod.rs +++ b/libc/src/unix/bsd/netbsdlike/openbsdlike/mod.rs @@ -17,29 +17,21 @@ pub type pthread_rwlockattr_t = *mut ::c_void; pub type caddr_t = *mut ::c_char; s! { - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: u16, - pub d_type: u8, - pub d_namlen: u8, - __d_padding: [u8; 4], - pub d_name: [::c_char; 256], + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + + pub struct in_addr { + pub s_addr: ::in_addr_t, } - pub struct glob_t { - pub gl_pathc: ::c_int, - pub gl_matchc: ::c_int, - pub gl_offs: ::c_int, - pub gl_flags: ::c_int, - pub gl_pathv: *mut *mut ::c_char, - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - __unused6: *mut ::c_void, - __unused7: *mut ::c_void, + pub struct sockaddr_in { + pub sin_len: u8, + pub sin_family: ::sa_family_t, + pub sin_port: ::in_port_t, + pub sin_addr: ::in_addr, + pub sin_zero: [::int8_t; 8], } pub struct kevent { @@ -99,25 +91,6 @@ s! { pub ai_next: *mut ::addrinfo, } - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_pad2: i64, - __ss_pad3: [u8; 240], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub si_addr: *mut ::c_char, - #[cfg(target_pointer_width = "32")] - __pad: [u8; 112], - #[cfg(target_pointer_width = "64")] - __pad: [u8; 108], - } - pub struct Dl_info { pub dli_fname: *const ::c_char, pub dli_fbase: *mut ::c_void, @@ -125,19 +98,6 @@ s! { pub dli_saddr: *mut ::c_void, } - pub struct lastlog { - ll_time: ::time_t, - ll_line: [::c_char; UT_LINESIZE], - ll_host: [::c_char; UT_HOSTSIZE], - } - - pub struct utmp { - pub ut_line: [::c_char; UT_LINESIZE], - pub ut_name: [::c_char; UT_NAMESIZE], - pub ut_host: [::c_char; UT_HOSTSIZE], - pub ut_time: ::time_t, - } - pub struct if_data { pub ifi_type: ::c_uchar, pub ifi_addrlen: ::c_uchar, @@ -204,6 +164,230 @@ s! { } } +s_no_extra_traits! { + pub struct dirent { + pub d_fileno: ::ino_t, + pub d_off: ::off_t, + pub d_reclen: u16, + pub d_type: u8, + pub d_namlen: u8, + __d_padding: [u8; 4], + pub d_name: [::c_char; 256], + } + + pub struct sockaddr_storage { + pub ss_len: u8, + pub ss_family: ::sa_family_t, + __ss_pad1: [u8; 6], + __ss_pad2: i64, + __ss_pad3: [u8; 240], + } + + pub struct siginfo_t { + pub si_signo: ::c_int, + pub si_code: ::c_int, + pub si_errno: ::c_int, + pub si_addr: *mut ::c_char, + #[cfg(target_pointer_width = "32")] + __pad: [u8; 112], + #[cfg(target_pointer_width = "64")] + __pad: [u8; 108], + } + + pub struct lastlog { + ll_time: ::time_t, + ll_line: [::c_char; UT_LINESIZE], + ll_host: [::c_char; UT_HOSTSIZE], + } + + pub struct utmp { + pub ut_line: [::c_char; UT_LINESIZE], + pub ut_name: [::c_char; UT_NAMESIZE], + pub ut_host: [::c_char; UT_HOSTSIZE], + pub ut_time: ::time_t, + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_fileno == other.d_fileno + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self.d_namlen == other.d_namlen + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for dirent {} + + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_fileno", &self.d_fileno) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + .field("d_namlen", &self.d_namlen) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_fileno.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_namlen.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.ss_len == other.ss_len + && self.ss_family == other.ss_family + } + } + + impl Eq for sockaddr_storage {} + + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("ss_len", &self.ss_len) + .field("ss_family", &self.ss_family) + .finish() + } + } + + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ss_len.hash(state); + self.ss_family.hash(state); + } + } + + impl PartialEq for siginfo_t { + fn eq(&self, other: &siginfo_t) -> bool { + self.si_signo == other.si_signo + && self.si_code == other.si_code + && self.si_errno == other.si_errno + && self.si_addr == other.si_addr + } + } + + impl Eq for siginfo_t {} + + impl ::fmt::Debug for siginfo_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("siginfo_t") + .field("si_signo", &self.si_signo) + .field("si_code", &self.si_code) + .field("si_errno", &self.si_errno) + .field("si_addr", &self.si_addr) + .finish() + } + } + + impl ::hash::Hash for siginfo_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.si_signo.hash(state); + self.si_code.hash(state); + self.si_errno.hash(state); + self.si_addr.hash(state); + } + } + + impl PartialEq for lastlog { + fn eq(&self, other: &lastlog) -> bool { + self.ll_time == other.ll_time + && self + .ll_line + .iter() + .zip(other.ll_line.iter()) + .all(|(a,b)| a == b) + && self + .ll_host + .iter() + .zip(other.ll_host.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for lastlog {} + + impl ::fmt::Debug for lastlog { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("lastlog") + .field("ll_time", &self.ll_time) + // FIXME: .field("ll_line", &self.ll_line) + // FIXME: .field("ll_host", &self.ll_host) + .finish() + } + } + + impl ::hash::Hash for lastlog { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ll_time.hash(state); + self.ll_line.hash(state); + self.ll_host.hash(state); + } + } + + impl PartialEq for utmp { + fn eq(&self, other: &utmp) -> bool { + self.ut_time == other.ut_time + && self + .ut_line + .iter() + .zip(other.ut_line.iter()) + .all(|(a,b)| a == b) + && self + .ut_name + .iter() + .zip(other.ut_name.iter()) + .all(|(a,b)| a == b) + && self + .ut_host + .iter() + .zip(other.ut_host.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for utmp {} + + impl ::fmt::Debug for utmp { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utmp") + // FIXME: .field("ut_line", &self.ut_line) + // FIXME: .field("ut_name", &self.ut_name) + // FIXME: .field("ut_host", &self.ut_host) + .field("ut_time", &self.ut_time) + .finish() + } + } + + impl ::hash::Hash for utmp { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ut_line.hash(state); + self.ut_name.hash(state); + self.ut_host.hash(state); + self.ut_time.hash(state); + } + } + } +} + pub const UT_NAMESIZE: usize = 32; pub const UT_LINESIZE: usize = 8; pub const UT_HOSTSIZE: usize = 256; @@ -215,8 +399,6 @@ pub const O_RSYNC: ::c_int = O_SYNC; pub const MS_SYNC : ::c_int = 0x0002; pub const MS_INVALIDATE : ::c_int = 0x0004; -pub const PTHREAD_STACK_MIN : ::size_t = 2048; - pub const POLLNORM: ::c_short = ::POLLRDNORM; pub const ENOATTR : ::c_int = 83; @@ -757,9 +939,6 @@ cfg_if! { if #[cfg(target_os = "openbsd")] { mod openbsd; pub use self::openbsd::*; - } else if #[cfg(target_os = "bitrig")] { - mod bitrig; - pub use self::bitrig::*; } else { // Unknown target_os } diff --git a/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/aarch64.rs b/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/aarch64.rs index 2a28c2a..6a8cbb5 100644 --- a/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/aarch64.rs +++ b/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/aarch64.rs @@ -1,9 +1,14 @@ -use dox::mem; - pub type c_long = i64; pub type c_ulong = u64; pub type c_char = u8; // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_long>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} diff --git a/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs b/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs index a2a7a30..c168711 100644 --- a/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs +++ b/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs @@ -1,4 +1,19 @@ s! { + pub struct glob_t { + pub gl_pathc: ::size_t, + pub gl_matchc: ::size_t, + pub gl_offs: ::size_t, + pub gl_flags: ::c_int, + pub gl_pathv: *mut *mut ::c_char, + __unused1: *mut ::c_void, + __unused2: *mut ::c_void, + __unused3: *mut ::c_void, + __unused4: *mut ::c_void, + __unused5: *mut ::c_void, + __unused6: *mut ::c_void, + __unused7: *mut ::c_void, + } + pub struct lconv { pub decimal_point: *mut ::c_char, pub thousands_sep: *mut ::c_char, @@ -26,42 +41,6 @@ s! { pub int_n_sign_posn: ::c_char, } - pub struct statfs { - pub f_flags: ::uint32_t, - pub f_bsize: ::uint32_t, - pub f_iosize: ::uint32_t, - pub f_blocks: ::uint64_t, - pub f_bfree: ::uint64_t, - pub f_bavail: ::int64_t, - pub f_files: ::uint64_t, - pub f_ffree: ::uint64_t, - pub f_favail: ::int64_t, - pub f_syncwrites: ::uint64_t, - pub f_syncreads: ::uint64_t, - pub f_asyncwrites: ::uint64_t, - pub f_asyncreads: ::uint64_t, - pub f_fsid: ::fsid_t, - pub f_namemax: ::uint32_t, - pub f_owner: ::uid_t, - pub f_ctime: ::uint64_t, - pub f_fstypename: [::c_char; 16], - pub f_mntonname: [::c_char; 90], - pub f_mntfromname: [::c_char; 90], - pub f_mntfromspec: [::c_char; 90], - pub mount_info: mount_info, - } - - pub union mount_info { - pub ufs_args: ufs_args, - pub mfs_args: mfs_args, - pub nfs_args: nfs_args, - pub iso_args: iso_args, - pub msdosfs_args: msdosfs_args, - pub ntfs_args: ntfs_args, - pub tmpfs_args: tmpfs_args, - align: [::c_char; 160], - } - pub struct ufs_args { pub fspec: *mut ::c_char, pub export_info: export_args, @@ -165,6 +144,184 @@ s! { } } +s_no_extra_traits! { + pub union mount_info { + pub ufs_args: ufs_args, + pub mfs_args: mfs_args, + pub nfs_args: nfs_args, + pub iso_args: iso_args, + pub msdosfs_args: msdosfs_args, + pub ntfs_args: ntfs_args, + pub tmpfs_args: tmpfs_args, + align: [::c_char; 160], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for mount_info { + fn eq(&self, other: &mount_info) -> bool { + unsafe { + self.align + .iter() + .zip(other.align.iter()) + .all(|(a,b)| a == b) + } + } + } + + impl Eq for mount_info { } + + impl ::fmt::Debug for mount_info { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("mount_info") + // FIXME: .field("align", &self.align) + .finish() + } + } + + impl ::hash::Hash for mount_info { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + unsafe { self.align.hash(state) }; + } + } + } +} + +cfg_if! { + if #[cfg(libc_union)] { + s_no_extra_traits! { + // This type uses the union mount_info: + pub struct statfs { + pub f_flags: ::uint32_t, + pub f_bsize: ::uint32_t, + pub f_iosize: ::uint32_t, + pub f_blocks: ::uint64_t, + pub f_bfree: ::uint64_t, + pub f_bavail: ::int64_t, + pub f_files: ::uint64_t, + pub f_ffree: ::uint64_t, + pub f_favail: ::int64_t, + pub f_syncwrites: ::uint64_t, + pub f_syncreads: ::uint64_t, + pub f_asyncwrites: ::uint64_t, + pub f_asyncreads: ::uint64_t, + pub f_fsid: ::fsid_t, + pub f_namemax: ::uint32_t, + pub f_owner: ::uid_t, + pub f_ctime: ::uint64_t, + pub f_fstypename: [::c_char; 16], + pub f_mntonname: [::c_char; 90], + pub f_mntfromname: [::c_char; 90], + pub f_mntfromspec: [::c_char; 90], + pub mount_info: mount_info, + } + } + + cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for statfs { + fn eq(&self, other: &statfs) -> bool { + self.f_flags == other.f_flags + && self.f_bsize == other.f_bsize + && self.f_iosize == other.f_iosize + && self.f_blocks == other.f_blocks + && self.f_bfree == other.f_bfree + && self.f_bavail == other.f_bavail + && self.f_files == other.f_files + && self.f_ffree == other.f_ffree + && self.f_favail == other.f_favail + && self.f_syncwrites == other.f_syncwrites + && self.f_syncreads == other.f_syncreads + && self.f_asyncwrites == other.f_asyncwrites + && self.f_asyncreads == other.f_asyncreads + && self.f_fsid == other.f_fsid + && self.f_namemax == other.f_namemax + && self.f_owner == other.f_owner + && self.f_ctime == other.f_ctime + && self.f_fstypename + .iter() + .zip(other.f_fstypename.iter()) + .all(|(a,b)| a == b) + && self.f_mntonname + .iter() + .zip(other.f_mntonname.iter()) + .all(|(a,b)| a == b) + && self.f_mntfromname + .iter() + .zip(other.f_mntfromname.iter()) + .all(|(a,b)| a == b) + && self.f_mntfromspec + .iter() + .zip(other.f_mntfromspec.iter()) + .all(|(a,b)| a == b) + && self.mount_info == other.mount_info + } + } + + impl Eq for statfs { } + + impl ::fmt::Debug for statfs { + fn fmt(&self, f: &mut ::fmt::Formatter) + -> ::fmt::Result { + f.debug_struct("statfs") + .field("f_flags", &self.f_flags) + .field("f_bsize", &self.f_bsize) + .field("f_iosize", &self.f_iosize) + .field("f_blocks", &self.f_blocks) + .field("f_bfree", &self.f_bfree) + .field("f_bavail", &self.f_bavail) + .field("f_files", &self.f_files) + .field("f_ffree", &self.f_ffree) + .field("f_favail", &self.f_favail) + .field("f_syncwrites", &self.f_syncwrites) + .field("f_syncreads", &self.f_syncreads) + .field("f_asyncwrites", &self.f_asyncwrites) + .field("f_asyncreads", &self.f_asyncreads) + .field("f_fsid", &self.f_fsid) + .field("f_namemax", &self.f_namemax) + .field("f_owner", &self.f_owner) + .field("f_ctime", &self.f_ctime) + // FIXME: .field("f_fstypename", &self.f_fstypename) + // FIXME: .field("f_mntonname", &self.f_mntonname) + // FIXME: .field("f_mntfromname", &self.f_mntfromname) + // FIXME: .field("f_mntfromspec", &self.f_mntfromspec) + .field("mount_info", &self.mount_info) + .finish() + } + } + + impl ::hash::Hash for statfs { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.f_flags.hash(state); + self.f_bsize.hash(state); + self.f_iosize.hash(state); + self.f_blocks.hash(state); + self.f_bfree.hash(state); + self.f_bavail.hash(state); + self.f_files.hash(state); + self.f_ffree.hash(state); + self.f_favail.hash(state); + self.f_syncwrites.hash(state); + self.f_syncreads.hash(state); + self.f_asyncwrites.hash(state); + self.f_asyncreads.hash(state); + self.f_fsid.hash(state); + self.f_namemax.hash(state); + self.f_owner.hash(state); + self.f_ctime.hash(state); + self.f_fstypename.hash(state); + self.f_mntonname.hash(state); + self.f_mntfromname.hash(state); + self.f_mntfromspec.hash(state); + self.mount_info.hash(state); + } + } + } + } + } +} + //https://github.com/openbsd/src/blob/master/sys/sys/mount.h pub const ISOFSMNT_NORRIP: ::c_int = 0x1; // disable Rock Ridge Ext pub const ISOFSMNT_GENS: ::c_int = 0x2; // enable generation numbers @@ -246,10 +403,61 @@ pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast +pub const PTHREAD_STACK_MIN : ::size_t = 4096; pub const SIGSTKSZ : ::size_t = 28672; pub const PT_FIRSTMACH: ::c_int = 32; +fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES +} + +f! { + pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { + (cmsg as *mut ::c_uchar) + .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) + } + + pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { + _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length + } + + pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) + -> *mut ::cmsghdr + { + if cmsg.is_null() { + return ::CMSG_FIRSTHDR(mhdr); + }; + let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + + _ALIGN(::mem::size_of::<::cmsghdr>()); + let max = (*mhdr).msg_control as usize + + (*mhdr).msg_controllen as usize; + if next > max { + 0 as *mut ::cmsghdr + } else { + (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) + as *mut ::cmsghdr + } + } + + pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) + as ::c_uint + } + + pub fn WSTOPSIG(status: ::c_int) -> ::c_int { + status >> 8 + } + + pub fn WIFSIGNALED(status: ::c_int) -> bool { + (status & 0o177) != 0o177 && (status & 0o177) != 0 + } + + pub fn WIFSTOPPED(status: ::c_int) -> bool { + (status & 0o177) == 0o177 + } +} + extern { pub fn accept4(s: ::c_int, addr: *mut ::sockaddr, addrlen: *mut ::socklen_t, flags: ::c_int) -> ::c_int; @@ -260,14 +468,20 @@ extern { pub fn strtonum(nptr: *const ::c_char, minval: ::c_longlong, maxval: ::c_longlong, errstr: *mut *const ::c_char) -> ::c_longlong; - - pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; - pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; - pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int; } cfg_if! { + if #[cfg(libc_union)] { + extern { + // these functions use statfs which uses the union mount_info: + pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; + pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; + } + } +} + +cfg_if! { if #[cfg(target_arch = "x86")] { mod x86; pub use self::x86::*; diff --git a/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/x86.rs b/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/x86.rs index b63b69f..05538cd 100644 --- a/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/x86.rs +++ b/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/x86.rs @@ -1,9 +1,14 @@ -use dox::mem; - pub type c_long = i32; pub type c_ulong = u32; pub type c_char = i8; // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_int>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 4 - 1; + } +} diff --git a/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/x86_64.rs b/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/x86_64.rs index 581096f..7daa9d8 100644 --- a/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/x86_64.rs +++ b/libc/src/unix/bsd/netbsdlike/openbsdlike/openbsd/x86_64.rs @@ -1,5 +1,3 @@ -use dox::mem; - use PT_FIRSTMACH; pub type c_long = i64; @@ -7,8 +5,15 @@ pub type c_ulong = u64; pub type c_char = i8; // should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = mem::size_of::<::c_long>() - 1; +cfg_if! { + if #[cfg(libc_const_size_of)] { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; + } else { + #[doc(hidden)] + pub const _ALIGNBYTES: usize = 8 - 1; + } +} pub const PT_STEP: ::c_int = PT_FIRSTMACH + 0; pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; diff --git a/libc/src/unix/haiku/mod.rs b/libc/src/unix/haiku/mod.rs index 2aa5d13..26519a4 100644 --- a/libc/src/unix/haiku/mod.rs +++ b/libc/src/unix/haiku/mod.rs @@ -1,5 +1,3 @@ -use dox::{mem, Option}; - pub type rlim_t = ::uintptr_t; pub type sa_family_t = u8; pub type pthread_key_t = ::c_int; @@ -31,9 +29,23 @@ pub type nl_item = ::c_int; pub type id_t = i32; pub type idtype_t = ::c_uint; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} s! { + pub struct in_addr { + pub s_addr: ::in_addr_t, + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + pub struct sockaddr { pub sa_len: u8, pub sa_family: sa_family_t, @@ -57,20 +69,6 @@ s! { pub sin6_scope_id: u32, } - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 126] - } - - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: sa_family_t, - __ss_pad1: [u8; 6], - __ss_pad2: u64, - __ss_pad3: [u8; 112], - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -199,15 +197,6 @@ s! { pub st_blocks: blkcnt_t, } - pub struct dirent { - pub d_dev: dev_t, - pub d_pdev: dev_t, - pub d_ino: ino_t, - pub d_pino: i64, - pub d_reclen: ::c_ushort, - pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX - } - pub struct glob_t { pub gl_pathc: ::size_t, __unused1: ::size_t, @@ -319,6 +308,139 @@ s! { } } +s_no_extra_traits! { + pub struct sockaddr_un { + pub sun_len: u8, + pub sun_family: sa_family_t, + pub sun_path: [::c_char; 126] + } + pub struct sockaddr_storage { + pub ss_len: u8, + pub ss_family: sa_family_t, + __ss_pad1: [u8; 6], + __ss_pad2: u64, + __ss_pad3: [u8; 112], + } + pub struct dirent { + pub d_dev: dev_t, + pub d_pdev: dev_t, + pub d_ino: ino_t, + pub d_pino: i64, + pub d_reclen: ::c_ushort, + pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_len == other.sun_len + && self.sun_family == other.sun_family + && self + .sun_path + .iter() + .zip(other.sun_path.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr_un {} + impl ::fmt::Debug for sockaddr_un { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_un") + .field("sun_len", &self.sun_len) + .field("sun_family", &self.sun_family) + // FIXME: .field("sun_path", &self.sun_path) + .finish() + } + } + impl ::hash::Hash for sockaddr_un { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sun_len.hash(state); + self.sun_family.hash(state); + self.sun_path.hash(state); + } + } + + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.ss_len == other.ss_len + && self.ss_family == other.ss_family + && self + .__ss_pad1 + .iter() + .zip(other.__ss_pad1.iter()) + .all(|(a, b)| a == b) + && self.__ss_pad2 == other.__ss_pad2 + && self + .__ss_pad3 + .iter() + .zip(other.__ss_pad3.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for sockaddr_storage {} + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("ss_len", &self.ss_len) + .field("ss_family", &self.ss_family) + .field("__ss_pad1", &self.__ss_pad1) + .field("__ss_pad2", &self.__ss_pad2) + // FIXME: .field("__ss_pad3", &self.__ss_pad3) + .finish() + } + } + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ss_len.hash(state); + self.ss_family.hash(state); + self.__ss_pad1.hash(state); + self.__ss_pad2.hash(state); + self.__ss_pad3.hash(state); + } + } + + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_dev == other.d_dev + && self.d_pdev == other.d_pdev + && self.d_ino == other.d_ino + && self.d_pino == other.d_pino + && self.d_reclen == other.d_reclen + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent {} + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_dev", &self.d_dev) + .field("d_pdev", &self.d_pdev) + .field("d_ino", &self.d_ino) + .field("d_pino", &self.d_pino) + .field("d_reclen", &self.d_reclen) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_dev.hash(state); + self.d_pdev.hash(state); + self.d_ino.hash(state); + self.d_pino.hash(state); + self.d_reclen.hash(state); + self.d_name.hash(state); + } + } + } +} + // intentionally not public, only used for fd_set cfg_if! { if #[cfg(target_pointer_width = "32")] { @@ -1028,20 +1150,20 @@ pub const TCIOFLUSH: ::c_int = 0x03; f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; (*set).fds_bits[fd / size] &= !(1 << (fd % size)); return } pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 } pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; (*set).fds_bits[fd / size] |= 1 << (fd % size); return } @@ -1096,6 +1218,12 @@ extern { #[link(name = "bsd")] extern { + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; + pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; pub fn clock_settime(clk_id: ::c_int, tp: *const ::timespec) -> ::c_int; pub fn pthread_create(thread: *mut ::pthread_t, @@ -1132,7 +1260,7 @@ extern { pub fn glob(pattern: *const ::c_char, flags: ::c_int, - errfunc: Option<extern fn(epath: *const ::c_char, + errfunc: ::Option<extern fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, pglob: *mut ::glob_t) -> ::c_int; pub fn globfree(pglob: *mut ::glob_t); @@ -1178,7 +1306,7 @@ extern { pub fn execvpe(file: *const ::c_char, argv: *const *const ::c_char, environment: *const *const ::c_char) -> ::c_int; #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r(uid: ::uid_t, + pub fn getgrgid_r(gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, @@ -1224,9 +1352,9 @@ extern { #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork(prepare: Option<unsafe extern fn()>, - parent: Option<unsafe extern fn()>, - child: Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; pub fn getgrgid(gid: ::gid_t) -> *mut ::group; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "popen$UNIX2003")] diff --git a/libc/src/unix/hermit/mod.rs b/libc/src/unix/hermit/mod.rs index ba7a90f..288cc46 100644 --- a/libc/src/unix/hermit/mod.rs +++ b/libc/src/unix/hermit/mod.rs @@ -19,8 +19,6 @@ pub type c_long = i64; pub type c_ulong = u64; -pub type uid_t = u16; -pub type gid_t = u16; pub type speed_t = ::c_uint; pub type mode_t = u32; pub type dev_t = i16; @@ -49,7 +47,336 @@ pub type pthread_mutexattr_t = usize; pub type pthread_rwlock_t = usize; pub type pthread_rwlockattr_t = usize; +s_no_extra_traits! { + pub struct dirent { + pub d_ino: ::c_long, + pub d_off: off_t, + pub d_reclen: u16, + pub d_name: [::c_char; 256], + } + + // Dummy + pub struct sockaddr_un { + pub sun_family: sa_family_t, + pub sun_path: [::c_char; 108], + } + + pub struct sockaddr { + pub sa_len: u8, + pub sa_family: sa_family_t, + pub sa_data: [::c_char; 14], + } + + pub struct sockaddr_in { + pub sin_len: u8, + pub sin_family: sa_family_t, + pub sin_port: ::in_port_t, + pub sin_addr: ::in_addr, + pub sin_zero: [::c_char; 8], + } + + pub struct fd_set { + fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], + } + + pub struct sockaddr_storage { + pub s2_len: u8, + pub ss_family: sa_family_t, + pub s2_data1: [::c_char; 2], + pub s2_data2: [u32; 3], + pub s2_data3: [u32; 3], + } + + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: dev_t, + pub st_size: off_t, + pub st_atime: time_t, + pub st_atime_nsec: ::c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: ::c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: ::c_long, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_spare4: [::c_long; 2], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent {} + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_family == other.sun_family + && self + .sun_path + .iter() + .zip(other.sun_path.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr_un {} + impl ::fmt::Debug for sockaddr_un { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_un") + .field("sun_family", &self.sun_family) + // FIXME: .field("sun_path", &self.sun_path) + .finish() + } + } + impl ::hash::Hash for sockaddr_un { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sun_family.hash(state); + self.sun_path.hash(state); + } + } + + impl PartialEq for sockaddr { + fn eq(&self, other: &sockaddr) -> bool { + self.sa_len == other.sa_len + && self.sa_family == other.sa_family + && self + .sa_data + .iter() + .zip(other.sa_data.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr {} + impl ::fmt::Debug for sockaddr { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr") + .field("sa_len", &self.sa_len) + .field("sa_family", &self.sa_family) + // FIXME: .field("sa_data", &self.sa_data) + .finish() + } + } + impl ::hash::Hash for sockaddr { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sa_len.hash(state); + self.sa_family.hash(state); + self.sa_data.hash(state); + } + } + + impl PartialEq for sockaddr_in { + fn eq(&self, other: &sockaddr_in) -> bool { + self.sin_len == other.sin_len + && self.sin_family == other.sin_family + && self.sin_port == other.sin_port + && self.sin_addr == other.sin_addr + && self + .sin_zero + .iter() + .zip(other.sin_zero.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr_in {} + impl ::fmt::Debug for sockaddr_in { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_in") + .field("sin_len", &self.sin_len) + .field("sin_family", &self.sin_family) + .field("sin_port", &self.sin_port) + .field("sin_addr", &self.sin_addr) + // FIXME: .field("sin_zero", &self.sin_zero) + .finish() + } + } + impl ::hash::Hash for sockaddr_in { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sin_len.hash(state); + self.sin_family.hash(state); + self.sin_port.hash(state); + self.sin_addr.hash(state); + self.sin_zero.hash(state); + } + } + + impl PartialEq for fd_set { + fn eq(&self, other: &fd_set) -> bool { + self.fds_bits + .iter() + .zip(other.fds_bits.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for fd_set {} + impl ::fmt::Debug for fd_set { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("fd_set") + // FIXME: .field("fds_bits", &self.fds_bits) + .finish() + } + } + impl ::hash::Hash for fd_set { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.fds_bits.hash(state); + } + } + + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.s2_len == other.s2_len + && self.ss_family == other.ss_family + && self.s2_data1 + .iter() + .zip(other.s2_data1.iter()) + .all(|(a,b)| a == b) + && self.s2_data2 + .iter() + .zip(other.s2_data2.iter()) + .all(|(a,b)| a == b) + && self.s2_data3 + .iter() + .zip(other.s2_data3.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr_storage {} + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("s2_len", &self.s2_len) + .field("ss_family", &self.ss_family) + // FIXME: .field("s2_data1", &self.s2_data1) + // FIXME: .field("s2_data2", &self.s2_data2) + // FIXME: .field("s2_data3", &self.s2_data3) + .finish() + } + } + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.s2_len.hash(state); + self.ss_family.hash(state); + self.s2_data1.hash(state); + self.s2_data2.hash(state); + self.s2_data3.hash(state); + } + } + + impl PartialEq for stat { + fn eq(&self, other: &stat) -> bool { + self.st_dev == other.st_dev + && self.st_ino == other.st_ino + && self.st_mode == other.st_mode + && self.st_nlink == other.st_nlink + && self.st_uid == other.st_uid + && self.st_gid == other.st_gid + && self.st_rdev == other.st_rdev + && self.st_size == other.st_size + && self.st_atime == other.st_atime + && self.st_atime_nsec == other.st_atime_nsec + && self.st_mtime == other.st_mtime + && self.st_mtime_nsec == other.st_mtime_nsec + && self.st_ctime == other.st_ctime + && self.st_ctime_nsec == other.st_ctime_nsec + && self.st_blksize == other.st_blksize + && self.st_blocks == other.st_blocks + && self + .st_spare4 + .iter() + .zip(other.st_spare4.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for stat {} + impl ::fmt::Debug for stat { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("stat") + .field("st_dev", &self.st_dev) + .field("st_ino", &self.st_ino) + .field("st_mode", &self.st_mode) + .field("st_nlink", &self.st_nlink) + .field("st_uid", &self.st_uid) + .field("st_gid", &self.st_gid) + .field("st_rdev", &self.st_rdev) + .field("st_size", &self.st_size) + .field("st_atime", &self.st_atime) + .field("st_atime_nsec", &self.st_atime_nsec) + .field("st_mtime", &self.st_mtime) + .field("st_mtime_nsec", &self.st_mtime_nsec) + .field("st_ctime", &self.st_ctime) + .field("st_ctime_nsec", &self.st_ctime_nsec) + .field("st_blksize", &self.st_blksize) + .field("st_blocks", &self.st_blocks) + // FIXME: .field("st_spare4", &self.st_spare4) + .finish() + } + } + impl ::hash::Hash for stat { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.st_dev.hash(state); + self.st_ino.hash(state); + self.st_mode.hash(state); + self.st_nlink.hash(state); + self.st_uid.hash(state); + self.st_gid.hash(state); + self.st_rdev.hash(state); + self.st_size.hash(state); + self.st_atime.hash(state); + self.st_atime_nsec.hash(state); + self.st_mtime.hash(state); + self.st_mtime_nsec.hash(state); + self.st_ctime.hash(state); + self.st_ctime_nsec.hash(state); + self.st_blksize.hash(state); + self.st_blocks.hash(state); + self.st_spare4.hash(state); + } + } + } +} + s! { + pub struct in_addr { + pub s_addr: ::in_addr_t, + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -61,19 +388,8 @@ s! { pub ai_next: *mut addrinfo, } - pub struct dirent { - pub d_ino: ::c_long, - pub d_off: off_t, - pub d_reclen: u16, - pub d_name: [::c_char; 256], - } - pub struct Dl_info {} - pub struct fd_set { - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], - } - pub struct lconv { pub decimal_point: *mut ::c_char, pub thousands_sep: *mut ::c_char, @@ -132,20 +448,6 @@ s! { pub sa_handler: usize, } - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [::c_char; 8], - } - pub struct sockaddr_in6 { pub sin6_len: u8, pub sin6_family: sa_family_t, @@ -155,40 +457,6 @@ s! { pub sin6_scope_id: u32, } - pub struct sockaddr_storage { - pub s2_len: u8, - pub ss_family: sa_family_t, - pub s2_data1: [::c_char; 2], - pub s2_data2: [u32; 3], - pub s2_data3: [u32; 3], - } - - // Dummy - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 108], - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: dev_t, - pub st_size: off_t, - pub st_atime: time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: blksize_t, - pub st_blocks: blkcnt_t, - pub st_spare4: [::c_long; 2], - } - pub struct statvfs {} pub struct tm { @@ -696,6 +964,12 @@ f! { } extern { + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; + pub fn abs(i: ::c_int) -> ::c_int; pub fn atof(s: *const ::c_char) -> ::c_double; pub fn labs(i: ::c_long) -> ::c_long; diff --git a/libc/src/unix/mod.rs b/libc/src/unix/mod.rs index 88e13c5..1565b63 100644 --- a/libc/src/unix/mod.rs +++ b/libc/src/unix/mod.rs @@ -3,8 +3,6 @@ //! More functions and definitions can be found in the more specific modules //! according to the platform in question. -use dox::Option; - pub type int8_t = i8; pub type int16_t = i16; pub type int32_t = i32; @@ -41,8 +39,18 @@ pub type in_port_t = u16; pub type sighandler_t = ::size_t; pub type cc_t = ::c_uchar; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum DIR {} +impl ::Copy for DIR {} +impl ::Clone for DIR { + fn clone(&self) -> DIR { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum locale_t {} +impl ::Copy for locale_t {} +impl ::Clone for locale_t { + fn clone(&self) -> locale_t { *self } +} s! { pub struct group { @@ -127,23 +135,6 @@ s! { __reserved: [c_long; 16], } - #[cfg_attr(target_os = "netbsd", repr(packed))] - pub struct in_addr { - pub s_addr: in_addr_t, - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct in6_addr { - pub s6_addr: [u8; 16], - #[cfg(not(feature = "align"))] - __align: [u32; 0], - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - pub struct ipv6_mreq { pub ipv6mr_multiaddr: in6_addr, #[cfg(target_os = "android")] @@ -232,7 +223,11 @@ pub const DT_REG: u8 = 8; pub const DT_LNK: u8 = 10; pub const DT_SOCK: u8 = 12; -pub const FD_CLOEXEC: ::c_int = 0x1; +cfg_if! { + if #[cfg(not(target_os = "redox"))] { + pub const FD_CLOEXEC: ::c_int = 0x1; + } +} pub const USRQUOTA: ::c_int = 0; pub const GRPQUOTA: ::c_int = 1; @@ -310,9 +305,7 @@ pub const ATF_PUBL: ::c_int = 0x08; pub const ATF_USETRAILERS: ::c_int = 0x10; cfg_if! { - if #[cfg(cross_platform_docs)] { - // on dox builds don't pull in anything - } else if #[cfg(target_os = "l4re")] { + if #[cfg(target_os = "l4re")] { // required libraries for L4Re are linked externally, ATM } else if #[cfg(feature = "use_std")] { // cargo build, don't pull in anything extra as the libstd dep @@ -338,8 +331,7 @@ cfg_if! { } else if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "android", - target_os = "openbsd", - target_os = "bitrig"))] { + target_os = "openbsd"))] { #[link(name = "c")] #[link(name = "m")] extern {} @@ -356,6 +348,17 @@ cfg_if! { // to "pthread" needs to be added. #[link(name = "pthread")] extern {} + } else if #[cfg(target_env = "illumos")] { + #[link(name = "c")] + #[link(name = "m")] + extern {} + } else if #[cfg(target_os = "redox")] { + #[cfg_attr(feature = "rustc-dep-of-std", + link(name = "c", kind = "static-nobundle", + cfg(target_feature = "crt-static")))] + #[cfg_attr(feature = "rustc-dep-of-std", + link(name = "c", cfg(not(target_feature = "crt-static"))))] + extern {} } else { #[link(name = "c")] #[link(name = "m")] @@ -365,8 +368,18 @@ cfg_if! { } } +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum FILE {} +impl ::Copy for FILE {} +impl ::Clone for FILE { + fn clone(&self) -> FILE { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos_t {} // TODO: fill this out with a struct +impl ::Copy for fpos_t {} +impl ::Clone for fpos_t { + fn clone(&self) -> fpos_t { *self } +} extern { pub fn isalnum(c: c_int) -> c_int; @@ -509,20 +522,26 @@ extern { pub fn snprintf(s: *mut ::c_char, n: ::size_t, format: *const ::c_char, ...) -> ::c_int; pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int; + #[cfg_attr(target_os = "linux", link_name = "__isoc99_fscanf")] pub fn fscanf(stream: *mut ::FILE, format: *const ::c_char, ...) -> ::c_int; + #[cfg_attr(target_os = "linux", link_name = "__isoc99_scanf")] pub fn scanf(format: *const ::c_char, ...) -> ::c_int; + #[cfg_attr(target_os = "linux", link_name = "__isoc99_sscanf")] pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) -> ::c_int; pub fn getchar_unlocked() -> ::c_int; pub fn putchar_unlocked(c: ::c_int) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__socket30")] + #[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")] pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "connect$UNIX2003")] + #[cfg_attr(target_os = "illumos", link_name = "__xnet_connect")] pub fn connect(socket: ::c_int, address: *const sockaddr, len: socklen_t) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "listen$UNIX2003")] + #[cfg_attr(target_os = "illumos", link_name = "__xnet_listen")] pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "accept$UNIX2003")] @@ -541,10 +560,12 @@ extern { option_len: socklen_t) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "socketpair$UNIX2003")] + #[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")] pub fn socketpair(domain: ::c_int, type_: ::c_int, protocol: ::c_int, socket_vector: *mut ::c_int) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "sendto$UNIX2003")] + #[cfg_attr(target_os = "illumos", link_name = "__xnet_sendto")] pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t, flags: ::c_int, addr: *const sockaddr, addrlen: socklen_t) -> ::ssize_t; @@ -604,8 +625,13 @@ extern { pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_readdir_r")] #[cfg_attr(target_os = "freebsd", link_name = "readdir_r@FBSD_1.0")] + /// The 64-bit libc on Solaris and illumos only has readdir_r. If a + /// 32-bit Solaris or illumos target is ever created, it should use + /// __posix_readdir_r. See libc(3LIB) on Solaris or illumos: + /// https://illumos.org/man/3lib/libc + /// https://docs.oracle.com/cd/E36784_01/html/E36873/libc-3lib.html + /// https://www.unix.com/man-page/opensolaris/3LIB/libc/ pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent, result: *mut *mut ::dirent) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), @@ -824,6 +850,14 @@ extern { pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")] + #[deprecated( + since="0.2.54", + note= + "The signature of this function is incorrect. \ + If you are using it, please report that in the following issue \ + so that we can evaluate the impact of fixing it: \ + https://github.com/rust-lang/libc/issues/1338" + )] pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__times13")] @@ -845,7 +879,7 @@ extern { #[cfg_attr(target_os = "netbsd", link_name = "__libc_thr_yield")] pub fn sched_yield() -> ::c_int; pub fn pthread_key_create(key: *mut pthread_key_t, - dtor: Option<unsafe extern fn(*mut ::c_void)>) + dtor: ::Option<unsafe extern fn(*mut ::c_void)>) -> ::c_int; pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int; pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void; @@ -913,6 +947,7 @@ extern { pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; + #[cfg_attr(target_os = "illumos", link_name = "__xnet_getsockopt")] pub fn getsockopt(sockfd: ::c_int, level: ::c_int, optname: ::c_int, @@ -1011,16 +1046,11 @@ extern { locale: *const ::c_char) -> *mut ::c_char; pub fn localeconv() -> *mut lconv; - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "sem_wait$UNIX2003")] pub fn sem_wait(sem: *mut sem_t) -> ::c_int; pub fn sem_trywait(sem: *mut sem_t) -> ::c_int; pub fn sem_post(sem: *mut sem_t) -> ::c_int; - pub fn sem_init(sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint) - -> ::c_int; pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int; pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int; @@ -1077,10 +1107,8 @@ extern { pub fn tcdrain(fd: ::c_int) -> ::c_int; pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t; pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t; - pub fn cfmakeraw(termios: *mut ::termios); pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; - pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int; pub fn tcsetattr(fd: ::c_int, optional_actions: ::c_int, @@ -1114,6 +1142,16 @@ extern { } cfg_if! { + if #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] { + extern { + pub fn cfmakeraw(termios: *mut ::termios); + pub fn cfsetspeed(termios: *mut ::termios, + speed: ::speed_t) -> ::c_int; + } + } +} + +cfg_if! { if #[cfg(target_env = "uclibc")] { mod uclibc; pub use self::uclibc::*; @@ -1130,32 +1168,37 @@ cfg_if! { target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd", - target_os = "netbsd", - target_os = "bitrig"))] { + target_os = "netbsd"))] { mod bsd; pub use self::bsd::*; - } else if #[cfg(target_os = "solaris")] { - mod solaris; - pub use self::solaris::*; + } else if #[cfg(any(target_os = "solaris", + target_os = "illumos"))] { + mod solarish; + pub use self::solarish::*; } else if #[cfg(target_os = "haiku")] { mod haiku; pub use self::haiku::*; } else if #[cfg(target_os = "hermit")] { mod hermit; pub use self::hermit::*; + } else if #[cfg(target_os = "redox")] { + mod redox; + pub use self::redox::*; } else { // Unknown target_os } } cfg_if! { - if #[cfg(core_cvoid)] { - pub use core::ffi::c_void; + if #[cfg(libc_core_cvoid)] { + pub use ::ffi::c_void; } else { // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help // enable more optimization opportunities around it recognizing things // like malloc/free. #[repr(u8)] + #[allow(missing_copy_implementations)] + #[allow(missing_debug_implementations)] pub enum c_void { // Two dummy variants so the #[repr] attribute can be used. #[doc(hidden)] @@ -1165,3 +1208,13 @@ cfg_if! { } } } + +cfg_if! { + if #[cfg(libc_align)] { + mod align; + pub use self::align::*; + } else { + mod no_align; + pub use self::no_align::*; + } +} diff --git a/libc/src/unix/newlib/align.rs b/libc/src/unix/newlib/align.rs new file mode 100644 index 0000000..c018fbc --- /dev/null +++ b/libc/src/unix/newlib/align.rs @@ -0,0 +1,61 @@ +macro_rules! expand_align { + () => { + s! { + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))), + repr(align(8)))] + pub struct pthread_mutex_t { // Unverified + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))), + repr(align(8)))] + pub struct pthread_rwlock_t { // Unverified + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + + #[cfg_attr(any(target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64"), + repr(align(4)))] + #[cfg_attr(not(any(target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64")), + repr(align(8)))] + pub struct pthread_mutexattr_t { // Unverified + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + #[repr(align(8))] + pub struct pthread_cond_t { // Unverified + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + + #[repr(align(4))] + pub struct pthread_condattr_t { // Unverified + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + } +} diff --git a/libc/src/unix/newlib/mod.rs b/libc/src/unix/newlib/mod.rs index 0cc411d..c9a25a3 100644 --- a/libc/src/unix/newlib/mod.rs +++ b/libc/src/unix/newlib/mod.rs @@ -1,5 +1,3 @@ -use dox::mem; - pub type blkcnt_t = i32; pub type blksize_t = i32; pub type clock_t = i32; @@ -238,103 +236,10 @@ s! { __size: [u64; 7] } - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))), - repr(align(8)))] - pub struct pthread_mutex_t { // Unverified - #[cfg(all(not(feature = "align"), - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))), - repr(align(8)))] - pub struct pthread_rwlock_t { // Unverified - #[cfg(all(not(feature = "align"), - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCK_T], - } - - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "32", - target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(any(target_pointer_width = "32", - target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))), - repr(align(8)))] - pub struct pthread_mutexattr_t { // Unverified - #[cfg(all(not(feature = "align"), - any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")))] - __align: [::c_int; 0], - #[cfg(all(not(feature = "align"), - not(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T], - } - pub struct pthread_rwlockattr_t { // Unverified __lockkind: ::c_int, __pshared: ::c_int, } - - #[cfg_attr(feature = "align", repr(align(8)))] - pub struct pthread_cond_t { // Unverified - #[cfg(not(feature = "align"))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_condattr_t { // Unverified - #[cfg(not(feature = "align"))] - __align: [::c_int; 0], - size: [u8; __SIZEOF_PTHREAD_CONDATTR_T], - } - } // unverified constants @@ -501,7 +406,8 @@ pub const SEEK_SET: ::c_int = 0; pub const SEEK_CUR: ::c_int = 1; pub const SEEK_END: ::c_int = 2; -pub const FIONBIO: ::c_int = 1; +pub const FIONBIO: ::c_ulong = 1; +pub const FIOCLEX: ::c_ulong = 0x20006601; pub const S_BLKSIZE: ::mode_t = 1024; pub const S_IREAD: ::mode_t = 256; @@ -552,15 +458,41 @@ pub const SHUT_RD: ::c_int = 0; pub const SHUT_WR: ::c_int = 1; pub const SHUT_RDWR: ::c_int = 2; -pub const SO_REUSEADDR: ::c_int = 4; -pub const SO_LINGER: ::c_int = 128; -pub const SO_OOBINLINE: ::c_int = 256; -pub const SO_SNDBUF: ::c_int = 4097; -pub const SO_RCVBUF: ::c_int = 4098; -pub const SO_SNDLOWAT: ::c_int = 4099; -pub const SO_RCVLOWAT: ::c_int = 4100; -pub const SO_TYPE: ::c_int = 4104; -pub const SO_ERROR: ::c_int = 4105; +pub const SO_BINTIME: ::c_int = 0x2000; +pub const SO_NO_OFFLOAD: ::c_int = 0x4000; +pub const SO_NO_DDP: ::c_int = 0x8000; +pub const SO_REUSEPORT_LB: ::c_int = 0x10000; +pub const SO_LABEL: ::c_int = 0x1009; +pub const SO_PEERLABEL: ::c_int = 0x1010; +pub const SO_LISTENQLIMIT: ::c_int = 0x1011; +pub const SO_LISTENQLEN: ::c_int = 0x1012; +pub const SO_LISTENINCQLEN: ::c_int = 0x1013; +pub const SO_SETFIB: ::c_int = 0x1014; +pub const SO_USER_COOKIE: ::c_int = 0x1015; +pub const SO_PROTOCOL: ::c_int = 0x1016; +pub const SO_PROTOTYPE: ::c_int = SO_PROTOCOL; +pub const SO_VENDOR: ::c_int = 0x80000000; +pub const SO_DEBUG: ::c_int = 0x01; +pub const SO_ACCEPTCONN: ::c_int = 0x0002; +pub const SO_REUSEADDR: ::c_int = 0x0004; +pub const SO_KEEPALIVE: ::c_int = 0x0008; +pub const SO_DONTROUTE: ::c_int = 0x0010; +pub const SO_BROADCAST: ::c_int = 0x0020; +pub const SO_USELOOPBACK: ::c_int = 0x0040; +pub const SO_LINGER: ::c_int = 0x0080; +pub const SO_OOBINLINE: ::c_int = 0x0100; +pub const SO_REUSEPORT: ::c_int = 0x0200; +pub const SO_TIMESTAMP: ::c_int = 0x0400; +pub const SO_NOSIGPIPE: ::c_int = 0x0800; +pub const SO_ACCEPTFILTER: ::c_int = 0x1000; +pub const SO_SNDBUF: ::c_int = 0x1001; +pub const SO_RCVBUF: ::c_int = 0x1002; +pub const SO_SNDLOWAT: ::c_int = 0x1003; +pub const SO_RCVLOWAT: ::c_int = 0x1004; +pub const SO_SNDTIMEO: ::c_int = 0x1005; +pub const SO_RCVTIMEO: ::c_int = 0x1006; +pub const SO_ERROR: ::c_int = 0x1007; +pub const SO_TYPE: ::c_int = 0x1008; pub const SOCK_CLOEXEC: ::c_int = O_CLOEXEC; @@ -586,20 +518,32 @@ pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit pub const IFF_ALTPHYS: ::c_int = IFF_LINK2; // use alternate physical connection pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast -pub const IPPROTO_IP: ::c_int = 0; -pub const IPPROTO_UDP: ::c_int = 17; -pub const IPPROTO_TCP: ::c_int = 6; - pub const TCP_NODELAY: ::c_int = 8193; pub const TCP_MAXSEG: ::c_int = 8194; +pub const TCP_NOPUSH: ::c_int = 4; +pub const TCP_NOOPT: ::c_int = 8; +pub const TCP_KEEPIDLE: ::c_int = 256; +pub const TCP_KEEPINTVL: ::c_int = 512; +pub const TCP_KEEPCNT: ::c_int = 1024; -pub const IP_TOS: ::c_int = 7; +pub const IP_TOS: ::c_int = 3; pub const IP_TTL: ::c_int = 8; -pub const IP_MULTICAST_LOOP: ::c_int = 9; +pub const IP_MULTICAST_IF: ::c_int = 9; pub const IP_MULTICAST_TTL: ::c_int = 10; +pub const IP_MULTICAST_LOOP: ::c_int = 11; pub const IP_ADD_MEMBERSHIP: ::c_int = 11; pub const IP_DROP_MEMBERSHIP: ::c_int = 12; +pub const IPV6_UNICAST_HOPS: ::c_int = 4; +pub const IPV6_MULTICAST_IF: ::c_int = 9; +pub const IPV6_MULTICAST_HOPS: ::c_int = 10; +pub const IPV6_MULTICAST_LOOP: ::c_int = 11; +pub const IPV6_V6ONLY: ::c_int = 27; +pub const IPV6_JOIN_GROUP: ::c_int = 12; +pub const IPV6_LEAVE_GROUP: ::c_int = 13; +pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12; +pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13; + pub const HOST_NOT_FOUND: ::c_int = 1; pub const NO_DATA: ::c_int = 2; pub const NO_ADDRESS: ::c_int = 2; @@ -627,20 +571,20 @@ pub const EAI_SOCKTYPE: ::c_int = -307; f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); return } pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 } pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; (*set).fds_bits[fd / bits] |= 1 << (fd % bits); return @@ -654,6 +598,12 @@ f! { } extern { + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; + pub fn abs(i: ::c_int) -> ::c_int; pub fn atof(s: *const ::c_char) -> ::c_double; pub fn labs(i: ::c_long) -> ::c_long; @@ -674,7 +624,7 @@ extern { envp: *const *const ::c_char) -> ::c_int; #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r(uid: ::uid_t, + pub fn getgrgid_r(gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, @@ -720,9 +670,9 @@ extern { #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork(prepare: Option<unsafe extern fn()>, - parent: Option<unsafe extern fn()>, - child: Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; pub fn getgrgid(gid: ::gid_t) -> *mut ::group; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "popen$UNIX2003")] @@ -744,3 +694,14 @@ cfg_if! { pub use target_arch_not_implemented; } } + +cfg_if! { + if #[cfg(libc_align)] { + #[macro_use] + mod align; + } else { + #[macro_use] + mod no_align; + } +} +expand_align!(); diff --git a/libc/src/unix/newlib/no_align.rs b/libc/src/unix/newlib/no_align.rs new file mode 100644 index 0000000..316c464 --- /dev/null +++ b/libc/src/unix/newlib/no_align.rs @@ -0,0 +1,51 @@ +macro_rules! expand_align { + () => { + s! { + pub struct pthread_mutex_t { // Unverified + #[cfg(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))] + __align: [::c_long; 0], + #[cfg(not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + pub struct pthread_rwlock_t { // Unverified + #[cfg(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))] + __align: [::c_long; 0], + #[cfg(not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + + pub struct pthread_mutexattr_t { // Unverified + #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64", + target_arch = "mips64", target_arch = "s390x", + target_arch = "sparc64"))] + __align: [::c_int; 0], + #[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64", + target_arch = "mips64", target_arch = "s390x", + target_arch = "sparc64")))] + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + pub struct pthread_cond_t { // Unverified + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + + pub struct pthread_condattr_t { // Unverified + __align: [::c_int; 0], + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + } +} diff --git a/libc/src/unix/no_align.rs b/libc/src/unix/no_align.rs new file mode 100644 index 0000000..f6b9f4c --- /dev/null +++ b/libc/src/unix/no_align.rs @@ -0,0 +1,6 @@ +s! { + pub struct in6_addr { + pub s6_addr: [u8; 16], + __align: [u32; 0], + } +} diff --git a/libc/src/unix/notbsd/android/b32/mod.rs b/libc/src/unix/notbsd/android/b32/mod.rs index 394abe8..a8cc51b 100644 --- a/libc/src/unix/notbsd/android/b32/mod.rs +++ b/libc/src/unix/notbsd/android/b32/mod.rs @@ -14,7 +14,7 @@ s! { pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, pub sa_flags: ::c_ulong, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, } pub struct rlimit64 { diff --git a/libc/src/unix/notbsd/android/b64/mod.rs b/libc/src/unix/notbsd/android/b64/mod.rs index fb94334..46becc5 100644 --- a/libc/src/unix/notbsd/android/b64/mod.rs +++ b/libc/src/unix/notbsd/android/b64/mod.rs @@ -16,7 +16,7 @@ s! { pub sa_flags: ::c_uint, pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, } pub struct rlimit64 { @@ -34,25 +34,6 @@ s! { __reserved: [::c_char; 16], } - pub struct pthread_mutex_t { - value: ::c_int, - __reserved: [::c_char; 36], - } - - pub struct pthread_cond_t { - value: ::c_int, - __reserved: [::c_char; 44], - } - - pub struct pthread_rwlock_t { - numLocks: ::c_int, - writerThreadId: ::c_int, - pendingReaders: ::c_int, - pendingWriters: ::c_int, - attr: i32, - __reserved: [::c_char; 36], - } - pub struct passwd { pub pw_name: *mut ::c_char, pub pw_passwd: *mut ::c_char, @@ -126,6 +107,130 @@ s! { } } +s_no_extra_traits!{ + pub struct pthread_mutex_t { + value: ::c_int, + __reserved: [::c_char; 36], + } + + pub struct pthread_cond_t { + value: ::c_int, + __reserved: [::c_char; 44], + } + + pub struct pthread_rwlock_t { + numLocks: ::c_int, + writerThreadId: ::c_int, + pendingReaders: ::c_int, + pendingWriters: ::c_int, + attr: i32, + __reserved: [::c_char; 36], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for pthread_mutex_t { + fn eq(&self, other: &pthread_mutex_t) -> bool { + self.value == other.value + && self + .__reserved + .iter() + .zip(other.__reserved.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for pthread_mutex_t {} + + impl ::fmt::Debug for pthread_mutex_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_mutex_t") + .field("value", &self.value) + // FIXME: .field("__reserved", &self.__reserved) + .finish() + } + } + + impl ::hash::Hash for pthread_mutex_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.value.hash(state); + self.__reserved.hash(state); + } + } + + impl PartialEq for pthread_cond_t { + fn eq(&self, other: &pthread_cond_t) -> bool { + self.value == other.value + && self + .__reserved + .iter() + .zip(other.__reserved.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for pthread_cond_t {} + + impl ::fmt::Debug for pthread_cond_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_cond_t") + .field("value", &self.value) + // FIXME: .field("__reserved", &self.__reserved) + .finish() + } + } + + impl ::hash::Hash for pthread_cond_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.value.hash(state); + self.__reserved.hash(state); + } + } + + impl PartialEq for pthread_rwlock_t { + fn eq(&self, other: &pthread_rwlock_t) -> bool { + self.numLocks == other.numLocks + && self.writerThreadId == other.writerThreadId + && self.pendingReaders == other.pendingReaders + && self.pendingWriters == other.pendingWriters + && self.attr == other.attr + && self + .__reserved + .iter() + .zip(other.__reserved.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for pthread_rwlock_t {} + + impl ::fmt::Debug for pthread_rwlock_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_rwlock_t") + .field("numLocks", &self.numLocks) + .field("writerThreadId", &self.writerThreadId) + .field("pendingReaders", &self.pendingReaders) + .field("pendingWriters", &self.pendingWriters) + .field("attr", &self.attr) + // FIXME: .field("__reserved", &self.__reserved) + .finish() + } + } + + impl ::hash::Hash for pthread_rwlock_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.numLocks.hash(state); + self.writerThreadId.hash(state); + self.pendingReaders.hash(state); + self.pendingWriters.hash(state); + self.attr.hash(state); + self.__reserved.hash(state); + } + } + } +} + pub const RTLD_GLOBAL: ::c_int = 0x00100; pub const RTLD_NOW: ::c_int = 2; pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; diff --git a/libc/src/unix/notbsd/android/mod.rs b/libc/src/unix/notbsd/android/mod.rs index 972281c..a430b1a 100644 --- a/libc/src/unix/notbsd/android/mod.rs +++ b/libc/src/unix/notbsd/android/mod.rs @@ -1,7 +1,5 @@ //! Android-specific definitions for linux-like values -use dox::{mem, Option}; - pub type clock_t = ::c_long; pub type time_t = ::c_long; pub type suseconds_t = ::c_long; @@ -25,36 +23,12 @@ pub type idtype_t = ::c_int; pub type loff_t = ::c_longlong; s! { - pub struct dirent { - pub d_ino: u64, - pub d_off: i64, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct dirent64 { - pub d_ino: u64, - pub d_off: i64, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - pub struct stack_t { pub ss_sp: *mut ::c_void, pub ss_flags: ::c_int, pub ss_size: ::size_t } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - pub struct __fsid_t { __val: [::c_int; 2], } @@ -116,33 +90,11 @@ s! { __reserved: [::c_int; 3], } - pub struct lastlog { - ll_time: ::time_t, - ll_line: [::c_char; UT_LINESIZE], - ll_host: [::c_char; UT_HOSTSIZE], - } - pub struct exit_status { pub e_termination: ::c_short, pub e_exit: ::c_short, } - pub struct utmp { - pub ut_type: ::c_short, - pub ut_pid: ::pid_t, - pub ut_line: [::c_char; UT_LINESIZE], - pub ut_id: [::c_char; 4], - - pub ut_user: [::c_char; UT_NAMESIZE], - pub ut_host: [::c_char; UT_HOSTSIZE], - pub ut_exit: exit_status, - pub ut_session: ::c_long, - pub ut_tv: ::timeval, - - pub ut_addr_v6: [::int32_t; 4], - unused: [::c_char; 20], - } - pub struct statvfs { pub f_bsize: ::c_ulong, pub f_frsize: ::c_ulong, @@ -238,6 +190,361 @@ s! { pub ipi6_addr: ::in6_addr, pub ipi6_ifindex: ::c_int, } + + pub struct inotify_event { + pub wd: ::c_int, + pub mask: ::uint32_t, + pub cookie: ::uint32_t, + pub len: ::uint32_t + } +} + +s_no_extra_traits!{ + pub struct dirent { + pub d_ino: u64, + pub d_off: i64, + pub d_reclen: ::c_ushort, + pub d_type: ::c_uchar, + pub d_name: [::c_char; 256], + } + + pub struct dirent64 { + pub d_ino: u64, + pub d_off: i64, + pub d_reclen: ::c_ushort, + pub d_type: ::c_uchar, + pub d_name: [::c_char; 256], + } + + pub struct siginfo_t { + pub si_signo: ::c_int, + pub si_errno: ::c_int, + pub si_code: ::c_int, + pub _pad: [::c_int; 29], + _align: [usize; 0], + } + + pub struct lastlog { + ll_time: ::time_t, + ll_line: [::c_char; UT_LINESIZE], + ll_host: [::c_char; UT_HOSTSIZE], + } + + pub struct utmp { + pub ut_type: ::c_short, + pub ut_pid: ::pid_t, + pub ut_line: [::c_char; UT_LINESIZE], + pub ut_id: [::c_char; 4], + pub ut_user: [::c_char; UT_NAMESIZE], + pub ut_host: [::c_char; UT_HOSTSIZE], + pub ut_exit: exit_status, + pub ut_session: ::c_long, + pub ut_tv: ::timeval, + pub ut_addr_v6: [::int32_t; 4], + unused: [::c_char; 20], + } + + pub struct sockaddr_alg { + pub salg_family: ::sa_family_t, + pub salg_type: [::c_uchar; 14], + pub salg_feat: u32, + pub salg_mask: u32, + pub salg_name: [::c_uchar; 64], + } + + pub struct af_alg_iv { + pub ivlen: u32, + pub iv: [::c_uchar; 0], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for dirent {} + + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for dirent64 { + fn eq(&self, other: &dirent64) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for dirent64 {} + + impl ::fmt::Debug for dirent64 { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent64") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + + impl ::hash::Hash for dirent64 { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for siginfo_t { + fn eq(&self, other: &siginfo_t) -> bool { + self.si_signo == other.si_signo + && self.si_errno == other.si_errno + && self.si_code == other.si_code + // Ignore _pad + // Ignore _align + } + } + + impl Eq for siginfo_t {} + + impl ::fmt::Debug for siginfo_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("siginfo_t") + .field("si_signo", &self.si_signo) + .field("si_errno", &self.si_errno) + .field("si_code", &self.si_code) + // Ignore _pad + // Ignore _align + .finish() + } + } + + impl ::hash::Hash for siginfo_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.si_signo.hash(state); + self.si_errno.hash(state); + self.si_code.hash(state); + // Ignore _pad + // Ignore _align + } + } + + impl PartialEq for lastlog { + fn eq(&self, other: &lastlog) -> bool { + self.ll_time == other.ll_time + && self + .ll_line + .iter() + .zip(other.ll_line.iter()) + .all(|(a,b)| a == b) + && self + .ll_host + .iter() + .zip(other.ll_host.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for lastlog {} + + impl ::fmt::Debug for lastlog { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("lastlog") + .field("ll_time", &self.ll_time) + .field("ll_line", &self.ll_line) + // FIXME: .field("ll_host", &self.ll_host) + .finish() + } + } + + impl ::hash::Hash for lastlog { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ll_time.hash(state); + self.ll_line.hash(state); + self.ll_host.hash(state); + } + } + + impl PartialEq for utmp { + fn eq(&self, other: &utmp) -> bool { + self.ut_type == other.ut_type + && self.ut_pid == other.ut_pid + && self + .ut_line + .iter() + .zip(other.ut_line.iter()) + .all(|(a,b)| a == b) + && self.ut_id == other.ut_id + && self + .ut_user + .iter() + .zip(other.ut_user.iter()) + .all(|(a,b)| a == b) + && self + .ut_host + .iter() + .zip(other.ut_host.iter()) + .all(|(a,b)| a == b) + && self.ut_exit == other.ut_exit + && self.ut_session == other.ut_session + && self.ut_tv == other.ut_tv + && self.ut_addr_v6 == other.ut_addr_v6 + && self.unused == other.unused + } + } + + impl Eq for utmp {} + + impl ::fmt::Debug for utmp { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utmp") + .field("ut_type", &self.ut_type) + .field("ut_pid", &self.ut_pid) + .field("ut_line", &self.ut_line) + .field("ut_id", &self.ut_id) + .field("ut_user", &self.ut_user) + // FIXME: .field("ut_host", &self.ut_host) + .field("ut_exit", &self.ut_exit) + .field("ut_session", &self.ut_session) + .field("ut_tv", &self.ut_tv) + .field("ut_addr_v6", &self.ut_addr_v6) + .field("unused", &self.unused) + .finish() + } + } + + impl ::hash::Hash for utmp { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ut_type.hash(state); + self.ut_pid.hash(state); + self.ut_line.hash(state); + self.ut_id.hash(state); + self.ut_user.hash(state); + self.ut_host.hash(state); + self.ut_exit.hash(state); + self.ut_session.hash(state); + self.ut_tv.hash(state); + self.ut_addr_v6.hash(state); + self.unused.hash(state); + } + } + + impl PartialEq for sockaddr_alg { + fn eq(&self, other: &sockaddr_alg) -> bool { + self.salg_family == other.salg_family + && self + .salg_type + .iter() + .zip(other.salg_type.iter()) + .all(|(a, b)| a == b) + && self.salg_feat == other.salg_feat + && self.salg_mask == other.salg_mask + && self + .salg_name + .iter() + .zip(other.salg_name.iter()) + .all(|(a, b)| a == b) + } + } + + impl Eq for sockaddr_alg {} + + impl ::fmt::Debug for sockaddr_alg { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_alg") + .field("salg_family", &self.salg_family) + .field("salg_type", &self.salg_type) + .field("salg_feat", &self.salg_feat) + .field("salg_mask", &self.salg_mask) + .field("salg_name", &&self.salg_name[..]) + .finish() + } + } + + impl ::hash::Hash for sockaddr_alg { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.salg_family.hash(state); + self.salg_type.hash(state); + self.salg_feat.hash(state); + self.salg_mask.hash(state); + self.salg_name.hash(state); + } + } + + impl af_alg_iv { + fn as_slice(&self) -> &[u8] { + unsafe { + ::core::slice::from_raw_parts( + self.iv.as_ptr(), + self.ivlen as usize + ) + } + } + } + + impl PartialEq for af_alg_iv { + fn eq(&self, other: &af_alg_iv) -> bool { + *self.as_slice() == *other.as_slice() + } + } + + impl Eq for af_alg_iv {} + + impl ::fmt::Debug for af_alg_iv { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("af_alg_iv") + .field("iv", &self.as_slice()) + .finish() + } + } + + impl ::hash::Hash for af_alg_iv { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.as_slice().hash(state); + } + } + } } pub const O_TRUNC: ::c_int = 512; @@ -1052,6 +1359,15 @@ pub const SFD_NONBLOCK: ::c_int = O_NONBLOCK; pub const SOCK_NONBLOCK: ::c_int = O_NONBLOCK; pub const SO_ORIGINAL_DST: ::c_int = 80; +pub const IP_ORIGDSTADDR : ::c_int = 20; +pub const IP_RECVORIGDSTADDR : ::c_int = IP_ORIGDSTADDR; +pub const IPV6_ORIGDSTADDR : ::c_int = 74; +pub const IPV6_RECVORIGDSTADDR : ::c_int = IPV6_ORIGDSTADDR; +pub const IPV6_FLOWINFO: ::c_int = 11; +pub const IPV6_FLOWLABEL_MGR: ::c_int = 32; +pub const IPV6_FLOWINFO_SEND: ::c_int = 33; +pub const IPV6_FLOWINFO_FLOWLABEL: ::c_int = 0x000fffff; +pub const IPV6_FLOWINFO_PRIORITY: ::c_int = 0x0ff00000; pub const IUTF8: ::tcflag_t = 0x00004000; pub const CMSPAR: ::tcflag_t = 0o10000000000; pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; @@ -1476,7 +1792,87 @@ pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002; // Similarity to Linux it's not used but defined for compatibility. pub const ENOATTR: ::c_int = ::ENODATA; +// linux/if_alg.h +pub const ALG_SET_KEY: ::c_int = 1; +pub const ALG_SET_IV: ::c_int = 2; +pub const ALG_SET_OP: ::c_int = 3; +pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4; +pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5; + +pub const ALG_OP_DECRYPT: ::c_int = 0; +pub const ALG_OP_ENCRYPT: ::c_int = 1; + +// uapi/linux/inotify.h +pub const IN_ACCESS: ::uint32_t = 0x0000_0001; +pub const IN_MODIFY: ::uint32_t = 0x0000_0002; +pub const IN_ATTRIB: ::uint32_t = 0x0000_0004; +pub const IN_CLOSE_WRITE: ::uint32_t = 0x0000_0008; +pub const IN_CLOSE_NOWRITE: ::uint32_t = 0x0000_0010; +pub const IN_CLOSE: ::uint32_t = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE); +pub const IN_OPEN: ::uint32_t = 0x0000_0020; +pub const IN_MOVED_FROM: ::uint32_t = 0x0000_0040; +pub const IN_MOVED_TO: ::uint32_t = 0x0000_0080; +pub const IN_MOVE: ::uint32_t = (IN_MOVED_FROM | IN_MOVED_TO); +pub const IN_CREATE: ::uint32_t = 0x0000_0100; +pub const IN_DELETE: ::uint32_t = 0x0000_0200; +pub const IN_DELETE_SELF: ::uint32_t = 0x0000_0400; +pub const IN_MOVE_SELF: ::uint32_t = 0x0000_0800; +pub const IN_UNMOUNT: ::uint32_t = 0x0000_2000; +pub const IN_Q_OVERFLOW: ::uint32_t = 0x0000_4000; +pub const IN_IGNORED: ::uint32_t = 0x0000_8000; +pub const IN_ONLYDIR: ::uint32_t = 0x0100_0000; +pub const IN_DONT_FOLLOW: ::uint32_t = 0x0200_0000; +// pub const IN_EXCL_UNLINK: ::uint32_t = 0x0400_0000; + +// pub const IN_MASK_CREATE: ::uint32_t = 0x1000_0000; +// pub const IN_MASK_ADD: ::uint32_t = 0x2000_0000; +pub const IN_ISDIR: ::uint32_t = 0x4000_0000; +pub const IN_ONESHOT: ::uint32_t = 0x8000_0000; + +pub const IN_ALL_EVENTS: ::uint32_t = ( + IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | + IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | + IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | + IN_MOVE_SELF +); + +pub const IN_CLOEXEC: ::c_int = O_CLOEXEC; +pub const IN_NONBLOCK: ::c_int = O_NONBLOCK; + +pub const FUTEX_WAIT: ::c_int = 0; +pub const FUTEX_WAKE: ::c_int = 1; +pub const FUTEX_FD: ::c_int = 2; +pub const FUTEX_REQUEUE: ::c_int = 3; +pub const FUTEX_CMP_REQUEUE: ::c_int = 4; +pub const FUTEX_WAKE_OP: ::c_int = 5; +pub const FUTEX_LOCK_PI: ::c_int = 6; +pub const FUTEX_UNLOCK_PI: ::c_int = 7; +pub const FUTEX_TRYLOCK_PI: ::c_int = 8; +pub const FUTEX_WAIT_BITSET: ::c_int = 9; +pub const FUTEX_WAKE_BITSET: ::c_int = 10; +pub const FUTEX_WAIT_REQUEUE_PI: ::c_int = 11; +pub const FUTEX_CMP_REQUEUE_PI: ::c_int = 12; + +pub const FUTEX_PRIVATE_FLAG: ::c_int = 128; +pub const FUTEX_CLOCK_REALTIME: ::c_int = 256; +pub const FUTEX_CMD_MASK: ::c_int = + !(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME); + f! { + pub fn CMSG_NXTHDR(mhdr: *const msghdr, + cmsg: *const cmsghdr) -> *mut cmsghdr { + let next = (cmsg as usize + + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) + as *mut cmsghdr; + let max = (*mhdr).msg_control as usize + + (*mhdr).msg_controllen as usize; + if (next.offset(1)) as usize > max { + 0 as *mut cmsghdr + } else { + next as *mut cmsghdr + } + } + pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.__bits.iter_mut() { *slot = 0; @@ -1484,21 +1880,21 @@ f! { } pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in___bits = 8 * mem::size_of_val(&cpuset.__bits[0]); + let size_in___bits = 8 * ::mem::size_of_val(&cpuset.__bits[0]); let (idx, offset) = (cpu / size_in___bits, cpu % size_in___bits); cpuset.__bits[idx] |= 1 << offset; () } pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in___bits = 8 * mem::size_of_val(&cpuset.__bits[0]); + let size_in___bits = 8 * ::mem::size_of_val(&cpuset.__bits[0]); let (idx, offset) = (cpu / size_in___bits, cpu % size_in___bits); cpuset.__bits[idx] &= !(1 << offset); () } pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in___bits = 8 * mem::size_of_val(&cpuset.__bits[0]); + let size_in___bits = 8 * ::mem::size_of_val(&cpuset.__bits[0]); let (idx, offset) = (cpu / size_in___bits, cpu % size_in___bits); 0 != (cpuset.__bits[idx] & (1 << offset)) } @@ -1654,7 +2050,7 @@ extern { pub fn setfsuid(uid: ::uid_t) -> ::c_int; pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int; #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r(uid: ::uid_t, + pub fn getgrgid_r(gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, @@ -1700,9 +2096,9 @@ extern { #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork(prepare: Option<unsafe extern fn()>, - parent: Option<unsafe extern fn()>, - child: Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; pub fn getgrgid(gid: ::gid_t) -> *mut ::group; pub fn getgrouplist(user: *const ::c_char, group: ::gid_t, @@ -1722,6 +2118,16 @@ extern { f: extern fn(*mut ::c_void) -> *mut ::c_void, value: *mut ::c_void) -> ::c_int; pub fn __errno() -> *mut ::c_int; + pub fn inotify_rm_watch(fd: ::c_int, wd: ::uint32_t) -> ::c_int; + pub fn sendmmsg(sockfd: ::c_int, msgvec: *const ::mmsghdr, vlen: ::c_uint, + flags: ::c_int) -> ::c_int; + pub fn recvmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::c_uint, + flags: ::c_int, timeout: *const ::timespec) -> ::c_int; + pub fn inotify_init() -> ::c_int; + pub fn inotify_init1(flags: ::c_int) -> ::c_int; + pub fn inotify_add_watch(fd: ::c_int, + path: *const ::c_char, + mask: ::uint32_t) -> ::c_int; } cfg_if! { diff --git a/libc/src/unix/notbsd/emscripten/align.rs b/libc/src/unix/notbsd/emscripten/align.rs new file mode 100644 index 0000000..26a49b2 --- /dev/null +++ b/libc/src/unix/notbsd/emscripten/align.rs @@ -0,0 +1,66 @@ +macro_rules! expand_align { + () => { + s! { + #[repr(align(4))] + pub struct pthread_mutex_t { + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + #[repr(align(4))] + pub struct pthread_rwlock_t { + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + + #[repr(align(4))] + pub struct pthread_mutexattr_t { + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + #[repr(align(4))] + pub struct pthread_rwlockattr_t { + size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], + } + + #[repr(align(4))] + pub struct pthread_condattr_t { + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + + s_no_extra_traits! { + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct pthread_cond_t { + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + } + + cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for pthread_cond_t { + fn eq(&self, other: &pthread_cond_t) -> bool { + self.size + .iter() + .zip(other.size.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_cond_t {} + impl ::fmt::Debug for pthread_cond_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_cond_t") + // FIXME: .field("size", &self.size) + .finish() + } + } + impl ::hash::Hash for pthread_cond_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.size.hash(state); + } + } + } + } + } +} diff --git a/libc/src/unix/notbsd/emscripten.rs b/libc/src/unix/notbsd/emscripten/mod.rs index 28791d8..0f8c76e 100644 --- a/libc/src/unix/notbsd/emscripten.rs +++ b/libc/src/unix/notbsd/emscripten/mod.rs @@ -1,5 +1,3 @@ -use dox::{mem, Option}; - pub type c_char = i8; pub type wchar_t = i32; pub type useconds_t = u32; @@ -35,25 +33,14 @@ pub type c_long = i32; pub type c_ulong = u32; pub type nlink_t = u32; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos64_t {} // TODO: fill this out with a struct +impl ::Copy for fpos64_t {} +impl ::Clone for fpos64_t { + fn clone(&self) -> fpos64_t { *self } +} s! { - 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; 256], - } - - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - pub struct rlimit64 { pub rlim_cur: rlim64_t, pub rlim_max: rlim64_t, @@ -72,51 +59,6 @@ s! { __unused5: *mut ::c_void, } - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_mutex_t { - #[cfg(not(feature = "align"))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_rwlock_t { - #[cfg(not(feature = "align"))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCK_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_mutexattr_t { - #[cfg(not(feature = "align"))] - __align: [::c_int; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_rwlockattr_t { - #[cfg(not(feature = "align"))] - __align: [::c_int; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - #[cfg_attr(all(feature = "align", target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", target_pointer_width = "64"), - repr(align(8)))] - pub struct pthread_cond_t { - #[cfg(not(feature = "align"))] - __align: [*const ::c_void; 0], - size: [u8; __SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_condattr_t { - #[cfg(not(feature = "align"))] - __align: [::c_int; 0], - size: [u8; __SIZEOF_PTHREAD_CONDATTR_T], - } - pub struct passwd { pub pw_name: *mut ::c_char, pub pw_passwd: *mut ::c_char, @@ -225,11 +167,6 @@ s! { pub msgseg: ::c_ushort, } - pub struct mmsghdr { - pub msg_hdr: ::msghdr, - pub msg_len: ::c_uint, - } - pub struct sembuf { pub sem_num: ::c_ushort, pub sem_op: ::c_short, @@ -257,7 +194,7 @@ s! { pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, pub sa_flags: ::c_int, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, } pub struct ipc_perm { @@ -291,23 +228,6 @@ s! { pub l_pid: ::pid_t, } - pub struct sysinfo { - pub uptime: ::c_ulong, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub __reserved: [::c_char; 256], - } - pub struct pthread_attr_t { __size: [u32; 11] } @@ -482,6 +402,177 @@ s! { } } +s_no_extra_traits! { + 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; 256], + } + + pub struct dirent64 { + pub d_ino: ::ino64_t, + pub d_off: ::off64_t, + pub d_reclen: ::c_ushort, + pub d_type: ::c_uchar, + pub d_name: [::c_char; 256], + } + + pub struct sysinfo { + pub uptime: ::c_ulong, + pub loads: [::c_ulong; 3], + pub totalram: ::c_ulong, + pub freeram: ::c_ulong, + pub sharedram: ::c_ulong, + pub bufferram: ::c_ulong, + pub totalswap: ::c_ulong, + pub freeswap: ::c_ulong, + pub procs: ::c_ushort, + pub pad: ::c_ushort, + pub totalhigh: ::c_ulong, + pub freehigh: ::c_ulong, + pub mem_unit: ::c_uint, + pub __reserved: [::c_char; 256], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent {} + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for dirent64 { + fn eq(&self, other: &dirent64) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for dirent64 {} + impl ::fmt::Debug for dirent64 { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent64") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + impl ::hash::Hash for dirent64 { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for sysinfo { + fn eq(&self, other: &sysinfo) -> bool { + self.uptime == other.uptime + && self.loads == other.loads + && self.totalram == other.totalram + && self.freeram == other.freeram + && self.sharedram == other.sharedram + && self.bufferram == other.bufferram + && self.totalswap == other.totalswap + && self.freeswap == other.freeswap + && self.procs == other.procs + && self.pad == other.pad + && self.totalhigh == other.totalhigh + && self.freehigh == other.freehigh + && self.mem_unit == other.mem_unit + && self + .__reserved + .iter() + .zip(other.__reserved.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sysinfo {} + impl ::fmt::Debug for sysinfo { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sysinfo") + .field("uptime", &self.uptime) + .field("loads", &self.loads) + .field("totalram", &self.totalram) + .field("freeram", &self.freeram) + .field("sharedram", &self.sharedram) + .field("bufferram", &self.bufferram) + .field("totalswap", &self.totalswap) + .field("freeswap", &self.freeswap) + .field("procs", &self.procs) + .field("pad", &self.pad) + .field("totalhigh", &self.totalhigh) + .field("freehigh", &self.freehigh) + .field("mem_unit", &self.mem_unit) + // FIXME: .field("__reserved", &self.__reserved) + .finish() + } + } + impl ::hash::Hash for sysinfo { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.uptime.hash(state); + self.loads.hash(state); + self.totalram.hash(state); + self.freeram.hash(state); + self.sharedram.hash(state); + self.bufferram.hash(state); + self.totalswap.hash(state); + self.freeswap.hash(state); + self.procs.hash(state); + self.pad.hash(state); + self.totalhigh.hash(state); + self.freehigh.hash(state); + self.mem_unit.hash(state); + self.__reserved.hash(state); + } + } + } +} + pub const ABDAY_1: ::nl_item = 0x20000; pub const ABDAY_2: ::nl_item = 0x20001; pub const ABDAY_3: ::nl_item = 0x20002; @@ -1510,6 +1601,23 @@ pub const ARPD_FLUSH: ::c_ushort = 0x03; pub const ATF_MAGIC: ::c_int = 0x80; f! { + pub fn CMSG_NXTHDR(mhdr: *const msghdr, + cmsg: *const cmsghdr) -> *mut cmsghdr { + if ((*cmsg).cmsg_len as usize) < ::mem::size_of::<cmsghdr>() { + return 0 as *mut cmsghdr; + }; + let next = (cmsg as usize + + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) + as *mut cmsghdr; + let max = (*mhdr).msg_control as usize + + (*mhdr).msg_controllen as usize; + if (next.offset(1)) as usize > max { + 0 as *mut cmsghdr + } else { + next as *mut cmsghdr + } + } + pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.bits.iter_mut() { *slot = 0; @@ -1517,21 +1625,23 @@ f! { } pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc + let size_in_bits + = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); cpuset.bits[idx] |= 1 << offset; () } pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc + let size_in_bits + = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); cpuset.bits[idx] &= !(1 << offset); () } pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); + let size_in_bits = 8 * ::mem::size_of_val(&cpuset.bits[0]); let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); 0 != (cpuset.bits[idx] & (1 << offset)) } @@ -1640,7 +1750,7 @@ extern { pub fn glob(pattern: *const c_char, flags: ::c_int, - errfunc: Option<extern fn(epath: *const c_char, + errfunc: ::Option<extern fn(epath: *const c_char, errno: ::c_int) -> ::c_int>, pglob: *mut ::glob_t) -> ::c_int; pub fn globfree(pglob: *mut ::glob_t); @@ -1666,9 +1776,9 @@ extern { pub fn getdomainname(name: *mut ::c_char, len: ::size_t) -> ::c_int; pub fn setdomainname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn sendmmsg(sockfd: ::c_int, msgvec: *mut mmsghdr, vlen: ::c_uint, + pub fn sendmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::c_uint, flags: ::c_int) -> ::c_int; - pub fn recvmmsg(sockfd: ::c_int, msgvec: *mut mmsghdr, vlen: ::c_uint, + pub fn recvmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::c_uint, flags: ::c_int, timeout: *mut ::timespec) -> ::c_int; pub fn sync(); pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; @@ -1679,3 +1789,14 @@ extern { f: extern fn(*mut ::c_void) -> *mut ::c_void, value: *mut ::c_void) -> ::c_int; } + +cfg_if! { + if #[cfg(libc_align)] { + #[macro_use] + mod align; + } else { + #[macro_use] + mod no_align; + } +} +expand_align!(); diff --git a/libc/src/unix/notbsd/emscripten/no_align.rs b/libc/src/unix/notbsd/emscripten/no_align.rs new file mode 100644 index 0000000..ece4dff --- /dev/null +++ b/libc/src/unix/notbsd/emscripten/no_align.rs @@ -0,0 +1,63 @@ +macro_rules! expand_align { + () => { + s! { + pub struct pthread_mutex_t { + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + pub struct pthread_rwlock_t { + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + + pub struct pthread_mutexattr_t { + __align: [::c_int; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + pub struct pthread_rwlockattr_t { + __align: [::c_int; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], + } + + pub struct pthread_condattr_t { + __align: [::c_int; 0], + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + + s_no_extra_traits! { + pub struct pthread_cond_t { + __align: [*const ::c_void; 0], + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + } + + cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for pthread_cond_t { + fn eq(&self, other: &pthread_cond_t) -> bool { + self.size + .iter() + .zip(other.size.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_cond_t {} + impl ::fmt::Debug for pthread_cond_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_cond_t") + // FIXME: .field("size", &self.size) + .finish() + } + } + impl ::hash::Hash for pthread_cond_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.size.hash(state); + } + } + } + } + } +} diff --git a/libc/src/unix/notbsd/linux/align.rs b/libc/src/unix/notbsd/linux/align.rs new file mode 100644 index 0000000..0ff4649 --- /dev/null +++ b/libc/src/unix/notbsd/linux/align.rs @@ -0,0 +1,98 @@ +macro_rules! expand_align { + () => { + s! { + #[cfg_attr(any(target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64", + target_arch = "aarch64"), + repr(align(4)))] + #[cfg_attr(not(any(target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64", + target_arch = "aarch64")), + repr(align(8)))] + pub struct pthread_mutexattr_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + #[cfg_attr(any(target_env = "musl", target_pointer_width = "32"), + repr(align(4)))] + #[cfg_attr(all(not(target_env = "musl"), + target_pointer_width = "64"), + repr(align(8)))] + pub struct pthread_rwlockattr_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], + } + + #[repr(align(4))] + pub struct pthread_condattr_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + + s_no_extra_traits! { + #[cfg_attr(all(target_env = "musl", + target_pointer_width = "32"), + repr(align(4)))] + #[cfg_attr(all(target_env = "musl", + target_pointer_width = "64"), + repr(align(8)))] + #[cfg_attr(all(not(target_env = "musl"), + target_arch = "x86"), + repr(align(4)))] + #[cfg_attr(all(not(target_env = "musl"), + not(target_arch = "x86")), + repr(align(8)))] + pub struct pthread_cond_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc", + target_arch = "x86_64", + target_arch = "x86")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc", + target_arch = "x86_64", + target_arch = "x86"))), + repr(align(8)))] + pub struct pthread_mutex_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc", + target_arch = "x86_64", + target_arch = "x86")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc", + target_arch = "x86_64", + target_arch = "x86"))), + repr(align(8)))] + pub struct pthread_rwlock_t { + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + } + } +} diff --git a/libc/src/unix/notbsd/linux/mips/align.rs b/libc/src/unix/notbsd/linux/mips/align.rs new file mode 100644 index 0000000..4a0e074 --- /dev/null +++ b/libc/src/unix/notbsd/linux/mips/align.rs @@ -0,0 +1,13 @@ +s! { + // FIXME this is actually a union + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct sem_t { + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + } +} diff --git a/libc/src/unix/notbsd/linux/mips/mips32.rs b/libc/src/unix/notbsd/linux/mips/mips32.rs index a6c08a5..d9d5589 100644 --- a/libc/src/unix/notbsd/linux/mips/mips32.rs +++ b/libc/src/unix/notbsd/linux/mips/mips32.rs @@ -133,7 +133,7 @@ s! { pub sa_flags: ::c_int, pub sa_sigaction: ::sighandler_t, pub sa_mask: sigset_t, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, _resv: [::c_int; 1], } @@ -353,7 +353,6 @@ pub const SYS_mknod: ::c_long = 4000 + 14; pub const SYS_chmod: ::c_long = 4000 + 15; pub const SYS_lchown: ::c_long = 4000 + 16; pub const SYS_break: ::c_long = 4000 + 17; -pub const SYS_unused18: ::c_long = 4000 + 18; pub const SYS_lseek: ::c_long = 4000 + 19; pub const SYS_getpid: ::c_long = 4000 + 20; pub const SYS_mount: ::c_long = 4000 + 21; @@ -363,7 +362,6 @@ pub const SYS_getuid: ::c_long = 4000 + 24; pub const SYS_stime: ::c_long = 4000 + 25; pub const SYS_ptrace: ::c_long = 4000 + 26; pub const SYS_alarm: ::c_long = 4000 + 27; -pub const SYS_unused28: ::c_long = 4000 + 28; pub const SYS_pause: ::c_long = 4000 + 29; pub const SYS_utime: ::c_long = 4000 + 30; pub const SYS_stty: ::c_long = 4000 + 31; @@ -394,7 +392,6 @@ pub const SYS_fcntl: ::c_long = 4000 + 55; pub const SYS_mpx: ::c_long = 4000 + 56; pub const SYS_setpgid: ::c_long = 4000 + 57; pub const SYS_ulimit: ::c_long = 4000 + 58; -pub const SYS_unused59: ::c_long = 4000 + 59; pub const SYS_umask: ::c_long = 4000 + 60; pub const SYS_chroot: ::c_long = 4000 + 61; pub const SYS_ustat: ::c_long = 4000 + 62; @@ -417,9 +414,7 @@ pub const SYS_gettimeofday: ::c_long = 4000 + 78; pub const SYS_settimeofday: ::c_long = 4000 + 79; pub const SYS_getgroups: ::c_long = 4000 + 80; pub const SYS_setgroups: ::c_long = 4000 + 81; -pub const SYS_reserved82: ::c_long = 4000 + 82; pub const SYS_symlink: ::c_long = 4000 + 83; -pub const SYS_unused84: ::c_long = 4000 + 84; pub const SYS_readlink: ::c_long = 4000 + 85; pub const SYS_uselib: ::c_long = 4000 + 86; pub const SYS_swapon: ::c_long = 4000 + 87; @@ -444,7 +439,6 @@ pub const SYS_getitimer: ::c_long = 4000 + 105; pub const SYS_stat: ::c_long = 4000 + 106; pub const SYS_lstat: ::c_long = 4000 + 107; pub const SYS_fstat: ::c_long = 4000 + 108; -pub const SYS_unused109: ::c_long = 4000 + 109; pub const SYS_iopl: ::c_long = 4000 + 110; pub const SYS_vhangup: ::c_long = 4000 + 111; pub const SYS_idle: ::c_long = 4000 + 112; @@ -485,7 +479,6 @@ pub const SYS_writev: ::c_long = 4000 + 146; pub const SYS_cacheflush: ::c_long = 4000 + 147; pub const SYS_cachectl: ::c_long = 4000 + 148; pub const SYS_sysmips: ::c_long = 4000 + 149; -pub const SYS_unused150: ::c_long = 4000 + 150; pub const SYS_getsid: ::c_long = 4000 + 151; pub const SYS_fdatasync: ::c_long = 4000 + 152; pub const SYS__sysctl: ::c_long = 4000 + 153; @@ -556,7 +549,6 @@ pub const SYS_mincore: ::c_long = 4000 + 217; pub const SYS_madvise: ::c_long = 4000 + 218; pub const SYS_getdents64: ::c_long = 4000 + 219; pub const SYS_fcntl64: ::c_long = 4000 + 220; -pub const SYS_reserved221: ::c_long = 4000 + 221; pub const SYS_gettid: ::c_long = 4000 + 222; pub const SYS_readahead: ::c_long = 4000 + 223; pub const SYS_setxattr: ::c_long = 4000 + 224; diff --git a/libc/src/unix/notbsd/linux/mips/mips64.rs b/libc/src/unix/notbsd/linux/mips/mips64.rs index e8b02a3..f480e50 100644 --- a/libc/src/unix/notbsd/linux/mips/mips64.rs +++ b/libc/src/unix/notbsd/linux/mips/mips64.rs @@ -131,7 +131,7 @@ s! { pub sa_flags: ::c_int, pub sa_sigaction: ::sighandler_t, pub sa_mask: sigset_t, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, } pub struct stack_t { @@ -496,7 +496,6 @@ pub const SYS_nfsservctl: ::c_long = 5000 + 173; pub const SYS_getpmsg: ::c_long = 5000 + 174; pub const SYS_putpmsg: ::c_long = 5000 + 175; pub const SYS_afs_syscall: ::c_long = 5000 + 176; -pub const SYS_reserved177: ::c_long = 5000 + 177; pub const SYS_gettid: ::c_long = 5000 + 178; pub const SYS_readahead: ::c_long = 5000 + 179; pub const SYS_setxattr: ::c_long = 5000 + 180; @@ -512,7 +511,6 @@ pub const SYS_removexattr: ::c_long = 5000 + 189; pub const SYS_lremovexattr: ::c_long = 5000 + 190; pub const SYS_fremovexattr: ::c_long = 5000 + 191; pub const SYS_tkill: ::c_long = 5000 + 192; -pub const SYS_reserved193: ::c_long = 5000 + 193; pub const SYS_futex: ::c_long = 5000 + 194; pub const SYS_sched_setaffinity: ::c_long = 5000 + 195; pub const SYS_sched_getaffinity: ::c_long = 5000 + 196; diff --git a/libc/src/unix/notbsd/linux/mips/mod.rs b/libc/src/unix/notbsd/linux/mips/mod.rs index 8809bef..35534b4 100644 --- a/libc/src/unix/notbsd/linux/mips/mod.rs +++ b/libc/src/unix/notbsd/linux/mips/mod.rs @@ -20,20 +20,6 @@ s! { __unused5: *mut ::c_void, } - // FIXME this is actually a union - #[cfg_attr(all(feature = "align", target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", target_pointer_width = "64"), - repr(align(8)))] - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - #[cfg(not(feature = "align"))] - __align: [::c_long; 0], - } - pub struct termios2 { pub c_iflag: ::tcflag_t, pub c_oflag: ::tcflag_t, @@ -720,10 +706,10 @@ pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10; pub const GENL_ID_VFS_DQUOT: ::c_int = ::NLMSG_MIN_TYPE + 1; pub const GENL_ID_PMCRAID: ::c_int = ::NLMSG_MIN_TYPE + 2; -pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32; -pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32; -pub const NFT_SET_MAXNAMELEN: ::c_int = 32; -pub const NFT_OBJ_MAXNAMELEN: ::c_int = 32; +pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256; +pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 256; +pub const NFT_SET_MAXNAMELEN: ::c_int = 256; +pub const NFT_OBJ_MAXNAMELEN: ::c_int = 256; pub const NFT_USERDATA_MAXLEN: ::c_int = 256; pub const NFT_REG_VERDICT: ::c_int = 0; @@ -780,7 +766,7 @@ pub const NFT_MSG_NEWOBJ: ::c_int = 18; pub const NFT_MSG_GETOBJ: ::c_int = 19; pub const NFT_MSG_DELOBJ: ::c_int = 20; pub const NFT_MSG_GETOBJ_RESET: ::c_int = 21; -pub const NFT_MSG_MAX: ::c_int = 22; +pub const NFT_MSG_MAX: ::c_int = 25; pub const NFT_SET_ANONYMOUS: ::c_int = 0x1; pub const NFT_SET_CONSTANT: ::c_int = 0x2; @@ -927,7 +913,7 @@ extern { sz: ::c_int) -> ::c_int; pub fn glob64(pattern: *const ::c_char, flags: ::c_int, - errfunc: ::dox::Option<extern fn(epath: *const ::c_char, + errfunc: ::Option<extern fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, pglob: *mut glob64_t) -> ::c_int; @@ -962,3 +948,13 @@ cfg_if! { // Unknown target_arch } } + +cfg_if! { + if #[cfg(libc_align)] { + mod align; + pub use self::align::*; + } else { + mod no_align; + pub use self::no_align::*; + } +} diff --git a/libc/src/unix/notbsd/linux/mips/no_align.rs b/libc/src/unix/notbsd/linux/mips/no_align.rs new file mode 100644 index 0000000..e32bf67 --- /dev/null +++ b/libc/src/unix/notbsd/linux/mips/no_align.rs @@ -0,0 +1,10 @@ +s! { + // FIXME this is actually a union + pub struct sem_t { + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + __align: [::c_long; 0], + } +} diff --git a/libc/src/unix/notbsd/linux/mod.rs b/libc/src/unix/notbsd/linux/mod.rs index 8669a06..2419a41 100644 --- a/libc/src/unix/notbsd/linux/mod.rs +++ b/libc/src/unix/notbsd/linux/mod.rs @@ -1,7 +1,5 @@ //! Linux-specific definitions for linux-like values -use dox::{mem, Option}; - pub type useconds_t = u32; pub type dev_t = u64; pub type socklen_t = u32; @@ -38,25 +36,14 @@ pub type Elf64_Sxword = i64; pub type Elf32_Section = u16; pub type Elf64_Section = u16; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos64_t {} // TODO: fill this out with a struct +impl ::Copy for fpos64_t {} +impl ::Clone for fpos64_t { + fn clone(&self) -> fpos64_t { *self } +} s! { - 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; 256], - } - - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - pub struct rlimit64 { pub rlim_cur: rlim64_t, pub rlim_max: rlim64_t, @@ -75,150 +62,6 @@ s! { __unused5: *mut ::c_void, } - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "x86_64", - target_arch = "x86")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "x86_64", - target_arch = "x86")))), - repr(align(8)))] - pub struct pthread_mutex_t { - #[cfg(all(not(feature = "align"), - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "x86_64", - target_arch = "x86")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "x86_64", - target_arch = "x86")))), - repr(align(8)))] - pub struct pthread_rwlock_t { - #[cfg(all(not(feature = "align"), - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCK_T], - } - - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "32", - target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64", - all(target_arch = "aarch64", target_env = "musl"))), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(any(target_pointer_width = "32", - target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64", - all(target_arch = "aarch64", target_env = "musl")))), - repr(align(8)))] - pub struct pthread_mutexattr_t { - #[cfg(all(not(features = "align"), - any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64", - all(target_arch = "aarch64", target_env = "musl"))))] - __align: [::c_int; 0], - #[cfg(all(not(features = "align"), - not(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64", - all(target_arch = "aarch64", target_env = "musl")))))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[cfg_attr(all(feature = "align", - any(target_env = "musl", target_pointer_width = "32")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(target_env = "musl"), - target_pointer_width = "64"), - repr(align(8)))] - pub struct pthread_rwlockattr_t { - #[cfg(all(not(feature = "align"), target_env = "musl"))] - __align: [::c_int; 0], - #[cfg(all(not(feature = "align"), not(target_env = "musl")))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - #[cfg_attr(all(feature = "align", - target_env = "musl", - target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - target_env = "musl", - target_pointer_width = "64"), - repr(align(8)))] - #[cfg_attr(all(feature = "align", - not(target_env = "musl"), - target_arch = "x86"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(target_env = "musl"), - not(target_arch = "x86")), - repr(align(8)))] - pub struct pthread_cond_t { - #[cfg(all(not(feature = "align"), target_env = "musl"))] - __align: [*const ::c_void; 0], - #[cfg(not(any(feature = "align", target_env = "musl")))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_condattr_t { - #[cfg(not(feature = "align"))] - __align: [::c_int; 0], - size: [u8; __SIZEOF_PTHREAD_CONDATTR_T], - } - pub struct passwd { pub pw_name: *mut ::c_char, pub pw_passwd: *mut ::c_char, @@ -346,11 +189,6 @@ s! { pub msgseg: ::c_ushort, } - pub struct mmsghdr { - pub msg_hdr: ::msghdr, - pub msg_len: ::c_uint, - } - pub struct sembuf { pub sem_num: ::c_ushort, pub sem_op: ::c_short, @@ -655,6 +493,265 @@ s! { pub updated: ::c_ulong, pub ha: [::c_uchar; ::MAX_ADDR_LEN], } + + pub struct inotify_event { + pub wd: ::c_int, + pub mask: ::uint32_t, + pub cookie: ::uint32_t, + pub len: ::uint32_t + } +} + +s_no_extra_traits!{ + 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; 256], + } + + pub struct dirent64 { + pub d_ino: ::ino64_t, + pub d_off: ::off64_t, + pub d_reclen: ::c_ushort, + pub d_type: ::c_uchar, + pub d_name: [::c_char; 256], + } + + pub struct sockaddr_alg { + pub salg_family: ::sa_family_t, + pub salg_type: [::c_uchar; 14], + pub salg_feat: u32, + pub salg_mask: u32, + pub salg_name: [::c_uchar; 64], + } + + pub struct af_alg_iv { + pub ivlen: u32, + pub iv: [::c_uchar; 0], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for dirent { + fn eq(&self, other: &dirent) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for dirent {} + + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for dirent64 { + fn eq(&self, other: &dirent64) -> bool { + self.d_ino == other.d_ino + && self.d_off == other.d_off + && self.d_reclen == other.d_reclen + && self.d_type == other.d_type + && self + .d_name + .iter() + .zip(other.d_name.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for dirent64 {} + + impl ::fmt::Debug for dirent64 { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("dirent64") + .field("d_ino", &self.d_ino) + .field("d_off", &self.d_off) + .field("d_reclen", &self.d_reclen) + .field("d_type", &self.d_type) + // FIXME: .field("d_name", &self.d_name) + .finish() + } + } + + impl ::hash::Hash for dirent64 { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } + } + + impl PartialEq for pthread_cond_t { + fn eq(&self, other: &pthread_cond_t) -> bool { + self.size.iter().zip(other.size.iter()).all(|(a,b)| a == b) + } + } + + impl Eq for pthread_cond_t {} + + impl ::fmt::Debug for pthread_cond_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_cond_t") + // FIXME: .field("size", &self.size) + .finish() + } + } + + impl ::hash::Hash for pthread_cond_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.size.hash(state); + } + } + + impl PartialEq for pthread_mutex_t { + fn eq(&self, other: &pthread_mutex_t) -> bool { + self.size.iter().zip(other.size.iter()).all(|(a,b)| a == b) + } + } + + impl Eq for pthread_mutex_t {} + + impl ::fmt::Debug for pthread_mutex_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_mutex_t") + // FIXME: .field("size", &self.size) + .finish() + } + } + + impl ::hash::Hash for pthread_mutex_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.size.hash(state); + } + } + + impl PartialEq for pthread_rwlock_t { + fn eq(&self, other: &pthread_rwlock_t) -> bool { + self.size.iter().zip(other.size.iter()).all(|(a,b)| a == b) + } + } + + impl Eq for pthread_rwlock_t {} + + impl ::fmt::Debug for pthread_rwlock_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_rwlock_t") + // FIXME: .field("size", &self.size) + .finish() + } + } + + impl ::hash::Hash for pthread_rwlock_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.size.hash(state); + } + } + + impl PartialEq for sockaddr_alg { + fn eq(&self, other: &sockaddr_alg) -> bool { + self.salg_family == other.salg_family + && self + .salg_type + .iter() + .zip(other.salg_type.iter()) + .all(|(a, b)| a == b) + && self.salg_feat == other.salg_feat + && self.salg_mask == other.salg_mask + && self + .salg_name + .iter() + .zip(other.salg_name.iter()) + .all(|(a, b)| a == b) + } + } + + impl Eq for sockaddr_alg {} + + impl ::fmt::Debug for sockaddr_alg { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_alg") + .field("salg_family", &self.salg_family) + .field("salg_type", &self.salg_type) + .field("salg_feat", &self.salg_feat) + .field("salg_mask", &self.salg_mask) + .field("salg_name", &&self.salg_name[..]) + .finish() + } + } + + impl ::hash::Hash for sockaddr_alg { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.salg_family.hash(state); + self.salg_type.hash(state); + self.salg_feat.hash(state); + self.salg_mask.hash(state); + self.salg_name.hash(state); + } + } + + impl af_alg_iv { + fn as_slice(&self) -> &[u8] { + unsafe { + ::core::slice::from_raw_parts( + self.iv.as_ptr(), + self.ivlen as usize + ) + } + } + } + + impl PartialEq for af_alg_iv { + fn eq(&self, other: &af_alg_iv) -> bool { + *self.as_slice() == *other.as_slice() + } + } + + impl Eq for af_alg_iv {} + + impl ::fmt::Debug for af_alg_iv { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("af_alg_iv") + .field("iv", &self.as_slice()) + .finish() + } + } + + impl ::hash::Hash for af_alg_iv { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.as_slice().hash(state); + } + } + } } pub const ABDAY_1: ::nl_item = 0x20000; @@ -1315,6 +1412,15 @@ pub const FALLOC_FL_UNSHARE_RANGE: ::c_int = 0x40; pub const ENOATTR: ::c_int = ::ENODATA; pub const SO_ORIGINAL_DST: ::c_int = 80; +pub const IP_ORIGDSTADDR : ::c_int = 20; +pub const IP_RECVORIGDSTADDR : ::c_int = IP_ORIGDSTADDR; +pub const IPV6_ORIGDSTADDR : ::c_int = 74; +pub const IPV6_RECVORIGDSTADDR : ::c_int = IPV6_ORIGDSTADDR; +pub const IPV6_FLOWINFO: ::c_int = 11; +pub const IPV6_FLOWLABEL_MGR: ::c_int = 32; +pub const IPV6_FLOWINFO_SEND: ::c_int = 33; +pub const IPV6_FLOWINFO_FLOWLABEL: ::c_int = 0x000fffff; +pub const IPV6_FLOWINFO_PRIORITY: ::c_int = 0x0ff00000; pub const IUTF8: ::tcflag_t = 0x00004000; pub const CMSPAR: ::tcflag_t = 0o10000000000; @@ -1696,7 +1802,92 @@ pub const SOF_TIMESTAMPING_SOFTWARE: ::c_uint = 1 << 4; pub const SOF_TIMESTAMPING_SYS_HARDWARE: ::c_uint = 1 << 5; pub const SOF_TIMESTAMPING_RAW_HARDWARE: ::c_uint = 1 << 6; +// linux/if_alg.h +pub const ALG_SET_KEY: ::c_int = 1; +pub const ALG_SET_IV: ::c_int = 2; +pub const ALG_SET_OP: ::c_int = 3; +pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4; +pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5; + +pub const ALG_OP_DECRYPT: ::c_int = 0; +pub const ALG_OP_ENCRYPT: ::c_int = 1; + +// uapi/linux/inotify.h +pub const IN_ACCESS: ::uint32_t = 0x0000_0001; +pub const IN_MODIFY: ::uint32_t = 0x0000_0002; +pub const IN_ATTRIB: ::uint32_t = 0x0000_0004; +pub const IN_CLOSE_WRITE: ::uint32_t = 0x0000_0008; +pub const IN_CLOSE_NOWRITE: ::uint32_t = 0x0000_0010; +pub const IN_CLOSE: ::uint32_t = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE); +pub const IN_OPEN: ::uint32_t = 0x0000_0020; +pub const IN_MOVED_FROM: ::uint32_t = 0x0000_0040; +pub const IN_MOVED_TO: ::uint32_t = 0x0000_0080; +pub const IN_MOVE: ::uint32_t = (IN_MOVED_FROM | IN_MOVED_TO); +pub const IN_CREATE: ::uint32_t = 0x0000_0100; +pub const IN_DELETE: ::uint32_t = 0x0000_0200; +pub const IN_DELETE_SELF: ::uint32_t = 0x0000_0400; +pub const IN_MOVE_SELF: ::uint32_t = 0x0000_0800; +pub const IN_UNMOUNT: ::uint32_t = 0x0000_2000; +pub const IN_Q_OVERFLOW: ::uint32_t = 0x0000_4000; +pub const IN_IGNORED: ::uint32_t = 0x0000_8000; +pub const IN_ONLYDIR: ::uint32_t = 0x0100_0000; +pub const IN_DONT_FOLLOW: ::uint32_t = 0x0200_0000; +// pub const IN_EXCL_UNLINK: ::uint32_t = 0x0400_0000; + +// pub const IN_MASK_CREATE: ::uint32_t = 0x1000_0000; +// pub const IN_MASK_ADD: ::uint32_t = 0x2000_0000; +pub const IN_ISDIR: ::uint32_t = 0x4000_0000; +pub const IN_ONESHOT: ::uint32_t = 0x8000_0000; + +pub const IN_ALL_EVENTS: ::uint32_t = ( + IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | + IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | + IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | + IN_MOVE_SELF +); + +pub const IN_CLOEXEC: ::c_int = O_CLOEXEC; +pub const IN_NONBLOCK: ::c_int = O_NONBLOCK; + +pub const FUTEX_WAIT: ::c_int = 0; +pub const FUTEX_WAKE: ::c_int = 1; +pub const FUTEX_FD: ::c_int = 2; +pub const FUTEX_REQUEUE: ::c_int = 3; +pub const FUTEX_CMP_REQUEUE: ::c_int = 4; +pub const FUTEX_WAKE_OP: ::c_int = 5; +pub const FUTEX_LOCK_PI: ::c_int = 6; +pub const FUTEX_UNLOCK_PI: ::c_int = 7; +pub const FUTEX_TRYLOCK_PI: ::c_int = 8; +pub const FUTEX_WAIT_BITSET: ::c_int = 9; +pub const FUTEX_WAKE_BITSET: ::c_int = 10; +pub const FUTEX_WAIT_REQUEUE_PI: ::c_int = 11; +pub const FUTEX_CMP_REQUEUE_PI: ::c_int = 12; + +pub const FUTEX_PRIVATE_FLAG: ::c_int = 128; +pub const FUTEX_CLOCK_REALTIME: ::c_int = 256; +pub const FUTEX_CMD_MASK: ::c_int = + !(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME); + f! { + pub fn CMSG_NXTHDR(mhdr: *const msghdr, + cmsg: *const cmsghdr) -> *mut cmsghdr { + if ((*cmsg).cmsg_len as usize) < ::mem::size_of::<cmsghdr>() { + return 0 as *mut cmsghdr; + }; + let next = (cmsg as usize + + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) + as *mut cmsghdr; + let max = (*mhdr).msg_control as usize + + (*mhdr).msg_controllen as usize; + if (next.offset(1)) as usize > max || + next as usize + super::CMSG_ALIGN((*next).cmsg_len as usize) > max + { + 0 as *mut cmsghdr + } else { + next as *mut cmsghdr + } + } + pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.bits.iter_mut() { *slot = 0; @@ -1704,21 +1895,23 @@ f! { } pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc + let size_in_bits + = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); cpuset.bits[idx] |= 1 << offset; () } pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc + let size_in_bits + = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); cpuset.bits[idx] &= !(1 << offset); () } pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); + let size_in_bits = 8 * ::mem::size_of_val(&cpuset.bits[0]); let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); 0 != (cpuset.bits[idx] & (1 << offset)) } @@ -1979,7 +2172,7 @@ extern { pub fn glob(pattern: *const c_char, flags: ::c_int, - errfunc: Option<extern fn(epath: *const c_char, + errfunc: ::Option<extern fn(epath: *const c_char, errno: ::c_int) -> ::c_int>, pglob: *mut ::glob_t) -> ::c_int; pub fn globfree(pglob: *mut ::glob_t); @@ -2008,9 +2201,9 @@ extern { pub fn getdomainname(name: *mut ::c_char, len: ::size_t) -> ::c_int; pub fn setdomainname(name: *const ::c_char, len: ::size_t) -> ::c_int; pub fn vhangup() -> ::c_int; - pub fn sendmmsg(sockfd: ::c_int, msgvec: *mut mmsghdr, vlen: ::c_uint, + pub fn sendmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::c_uint, flags: ::c_int) -> ::c_int; - pub fn recvmmsg(sockfd: ::c_int, msgvec: *mut mmsghdr, vlen: ::c_uint, + pub fn recvmmsg(sockfd: ::c_int, msgvec: *mut ::mmsghdr, vlen: ::c_uint, flags: ::c_int, timeout: *mut ::timespec) -> ::c_int; pub fn sync(); pub fn syscall(num: ::c_long, ...) -> ::c_long; @@ -2104,7 +2297,7 @@ extern { count: ::size_t) -> ::ssize_t; pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int; #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r(uid: ::uid_t, + pub fn getgrgid_r(gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, @@ -2152,9 +2345,9 @@ extern { #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork(prepare: Option<unsafe extern fn()>, - parent: Option<unsafe extern fn()>, - child: Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; pub fn getgrgid(gid: ::gid_t) -> *mut ::group; pub fn getgrouplist(user: *const ::c_char, group: ::gid_t, @@ -2173,7 +2366,7 @@ extern { f: extern fn(*mut ::c_void) -> *mut ::c_void, value: *mut ::c_void) -> ::c_int; pub fn dl_iterate_phdr( - callback: Option<unsafe extern fn( + callback: ::Option<unsafe extern fn( info: *mut ::dl_phdr_info, size: ::size_t, data: *mut ::c_void @@ -2259,6 +2452,12 @@ extern { nobj: ::size_t, stream: *mut ::FILE ) -> ::size_t; + pub fn inotify_rm_watch(fd: ::c_int, wd: ::c_int) -> ::c_int; + pub fn inotify_init() -> ::c_int; + pub fn inotify_init1(flags: ::c_int) -> ::c_int; + pub fn inotify_add_watch(fd: ::c_int, + path: *const ::c_char, + mask: ::uint32_t) -> ::c_int; } cfg_if! { @@ -2277,3 +2476,14 @@ cfg_if! { pub use self::other::*; } } + +cfg_if! { + if #[cfg(libc_align)] { + #[macro_use] + mod align; + } else { + #[macro_use] + mod no_align; + } +} +expand_align!(); diff --git a/libc/src/unix/notbsd/linux/musl/b32/mips.rs b/libc/src/unix/notbsd/linux/musl/b32/mips.rs index b0694d1..37430af 100644 --- a/libc/src/unix/notbsd/linux/musl/b32/mips.rs +++ b/libc/src/unix/notbsd/linux/musl/b32/mips.rs @@ -514,7 +514,6 @@ pub const SYS_mknod: ::c_long = 4000 + 14; pub const SYS_chmod: ::c_long = 4000 + 15; pub const SYS_lchown: ::c_long = 4000 + 16; pub const SYS_break: ::c_long = 4000 + 17; -pub const SYS_unused18: ::c_long = 4000 + 18; pub const SYS_lseek: ::c_long = 4000 + 19; pub const SYS_getpid: ::c_long = 4000 + 20; pub const SYS_mount: ::c_long = 4000 + 21; @@ -524,7 +523,6 @@ pub const SYS_getuid: ::c_long = 4000 + 24; pub const SYS_stime: ::c_long = 4000 + 25; pub const SYS_ptrace: ::c_long = 4000 + 26; pub const SYS_alarm: ::c_long = 4000 + 27; -pub const SYS_unused28: ::c_long = 4000 + 28; pub const SYS_pause: ::c_long = 4000 + 29; pub const SYS_utime: ::c_long = 4000 + 30; pub const SYS_stty: ::c_long = 4000 + 31; @@ -555,7 +553,6 @@ pub const SYS_fcntl: ::c_long = 4000 + 55; pub const SYS_mpx: ::c_long = 4000 + 56; pub const SYS_setpgid: ::c_long = 4000 + 57; pub const SYS_ulimit: ::c_long = 4000 + 58; -pub const SYS_unused59: ::c_long = 4000 + 59; pub const SYS_umask: ::c_long = 4000 + 60; pub const SYS_chroot: ::c_long = 4000 + 61; pub const SYS_ustat: ::c_long = 4000 + 62; @@ -578,9 +575,7 @@ pub const SYS_gettimeofday: ::c_long = 4000 + 78; pub const SYS_settimeofday: ::c_long = 4000 + 79; pub const SYS_getgroups: ::c_long = 4000 + 80; pub const SYS_setgroups: ::c_long = 4000 + 81; -pub const SYS_reserved82: ::c_long = 4000 + 82; pub const SYS_symlink: ::c_long = 4000 + 83; -pub const SYS_unused84: ::c_long = 4000 + 84; pub const SYS_readlink: ::c_long = 4000 + 85; pub const SYS_uselib: ::c_long = 4000 + 86; pub const SYS_swapon: ::c_long = 4000 + 87; @@ -605,7 +600,6 @@ pub const SYS_getitimer: ::c_long = 4000 + 105; pub const SYS_stat: ::c_long = 4000 + 106; pub const SYS_lstat: ::c_long = 4000 + 107; pub const SYS_fstat: ::c_long = 4000 + 108; -pub const SYS_unused109: ::c_long = 4000 + 109; pub const SYS_iopl: ::c_long = 4000 + 110; pub const SYS_vhangup: ::c_long = 4000 + 111; pub const SYS_idle: ::c_long = 4000 + 112; @@ -645,7 +639,6 @@ pub const SYS_writev: ::c_long = 4000 + 146; pub const SYS_cacheflush: ::c_long = 4000 + 147; pub const SYS_cachectl: ::c_long = 4000 + 148; pub const SYS_sysmips: ::c_long = 4000 + 149; -pub const SYS_unused150: ::c_long = 4000 + 150; pub const SYS_getsid: ::c_long = 4000 + 151; pub const SYS_fdatasync: ::c_long = 4000 + 152; pub const SYS__sysctl: ::c_long = 4000 + 153; @@ -714,7 +707,6 @@ pub const SYS_mincore: ::c_long = 4000 + 217; pub const SYS_madvise: ::c_long = 4000 + 218; pub const SYS_getdents64: ::c_long = 4000 + 219; pub const SYS_fcntl64: ::c_long = 4000 + 220; -pub const SYS_reserved221: ::c_long = 4000 + 221; pub const SYS_gettid: ::c_long = 4000 + 222; pub const SYS_readahead: ::c_long = 4000 + 223; pub const SYS_setxattr: ::c_long = 4000 + 224; diff --git a/libc/src/unix/notbsd/linux/musl/b32/x86.rs b/libc/src/unix/notbsd/linux/musl/b32/x86.rs index b6ea8c1..8bfb60b 100644 --- a/libc/src/unix/notbsd/linux/musl/b32/x86.rs +++ b/libc/src/unix/notbsd/linux/musl/b32/x86.rs @@ -116,15 +116,6 @@ s! { __private: [u32; 22] } - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 112], - } - pub struct siginfo_t { pub si_signo: ::c_int, pub si_errno: ::c_int, @@ -176,6 +167,62 @@ s! { } } +s_no_extra_traits!{ + pub struct ucontext_t { + pub uc_flags: ::c_ulong, + pub uc_link: *mut ucontext_t, + pub uc_stack: ::stack_t, + pub uc_mcontext: mcontext_t, + pub uc_sigmask: ::sigset_t, + __private: [u8; 112], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for ucontext_t { + fn eq(&self, other: &ucontext_t) -> bool { + self.uc_flags == other.uc_flags + && self.uc_link == other.uc_link + && self.uc_stack == other.uc_stack + && self.uc_mcontext == other.uc_mcontext + && self.uc_sigmask == other.uc_sigmask + && self + .__private + .iter() + .zip(other.__private.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for ucontext_t {} + + impl ::fmt::Debug for ucontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ucontext_t") + .field("uc_flags", &self.uc_flags) + .field("uc_link", &self.uc_link) + .field("uc_stack", &self.uc_stack) + .field("uc_mcontext", &self.uc_mcontext) + .field("uc_sigmask", &self.uc_sigmask) + // Ignore __private field + .finish() + } + } + + impl ::hash::Hash for ucontext_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + self.__private.hash(state); + } + } + } +} + pub const SIGSTKSZ: ::size_t = 8192; pub const MINSIGSTKSZ: ::size_t = 2048; diff --git a/libc/src/unix/notbsd/linux/musl/b64/x86_64.rs b/libc/src/unix/notbsd/linux/musl/b64/x86_64.rs index 0e0fcec..94c5d88 100644 --- a/libc/src/unix/notbsd/linux/musl/b64/x86_64.rs +++ b/libc/src/unix/notbsd/linux/musl/b64/x86_64.rs @@ -51,15 +51,6 @@ s! { __private: [u64; 32], } - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 512], - } - pub struct ipc_perm { pub __ipc_perm_key: ::key_t, pub uid: ::uid_t, @@ -73,6 +64,62 @@ s! { } } +s_no_extra_traits!{ + pub struct ucontext_t { + pub uc_flags: ::c_ulong, + pub uc_link: *mut ucontext_t, + pub uc_stack: ::stack_t, + pub uc_mcontext: mcontext_t, + pub uc_sigmask: ::sigset_t, + __private: [u8; 512], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for ucontext_t { + fn eq(&self, other: &ucontext_t) -> bool { + self.uc_flags == other.uc_flags + && self.uc_link == other.uc_link + && self.uc_stack == other.uc_stack + && self.uc_mcontext == other.uc_mcontext + && self.uc_sigmask == other.uc_sigmask + && self + .__private + .iter() + .zip(other.__private.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for ucontext_t {} + + impl ::fmt::Debug for ucontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ucontext_t") + .field("uc_flags", &self.uc_flags) + .field("uc_link", &self.uc_link) + .field("uc_stack", &self.uc_stack) + .field("uc_mcontext", &self.uc_mcontext) + .field("uc_sigmask", &self.uc_sigmask) + // Ignore __private field + .finish() + } + } + + impl ::hash::Hash for ucontext_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + self.__private.hash(state); + } + } + } +} + // Syscall table pub const SYS_read: ::c_long = 0; diff --git a/libc/src/unix/notbsd/linux/musl/mod.rs b/libc/src/unix/notbsd/linux/musl/mod.rs index 5ab5d0f..4f4a3d8 100644 --- a/libc/src/unix/notbsd/linux/musl/mod.rs +++ b/libc/src/unix/notbsd/linux/musl/mod.rs @@ -37,7 +37,7 @@ s! { pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, pub sa_flags: ::c_int, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, } pub struct statvfs { @@ -78,7 +78,9 @@ s! { pub l_len: ::off_t, pub l_pid: ::pid_t, } +} +s_no_extra_traits!{ pub struct sysinfo { pub uptime: ::c_ulong, pub loads: [::c_ulong; 3], @@ -97,6 +99,75 @@ s! { } } +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for sysinfo { + fn eq(&self, other: &sysinfo) -> bool { + self.uptime == other.uptime + && self.loads == other.loads + && self.totalram == other.totalram + && self.freeram == other.freeram + && self.sharedram == other.sharedram + && self.bufferram == other.bufferram + && self.totalswap == other.totalswap + && self.freeswap == other.freeswap + && self.procs == other.procs + && self.pad == other.pad + && self.totalhigh == other.totalhigh + && self.freehigh == other.freehigh + && self.mem_unit == other.mem_unit + && self + .__reserved + .iter() + .zip(other.__reserved.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for sysinfo {} + + impl ::fmt::Debug for sysinfo { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sysinfo") + .field("uptime", &self.uptime) + .field("loads", &self.loads) + .field("totalram", &self.totalram) + .field("freeram", &self.freeram) + .field("sharedram", &self.sharedram) + .field("bufferram", &self.bufferram) + .field("totalswap", &self.totalswap) + .field("freeswap", &self.freeswap) + .field("procs", &self.procs) + .field("pad", &self.pad) + .field("totalhigh", &self.totalhigh) + .field("freehigh", &self.freehigh) + .field("mem_unit", &self.mem_unit) + // FIXME: .field("__reserved", &self.__reserved) + .finish() + } + } + + impl ::hash::Hash for sysinfo { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.uptime.hash(state); + self.loads.hash(state); + self.totalram.hash(state); + self.freeram.hash(state); + self.sharedram.hash(state); + self.bufferram.hash(state); + self.totalswap.hash(state); + self.freeswap.hash(state); + self.procs.hash(state); + self.pad.hash(state); + self.totalhigh.hash(state); + self.freehigh.hash(state); + self.mem_unit.hash(state); + self.__reserved.hash(state); + } + } + } +} + pub const SFD_CLOEXEC: ::c_int = 0x080000; pub const NCCS: usize = 32; diff --git a/libc/src/unix/notbsd/linux/no_align.rs b/libc/src/unix/notbsd/linux/no_align.rs new file mode 100644 index 0000000..1f5f2ee --- /dev/null +++ b/libc/src/unix/notbsd/linux/no_align.rs @@ -0,0 +1,80 @@ +macro_rules! expand_align { + () => { + s! { + pub struct pthread_mutexattr_t { + #[cfg(any(target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64", + all(target_arch = "aarch64", + target_env = "musl")))] + __align: [::c_int; 0], + #[cfg(not(any(target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64", + all(target_arch = "aarch64", + target_env = "musl"))))] + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + pub struct pthread_rwlockattr_t { + #[cfg(target_env = "musl")] + __align: [::c_int; 0], + #[cfg(not(target_env = "musl"))] + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], + } + + pub struct pthread_condattr_t { + __align: [::c_int; 0], + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + + s_no_extra_traits! { + pub struct pthread_cond_t { + #[cfg(target_env = "musl")] + __align: [*const ::c_void; 0], + #[cfg(not(target_env = "musl"))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + + pub struct pthread_mutex_t { + #[cfg(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc", + all(target_arch = "x86_64", + target_pointer_width = "32")))] + __align: [::c_long; 0], + #[cfg(not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc", + all(target_arch = "x86_64", + target_pointer_width = "32"))))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + pub struct pthread_rwlock_t { + #[cfg(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc", + all(target_arch = "x86_64", + target_pointer_width = "32")))] + __align: [::c_long; 0], + #[cfg(not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc", + all(target_arch = "x86_64", + target_pointer_width = "32"))))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + } + } +} diff --git a/libc/src/unix/notbsd/linux/other/align.rs b/libc/src/unix/notbsd/linux/other/align.rs new file mode 100644 index 0000000..4a0e074 --- /dev/null +++ b/libc/src/unix/notbsd/linux/other/align.rs @@ -0,0 +1,13 @@ +s! { + // FIXME this is actually a union + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct sem_t { + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + } +} diff --git a/libc/src/unix/notbsd/linux/other/b32/arm.rs b/libc/src/unix/notbsd/linux/other/b32/arm.rs index a70af43..7f00d9a 100644 --- a/libc/src/unix/notbsd/linux/other/b32/arm.rs +++ b/libc/src/unix/notbsd/linux/other/b32/arm.rs @@ -136,9 +136,6 @@ pub const SO_RCVBUFFORCE: ::c_int = 33; pub const FIOCLEX: ::c_ulong = 0x5451; pub const FIONBIO: ::c_ulong = 0x5421; -pub const PTRACE_GETFPXREGS: ::c_uint = 18; -pub const PTRACE_SETFPXREGS: ::c_uint = 19; - pub const MCL_CURRENT: ::c_int = 0x0001; pub const MCL_FUTURE: ::c_int = 0x0002; diff --git a/libc/src/unix/notbsd/linux/other/b32/x86.rs b/libc/src/unix/notbsd/linux/other/b32/x86.rs index 6c41718..e7c3b9a 100644 --- a/libc/src/unix/notbsd/linux/other/b32/x86.rs +++ b/libc/src/unix/notbsd/linux/other/b32/x86.rs @@ -31,22 +31,6 @@ s! { pub st_space: [::c_long; 20], } - pub struct user_fpxregs_struct { - pub cwd: ::c_ushort, - pub swd: ::c_ushort, - pub twd: ::c_ushort, - pub fop: ::c_ushort, - pub fip: ::c_long, - pub fcs: ::c_long, - pub foo: ::c_long, - pub fos: ::c_long, - pub mxcsr: ::c_long, - __reserved: ::c_long, - pub st_space: [::c_long; 32], - pub xmm_space: [::c_long; 32], - padding: [::c_long; 56], - } - pub struct user_regs_struct { pub ebx: ::c_long, pub ecx: ::c_long, @@ -92,15 +76,6 @@ s! { pub cr2: ::c_ulong, } - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 112], - } - pub struct ipc_perm { pub __key: ::key_t, pub uid: ::uid_t, @@ -213,6 +188,133 @@ s! { } } +s_no_extra_traits!{ + pub struct user_fpxregs_struct { + pub cwd: ::c_ushort, + pub swd: ::c_ushort, + pub twd: ::c_ushort, + pub fop: ::c_ushort, + pub fip: ::c_long, + pub fcs: ::c_long, + pub foo: ::c_long, + pub fos: ::c_long, + pub mxcsr: ::c_long, + __reserved: ::c_long, + pub st_space: [::c_long; 32], + pub xmm_space: [::c_long; 32], + padding: [::c_long; 56], + } + + pub struct ucontext_t { + pub uc_flags: ::c_ulong, + pub uc_link: *mut ucontext_t, + pub uc_stack: ::stack_t, + pub uc_mcontext: mcontext_t, + pub uc_sigmask: ::sigset_t, + __private: [u8; 112], + __ssp: [::c_ulong; 4], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for user_fpxregs_struct { + fn eq(&self, other: &user_fpxregs_struct) -> bool { + self.cwd == other.cwd + && self.swd == other.swd + && self.twd == other.twd + && self.fop == other.fop + && self.fip == other.fip + && self.fcs == other.fcs + && self.foo == other.foo + && self.fos == other.fos + && self.mxcsr == other.mxcsr + // Ignore __reserved field + && self.st_space == other.st_space + && self.xmm_space == other.xmm_space + // Ignore padding field + } + } + + impl Eq for user_fpxregs_struct {} + + impl ::fmt::Debug for user_fpxregs_struct { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("user_fpxregs_struct") + .field("cwd", &self.cwd) + .field("swd", &self.swd) + .field("twd", &self.twd) + .field("fop", &self.fop) + .field("fip", &self.fip) + .field("fcs", &self.fcs) + .field("foo", &self.foo) + .field("fos", &self.fos) + .field("mxcsr", &self.mxcsr) + // Ignore __reserved field + .field("st_space", &self.st_space) + .field("xmm_space", &self.xmm_space) + // Ignore padding field + .finish() + } + } + + impl ::hash::Hash for user_fpxregs_struct { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.cwd.hash(state); + self.swd.hash(state); + self.twd.hash(state); + self.fop.hash(state); + self.fip.hash(state); + self.fcs.hash(state); + self.foo.hash(state); + self.fos.hash(state); + self.mxcsr.hash(state); + // Ignore __reserved field + self.st_space.hash(state); + self.xmm_space.hash(state); + // Ignore padding field + } + } + + impl PartialEq for ucontext_t { + fn eq(&self, other: &ucontext_t) -> bool { + self.uc_flags == other.uc_flags + && self.uc_link == other.uc_link + && self.uc_stack == other.uc_stack + && self.uc_mcontext == other.uc_mcontext + && self.uc_sigmask == other.uc_sigmask + // Ignore __private field + } + } + + impl Eq for ucontext_t {} + + impl ::fmt::Debug for ucontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ucontext_t") + .field("uc_flags", &self.uc_flags) + .field("uc_link", &self.uc_link) + .field("uc_stack", &self.uc_stack) + .field("uc_mcontext", &self.uc_mcontext) + .field("uc_sigmask", &self.uc_sigmask) + // Ignore __private field + .finish() + } + } + + impl ::hash::Hash for ucontext_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + // Ignore __private field + } + } + } +} + pub const O_DIRECT: ::c_int = 0x4000; pub const O_DIRECTORY: ::c_int = 0x10000; pub const O_NOFOLLOW: ::c_int = 0x20000; diff --git a/libc/src/unix/notbsd/linux/other/b64/aarch64.rs b/libc/src/unix/notbsd/linux/other/b64/aarch64.rs index d6e37ff..3bd2e02 100644 --- a/libc/src/unix/notbsd/linux/other/b64/aarch64.rs +++ b/libc/src/unix/notbsd/linux/other/b64/aarch64.rs @@ -786,7 +786,6 @@ pub const SYS_rt_tgsigqueueinfo: ::c_long = 240; pub const SYS_perf_event_open: ::c_long = 241; pub const SYS_accept4: ::c_long = 242; pub const SYS_recvmmsg: ::c_long = 243; -pub const SYS_arch_specific_syscall: ::c_long = 244; pub const SYS_wait4: ::c_long = 260; pub const SYS_prlimit64: ::c_long = 261; pub const SYS_fanotify_init: ::c_long = 262; @@ -818,7 +817,6 @@ pub const SYS_pwritev2: ::c_long = 287; pub const SYS_pkey_mprotect: ::c_long = 288; pub const SYS_pkey_alloc: ::c_long = 289; pub const SYS_pkey_free: ::c_long = 290; -pub const SYS_syscalls: ::c_long = 291; #[link(name = "util")] extern { diff --git a/libc/src/unix/notbsd/linux/other/b64/sparc64.rs b/libc/src/unix/notbsd/linux/other/b64/sparc64.rs index 325c793..5d26865 100644 --- a/libc/src/unix/notbsd/linux/other/b64/sparc64.rs +++ b/libc/src/unix/notbsd/linux/other/b64/sparc64.rs @@ -495,7 +495,7 @@ pub const VEOL2: usize = 6; pub const VMIN: usize = 4; pub const IEXTEN: ::tcflag_t = 0x8000; pub const TOSTOP: ::tcflag_t = 0x100; -pub const FLUSHO: ::tcflag_t = 0x2000; +pub const FLUSHO: ::tcflag_t = 0x1000; pub const EXTPROC: ::tcflag_t = 0x10000; pub const TCGETS: ::c_ulong = 0x40245408; pub const TCSETS: ::c_ulong = 0x80245409; diff --git a/libc/src/unix/notbsd/linux/other/b64/x86_64.rs b/libc/src/unix/notbsd/linux/other/b64/x86_64.rs index 0d7137e..79f27e0 100644 --- a/libc/src/unix/notbsd/linux/other/b64/x86_64.rs +++ b/libc/src/unix/notbsd/linux/other/b64/x86_64.rs @@ -112,20 +112,6 @@ s! { __private: [u64; 12], } - pub struct user_fpregs_struct { - pub cwd: ::c_ushort, - pub swd: ::c_ushort, - pub ftw: ::c_ushort, - pub fop: ::c_ushort, - pub rip: ::c_ulonglong, - pub rdp: ::c_ulonglong, - pub mxcsr: ::c_uint, - pub mxcr_mask: ::c_uint, - pub st_space: [::c_uint; 32], - pub xmm_space: [::c_uint; 64], - padding: [::c_uint; 24], - } - pub struct user_regs_struct { pub r15: ::c_ulonglong, pub r14: ::c_ulonglong, @@ -184,15 +170,6 @@ s! { __private: [u64; 8], } - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 512], - } - pub struct ipc_perm { pub __key: ::key_t, pub uid: ::uid_t, @@ -232,6 +209,127 @@ s! { } } +s_no_extra_traits! { + pub struct user_fpregs_struct { + pub cwd: ::c_ushort, + pub swd: ::c_ushort, + pub ftw: ::c_ushort, + pub fop: ::c_ushort, + pub rip: ::c_ulonglong, + pub rdp: ::c_ulonglong, + pub mxcsr: ::c_uint, + pub mxcr_mask: ::c_uint, + pub st_space: [::c_uint; 32], + pub xmm_space: [::c_uint; 64], + padding: [::c_uint; 24], + } + + pub struct ucontext_t { + pub uc_flags: ::c_ulong, + pub uc_link: *mut ucontext_t, + pub uc_stack: ::stack_t, + pub uc_mcontext: mcontext_t, + pub uc_sigmask: ::sigset_t, + __private: [u8; 512], + __ssp: [::c_ulonglong; 4], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for user_fpregs_struct { + fn eq(&self, other: &user_fpregs_struct) -> bool { + self.cwd == other.cwd + && self.swd == other.swd + && self.ftw == other.ftw + && self.fop == other.fop + && self.rip == other.rip + && self.rdp == other.rdp + && self.mxcsr == other.mxcsr + && self.mxcr_mask == other.mxcr_mask + && self.st_space == other.st_space + && self + .xmm_space + .iter() + .zip(other.xmm_space.iter()) + .all(|(a,b)| a == b) + // Ignore padding field + } + } + + impl Eq for user_fpregs_struct {} + + impl ::fmt::Debug for user_fpregs_struct { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("user_fpregs_struct") + .field("cwd", &self.cwd) + .field("ftw", &self.ftw) + .field("fop", &self.fop) + .field("rip", &self.rip) + .field("rdp", &self.rdp) + .field("mxcsr", &self.mxcsr) + .field("mxcr_mask", &self.mxcr_mask) + .field("st_space", &self.st_space) + // FIXME: .field("xmm_space", &self.xmm_space) + // Ignore padding field + .finish() + } + } + + impl ::hash::Hash for user_fpregs_struct { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.cwd.hash(state); + self.ftw.hash(state); + self.fop.hash(state); + self.rip.hash(state); + self.rdp.hash(state); + self.mxcsr.hash(state); + self.mxcr_mask.hash(state); + self.st_space.hash(state); + self.xmm_space.hash(state); + // Ignore padding field + } + } + + impl PartialEq for ucontext_t { + fn eq(&self, other: &ucontext_t) -> bool { + self.uc_flags == other.uc_flags + && self.uc_link == other.uc_link + && self.uc_stack == other.uc_stack + && self.uc_mcontext == other.uc_mcontext + && self.uc_sigmask == other.uc_sigmask + // Ignore __private field + } + } + + impl Eq for ucontext_t {} + + impl ::fmt::Debug for ucontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ucontext_t") + .field("uc_flags", &self.uc_flags) + .field("uc_link", &self.uc_link) + .field("uc_stack", &self.uc_stack) + .field("uc_mcontext", &self.uc_mcontext) + .field("uc_sigmask", &self.uc_sigmask) + // Ignore __private field + .finish() + } + } + + impl ::hash::Hash for ucontext_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + // Ignore __private field + } + } + } +} + pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; diff --git a/libc/src/unix/notbsd/linux/other/mod.rs b/libc/src/unix/notbsd/linux/other/mod.rs index c1e3393..1a97d1c 100644 --- a/libc/src/unix/notbsd/linux/other/mod.rs +++ b/libc/src/unix/notbsd/linux/other/mod.rs @@ -29,49 +29,13 @@ s! { pub tv_usec: ::int32_t, } - pub struct utmpx { - pub ut_type: ::c_short, - pub ut_pid: ::pid_t, - pub ut_line: [::c_char; __UT_LINESIZE], - pub ut_id: [::c_char; 4], - - pub ut_user: [::c_char; __UT_NAMESIZE], - pub ut_host: [::c_char; __UT_HOSTSIZE], - pub ut_exit: __exit_status, - - #[cfg(any(target_arch = "aarch64", - target_arch = "sparc64", - all(target_pointer_width = "32", - not(target_arch = "x86_64"))))] - pub ut_session: ::c_long, - #[cfg(any(target_arch = "aarch64", - target_arch = "sparc64", - all(target_pointer_width = "32", - not(target_arch = "x86_64"))))] - pub ut_tv: ::timeval, - - #[cfg(not(any(target_arch = "aarch64", - target_arch = "sparc64", - all(target_pointer_width = "32", - not(target_arch = "x86_64")))))] - pub ut_session: ::int32_t, - #[cfg(not(any(target_arch = "aarch64", - target_arch = "sparc64", - all(target_pointer_width = "32", - not(target_arch = "x86_64")))))] - pub ut_tv: __timeval, - - pub ut_addr_v6: [::int32_t; 4], - __glibc_reserved: [::c_char; 20], - } - pub struct sigaction { pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, #[cfg(target_arch = "sparc64")] __reserved0: ::c_int, pub sa_flags: ::c_int, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, } pub struct stack_t { @@ -84,6 +48,12 @@ s! { pub si_signo: ::c_int, pub si_errno: ::c_int, pub si_code: ::c_int, + #[deprecated( + since="0.2.54", + note="Please leave a comment on \ + https://github.com/rust-lang/libc/pull/1316 if you're using \ + this field" + )] pub _pad: [::c_int; 29], #[cfg(target_arch = "x86_64")] _align: [u64; 0], @@ -157,20 +127,6 @@ s! { pub l_pid: ::pid_t, } - // FIXME this is actually a union - #[cfg_attr(all(feature = "align", target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", target_pointer_width = "64"), - repr(align(8)))] - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - #[cfg(not(feature = "align"))] - __align: [::c_long; 0], - } - pub struct mallinfo { pub arena: ::c_int, pub ordblks: ::c_int, @@ -244,6 +200,113 @@ s! { } } +impl siginfo_t { + pub unsafe fn si_addr(&self) -> *mut ::c_void { + #[repr(C)] + struct siginfo_sigfault { + _si_signo: ::c_int, + _si_errno: ::c_int, + _si_code: ::c_int, + si_addr: *mut ::c_void + } + (*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr + } +} + +s_no_extra_traits! { + pub struct utmpx { + pub ut_type: ::c_short, + pub ut_pid: ::pid_t, + pub ut_line: [::c_char; __UT_LINESIZE], + pub ut_id: [::c_char; 4], + + pub ut_user: [::c_char; __UT_NAMESIZE], + pub ut_host: [::c_char; __UT_HOSTSIZE], + pub ut_exit: __exit_status, + + #[cfg(any(target_arch = "aarch64", + all(target_pointer_width = "32", + not(target_arch = "x86_64"))))] + pub ut_session: ::c_long, + #[cfg(any(target_arch = "aarch64", + all(target_pointer_width = "32", + not(target_arch = "x86_64"))))] + pub ut_tv: ::timeval, + + #[cfg(not(any(target_arch = "aarch64", + all(target_pointer_width = "32", + not(target_arch = "x86_64")))))] + pub ut_session: ::int32_t, + #[cfg(not(any(target_arch = "aarch64", + all(target_pointer_width = "32", + not(target_arch = "x86_64")))))] + pub ut_tv: __timeval, + + pub ut_addr_v6: [::int32_t; 4], + __glibc_reserved: [::c_char; 20], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for utmpx { + fn eq(&self, other: &utmpx) -> bool { + self.ut_type == other.ut_type + && self.ut_pid == other.ut_pid + && self.ut_line == other.ut_line + && self.ut_id == other.ut_id + && self.ut_user == other.ut_user + && self + .ut_host + .iter() + .zip(other.ut_host.iter()) + .all(|(a,b)| a == b) + && self.ut_exit == other.ut_exit + && self.ut_session == other.ut_session + && self.ut_tv == other.ut_tv + && self.ut_addr_v6 == other.ut_addr_v6 + && self.__glibc_reserved == other.__glibc_reserved + } + } + + impl Eq for utmpx {} + + impl ::fmt::Debug for utmpx { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utmpx") + .field("ut_type", &self.ut_type) + .field("ut_pid", &self.ut_pid) + .field("ut_line", &self.ut_line) + .field("ut_id", &self.ut_id) + .field("ut_user", &self.ut_user) + // FIXME: .field("ut_host", &self.ut_host) + .field("ut_exit", &self.ut_exit) + .field("ut_session", &self.ut_session) + .field("ut_tv", &self.ut_tv) + .field("ut_addr_v6", &self.ut_addr_v6) + .field("__glibc_reserved", &self.__glibc_reserved) + .finish() + } + } + + impl ::hash::Hash for utmpx { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ut_type.hash(state); + self.ut_pid.hash(state); + self.ut_line.hash(state); + self.ut_id.hash(state); + self.ut_user.hash(state); + self.ut_host.hash(state); + self.ut_exit.hash(state); + self.ut_session.hash(state); + self.ut_tv.hash(state); + self.ut_addr_v6.hash(state); + self.__glibc_reserved.hash(state); + } + } + } +} + pub const __UT_LINESIZE: usize = 32; pub const __UT_NAMESIZE: usize = 32; pub const __UT_HOSTSIZE: usize = 256; @@ -273,7 +336,6 @@ pub const SOL_PNPIPE: ::c_int = 275; pub const SOL_RDS: ::c_int = 276; pub const SOL_IUCV: ::c_int = 277; pub const SOL_CAIF: ::c_int = 278; -pub const SOL_ALG: ::c_int = 279; pub const SOL_NFC: ::c_int = 280; pub const SOL_XDP: ::c_int = 283; @@ -622,24 +684,10 @@ pub const NFPROTO_INET: ::c_int = 1; pub const NFPROTO_NETDEV: ::c_int = 5; // linux/netfilter/nf_tables.h -cfg_if!{ - if #[cfg(any(target_arch = "arm", target_arch = "powerpc", - target_arch = "powerpc64", target_arch = "aarch64"))] { - pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32; - pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32; - pub const NFT_SET_MAXNAMELEN: ::c_int = 32; - pub const NFT_OBJ_MAXNAMELEN: ::c_int = 32; - } else if #[cfg(target_arch = "sparc64")] { - pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32; - pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32; - pub const NFT_SET_MAXNAMELEN: ::c_int = 32; - } else { - pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256; - pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 256; - pub const NFT_SET_MAXNAMELEN: ::c_int = 256; - pub const NFT_OBJ_MAXNAMELEN: ::c_int = 256; - } -} +pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256; +pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 256; +pub const NFT_SET_MAXNAMELEN: ::c_int = 256; +pub const NFT_OBJ_MAXNAMELEN: ::c_int = 256; pub const NFT_USERDATA_MAXLEN: ::c_int = 256; pub const NFT_REG_VERDICT: ::c_int = 0; @@ -698,11 +746,9 @@ cfg_if! { pub const NFT_MSG_GETOBJ: ::c_int = 19; pub const NFT_MSG_DELOBJ: ::c_int = 20; pub const NFT_MSG_GETOBJ_RESET: ::c_int = 21; - pub const NFT_MSG_MAX: ::c_int = 22; - } else { - pub const NFT_MSG_MAX: ::c_int = 18; } } +pub const NFT_MSG_MAX: ::c_int = 25; pub const NFT_SET_ANONYMOUS: ::c_int = 0x1; pub const NFT_SET_CONSTANT: ::c_int = 0x2; @@ -879,7 +925,7 @@ extern { sz: ::c_int) -> ::c_int; pub fn glob64(pattern: *const ::c_char, flags: ::c_int, - errfunc: ::dox::Option<extern fn(epath: *const ::c_char, + errfunc: ::Option<extern fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, pglob: *mut glob64_t) -> ::c_int; @@ -939,3 +985,13 @@ cfg_if! { // Unknown target_arch } } + +cfg_if! { + if #[cfg(libc_align)] { + mod align; + pub use self::align::*; + } else { + mod no_align; + pub use self::no_align::*; + } +} diff --git a/libc/src/unix/notbsd/linux/other/no_align.rs b/libc/src/unix/notbsd/linux/other/no_align.rs new file mode 100644 index 0000000..e32bf67 --- /dev/null +++ b/libc/src/unix/notbsd/linux/other/no_align.rs @@ -0,0 +1,10 @@ +s! { + // FIXME this is actually a union + pub struct sem_t { + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + __align: [::c_long; 0], + } +} diff --git a/libc/src/unix/notbsd/linux/s390x/align.rs b/libc/src/unix/notbsd/linux/s390x/align.rs new file mode 100644 index 0000000..21e2190 --- /dev/null +++ b/libc/src/unix/notbsd/linux/s390x/align.rs @@ -0,0 +1,10 @@ +s! { + // FIXME this is actually a union + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct sem_t { + __size: [::c_char; 32], + } +} diff --git a/libc/src/unix/notbsd/linux/s390x.rs b/libc/src/unix/notbsd/linux/s390x/mod.rs index 9e3814f..d4cf956 100644 --- a/libc/src/unix/notbsd/linux/s390x.rs +++ b/libc/src/unix/notbsd/linux/s390x/mod.rs @@ -1,4 +1,4 @@ -use pthread_mutex_t; +use ::pthread_mutex_t; pub type blkcnt_t = i64; pub type blksize_t = i64; @@ -92,7 +92,7 @@ s! { pub sa_sigaction: ::sighandler_t, __glibc_reserved0: ::c_int, pub sa_flags: ::c_int, - pub sa_restorer: ::dox::Option<extern fn()>, + pub sa_restorer: ::Option<extern fn()>, pub sa_mask: sigset_t, } @@ -246,28 +246,11 @@ s! { pub l_pid: ::pid_t, } - // FIXME this is actually a union - #[cfg_attr(all(feature = "align", target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", target_pointer_width = "64"), - repr(align(8)))] - pub struct sem_t { - __size: [::c_char; 32], - #[cfg(not(feature = "align"))] - __align: [::c_long; 0], - } - pub struct __psw_t { pub mask: u64, pub addr: u64, } - // FIXME: This is actually a union. - pub struct fpreg_t { - pub d: ::c_double, - // f: ::c_float, - } - pub struct fpregset_t { pub fpc: u32, __pad: u32, @@ -334,6 +317,41 @@ s! { } } +s_no_extra_traits!{ + // FIXME: This is actually a union. + pub struct fpreg_t { + pub d: ::c_double, + // f: ::c_float, + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for fpreg_t { + fn eq(&self, other: &fpreg_t) -> bool { + self.d == other.d + } + } + + impl Eq for fpreg_t {} + + impl ::fmt::Debug for fpreg_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("fpreg_t") + .field("d", &self.d) + .finish() + } + } + + impl ::hash::Hash for fpreg_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + let d: u64 = unsafe { ::mem::transmute(self.d) }; + d.hash(state); + } + } + } +} + pub const SFD_CLOEXEC: ::c_int = 0x080000; pub const NCCS: usize = 32; @@ -764,10 +782,6 @@ pub const PTRACE_POKEUSER: ::c_uint = 6; pub const PTRACE_CONT: ::c_uint = 7; pub const PTRACE_KILL: ::c_uint = 8; pub const PTRACE_SINGLESTEP: ::c_uint = 9; -pub const PTRACE_GETREGS: ::c_uint = 12; -pub const PTRACE_SETREGS: ::c_uint = 13; -pub const PTRACE_GETFPREGS: ::c_uint = 14; -pub const PTRACE_SETFPREGS: ::c_uint = 15; pub const PTRACE_ATTACH: ::c_uint = 16; pub const PTRACE_DETACH: ::c_uint = 17; pub const PTRACE_SYSCALL: ::c_uint = 24; @@ -1304,7 +1318,7 @@ extern { sz: ::c_int) -> ::c_int; pub fn glob64(pattern: *const ::c_char, flags: ::c_int, - errfunc: ::dox::Option<extern fn(epath: *const ::c_char, + errfunc: ::Option<extern fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, pglob: *mut glob64_t) -> ::c_int; @@ -1334,3 +1348,13 @@ extern { pub fn swapcontext(uocp: *mut ucontext_t, ucp: *const ucontext_t) -> ::c_int; } + +cfg_if! { + if #[cfg(libc_align)] { + mod align; + pub use self::align::*; + } else { + mod no_align; + pub use self::no_align::*; + } +} diff --git a/libc/src/unix/notbsd/linux/s390x/no_align.rs b/libc/src/unix/notbsd/linux/s390x/no_align.rs new file mode 100644 index 0000000..8909114 --- /dev/null +++ b/libc/src/unix/notbsd/linux/s390x/no_align.rs @@ -0,0 +1,7 @@ +s! { + // FIXME this is actually a union + pub struct sem_t { + __size: [::c_char; 32], + __align: [::c_long; 0], + } +} diff --git a/libc/src/unix/notbsd/mod.rs b/libc/src/unix/notbsd/mod.rs index 668c25f..d0905e1 100644 --- a/libc/src/unix/notbsd/mod.rs +++ b/libc/src/unix/notbsd/mod.rs @@ -1,5 +1,3 @@ -use dox::mem; - pub type sa_family_t = u16; pub type pthread_key_t = ::c_uint; pub type speed_t = ::c_uint; @@ -8,9 +6,23 @@ pub type clockid_t = ::c_int; pub type key_t = ::c_int; pub type id_t = ::c_uint; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} s! { + pub struct in_addr { + pub s_addr: ::in_addr_t, + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + pub struct sockaddr { pub sa_family: sa_family_t, pub sa_data: [::c_char; 14], @@ -31,20 +43,6 @@ s! { pub sin6_scope_id: u32, } - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 108] - } - - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - __ss_align: ::size_t, - #[cfg(target_pointer_width = "32")] - __ss_pad2: [u8; 128 - 2 * 4], - #[cfg(target_pointer_width = "64")] - __ss_pad2: [u8; 128 - 2 * 8], - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -118,25 +116,6 @@ s! { pub dli_saddr: *mut ::c_void, } - #[cfg_attr(any(all(target_arch = "x86", - not(target_env = "musl"), - not(target_os = "android")), - target_arch = "x86_64"), - repr(packed))] - pub struct epoll_event { - pub events: ::uint32_t, - pub u64: ::uint64_t, - } - - pub struct utsname { - pub sysname: [::c_char; 65], - pub nodename: [::c_char; 65], - pub release: [::c_char; 65], - pub version: [::c_char; 65], - pub machine: [::c_char; 65], - pub domainname: [::c_char; 65] - } - pub struct lconv { pub decimal_point: *mut ::c_char, pub thousands_sep: *mut ::c_char, @@ -228,6 +207,195 @@ s! { pub ar_pln: u8, pub ar_op: u16, } + + pub struct mmsghdr { + pub msg_hdr: ::msghdr, + pub msg_len: ::c_uint, + } +} + +s_no_extra_traits!{ + #[cfg_attr( + any( + all( + target_arch = "x86", + not(target_env = "musl"), + not(target_os = "android")), + target_arch = "x86_64"), + repr(packed))] + pub struct epoll_event { + pub events: ::uint32_t, + pub u64: ::uint64_t, + } + + pub struct sockaddr_un { + pub sun_family: sa_family_t, + pub sun_path: [::c_char; 108] + } + + pub struct sockaddr_storage { + pub ss_family: sa_family_t, + __ss_align: ::size_t, + #[cfg(target_pointer_width = "32")] + __ss_pad2: [u8; 128 - 2 * 4], + #[cfg(target_pointer_width = "64")] + __ss_pad2: [u8; 128 - 2 * 8], + } + + pub struct utsname { + pub sysname: [::c_char; 65], + pub nodename: [::c_char; 65], + pub release: [::c_char; 65], + pub version: [::c_char; 65], + pub machine: [::c_char; 65], + pub domainname: [::c_char; 65] + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for epoll_event { + fn eq(&self, other: &epoll_event) -> bool { + self.events == other.events + && self.u64 == other.u64 + } + } + impl Eq for epoll_event {} + impl ::fmt::Debug for epoll_event { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let events = self.events; + let u64 = self.u64; + f.debug_struct("epoll_event") + .field("events", &events) + .field("u64", &u64) + .finish() + } + } + impl ::hash::Hash for epoll_event { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + let events = self.events; + let u64 = self.u64; + events.hash(state); + u64.hash(state); + } + } + + impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_family == other.sun_family + && self + .sun_path + .iter() + .zip(other.sun_path.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for sockaddr_un {} + impl ::fmt::Debug for sockaddr_un { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_un") + .field("sun_family", &self.sun_family) + // FIXME: .field("sun_path", &self.sun_path) + .finish() + } + } + impl ::hash::Hash for sockaddr_un { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sun_family.hash(state); + self.sun_path.hash(state); + } + } + + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.ss_family == other.ss_family + && self + .__ss_pad2 + .iter() + .zip(other.__ss_pad2.iter()) + .all(|(a, b)| a == b) + } + } + + impl Eq for sockaddr_storage {} + + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("ss_family", &self.ss_family) + .field("__ss_align", &self.__ss_align) + // FIXME: .field("__ss_pad2", &self.__ss_pad2) + .finish() + } + } + + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ss_family.hash(state); + self.__ss_pad2.hash(state); + } + } + + impl PartialEq for utsname { + fn eq(&self, other: &utsname) -> bool { + self.sysname + .iter() + .zip(other.sysname.iter()) + .all(|(a, b)| a == b) + && self + .nodename + .iter() + .zip(other.nodename.iter()) + .all(|(a, b)| a == b) + && self + .release + .iter() + .zip(other.release.iter()) + .all(|(a, b)| a == b) + && self + .version + .iter() + .zip(other.version.iter()) + .all(|(a, b)| a == b) + && self + .machine + .iter() + .zip(other.machine.iter()) + .all(|(a, b)| a == b) + && self + .domainname + .iter() + .zip(other.domainname.iter()) + .all(|(a, b)| a == b) + } + } + + impl Eq for utsname {} + + impl ::fmt::Debug for utsname { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utsname") + // FIXME: .field("sysname", &self.sysname) + // FIXME: .field("nodename", &self.nodename) + // FIXME: .field("release", &self.release) + // FIXME: .field("version", &self.version) + // FIXME: .field("machine", &self.machine) + // FIXME: .field("domainname", &self.domainname) + .finish() + } + } + + impl ::hash::Hash for utsname { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sysname.hash(state); + self.nodename.hash(state); + self.release.hash(state); + self.version.hash(state); + self.machine.hash(state); + self.domainname.hash(state); + } + } + } } // intentionally not public, only used for fd_set @@ -514,6 +682,7 @@ pub const SOL_DCCP: ::c_int = 269; pub const SOL_NETLINK: ::c_int = 270; pub const SOL_TIPC: ::c_int = 271; pub const SOL_BLUETOOTH: ::c_int = 274; +pub const SOL_ALG: ::c_int = 279; pub const AF_UNSPEC: ::c_int = 0; pub const AF_UNIX: ::c_int = 1; @@ -985,60 +1154,48 @@ pub const ARPHRD_IEEE802154: u16 = 804; pub const ARPHRD_VOID: u16 = 0xFFFF; pub const ARPHRD_NONE: u16 = 0xFFFE; +fn CMSG_ALIGN(len: usize) -> usize { + len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1) +} + f! { pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() { + if (*mhdr).msg_controllen as usize >= ::mem::size_of::<cmsghdr>() { (*mhdr).msg_control as *mut cmsghdr } else { 0 as *mut cmsghdr } } - pub fn CMSG_NXTHDR(mhdr: *const msghdr, - cmsg: *const cmsghdr) -> *mut cmsghdr { - if cmsg.is_null() { - return CMSG_FIRSTHDR(mhdr); - }; - let pad = mem::align_of::<cmsghdr>() - 1; - let next = cmsg as usize + (*cmsg).cmsg_len as usize + pad & !pad; - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next < max { - next as *mut cmsghdr - } else { - 0 as *mut cmsghdr - } - } - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut ::c_uchar { cmsg.offset(1) as *mut ::c_uchar } pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - let pad = mem::align_of::<cmsghdr>() as ::c_uint - 1; - mem::size_of::<cmsghdr>() as ::c_uint + ((length + pad) & !pad) + (CMSG_ALIGN(length as usize) + CMSG_ALIGN(::mem::size_of::<cmsghdr>())) + as ::c_uint } pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - mem::size_of::<cmsghdr>() as ::c_uint + length + CMSG_ALIGN(::mem::size_of::<cmsghdr>()) as ::c_uint + length } pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; (*set).fds_bits[fd / size] &= !(1 << (fd % size)); return } pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 } pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; (*set).fds_bits[fd / size] |= 1 << (fd % size); return } @@ -1103,6 +1260,12 @@ f! { } extern { + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; + pub fn fdatasync(fd: ::c_int) -> ::c_int; pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_uchar) -> ::c_int; @@ -1220,6 +1383,11 @@ extern { name: *mut ::c_char, termp: *const termios, winp: *const ::winsize) -> ::c_int; + pub fn forkpty(amaster: *mut ::c_int, + name: *mut ::c_char, + termp: *const termios, + winp: *const ::winsize) -> ::pid_t; + pub fn login_tty(fd: ::c_int) -> ::c_int; pub fn execvpe(file: *const ::c_char, argv: *const *const ::c_char, envp: *const *const ::c_char) -> ::c_int; pub fn fexecve(fd: ::c_int, argv: *const *const ::c_char, @@ -1259,7 +1427,3 @@ cfg_if! { // Unknown target_os } } - // pub fn forkpty(amaster: *mut ::c_int, - // name: *mut ::c_char, - // termp: *const termios, - // winp: *const ::winsize) -> ::pid_t; diff --git a/libc/src/unix/redox/mod.rs b/libc/src/unix/redox/mod.rs new file mode 100644 index 0000000..4bb1ab4 --- /dev/null +++ b/libc/src/unix/redox/mod.rs @@ -0,0 +1,588 @@ +pub type c_char = i8; +pub type c_long = i64; +pub type c_ulong = u64; +pub type wchar_t = i32; + +pub type blkcnt_t = ::c_ulong; +pub type blksize_t = ::c_long; +pub type clock_t = ::c_long; +pub type clockid_t = ::c_int; +pub type dev_t = ::c_long; +pub type fsblkcnt_t = ::c_ulong; +pub type fsfilcnt_t = ::c_ulong; +pub type ino_t = ::c_ulong; +pub type mode_t = ::c_int; +pub type nfds_t = ::c_ulong; +pub type nlink_t = ::c_ulong; +pub type off_t = ::c_long; +pub type pthread_t = *mut ::c_void; +pub type pthread_attr_t = *mut ::c_void; +pub type pthread_cond_t = *mut ::c_void; +pub type pthread_condattr_t = *mut ::c_void; +// Must be usize due to libstd/sys_common/thread_local.rs, +// should technically be *mut ::c_void +pub type pthread_key_t = usize; +pub type pthread_mutex_t = *mut ::c_void; +pub type pthread_mutexattr_t = *mut ::c_void; +pub type pthread_rwlock_t = *mut ::c_void; +pub type pthread_rwlockattr_t = *mut ::c_void; +pub type rlim_t = ::c_ulonglong; +pub type sa_family_t = u16; +pub type sem_t = *mut ::c_void; +pub type sigset_t = ::c_ulong; +pub type socklen_t = u32; +pub type speed_t = u32; +pub type suseconds_t = ::c_int; +pub type tcflag_t = u32; +pub type time_t = ::c_long; + +s! { + pub struct addrinfo { + pub ai_flags: ::c_int, + pub ai_family: ::c_int, + pub ai_socktype: ::c_int, + pub ai_protocol: ::c_int, + pub ai_addrlen: ::size_t, + pub ai_canonname: *mut ::c_char, + pub ai_addr: *mut ::sockaddr, + pub ai_next: *mut ::addrinfo, + } + + 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; 256], + } + + pub struct Dl_info { + pub dli_fname: *const ::c_char, + pub dli_fbase: *mut ::c_void, + pub dli_sname: *const ::c_char, + pub dli_saddr: *mut ::c_void, + } + + pub struct epoll_event { + pub events: u32, + pub u64: u64, + pub _pad: u64, + } + + pub struct fd_set { + fds_bits: [::c_ulong; ::FD_SETSIZE / ULONG_SIZE], + } + + pub struct in_addr { + pub s_addr: ::in_addr_t, + } + + pub struct ip_mreq { + pub imr_multiaddr: ::in_addr, + pub imr_interface: ::in_addr, + } + + pub struct lconv { + pub currency_symbol: *const ::c_char, + pub decimal_point: *const ::c_char, + pub frac_digits: ::c_char, + pub grouping: *const ::c_char, + pub int_curr_symbol: *const ::c_char, + pub int_frac_digits: ::c_char, + pub mon_decimal_point: *const ::c_char, + pub mon_grouping: *const ::c_char, + pub mon_thousands_sep: *const ::c_char, + pub negative_sign: *const ::c_char, + pub n_cs_precedes: ::c_char, + pub n_sep_by_space: ::c_char, + pub n_sign_posn: ::c_char, + pub positive_sign: *const ::c_char, + pub p_cs_precedes: ::c_char, + pub p_sep_by_space: ::c_char, + pub p_sign_posn: ::c_char, + pub thousands_sep: *const ::c_char, + } + + pub struct passwd { + pub pw_name: *mut ::c_char, + pub pw_passwd: *mut ::c_char, + pub pw_uid: ::uid_t, + pub pw_gid: ::gid_t, + pub pw_gecos: *mut ::c_char, + pub pw_dir: *mut ::c_char, + pub pw_shell: *mut ::c_char, + } + + pub struct sigaction { + pub sa_handler: ::sighandler_t, + pub sa_flags: ::c_ulong, + pub sa_restorer: ::Option<extern fn()>, + pub sa_mask: ::sigset_t, + } + + pub struct sockaddr { + pub sa_family: ::sa_family_t, + pub sa_data: [::c_char; 14], + } + + pub struct sockaddr_in { + pub sin_family: ::sa_family_t, + pub sin_port: ::in_port_t, + pub sin_addr: ::in_addr, + pub sin_zero: [::c_char; 8], + } + + pub struct sockaddr_in6 { + pub sin6_family: ::sa_family_t, + pub sin6_port: ::in_port_t, + pub sin6_flowinfo: u32, + pub sin6_addr: ::in6_addr, + pub sin6_scope_id: u32, + } + + pub struct sockaddr_storage { + pub ss_family: ::sa_family_t, + __ss_padding: [ + u8; + 128 - + ::core::mem::size_of::<sa_family_t>() - + ::core::mem::size_of::<c_ulong>() + ], + __ss_align: ::c_ulong, + } + + pub struct sockaddr_un { + pub sun_family: ::sa_family_t, + pub sun_path: [::c_char; 108] + } + + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_nlink: ::nlink_t, + pub st_mode: ::mode_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::dev_t, + pub st_size: ::off_t, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt_t, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + _pad: [::c_char; 24], + } + + pub struct statvfs { + pub f_bsize: ::c_ulong, + pub f_frsize: ::c_ulong, + pub f_blocks: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_bavail: ::fsblkcnt_t, + pub f_files: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + pub f_favail: ::fsfilcnt_t, + pub f_fsid: ::c_ulong, + pub f_flag: ::c_ulong, + pub f_namemax: ::c_ulong, + } + + pub struct termios { + pub c_iflag: ::tcflag_t, + pub c_oflag: ::tcflag_t, + pub c_cflag: ::tcflag_t, + pub c_lflag: ::tcflag_t, + pub c_line: ::cc_t, + pub c_cc: [::cc_t; ::NCCS], + pub c_ispeed: ::speed_t, + pub c_ospeed: ::speed_t, + } + + pub struct tm { + pub tm_sec: ::c_int, + pub tm_min: ::c_int, + pub tm_hour: ::c_int, + pub tm_mday: ::c_int, + pub tm_mon: ::c_int, + pub tm_year: ::c_int, + pub tm_wday: ::c_int, + pub tm_yday: ::c_int, + pub tm_isdst: ::c_int, + pub tm_gmtoff: ::c_long, + pub tm_zone: *const ::c_char, + } +} + +// TODO: relibc { + pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; +// } + +// dlfcn.h + +pub const RTLD_LAZY: ::c_int = 0x0001; +pub const RTLD_NOW: ::c_int = 0x0002; +pub const RTLD_GLOBAL: ::c_int = 0x0100; +pub const RTLD_LOCAL: ::c_int = 0x0000; + +// errno.h +pub const EPERM: ::c_int = 1; +pub const ENOENT: ::c_int = 2; +pub const ESRCH: ::c_int = 3; +pub const EINTR: ::c_int = 4; +pub const EIO: ::c_int = 5; +pub const ENXIO: ::c_int = 6; +pub const E2BIG: ::c_int = 7; +pub const ENOEXEC: ::c_int = 8; +pub const EBADF: ::c_int = 9; +pub const ECHILD: ::c_int = 10; +pub const EAGAIN: ::c_int = 11; +pub const ENOMEM: ::c_int = 12; +pub const EACCES: ::c_int = 13; +pub const EFAULT: ::c_int = 14; +pub const ENOTBLK: ::c_int = 15; +pub const EBUSY: ::c_int = 16; +pub const EEXIST: ::c_int = 17; +pub const EXDEV: ::c_int = 18; +pub const ENODEV: ::c_int = 19; +pub const ENOTDIR: ::c_int = 20; +pub const EISDIR: ::c_int = 21; +pub const EINVAL: ::c_int = 22; +pub const ENFILE: ::c_int = 23; +pub const EMFILE: ::c_int = 24; +pub const ENOTTY: ::c_int = 25; +pub const ETXTBSY: ::c_int = 26; +pub const EFBIG: ::c_int = 27; +pub const ENOSPC: ::c_int = 28; +pub const ESPIPE: ::c_int = 29; +pub const EROFS: ::c_int = 30; +pub const EMLINK: ::c_int = 31; +pub const EPIPE: ::c_int = 32; +pub const EDOM: ::c_int = 33; +pub const ERANGE: ::c_int = 34; +pub const EDEADLK: ::c_int = 35; +pub const ENOSYS: ::c_int = 38; +pub const EWOULDBLOCK: ::c_int = 41; +pub const EADDRINUSE: ::c_int = 98; +pub const EADDRNOTAVAIL: ::c_int = 99; +pub const ECONNABORTED: ::c_int = 103; +pub const ECONNRESET: ::c_int = 104; +pub const ENOTCONN: ::c_int = 107; +pub const ETIMEDOUT: ::c_int = 110; +pub const ECONNREFUSED: ::c_int = 111; +pub const EINPROGRESS: ::c_int = 115; + +// fcntl.h +pub const F_DUPFD: ::c_int = 0; +pub const F_GETFD: ::c_int = 1; +pub const F_SETFD: ::c_int = 2; +pub const F_GETFL: ::c_int = 3; +pub const F_SETFL: ::c_int = 4; +// TODO: relibc { + pub const F_DUPFD_CLOEXEC: ::c_int = ::F_DUPFD; +// } +pub const FD_CLOEXEC: ::c_int = 0x0100_0000; +pub const O_RDONLY: ::c_int = 0x0001_0000; +pub const O_WRONLY: ::c_int = 0x0002_0000; +pub const O_RDWR: ::c_int = 0x0003_0000; +pub const O_ACCMODE: ::c_int = 0x0003_0000; +pub const O_NONBLOCK: ::c_int = 0x0004_0000; +pub const O_APPEND: ::c_int = 0x0008_0000; +pub const O_SHLOCK: ::c_int = 0x0010_0000; +pub const O_EXLOCK: ::c_int = 0x0020_0000; +pub const O_ASYNC: ::c_int = 0x0040_0000; +pub const O_FSYNC: ::c_int = 0x0080_0000; +pub const O_CLOEXEC: ::c_int = 0x0100_0000; +pub const O_CREAT: ::c_int = 0x0200_0000; +pub const O_TRUNC: ::c_int = 0x0400_0000; +pub const O_EXCL: ::c_int = 0x0800_0000; +pub const O_DIRECTORY: ::c_int = 0x1000_0000; +pub const O_PATH: ::c_int = 0x2000_0000; +pub const O_SYMLINK: ::c_int = 0x4000_0000; +// Negative to allow it to be used as int +// TODO: Fix negative values missing from includes +pub const O_NOFOLLOW: ::c_int = -0x8000_0000; + +// netdb.h +pub const EAI_SYSTEM: ::c_int = -11; + +// netinet/in.h +// TODO: relibc { + pub const IP_TTL: ::c_int = 2; + pub const IPV6_UNICAST_HOPS: ::c_int = 16; + pub const IPV6_MULTICAST_IF: ::c_int = 17; + pub const IPV6_MULTICAST_HOPS: ::c_int = 18; + pub const IPV6_MULTICAST_LOOP: ::c_int = 19; + pub const IPV6_ADD_MEMBERSHIP: ::c_int = 20; + pub const IPV6_DROP_MEMBERSHIP: ::c_int = 21; + pub const IPV6_V6ONLY: ::c_int = 26; + pub const IP_MULTICAST_IF: ::c_int = 32; + pub const IP_MULTICAST_TTL: ::c_int = 33; + pub const IP_MULTICAST_LOOP: ::c_int = 34; + pub const IP_ADD_MEMBERSHIP: ::c_int = 35; + pub const IP_DROP_MEMBERSHIP: ::c_int = 36; +// } + +// netinet/tcp.h +pub const TCP_NODELAY: ::c_int = 1; +// TODO: relibc { + pub const TCP_KEEPIDLE: ::c_int = 1; +// } + +// poll.h +pub const POLLIN: ::c_short = 0x001; +pub const POLLPRI: ::c_short = 0x002; +pub const POLLOUT: ::c_short = 0x004; +pub const POLLERR: ::c_short = 0x008; +pub const POLLHUP: ::c_short = 0x010; +pub const POLLNVAL: ::c_short = 0x020; + +// pthread.h +pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; +pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; +pub const PTHREAD_MUTEX_INITIALIZER: ::pthread_mutex_t = -1isize as *mut _; +pub const PTHREAD_COND_INITIALIZER: ::pthread_cond_t = -1isize as *mut _; +pub const PTHREAD_RWLOCK_INITIALIZER: ::pthread_rwlock_t = -1isize as *mut _; +pub const PTHREAD_STACK_MIN : ::size_t = 4096; + +// signal.h +pub const SIG_BLOCK: ::c_int = 0; +pub const SIG_UNBLOCK: ::c_int = 1; +pub const SIG_SETMASK: ::c_int = 2; +pub const SIGHUP: ::c_int = 1; +pub const SIGINT: ::c_int = 2; +pub const SIGQUIT: ::c_int = 3; +pub const SIGILL: ::c_int = 4; +pub const SIGTRAP: ::c_int = 5; +pub const SIGABRT: ::c_int = 6; +pub const SIGBUS: ::c_int = 7; +pub const SIGFPE: ::c_int = 8; +pub const SIGKILL: ::c_int = 9; +pub const SIGUSR1: ::c_int = 10; +pub const SIGSEGV: ::c_int = 11; +pub const SIGUSR2: ::c_int = 12; +pub const SIGPIPE: ::c_int = 13; +pub const SIGALRM: ::c_int = 14; +pub const SIGTERM: ::c_int = 15; +pub const SIGSTKFLT: ::c_int = 16; +pub const SIGCHLD: ::c_int = 17; +pub const SIGCONT: ::c_int = 18; +pub const SIGSTOP: ::c_int = 19; +pub const SIGTSTP: ::c_int = 20; +pub const SIGTTIN: ::c_int = 21; +pub const SIGTTOU: ::c_int = 22; +pub const SIGURG: ::c_int = 23; +pub const SIGXCPU: ::c_int = 24; +pub const SIGXFSZ: ::c_int = 25; +pub const SIGVTALRM: ::c_int = 26; +pub const SIGPROF: ::c_int = 27; +pub const SIGWINCH: ::c_int = 28; +pub const SIGIO: ::c_int = 29; +pub const SIGPWR: ::c_int = 30; +pub const SIGSYS: ::c_int = 31; +pub const NSIG: ::c_int = 32; + +// sys/epoll.h +pub const EPOLL_CLOEXEC: ::c_int = 0x0100_0000; +pub const EPOLL_CTL_ADD: ::c_int = 1; +pub const EPOLL_CTL_DEL: ::c_int = 2; +pub const EPOLL_CTL_MOD: ::c_int = 3; +pub const EPOLLIN: ::c_int = 1; +pub const EPOLLPRI: ::c_int = 0; +pub const EPOLLOUT: ::c_int = 2; +pub const EPOLLRDNORM: ::c_int = 0; +pub const EPOLLNVAL: ::c_int = 0; +pub const EPOLLRDBAND: ::c_int = 0; +pub const EPOLLWRNORM: ::c_int = 0; +pub const EPOLLWRBAND: ::c_int = 0; +pub const EPOLLMSG: ::c_int = 0; +pub const EPOLLERR: ::c_int = 0; +pub const EPOLLHUP: ::c_int = 0; +pub const EPOLLRDHUP: ::c_int = 0; +pub const EPOLLEXCLUSIVE: ::c_int = 0; +pub const EPOLLWAKEUP: ::c_int = 0; +pub const EPOLLONESHOT: ::c_int = 0; +pub const EPOLLET: ::c_int = 0; + +// sys/stat.h +pub const S_IFMT: ::c_int = 0o0_170_000; +pub const S_IFDIR: ::c_int = 0o040_000; +pub const S_IFCHR: ::c_int = 0o020_000; +pub const S_IFBLK: ::c_int = 0o060_000; +pub const S_IFREG: ::c_int = 0o100_000; +pub const S_IFIFO: ::c_int = 0o010_000; +pub const S_IFLNK: ::c_int = 0o120_000; +pub const S_IFSOCK: ::c_int = 0o140_000; +pub const S_IRWXU: ::c_int = 0o0_700; +pub const S_IRUSR: ::c_int = 0o0_400; +pub const S_IWUSR: ::c_int = 0o0_200; +pub const S_IXUSR: ::c_int = 0o0_100; +pub const S_IRWXG: ::c_int = 0o0_070; +pub const S_IRGRP: ::c_int = 0o0_040; +pub const S_IWGRP: ::c_int = 0o0_020; +pub const S_IXGRP: ::c_int = 0o0_010; +pub const S_IRWXO: ::c_int = 0o0_007; +pub const S_IROTH: ::c_int = 0o0_004; +pub const S_IWOTH: ::c_int = 0o0_002; +pub const S_IXOTH: ::c_int = 0o0_001; + +// stdlib.h +pub const EXIT_SUCCESS: ::c_int = 0; +pub const EXIT_FAILURE: ::c_int = 1; + +// sys/ioctl.h +// TODO: relibc { + pub const FIONBIO: ::c_ulong = 0x5421; + pub const FIOCLEX: ::c_ulong = 0x5451; +// } +pub const TCGETS: ::c_ulong = 0x5401; +pub const TCSETS: ::c_ulong = 0x5402; +pub const TCFLSH: ::c_ulong = 0x540B; +pub const TIOCGPGRP: ::c_ulong = 0x540F; +pub const TIOCSPGRP: ::c_ulong = 0x5410; +pub const TIOCGWINSZ: ::c_ulong = 0x5413; +pub const TIOCSWINSZ: ::c_ulong = 0x5414; + +// sys/select.h +pub const FD_SETSIZE: usize = 1024; + +// sys/socket.h +pub const AF_UNIX: ::c_int = 1; +pub const AF_INET: ::c_int = 2; +pub const AF_INET6: ::c_int = 10; +pub const MSG_PEEK: ::c_int = 2; +pub const SHUT_RD: ::c_int = 0; +pub const SHUT_WR: ::c_int = 1; +pub const SHUT_RDWR: ::c_int = 2; +pub const SO_REUSEADDR: ::c_int = 2; +pub const SO_ERROR: ::c_int = 4; +pub const SO_BROADCAST: ::c_int = 6; +pub const SO_SNDBUF: ::c_int = 7; +pub const SO_RCVBUF: ::c_int = 8; +pub const SO_KEEPALIVE: ::c_int = 9; +pub const SO_LINGER: ::c_int = 13; +pub const SO_REUSEPORT: ::c_int = 15; +pub const SO_RCVTIMEO: ::c_int = 20; +pub const SO_SNDTIMEO: ::c_int = 21; +pub const SOCK_STREAM: ::c_int = 1; +pub const SOCK_DGRAM: ::c_int = 2; +pub const SOL_SOCKET: ::c_int = 1; + +// sys/wait.h +pub const WNOHANG: ::c_int = 1; + +// termios.h +pub const NCCS: usize = 32; + +// time.h +pub const CLOCK_REALTIME: ::c_int = 1; +pub const CLOCK_MONOTONIC: ::c_int = 4; + +// unistd.h +pub const _SC_PAGESIZE: ::c_int = 30; +pub const SEEK_SET: ::c_int = 0; +pub const SEEK_CUR: ::c_int = 1; +pub const SEEK_END: ::c_int = 2; +pub const STDIN_FILENO: ::c_int = 0; +pub const STDOUT_FILENO: ::c_int = 1; +pub const STDERR_FILENO: ::c_int = 2; + +// wait.h +pub fn WIFSTOPPED(status: ::c_int) -> bool { + (status & 0xff) == 0x7f +} + +pub fn WSTOPSIG(status: ::c_int) -> ::c_int { + (status >> 8) & 0xff +} + +pub fn WIFCONTINUED(status: ::c_int) -> bool { + status == 0xffff +} + +pub fn WIFSIGNALED(status: ::c_int) -> bool { + ((status & 0x7f) + 1) as i8 >= 2 +} + +pub fn WTERMSIG(status: ::c_int) -> ::c_int { + status & 0x7f +} + +pub fn WIFEXITED(status: ::c_int) -> bool { + (status & 0x7f) == 0 +} + +pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { + (status >> 8) & 0xff +} + +pub fn WCOREDUMP(status: ::c_int) -> bool { + (status & 0x80) != 0 +} + +// intentionally not public, only used for fd_set +cfg_if! { + if #[cfg(target_pointer_width = "32")] { + const ULONG_SIZE: usize = 32; + } else if #[cfg(target_pointer_width = "64")] { + const ULONG_SIZE: usize = 64; + } else { + // Unknown target_pointer_width + } +} + +extern { + // malloc.h + pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; + + // pthread.h + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_create(tid: *mut ::pthread_t, + attr: *const ::pthread_attr_t, + start: extern fn(*mut ::c_void) -> *mut ::c_void, + arg: *mut ::c_void) -> ::c_int; + pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, + clock_id: ::clockid_t) -> ::c_int; + + // signal.h + pub fn pthread_sigmask(how: ::c_int, + set: *const ::sigset_t, + oldset: *mut ::sigset_t) -> ::c_int; + + // sys/epoll.h + pub fn epoll_create(size: ::c_int) -> ::c_int; + pub fn epoll_create1(flags: ::c_int) -> ::c_int; + pub fn epoll_wait(epfd: ::c_int, + events: *mut ::epoll_event, + maxevents: ::c_int, + timeout: ::c_int) -> ::c_int; + pub fn epoll_ctl(epfd: ::c_int, + op: ::c_int, + fd: ::c_int, + event: *mut ::epoll_event) -> ::c_int; + + // sys/ioctl.h + pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; + + // sys/socket.h + pub fn bind(socket: ::c_int, address: *const ::sockaddr, + address_len: ::socklen_t) -> ::c_int; + pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, + flags: ::c_int, addr: *mut ::sockaddr, + addrlen: *mut ::socklen_t) -> ::ssize_t; + + // sys/uio.h + pub fn readv(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + pub fn writev(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + + // time.h + pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; +} diff --git a/libc/src/unix/solarish/compat.rs b/libc/src/unix/solarish/compat.rs new file mode 100644 index 0000000..8631d60 --- /dev/null +++ b/libc/src/unix/solarish/compat.rs @@ -0,0 +1,21 @@ +// Common functions that are unfortunately missing on illumos and +// Solaris, but often needed by other crates. + +use unix::solarish::*; + +pub unsafe fn cfmakeraw(termios: *mut ::termios) { + let mut t = *termios as ::termios; + t.c_iflag &= !(IMAXBEL|IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + t.c_oflag &= !OPOST; + t.c_lflag &= !(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + t.c_cflag &= !(CSIZE|PARENB); + t.c_cflag |= CS8; +} + +pub unsafe fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int { + // Neither of these functions on illumos or Solaris actually ever + // return an error + ::cfsetispeed(termios, speed); + ::cfsetospeed(termios, speed); + 0 +} diff --git a/libc/src/unix/solaris/mod.rs b/libc/src/unix/solarish/mod.rs index c991e62..1092d15 100644 --- a/libc/src/unix/solaris/mod.rs +++ b/libc/src/unix/solarish/mod.rs @@ -1,5 +1,3 @@ -use dox::{mem, Option}; - pub type c_char = i8; pub type c_long = i64; pub type c_ulong = u64; @@ -36,9 +34,23 @@ pub type nl_item = ::c_int; pub type id_t = ::c_int; pub type idtype_t = ::c_uint; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} s! { + pub struct in_addr { + pub s_addr: ::in_addr_t, + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + pub struct sockaddr { pub sa_family: sa_family_t, pub sa_data: [::c_char; 14], @@ -60,11 +72,6 @@ s! { pub __sin6_src_id: u32 } - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [c_char; 108] - } - pub struct passwd { pub pw_name: *mut ::c_char, pub pw_passwd: *mut ::c_char, @@ -99,15 +106,7 @@ s! { pub tm_isdst: ::c_int } - pub struct utsname { - pub sysname: [::c_char; 257], - pub nodename: [::c_char; 257], - pub release: [::c_char; 257], - pub version: [::c_char; 257], - pub machine: [::c_char; 257], - } - - pub struct msghdr { + pub struct msghdr { pub msg_name: *mut ::c_void, pub msg_namelen: ::socklen_t, pub msg_iov: *mut ::iovec, @@ -123,13 +122,6 @@ s! { pub cmsg_type: ::c_int, } - pub struct fd_set { - #[cfg(target_pointer_width = "64")] - fds_bits: [i64; FD_SETSIZE / 64], - #[cfg(target_pointer_width = "32")] - fds_bits: [i32; FD_SETSIZE / 32], - } - pub struct pthread_attr_t { __pthread_attrp: *mut ::c_void } @@ -195,13 +187,6 @@ s! { __unused10: *mut ::c_void, } - pub struct sockaddr_storage { - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_align: i64, - __ss_pad2: [u8; 240], - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -219,21 +204,21 @@ s! { bits: [u32; 4], } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub si_pad: ::c_int, - pub si_addr: *mut ::c_void, - __pad: [u8; 232], - } - pub struct sigaction { pub sa_flags: ::c_int, pub sa_sigaction: ::sighandler_t, pub sa_mask: sigset_t, } + pub struct sigevent { + pub sigev_notify: ::c_int, + pub sigev_signo: ::c_int, + pub sigev_value: ::sigval, + pub ss_sp: *mut ::c_void, + pub sigev_notify_attributes: *const ::pthread_attr_t, + __sigev_pad2: ::c_int, + } + pub struct stack_t { pub ss_sp: *mut ::c_void, pub ss_size: ::size_t, @@ -353,12 +338,296 @@ s! { pub portev_object: ::uintptr_t, pub portev_user: *mut ::c_void, } +} +s_no_extra_traits! { #[cfg_attr(any(target_arch = "x86", target_arch = "x86_64"), repr(packed))] pub struct epoll_event { pub events: ::uint32_t, pub u64: ::uint64_t, } + + pub struct sockaddr_un { + pub sun_family: sa_family_t, + pub sun_path: [c_char; 108] + } + + pub struct utsname { + pub sysname: [::c_char; 257], + pub nodename: [::c_char; 257], + pub release: [::c_char; 257], + pub version: [::c_char; 257], + pub machine: [::c_char; 257], + } + + pub struct fd_set { + #[cfg(target_pointer_width = "64")] + fds_bits: [i64; FD_SETSIZE / 64], + #[cfg(target_pointer_width = "32")] + fds_bits: [i32; FD_SETSIZE / 32], + } + + pub struct sockaddr_storage { + pub ss_family: ::sa_family_t, + __ss_pad1: [u8; 6], + __ss_align: i64, + __ss_pad2: [u8; 240], + } + + pub struct siginfo_t { + pub si_signo: ::c_int, + pub si_code: ::c_int, + pub si_errno: ::c_int, + pub si_pad: ::c_int, + pub si_addr: *mut ::c_void, + __pad: [u8; 232], + } + + pub struct sockaddr_dl { + pub sdl_family: ::c_ushort, + pub sdl_index: ::c_ushort, + pub sdl_type: ::c_uchar, + pub sdl_nlen: ::c_uchar, + pub sdl_alen: ::c_uchar, + pub sdl_slen: ::c_uchar, + pub sdl_data: [::c_char; 244], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for epoll_event { + fn eq(&self, other: &epoll_event) -> bool { + self.events == other.events + && self.u64 == other.u64 + } + } + impl Eq for epoll_event {} + impl ::fmt::Debug for epoll_event { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let events = self.events; + let u64 = self.u64; + f.debug_struct("epoll_event") + .field("events", &events) + .field("u64", &u64) + .finish() + } + } + impl ::hash::Hash for epoll_event { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + let events = self.events; + let u64 = self.u64; + events.hash(state); + u64.hash(state); + } + } + + impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_family == other.sun_family + && self + .sun_path + .iter() + .zip(other.sun_path.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for sockaddr_un {} + impl ::fmt::Debug for sockaddr_un { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_un") + .field("sun_family", &self.sun_family) + // FIXME: .field("sun_path", &self.sun_path) + .finish() + } + } + impl ::hash::Hash for sockaddr_un { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sun_family.hash(state); + self.sun_path.hash(state); + } + } + + impl PartialEq for utsname { + fn eq(&self, other: &utsname) -> bool { + self.sysname + .iter() + .zip(other.sysname.iter()) + .all(|(a, b)| a == b) + && self + .nodename + .iter() + .zip(other.nodename.iter()) + .all(|(a, b)| a == b) + && self + .release + .iter() + .zip(other.release.iter()) + .all(|(a, b)| a == b) + && self + .version + .iter() + .zip(other.version.iter()) + .all(|(a, b)| a == b) + && self + .machine + .iter() + .zip(other.machine.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for utsname {} + impl ::fmt::Debug for utsname { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utsname") + // FIXME: .field("sysname", &self.sysname) + // FIXME: .field("nodename", &self.nodename) + // FIXME: .field("release", &self.release) + // FIXME: .field("version", &self.version) + // FIXME: .field("machine", &self.machine) + .finish() + } + } + impl ::hash::Hash for utsname { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sysname.hash(state); + self.nodename.hash(state); + self.release.hash(state); + self.version.hash(state); + self.machine.hash(state); + } + } + + impl PartialEq for fd_set { + fn eq(&self, other: &fd_set) -> bool { + self.fds_bits + .iter() + .zip(other.fds_bits.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for fd_set {} + impl ::fmt::Debug for fd_set { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("fd_set") + // FIXME: .field("fds_bits", &self.fds_bits) + .finish() + } + } + impl ::hash::Hash for fd_set { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.fds_bits.hash(state); + } + } + + impl PartialEq for sockaddr_storage { + fn eq(&self, other: &sockaddr_storage) -> bool { + self.ss_family == other.ss_family + && self.__ss_pad1 == other.__ss_pad1 + && self.__ss_align == other.__ss_align + && self + .__ss_pad2 + .iter() + .zip(other.__ss_pad2.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for sockaddr_storage {} + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_storage") + .field("ss_family", &self.ss_family) + .field("__ss_pad1", &self.__ss_pad1) + .field("__ss_align", &self.__ss_align) + // FIXME: .field("__ss_pad2", &self.__ss_pad2) + .finish() + } + } + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.ss_family.hash(state); + self.__ss_pad1.hash(state); + self.__ss_align.hash(state); + self.__ss_pad2.hash(state); + } + } + + impl PartialEq for siginfo_t { + fn eq(&self, other: &siginfo_t) -> bool { + self.si_signo == other.si_signo + && self.si_code == other.si_code + && self.si_errno == other.si_errno + && self.si_addr == other.si_addr + && self + .__pad + .iter() + .zip(other.__pad.iter()) + .all(|(a, b)| a == b) + } + } + impl Eq for siginfo_t {} + impl ::fmt::Debug for siginfo_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("siginfo_t") + .field("si_signo", &self.si_signo) + .field("si_code", &self.si_code) + .field("si_errno", &self.si_errno) + .field("si_addr", &self.si_addr) + // FIXME: .field("__pad", &self.__pad) + .finish() + } + } + impl ::hash::Hash for siginfo_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.si_signo.hash(state); + self.si_code.hash(state); + self.si_errno.hash(state); + self.si_addr.hash(state); + self.__pad.hash(state); + } + } + + impl PartialEq for sockaddr_dl { + fn eq(&self, other: &sockaddr_dl) -> bool { + self.sdl_family == other.sdl_family + && self.sdl_index == other.sdl_index + && self.sdl_type == other.sdl_type + && self.sdl_nlen == other.sdl_nlen + && self.sdl_alen == other.sdl_alen + && self.sdl_slen == other.sdl_slen + && self + .sdl_data + .iter() + .zip(other.sdl_data.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for sockaddr_dl {} + impl ::fmt::Debug for sockaddr_dl { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_dl") + .field("sdl_family", &self.sdl_family) + .field("sdl_index", &self.sdl_index) + .field("sdl_type", &self.sdl_type) + .field("sdl_nlen", &self.sdl_nlen) + .field("sdl_alen", &self.sdl_alen) + .field("sdl_slen", &self.sdl_slen) + // FIXME: .field("sdl_data", &self.sdl_data) + .finish() + } + } + impl ::hash::Hash for sockaddr_dl { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.sdl_family.hash(state); + self.sdl_index.hash(state); + self.sdl_type.hash(state); + self.sdl_nlen.hash(state); + self.sdl_alen.hash(state); + self.sdl_slen.hash(state); + self.sdl_data.hash(state); + } + } + } } pub const LC_CTYPE: ::c_int = 0; @@ -475,6 +744,10 @@ pub const SIG_BLOCK: ::c_int = 1; pub const SIG_UNBLOCK: ::c_int = 2; pub const SIG_SETMASK: ::c_int = 3; +pub const SIGEV_NONE: ::c_int = 1; +pub const SIGEV_SIGNAL: ::c_int =2; +pub const SIGEV_THREAD: ::c_int = 3; + pub const IPV6_UNICAST_HOPS: ::c_int = 0x5; pub const IPV6_MULTICAST_IF: ::c_int = 0x6; pub const IPV6_MULTICAST_HOPS: ::c_int = 0x7; @@ -513,13 +786,16 @@ pub const TMP_MAX: ::c_uint = 17576; pub const O_RDONLY: ::c_int = 0; pub const O_WRONLY: ::c_int = 1; pub const O_RDWR: ::c_int = 2; -pub const O_SEARCH: ::c_int = 0x200000; -pub const O_EXEC: ::c_int = 0x400000; +pub const O_NDELAY: ::c_int = 0x04; pub const O_APPEND: ::c_int = 8; +pub const O_DSYNC: ::c_int = 0x40; pub const O_CREAT: ::c_int = 256; pub const O_EXCL: ::c_int = 1024; pub const O_NOCTTY: ::c_int = 2048; pub const O_TRUNC: ::c_int = 512; +pub const O_NOFOLLOW: ::c_int = 0x200000; +pub const O_SEARCH: ::c_int = 0x200000; +pub const O_EXEC: ::c_int = 0x400000; pub const O_CLOEXEC: ::c_int = 0x800000; pub const O_ACCMODE: ::c_int = 0x600003; pub const S_IFIFO: mode_t = 4096; @@ -602,17 +878,29 @@ pub const WNOWAIT: ::c_int = 0x80; pub const AT_FDCWD: ::c_int = 0xffd19553; pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x1000; -// Solaris defines a great many more of these; we only expose the -// standardized ones. pub const P_PID: idtype_t = 0; +pub const P_PPID: idtype_t = 1; pub const P_PGID: idtype_t = 2; +pub const P_SID: idtype_t = 3; +pub const P_CID: idtype_t = 4; +pub const P_UID: idtype_t = 5; +pub const P_GID: idtype_t = 6; pub const P_ALL: idtype_t = 7; +pub const P_LWPID: idtype_t = 8; +pub const P_TASKID: idtype_t = 9; +pub const P_PROJID: idtype_t = 10; +pub const P_POOLID: idtype_t = 11; +pub const P_ZONEID: idtype_t = 12; +pub const P_CTID: idtype_t = 13; +pub const P_CPUID: idtype_t = 14; +pub const P_PSETID: idtype_t = 15; pub const PROT_NONE: ::c_int = 0; pub const PROT_READ: ::c_int = 1; pub const PROT_WRITE: ::c_int = 2; pub const PROT_EXEC: ::c_int = 4; +pub const MAP_FILE: ::c_int = 0; pub const MAP_SHARED: ::c_int = 0x0001; pub const MAP_PRIVATE: ::c_int = 0x0002; pub const MAP_FIXED: ::c_int = 0x0010; @@ -754,6 +1042,7 @@ pub const EHOSTUNREACH: ::c_int = 148; pub const EWOULDBLOCK: ::c_int = EAGAIN; pub const EALREADY: ::c_int = 149; pub const EINPROGRESS: ::c_int = 150; +pub const ESTALE: ::c_int = 151; pub const EAI_AGAIN: ::c_int = 2; pub const EAI_BADFLAGS: ::c_int = 3; @@ -793,6 +1082,11 @@ pub const POLLOUT: ::c_short = 0x4; pub const POLLERR: ::c_short = 0x8; pub const POLLHUP: ::c_short = 0x10; pub const POLLNVAL: ::c_short = 0x20; +pub const POLLNORM: ::c_short = 0x0040; +pub const POLLRDNORM: ::c_short = 0x0040; +pub const POLLWRNORM: ::c_short = 0x4; /* POLLOUT */ +pub const POLLRDBAND: ::c_short = 0x0080; +pub const POLLWRBAND: ::c_short = 0x0100; pub const POSIX_MADV_NORMAL: ::c_int = 0; pub const POSIX_MADV_RANDOM: ::c_int = 1; @@ -845,9 +1139,43 @@ pub const MADV_WILLNEED: ::c_int = 3; pub const MADV_DONTNEED: ::c_int = 4; pub const MADV_FREE: ::c_int = 5; +pub const AF_UNSPEC: ::c_int = 0; +pub const AF_UNIX: ::c_int = 1; +pub const AF_LOCAL: ::c_int = 0; +pub const AF_FILE: ::c_int = 0; pub const AF_INET: ::c_int = 2; +pub const AF_IMPLINK: ::c_int = 3; +pub const AF_PUP: ::c_int = 4; +pub const AF_CHAOS: ::c_int = 5; +pub const AF_NS: ::c_int = 6; +pub const AF_NBS: ::c_int = 7; +pub const AF_ECMA: ::c_int = 8; +pub const AF_DATAKIT: ::c_int = 9; +pub const AF_CCITT: ::c_int = 10; +pub const AF_SNA: ::c_int = 11; +pub const AF_DECnet: ::c_int = 12; +pub const AF_DLI: ::c_int = 13; +pub const AF_LAT: ::c_int = 14; +pub const AF_HYLINK: ::c_int = 15; +pub const AF_APPLETALK: ::c_int = 16; +pub const AF_NIT: ::c_int = 17; +pub const AF_802: ::c_int = 18; +pub const AF_OSI: ::c_int = 19; +pub const AF_X25: ::c_int = 20; +pub const AF_OSINET: ::c_int = 21; +pub const AF_GOSIP: ::c_int = 22; +pub const AF_IPX: ::c_int = 23; +pub const AF_ROUTE: ::c_int = 24; +pub const AF_LINK: ::c_int = 25; pub const AF_INET6: ::c_int = 26; -pub const AF_UNIX: ::c_int = 1; +pub const AF_KEY: ::c_int = 27; +pub const AF_NCA: ::c_int = 28; +pub const AF_POLICY: ::c_int = 29; +pub const AF_INET_OFFLOAD: ::c_int = 30; +pub const AF_TRILL: ::c_int = 31; +pub const AF_PACKET: ::c_int = 32; +pub const AF_LX_NETLINK: ::c_int = 33; +pub const AF_MAX: ::c_int = 33; pub const SOCK_DGRAM: ::c_int = 1; pub const SOCK_STREAM: ::c_int = 2; pub const SOCK_RAW: ::c_int = 4; @@ -883,8 +1211,25 @@ pub const SO_SNDTIMEO: ::c_int = 0x1005; pub const SO_RCVTIMEO: ::c_int = 0x1006; pub const SO_ERROR: ::c_int = 0x1007; pub const SO_TYPE: ::c_int = 0x1008; +pub const SO_TIMESTAMP: ::c_int = 0x1013; +pub const SCM_RIGHTS: ::c_int = 0x1010; +pub const SCM_UCRED: ::c_int = 0x1012; +pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP; + +pub const MSG_OOB: ::c_int = 0x1; pub const MSG_PEEK: ::c_int = 0x2; +pub const MSG_DONTROUTE: ::c_int = 0x4; +pub const MSG_EOR: ::c_int = 0x8; +pub const MSG_CTRUNC: ::c_int = 0x10; +pub const MSG_TRUNC: ::c_int = 0x20; +pub const MSG_WAITALL: ::c_int = 0x40; +pub const MSG_DONTWAIT: ::c_int = 0x80; +pub const MSG_NOTIFICATION: ::c_int = 0x100; +pub const MSG_NOSIGNAL: ::c_int = 0x200; +pub const MSG_DUPCTRL: ::c_int = 0x800; +pub const MSG_XPG4_2: ::c_int = 0x8000; +pub const MSG_MAXIOVLEN: ::c_int = 16; // https://docs.oracle.com/cd/E23824_01/html/821-1475/if-7p.html pub const IFF_UP: ::c_int = 0x0000000001; // Address is up @@ -1137,9 +1482,6 @@ pub const NCCS: usize = 19; pub const LOG_CRON: ::c_int = 15 << 3; -pub const SYS_epoll_create: ::c_long = 213; -pub const SYS_epoll_create1: ::c_long = 291; - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __pthread_mutex_flag1: 0, __pthread_mutex_flag2: 0, @@ -1195,8 +1537,80 @@ pub const PORT_SOURCE_FILE: ::c_int = 7; pub const PORT_SOURCE_POSTWAIT: ::c_int = 8; pub const PORT_SOURCE_SIGNAL: ::c_int = 9; -pub const TIOCGWINSZ: ::c_int = 0x5468; -pub const TIOCSWINSZ: ::c_int = 0x5467; +const _TIOC: ::c_int = ('T' as i32) << 8; +const tIOC: ::c_int = ('t' as i32) << 8; +pub const TCGETA: ::c_int = (_TIOC|1); +pub const TCSETA: ::c_int = (_TIOC|2); +pub const TCSETAW: ::c_int = (_TIOC|3); +pub const TCSETAF: ::c_int = (_TIOC|4); +pub const TCSBRK: ::c_int = (_TIOC|5); +pub const TCXONC: ::c_int = (_TIOC|6); +pub const TCFLSH: ::c_int = (_TIOC|7); +pub const TCDSET: ::c_int = (_TIOC|32); +pub const TCGETS: ::c_int = (_TIOC|13); +pub const TCSETS: ::c_int = (_TIOC|14); +pub const TCSANOW: ::c_int = (_TIOC|14); +pub const TCSETSW: ::c_int = (_TIOC|15); +pub const TCSADRAIN: ::c_int = (_TIOC|15); +pub const TCSETSF: ::c_int = (_TIOC|16); +pub const TCSAFLUSH: ::c_int = (_TIOC|16); +pub const TCIFLUSH: ::c_int = 0; +pub const TCOFLUSH: ::c_int = 1; +pub const TCIOFLUSH: ::c_int = 2; +pub const TCOOFF: ::c_int = 0; +pub const TCOON: ::c_int = 1; +pub const TCIOFF: ::c_int = 2; +pub const TCION: ::c_int = 3; +pub const TIOC: ::c_int = _TIOC; +pub const TIOCKBON: ::c_int = (_TIOC|8); +pub const TIOCKBOF: ::c_int = (_TIOC|9); +pub const TIOCGWINSZ: ::c_int = (_TIOC|104); +pub const TIOCSWINSZ: ::c_int = (_TIOC|103); +pub const TIOCGSOFTCAR: ::c_int = (_TIOC|105); +pub const TIOCSSOFTCAR: ::c_int = (_TIOC|106); +pub const TIOCSETLD: ::c_int = (_TIOC|123); +pub const TIOCGETLD: ::c_int = (_TIOC|124); +pub const TIOCGPPS: ::c_int = (_TIOC|125); +pub const TIOCSPPS: ::c_int = (_TIOC|126); +pub const TIOCGPPSEV: ::c_int = (_TIOC|127); +pub const TIOCGETD: ::c_int = (tIOC|0); +pub const TIOCSETD: ::c_int = (tIOC|1); +pub const TIOCHPCL: ::c_int = (tIOC|2); +pub const TIOCGETP: ::c_int = (tIOC|8); +pub const TIOCSETP: ::c_int = (tIOC|9); +pub const TIOCSETN: ::c_int = (tIOC|10); +pub const TIOCEXCL: ::c_int = (tIOC|13); +pub const TIOCNXCL: ::c_int = (tIOC|14); +pub const TIOCFLUSH: ::c_int = (tIOC|16); +pub const TIOCSETC: ::c_int = (tIOC|17); +pub const TIOCGETC: ::c_int = (tIOC|18); +pub const TIOCLBIS: ::c_int = (tIOC|127); +pub const TIOCLBIC: ::c_int = (tIOC|126); +pub const TIOCLSET: ::c_int = (tIOC|125); +pub const TIOCLGET: ::c_int = (tIOC|124); +pub const TIOCSBRK: ::c_int = (tIOC|123); +pub const TIOCCBRK: ::c_int = (tIOC|122); +pub const TIOCSDTR: ::c_int = (tIOC|121); +pub const TIOCCDTR: ::c_int = (tIOC|120); +pub const TIOCSLTC: ::c_int = (tIOC|117); +pub const TIOCGLTC: ::c_int = (tIOC|116); +pub const TIOCOUTQ: ::c_int = (tIOC|115); +pub const TIOCNOTTY: ::c_int = (tIOC|113); +pub const TIOCSCTTY: ::c_int = (tIOC|132); +pub const TIOCSTOP: ::c_int = (tIOC|111); +pub const TIOCSTART: ::c_int = (tIOC|110); +pub const TIOCSILOOP: ::c_int = (tIOC|109); +pub const TIOCCILOOP: ::c_int = (tIOC|108); +pub const TIOCGPGRP: ::c_int = (tIOC|20); +pub const TIOCSPGRP: ::c_int = (tIOC|21); +pub const TIOCGSID: ::c_int = (tIOC|22); +pub const TIOCSTI: ::c_int = (tIOC|23); +pub const TIOCMSET: ::c_int = (tIOC|26); +pub const TIOCMBIS: ::c_int = (tIOC|27); +pub const TIOCMBIC: ::c_int = (tIOC|28); +pub const TIOCMGET: ::c_int = (tIOC|29); +pub const TIOCREMOTE: ::c_int = (tIOC|30); +pub const TIOCSIGNAL: ::c_int = (tIOC|31); pub const EPOLLIN: ::c_int = 0x1; pub const EPOLLPRI: ::c_int = 0x2; @@ -1217,22 +1631,116 @@ pub const EPOLL_CTL_ADD: ::c_int = 1; pub const EPOLL_CTL_MOD: ::c_int = 3; pub const EPOLL_CTL_DEL: ::c_int = 2; +/* termios */ +pub const B0: speed_t = 0; +pub const B50: speed_t = 1; +pub const B75: speed_t = 2; +pub const B110: speed_t = 3; +pub const B134: speed_t = 4; +pub const B150: speed_t = 5; +pub const B200: speed_t = 6; +pub const B300: speed_t = 7; +pub const B600: speed_t = 8; +pub const B1200: speed_t = 9; +pub const B1800: speed_t = 10; +pub const B2400: speed_t = 11; +pub const B4800: speed_t = 12; +pub const B9600: speed_t = 13; +pub const B19200: speed_t = 14; +pub const B38400: speed_t = 15; +pub const B57600: speed_t = 16; +pub const B76800: speed_t = 17; +pub const B115200: speed_t = 18; +pub const B153600: speed_t = 19; +pub const B230400: speed_t = 20; +pub const B307200: speed_t = 21; +pub const B460800: speed_t = 22; +pub const B921600: speed_t = 23; +pub const CSTART: ::tcflag_t = 021; +pub const CSTOP: ::tcflag_t = 023; +pub const CSWTCH: ::tcflag_t = 032; +pub const CSIZE: ::tcflag_t = 0o000060; +pub const CS5: ::tcflag_t = 0; +pub const CS6: ::tcflag_t = 0o000020; +pub const CS7: ::tcflag_t = 0o000040; +pub const CS8: ::tcflag_t = 0o000060; +pub const CSTOPB: ::tcflag_t = 0o000100; +pub const ECHO: ::tcflag_t = 0o000010; +pub const ECHOE: ::tcflag_t = 0o000020; +pub const ECHOK: ::tcflag_t = 0o000040; +pub const ECHONL: ::tcflag_t = 0o000100; +pub const ECHOCTL: ::tcflag_t = 0o001000; +pub const ECHOPRT: ::tcflag_t = 0o002000; +pub const ECHOKE: ::tcflag_t = 0o004000; +pub const EXTPROC: ::tcflag_t = 0o200000; +pub const IGNBRK: ::tcflag_t = 0o000001; +pub const BRKINT: ::tcflag_t = 0o000002; +pub const IGNPAR: ::tcflag_t = 0o000004; +pub const PARMRK: ::tcflag_t = 0o000010; +pub const INPCK: ::tcflag_t = 0o000020; +pub const ISTRIP: ::tcflag_t = 0o000040; +pub const INLCR: ::tcflag_t = 0o000100; +pub const IGNCR: ::tcflag_t = 0o000200; +pub const ICRNL: ::tcflag_t = 0o000400; +pub const IXON: ::tcflag_t = 0o002000; +pub const IXOFF: ::tcflag_t = 0o010000; +pub const IXANY: ::tcflag_t = 0o004000; +pub const IMAXBEL: ::tcflag_t = 0o020000; +pub const OPOST: ::tcflag_t = 0o000001; +pub const ONLCR: ::tcflag_t = 0o000004; +pub const OCRNL: ::tcflag_t = 0o000010; +pub const ONOCR: ::tcflag_t = 0o000020; +pub const ONLRET: ::tcflag_t = 0o000040; +pub const CREAD: ::tcflag_t = 0o000200; +pub const PARENB: ::tcflag_t = 0o000400; +pub const PARODD: ::tcflag_t = 0o001000; +pub const HUPCL: ::tcflag_t = 0o002000; +pub const CLOCAL: ::tcflag_t = 0o004000; +pub const CRTSCTS: ::tcflag_t = 0o20000000000; +pub const ISIG: ::tcflag_t = 0o000001; +pub const ICANON: ::tcflag_t = 0o000002; +pub const IEXTEN: ::tcflag_t = 0o100000; +pub const TOSTOP: ::tcflag_t = 0o000400; +pub const FLUSHO: ::tcflag_t = 0o020000; +pub const PENDIN: ::tcflag_t = 0o040000; +pub const NOFLSH: ::tcflag_t = 0o000200; +pub const VINTR: usize = 0; +pub const VQUIT: usize = 1; +pub const VERASE: usize = 2; +pub const VKILL: usize = 3; +pub const VEOF: usize = 4; +pub const VEOL: usize = 5; +pub const VEOL2: usize = 6; +pub const VMIN: usize = 4; +pub const VTIME: usize = 5; +pub const VSWTCH: usize = 7; +pub const VSTART: usize = 8; +pub const VSTOP: usize = 9; +pub const VSUSP: usize = 10; +pub const VDSUSP: usize = 11; +pub const VREPRINT: usize = 12; +pub const VDISCARD: usize = 13; +pub const VWERASE: usize = 14; +pub const VLNEXT: usize = 15; +pub const VSTATUS: usize = 16; +pub const VERASE2: usize = 17; + f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); return } pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 } pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; (*set).fds_bits[fd / bits] |= 1 << (fd % bits); return @@ -1255,11 +1763,39 @@ f! { pub fn WTERMSIG(status: ::c_int) -> ::c_int { status & 0x7F } + + pub fn WIFCONTINUED(status: ::c_int) -> bool { + (status & 0xffff) == 0xffff + } + + pub fn WSTOPSIG(status: ::c_int) -> ::c_int { + (status & 0xff00) >> 8 + } + + pub fn WIFSIGNALED(status: ::c_int) -> bool { + ((status & 0xff) > 0) && (status & 0xff00 == 0) + } + + pub fn WIFSTOPPED(status: ::c_int) -> bool { + ((status & 0xff) == 0x7f) && ((status & 0xff00) != 0) + } + + pub fn WCOREDUMP(status: ::c_int) -> bool { + (status & 0x80) != 0 + } } extern { + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; + pub fn abs(i: ::c_int) -> ::c_int; + pub fn acct(filename: *const ::c_char) -> ::c_int; pub fn atof(s: *const ::c_char) -> ::c_double; + pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; pub fn labs(i: ::c_long) -> ::c_long; pub fn rand() -> ::c_int; pub fn srand(seed: ::c_uint); @@ -1270,6 +1806,7 @@ extern { pub fn stack_getbounds(sp: *mut ::stack_t) -> ::c_int; pub fn mincore(addr: *const ::c_void, len: ::size_t, vec: *mut c_char) -> ::c_int; + pub fn initgroups(name: *const ::c_char, basegid: ::gid_t) -> ::c_int; pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int; pub fn ioctl(fildes: ::c_int, request: ::c_int, ...) -> ::c_int; @@ -1311,7 +1848,7 @@ extern { mode: ::mode_t, dev: dev_t) -> ::c_int; pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, mode: ::mode_t) -> ::c_int; - pub fn sethostname(name: *mut ::c_char, len: ::c_int) -> ::c_int; + pub fn sethostname(name: *const ::c_char, len: ::c_int) -> ::c_int; pub fn if_nameindex() -> *mut if_nameindex; pub fn if_freenameindex(ptr: *mut if_nameindex); pub fn pthread_create(native: *mut ::pthread_t, @@ -1333,15 +1870,17 @@ extern { pub fn glob(pattern: *const ::c_char, flags: ::c_int, - errfunc: Option<extern fn(epath: *const ::c_char, + errfunc: ::Option<extern fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, pglob: *mut ::glob_t) -> ::c_int; pub fn globfree(pglob: *mut ::glob_t); pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) - -> ::c_int; + -> ::c_int; + pub fn shm_open(name: *const ::c_char, oflag: ::c_int, mode: ::mode_t) + -> ::c_int; pub fn shm_unlink(name: *const ::c_char) -> ::c_int; pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); @@ -1364,6 +1903,7 @@ extern { times: *const ::timespec, flag: ::c_int) -> ::c_int; pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; + #[cfg_attr(target_os = "illumos", link_name = "__xnet_bind")] pub fn bind(socket: ::c_int, address: *const ::sockaddr, address_len: ::socklen_t) -> ::c_int; @@ -1374,9 +1914,11 @@ extern { iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; + #[cfg_attr(target_os = "illumos", link_name = "__xnet_sendmsg")] pub fn sendmsg(fd: ::c_int, msg: *const ::msghdr, flags: ::c_int) -> ::ssize_t; + #[cfg_attr(target_os = "illumos", link_name = "__xnet_recvmsg")] pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t; @@ -1393,8 +1935,9 @@ extern { pub fn fexecve(fd: ::c_int, argv: *const *const ::c_char, envp: *const *const ::c_char) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r(uid: ::uid_t, + #[cfg_attr(any(target_os = "solaris", target_os = "illumos"), + link_name = "__posix_getgrgid_r")] + pub fn getgrgid_r(gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, @@ -1404,11 +1947,16 @@ extern { pub fn sem_close(sem: *mut sem_t) -> ::c_int; pub fn getdtablesize() -> ::c_int; + // The epoll functions are actually only present on illumos. However, + // there are things using epoll on illumos (built using the + // x86_64-sun-solaris target) which would break until the illumos target is + // present in rustc. pub fn epoll_pwait(epfd: ::c_int, events: *mut ::epoll_event, maxevents: ::c_int, timeout: ::c_int, sigmask: *const ::sigset_t) -> ::c_int; + pub fn epoll_create(size: ::c_int) -> ::c_int; pub fn epoll_create1(flags: ::c_int) -> ::c_int; pub fn epoll_wait(epfd: ::c_int, @@ -1420,7 +1968,8 @@ extern { fd: ::c_int, event: *mut ::epoll_event) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")] + #[cfg_attr(any(target_os = "solaris", target_os = "illumos"), + link_name = "__posix_getgrnam_r")] pub fn getgrnam_r(name: *const ::c_char, grp: *mut ::group, buf: *mut ::c_char, @@ -1433,38 +1982,50 @@ extern { pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; pub fn sem_unlink(name: *const ::c_char) -> ::c_int; pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")] + #[cfg_attr(any(target_os = "solaris", target_os = "illumos"), + link_name = "__posix_getpwnam_r")] pub fn getpwnam_r(name: *const ::c_char, pwd: *mut passwd, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut passwd) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")] + #[cfg_attr(any(target_os = "solaris", target_os = "illumos"), + link_name = "__posix_getpwuid_r")] pub fn getpwuid_r(uid: ::uid_t, pwd: *mut passwd, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut passwd) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwent_r")] + #[cfg_attr(any(target_os = "solaris", target_os = "illumos"), + link_name = "__posix_getpwent_r")] pub fn getpwent_r(pwd: *mut passwd, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut passwd) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrent_r")] + #[cfg_attr(any(target_os = "solaris", target_os = "illumos"), + link_name = "__posix_getgrent_r")] pub fn getgrent_r(grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut ::group) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] + #[cfg_attr(any(target_os = "solaris", target_os = "illumos"), + link_name = "__posix_sigwait")] pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork(prepare: Option<unsafe extern fn()>, - parent: Option<unsafe extern fn()>, - child: Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; pub fn getgrgid(gid: ::gid_t) -> *mut ::group; + pub fn setgrent(); + pub fn endgrent(); + pub fn getgrent() -> *mut ::group; pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int; pub fn uname(buf: *mut ::utsname) -> ::c_int; + pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int; } + +mod compat; +pub use self::compat::*; diff --git a/libc/src/unix/uclibc/align.rs b/libc/src/unix/uclibc/align.rs new file mode 100644 index 0000000..3307c9d --- /dev/null +++ b/libc/src/unix/uclibc/align.rs @@ -0,0 +1,66 @@ +macro_rules! expand_align { + () => { + s! { + #[cfg_attr(any(target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64"), + repr(align(4)))] + #[cfg_attr(not(any(target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64")), + repr(align(8)))] + pub struct pthread_mutexattr_t { + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + #[repr(align(4))] + pub struct pthread_condattr_t { + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + + s_no_extra_traits! { + #[repr(align(8))] + #[allow(missing_debug_implementations)] + pub struct pthread_cond_t { + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))), + repr(align(8)))] + #[allow(missing_debug_implementations)] + pub struct pthread_mutex_t { + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))), + repr(align(8)))] + #[allow(missing_debug_implementations)] + pub struct pthread_rwlock_t { + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + } + } +} diff --git a/libc/src/unix/uclibc/arm/align.rs b/libc/src/unix/uclibc/arm/align.rs new file mode 100644 index 0000000..4a0e074 --- /dev/null +++ b/libc/src/unix/uclibc/arm/align.rs @@ -0,0 +1,13 @@ +s! { + // FIXME this is actually a union + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct sem_t { + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + } +} diff --git a/libc/src/unix/uclibc/arm/mod.rs b/libc/src/unix/uclibc/arm/mod.rs new file mode 100644 index 0000000..b250fb5 --- /dev/null +++ b/libc/src/unix/uclibc/arm/mod.rs @@ -0,0 +1,687 @@ +pub type c_char = u8; +pub type wchar_t = ::c_uint; +pub type c_long = i32; +pub type c_ulong = u32; +pub type time_t = ::c_long; + +pub type clock_t = ::c_long; +pub type fsblkcnt_t = ::c_ulong; +pub type fsfilcnt_t = ::c_ulong; +pub type ino_t = ::c_ulong; +pub type off_t = ::c_long; +pub type pthread_t = ::c_ulong; +pub type rlim_t = ::c_ulong; +pub type suseconds_t = ::c_long; + +pub type nlink_t = ::c_uint; +pub type blksize_t = ::c_long; +pub type blkcnt_t = ::c_long; + +s! { + pub struct cmsghdr { + pub cmsg_len: ::size_t, + pub cmsg_level: ::c_int, + pub cmsg_type: ::c_int, + } + + pub struct msghdr { + pub msg_name: *mut ::c_void, + pub msg_namelen: ::socklen_t, + pub msg_iov: *mut ::iovec, + pub msg_iovlen: ::c_int, + pub msg_control: *mut ::c_void, + pub msg_controllen: ::socklen_t, + pub msg_flags: ::c_int, + } + + pub struct pthread_attr_t { + __size: [::c_long; 9], + } + + pub struct stat { + pub st_dev: ::c_ulonglong, + pub __pad1: ::c_ushort, + pub st_ino: ::ino_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::c_ulonglong, + pub __pad2: ::c_ushort, + pub st_size: ::off_t, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt_t, + pub st_atim: ::timespec, + pub st_mtim: ::timespec, + pub st_ctim: ::timespec, + pub __unused4: ::c_ulong, + pub __unused5: ::c_ulong, + } + + pub struct stat64 + { + pub st_dev: ::c_ulonglong, + pub __pad1: ::c_uint, + pub __st_ino: ::ino_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::c_ulonglong, + pub __pad2: ::c_uint, + pub st_size: ::off64_t, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt64_t, + pub st_atim: ::timespec, + pub st_mtim: ::timespec, + pub st_ctim: ::timespec, + pub st_ino: ::ino64_t, + } + + pub struct flock { + pub l_type: ::c_short, + pub l_whence: ::c_short, + pub l_start: ::off_t, + pub l_len: ::off_t, + pub l_pid: ::pid_t, + } + + pub struct statfs { + pub f_type: ::c_int, + pub f_bsize: ::c_int, + pub f_blocks: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_bavail: ::fsblkcnt_t, + pub f_files: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + + pub f_fsid: ::fsid_t, + pub f_namelen: ::c_int, + pub f_frsize: ::c_int, + pub f_spare: [::c_int; 5], + } + + pub struct sigset_t { + __val: [::c_ulong; 2], + } + + pub struct sigaction { + pub sa_sigaction: ::sighandler_t, + // uClibc defines sa_flags as `unsigned long int`, + // but nix crate expects `int` + pub sa_flags: ::c_int, + pub sa_restorer: *mut ::c_void, + pub sa_mask: sigset_t, + } + + pub struct termios { + pub c_iflag: ::tcflag_t, + pub c_oflag: ::tcflag_t, + pub c_cflag: ::tcflag_t, + pub c_lflag: ::tcflag_t, + pub c_line: ::cc_t, + pub c_cc: [::cc_t; ::NCCS], + pub c_ispeed: ::speed_t, + pub c_ospeed: ::speed_t, + } + + pub struct siginfo_t { + pub si_signo: ::c_int, + pub si_errno: ::c_int, + pub si_code: ::c_int, + pub _pad: [::c_int; 29], + } + + pub struct stack_t { + pub ss_sp: *mut ::c_void, + ss_flags: ::c_int, + ss_size: ::size_t, + } + + pub struct ipc_perm { + pub __key: ::key_t, + pub uid: ::uid_t, + pub gid: ::gid_t, + pub cuid: ::uid_t, + pub cgid: ::gid_t, + pub mode: ::c_ushort, + pub __pad1: ::c_ushort, + pub __seq: ::c_ushort, + pub __pad2: ::c_ushort, + pub __unused1: ::c_ulong, + pub __unused2: ::c_ulong, + } + + pub struct msqid_ds { + pub msg_perm: ::ipc_perm, + pub msg_stime: ::time_t, + pub __unused1: ::c_ulong, + pub msg_rtime: ::time_t, + pub __unused2: ::c_ulong, + pub msg_ctime: ::time_t, + pub __unused3: ::c_ulong, + pub __msg_cbytes: ::c_ulong, + pub msg_qnum: ::msgqnum_t, + pub msg_qbytes: ::msglen_t, + pub msg_lspid: ::pid_t, + pub msg_lrpid: ::pid_t, + pub __unused4: ::c_ulong, + pub __unused5: ::c_ulong, + } + + pub struct shmid_ds { + pub shm_perm: ::ipc_perm, + pub shm_segsz: ::size_t, + pub shm_atime: ::time_t, + pub __unused1: ::c_ulong, + pub shm_dtime: ::time_t, + pub __unused2: ::c_ulong, + pub shm_ctime: ::time_t, + pub __unused3: ::c_ulong, + pub shm_cpid: ::pid_t, + pub shm_lpid: ::pid_t, + pub shm_nattch: ::shmatt_t, + pub __unused4: ::c_ulong, + pub __unused5: ::c_ulong, + } + + pub struct ucred { + pub pid: ::pid_t, + pub uid: ::uid_t, + pub gid: ::gid_t, + } + +} + +pub const O_CLOEXEC: ::c_int = 0o2000000; +pub const RLIM_INFINITY: rlim_t = !0; +pub const __SIZEOF_PTHREAD_ATTR_T: usize = 36; +pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24; +pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; +pub const __SIZEOF_PTHREAD_COND_COMPAT_T: usize = 12; +pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; +pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; +pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; +pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20; +pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4; +pub const NCCS: usize = 32; + +// I wasn't able to find those constants +// in uclibc build environment for armv7 +pub const AIO_ALLDONE: ::c_int = 2; // from linux/mod.rs +pub const AIO_CANCELED: ::c_int = 0; // from linux/mod.rs +pub const AIO_NOTCANCELED: ::c_int = 1; // from linux/mod.rs +pub const CLONE_NEWCGROUP: ::c_int = 0x02000000; // from linux/mod.rs +pub const EPOLLEXCLUSIVE: ::c_int = 0x10000000; // from linux/mod.rs +pub const EPOLLWAKEUP: ::c_int = 0x20000000; // from linux/other/mod.rs +pub const EXTPROC: ::tcflag_t = 0o200000; // from asm-generic/termbits.h +pub const F_GETPIPE_SZ: ::c_int = 1032; // from notbsd/mod.rs +pub const F_SETPIPE_SZ: ::c_int = 1031; // from notbsd/mod.rs +pub const LIO_NOP: ::c_int = 2; // from linux/mod.rs +pub const LIO_NOWAIT: ::c_int = 1; // from linux/mod.rs +pub const LIO_READ: ::c_int = 0; // from linux/mod.rs +pub const LIO_WAIT: ::c_int = 0; // from linux/mod.rs +pub const LIO_WRITE: ::c_int = 1; // from linux/mod.rs +pub const MAP_HUGETLB: ::c_int = 0x040000; // from linux/other/mod.rs +pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; +pub const RB_KEXEC: ::c_int = 0x45584543u32 as i32; // from linux/mod.rs +pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2u32 as i32; // from linux/mod.rs +pub const SO_BUSY_POLL: ::c_int = 46; // from src/unix/notbsd/mod.rs +pub const SO_PEEK_OFF: ::c_int = 42; // from src/unix/notbsd/mod.rs +pub const SO_REUSEPORT: ::c_int = 15; // from src/unix/notbsd/mod.rs +pub const SOL_NETLINK: ::c_int = 270; // from src/unix/notbsd/mod.rs +pub const _POSIX_VDISABLE: ::cc_t = 0; // from linux/mod.rs +pub const AT_EMPTY_PATH: ::c_int = 0x1000; // from notbsd/mod.rs + +// autogenerated constants with hand tuned types +pub const AT_NO_AUTOMOUNT: ::c_int = 0x800; +pub const B0: ::speed_t = 0; +pub const B1000000: ::speed_t = 0x1008; +pub const B110: ::speed_t = 0x3; +pub const B115200: ::speed_t = 0x1002; +pub const B1152000: ::speed_t = 0x1009; +pub const B1200: ::speed_t = 0x9; +pub const B134: ::speed_t = 0x4; +pub const B150: ::speed_t = 0x5; +pub const B1500000: ::speed_t = 0x100a; +pub const B1800: ::speed_t = 0xa; +pub const B19200: ::speed_t = 0xe; +pub const B200: ::speed_t = 0x6; +pub const B2000000: ::speed_t = 0x100b; +pub const B230400: ::speed_t = 0x1003; +pub const B2400: ::speed_t = 0xb; +pub const B2500000: ::speed_t = 0x100c; +pub const B300: ::speed_t = 0x7; +pub const B3000000: ::speed_t = 0x100d; +pub const B3500000: ::speed_t = 0x100e; +pub const B38400: ::speed_t = 0xf; +pub const B4000000: ::speed_t = 0x100f; +pub const B460800: ::speed_t = 0x1004; +pub const B4800: ::speed_t = 0xc; +pub const B50: ::speed_t = 0x1; +pub const B500000: ::speed_t = 0x1005; +pub const B57600: ::speed_t = 0x1001; +pub const B576000: ::speed_t = 0x1006; +pub const B600: ::speed_t = 0x8; +pub const B75: ::speed_t = 0x2; +pub const B921600: ::speed_t = 0x1007; +pub const B9600: ::speed_t = 0xd; +pub const BS1: ::c_int = 0x2000; +pub const BSDLY: ::c_int = 0x2000; +pub const CBAUD: ::tcflag_t = 0x100f; +pub const CBAUDEX: ::tcflag_t = 0x1000; +pub const CIBAUD: ::tcflag_t = 0x100f0000; +pub const CLOCAL: ::tcflag_t = 0x800; +pub const CMSPAR: ::tcflag_t = 0x40000000; +pub const CPU_SETSIZE: ::c_int = 0x400; +pub const CR1: ::c_int = 0x200; +pub const CR2: ::c_int = 0x400; +pub const CR3: ::c_int = 0x600; +pub const CRDLY: ::c_int = 0x600; +pub const CREAD: ::tcflag_t = 0x80; +pub const CS6: ::tcflag_t = 0x10; +pub const CS7: ::tcflag_t = 0x20; +pub const CS8: ::tcflag_t = 0x30; +pub const CSIZE: ::tcflag_t = 0x30; +pub const CSTOPB: ::tcflag_t = 0x40; +pub const EADDRINUSE: ::c_int = 0x62; +pub const EADDRNOTAVAIL: ::c_int = 0x63; +pub const EADV: ::c_int = 0x44; +pub const EAFNOSUPPORT: ::c_int = 0x61; +pub const EALREADY: ::c_int = 0x72; +pub const EBADE: ::c_int = 0x34; +pub const EBADFD: ::c_int = 0x4d; +pub const EBADMSG: ::c_int = 0x4a; +pub const EBADR: ::c_int = 0x35; +pub const EBADRQC: ::c_int = 0x38; +pub const EBADSLT: ::c_int = 0x39; +pub const EBFONT: ::c_int = 0x3b; +pub const ECANCELED: ::c_int = 0x7d; +pub const ECHOCTL: ::tcflag_t = 0x200; +pub const ECHOE: ::tcflag_t = 0x10; +pub const ECHOK: ::tcflag_t = 0x20; +pub const ECHOKE: ::tcflag_t = 0x800; +pub const ECHONL: ::tcflag_t = 0x40; +pub const ECHOPRT: ::tcflag_t = 0x400; +pub const ECHRNG: ::c_int = 0x2c; +pub const ECOMM: ::c_int = 0x46; +pub const ECONNABORTED: ::c_int = 0x67; +pub const ECONNREFUSED: ::c_int = 0x6f; +pub const ECONNRESET: ::c_int = 0x68; +pub const EDEADLK: ::c_int = 0x23; +pub const EDESTADDRREQ: ::c_int = 0x59; +pub const EDOTDOT: ::c_int = 0x49; +pub const EDQUOT: ::c_int = 0x7a; +pub const EFD_CLOEXEC: ::c_int = 0x80000; +pub const EFD_NONBLOCK: ::c_int = 0x800; +pub const EHOSTDOWN: ::c_int = 0x70; +pub const EHOSTUNREACH: ::c_int = 0x71; +pub const EHWPOISON: ::c_int = 0x85; +pub const EIDRM: ::c_int = 0x2b; +pub const EILSEQ: ::c_int = 0x54; +pub const EINPROGRESS: ::c_int = 0x73; +pub const EISCONN: ::c_int = 0x6a; +pub const EISNAM: ::c_int = 0x78; +pub const EKEYEXPIRED: ::c_int = 0x7f; +pub const EKEYREJECTED: ::c_int = 0x81; +pub const EKEYREVOKED: ::c_int = 0x80; +pub const EL2HLT: ::c_int = 0x33; +pub const EL2NSYNC: ::c_int = 0x2d; +pub const EL3HLT: ::c_int = 0x2e; +pub const EL3RST: ::c_int = 0x2f; +pub const ELIBACC: ::c_int = 0x4f; +pub const ELIBBAD: ::c_int = 0x50; +pub const ELIBEXEC: ::c_int = 0x53; +pub const ELIBMAX: ::c_int = 0x52; +pub const ELIBSCN: ::c_int = 0x51; +pub const ELNRNG: ::c_int = 0x30; +pub const ELOOP: ::c_int = 0x28; +pub const EMEDIUMTYPE: ::c_int = 0x7c; +pub const EMSGSIZE: ::c_int = 0x5a; +pub const EMULTIHOP: ::c_int = 0x48; +pub const ENAMETOOLONG: ::c_int = 0x24; +pub const ENAVAIL: ::c_int = 0x77; +pub const ENETDOWN: ::c_int = 0x64; +pub const ENETRESET: ::c_int = 0x66; +pub const ENETUNREACH: ::c_int = 0x65; +pub const ENOANO: ::c_int = 0x37; +pub const ENOBUFS: ::c_int = 0x69; +pub const ENOCSI: ::c_int = 0x32; +pub const ENODATA: ::c_int = 0x3d; +pub const ENOKEY: ::c_int = 0x7e; +pub const ENOLCK: ::c_int = 0x25; +pub const ENOLINK: ::c_int = 0x43; +pub const ENOMEDIUM: ::c_int = 0x7b; +pub const ENOMSG: ::c_int = 0x2a; +pub const ENONET: ::c_int = 0x40; +pub const ENOPKG: ::c_int = 0x41; +pub const ENOPROTOOPT: ::c_int = 0x5c; +pub const ENOSR: ::c_int = 0x3f; +pub const ENOSTR: ::c_int = 0x3c; +pub const ENOSYS: ::c_int = 0x26; +pub const ENOTCONN: ::c_int = 0x6b; +pub const ENOTEMPTY: ::c_int = 0x27; +pub const ENOTNAM: ::c_int = 0x76; +pub const ENOTRECOVERABLE: ::c_int = 0x83; +pub const ENOTSOCK: ::c_int = 0x58; +pub const ENOTUNIQ: ::c_int = 0x4c; +pub const EOPNOTSUPP: ::c_int = 0x5f; +pub const EOVERFLOW: ::c_int = 0x4b; +pub const EOWNERDEAD: ::c_int = 0x82; +pub const EPFNOSUPPORT: ::c_int = 0x60; +pub const EPOLL_CLOEXEC: ::c_int = 0x80000; +pub const EPROTO: ::c_int = 0x47; +pub const EPROTONOSUPPORT: ::c_int = 0x5d; +pub const EPROTOTYPE: ::c_int = 0x5b; +pub const EREMCHG: ::c_int = 0x4e; +pub const EREMOTE: ::c_int = 0x42; +pub const EREMOTEIO: ::c_int = 0x79; +pub const ERESTART: ::c_int = 0x55; +pub const ERFKILL: ::c_int = 0x84; +pub const ESHUTDOWN: ::c_int = 0x6c; +pub const ESOCKTNOSUPPORT: ::c_int = 0x5e; +pub const ESRMNT: ::c_int = 0x45; +pub const ESTALE: ::c_int = 0x74; +pub const ESTRPIPE: ::c_int = 0x56; +pub const ETIME: ::c_int = 0x3e; +pub const ETIMEDOUT: ::c_int = 0x6e; +pub const ETOOMANYREFS: ::c_int = 0x6d; +pub const EUCLEAN: ::c_int = 0x75; +pub const EUNATCH: ::c_int = 0x31; +pub const EUSERS: ::c_int = 0x57; +pub const EXFULL: ::c_int = 0x36; +pub const FF1: ::c_int = 0x8000; +pub const FFDLY: ::c_int = 0x8000; +pub const FIONBIO: ::c_ulong = 0x5421; +pub const FIOCLEX: ::c_ulong = 0x5451; +pub const FLUSHO: ::tcflag_t = 0x1000; +pub const F_GETLK: ::c_int = 0x5; +pub const F_SETLK: ::c_int = 0x6; +pub const F_SETLKW: ::c_int = 0x7; +pub const HUPCL: ::tcflag_t = 0x400; +pub const ICANON: ::tcflag_t = 0x2; +pub const IEXTEN: ::tcflag_t = 0x8000; +pub const IPV6_MULTICAST_HOPS: ::c_int = 0x12; +pub const IPV6_MULTICAST_IF: ::c_int = 0x11; +pub const IPV6_UNICAST_HOPS: ::c_int = 0x10; +pub const IP_MULTICAST_IF: ::c_int = 0x20; +pub const ISIG: ::tcflag_t = 0x1; +pub const IUTF8: ::tcflag_t = 0x4000; +pub const IXOFF: ::tcflag_t = 0x1000; +pub const IXON: ::tcflag_t = 0x400; +pub const MAP_ANON: ::c_int = 0x20; +pub const MAP_ANONYMOUS: ::c_int = 0x20; +pub const MAP_DENYWRITE: ::c_int = 0x800; +pub const MAP_EXECUTABLE: ::c_int = 0x1000; +pub const MAP_GROWSDOWN: ::c_int = 0x100; +pub const MAP_LOCKED: ::c_int = 0x2000; +pub const MAP_NONBLOCK: ::c_int = 0x10000; +pub const MAP_NORESERVE: ::c_int = 0x4000; +pub const MAP_POPULATE: ::c_int = 0x8000; +pub const MAP_STACK: ::c_int = 0x20000; +pub const MS_ACTIVE: u32 = 0x40000000; +pub const MS_DIRSYNC: u32 = 0x80; +pub const MS_I_VERSION: u32 = 0x800000; +pub const MS_KERNMOUNT: u32 = 0x400000; +pub const MS_MOVE: u32 = 0x2000; +pub const MS_POSIXACL: u32 = 0x10000; +pub const MS_PRIVATE: u32 = 0x40000; +pub const MS_REC: u32 = 0x4000; +pub const MS_RELATIME: u32 = 0x200000; +pub const MS_SHARED: u32 = 0x100000; +pub const MS_SILENT: u32 = 0x8000; +pub const MS_SLAVE: u32 = 0x80000; +pub const MS_STRICTATIME: u32 = 0x1000000; +pub const MS_UNBINDABLE: u32 = 0x20000; +pub const NLDLY: ::tcflag_t = 0x100; +pub const NOFLSH: ::tcflag_t = 0x80; +pub const OCRNL: ::c_int = 0x8; +pub const OFDEL: ::c_int = 0x80; +pub const OFILL: ::c_int = 0x40; +pub const OLCUC: ::tcflag_t = 0x2; +pub const ONLCR: ::tcflag_t = 0x4; +pub const ONLRET: ::tcflag_t = 0x20; +pub const ONOCR: ::tcflag_t = 0x10; +pub const O_ACCMODE: ::c_int = 0x3; +pub const O_APPEND: ::c_int = 0x400; +pub const O_CREAT: ::c_int = 0x40; +pub const O_DIRECT: ::c_int = 0x10000; +pub const O_DIRECTORY: ::c_int = 0x4000; +pub const O_DSYNC: ::c_int = 0x1000; +pub const O_EXCL: ::c_int = 0x80; +pub const O_NDELAY: ::c_int = 0x800; +pub const O_NOCTTY: ::c_int = 0x100; +pub const O_NOFOLLOW: ::c_int = 0x8000; +pub const O_NONBLOCK: ::c_int = 0x800; +pub const O_SYNC: ::c_int = 0o10000; +pub const O_TRUNC: ::c_int = 0x200; +pub const PARENB: ::tcflag_t = 0x100; +pub const PARODD: ::tcflag_t = 0x200; +pub const PENDIN: ::tcflag_t = 0x4000; +pub const POLLRDBAND: ::c_short = 0x80; +pub const POLLRDNORM: ::c_short = 0x40; +pub const POLLWRBAND: ::c_short = 0x200; +pub const POLLWRNORM: ::c_short = 0x100; +pub const QIF_ALL: ::uint32_t = 0x3f; +pub const QIF_BLIMITS: ::uint32_t = 0x1; +pub const QIF_BTIME: ::uint32_t = 0x10; +pub const QIF_ILIMITS: ::uint32_t = 0x4; +pub const QIF_INODES: ::uint32_t = 0x8; +pub const QIF_ITIME: ::uint32_t = 0x20; +pub const QIF_LIMITS: ::uint32_t = 0x5; +pub const QIF_SPACE: ::uint32_t = 0x2; +pub const QIF_TIMES: ::uint32_t = 0x30; +pub const QIF_USAGE: ::uint32_t = 0xa; +pub const SA_NOCLDSTOP: ::c_int = 0x1; +pub const SA_NOCLDWAIT: ::c_int = 0x2; +pub const SA_NODEFER: ::c_int = 0x40000000; +pub const SA_ONSTACK: ::c_int = 0x8000000; +pub const SA_RESETHAND: ::c_int = 0x80000000; +pub const SA_RESTART: ::c_int = 0x10000000; +pub const SA_SIGINFO: ::c_int = 0x4; +pub const SFD_CLOEXEC: ::c_int = 0x80000; +pub const SFD_NONBLOCK: ::c_int = 0x800; +pub const SIGBUS: ::c_int = 0x7; +pub const SIGCHLD: ::c_int = 0x11; +pub const SIGCONT: ::c_int = 0x12; +pub const SIGIO: ::c_int = 0x1d; +pub const SIGPROF: ::c_int = 0x1b; +pub const SIGPWR: ::c_int = 0x1e; +pub const SIGSTKFLT: ::c_int = 0x10; +pub const SIGSTOP: ::c_int = 0x13; +pub const SIGSYS: ::c_int = 0x1f; +pub const SIGTSTP: ::c_int = 0x14; +pub const SIGTTIN: ::c_int = 0x15; +pub const SIGTTOU: ::c_int = 0x16; +pub const SIGURG: ::c_int = 0x17; +pub const SIGUSR1: ::c_int = 0xa; +pub const SIGUSR2: ::c_int = 0xc; +pub const SIGVTALRM: ::c_int = 0x1a; +pub const SIGWINCH: ::c_int = 0x1c; +pub const SIGXCPU: ::c_int = 0x18; +pub const SIGXFSZ: ::c_int = 0x19; +pub const SIG_BLOCK: ::c_int = 0; +pub const SIG_SETMASK: ::c_int = 0x2; +pub const SIG_UNBLOCK: ::c_int = 0x1; +pub const SOCK_DGRAM: ::c_int = 0x2; +pub const SOCK_NONBLOCK: ::c_int = 0o0004000; +pub const SOCK_SEQPACKET: ::c_int = 0x5; +pub const SOCK_STREAM: ::c_int = 0x1; +pub const SOL_SOCKET: ::c_int = 0x1; +pub const SO_ACCEPTCONN: ::c_int = 0x1e; +pub const SO_BINDTODEVICE: ::c_int = 0x19; +pub const SO_BROADCAST: ::c_int = 0x6; +pub const SO_BSDCOMPAT: ::c_int = 0xe; +pub const SO_DOMAIN: ::c_int = 0x27; +pub const SO_DONTROUTE: ::c_int = 0x5; +pub const SO_ERROR: ::c_int = 0x4; +pub const SO_KEEPALIVE: ::c_int = 0x9; +pub const SO_LINGER: ::c_int = 0xd; +pub const SO_MARK: ::c_int = 0x24; +pub const SO_OOBINLINE: ::c_int = 0xa; +pub const SO_PASSCRED: ::c_int = 0x10; +pub const SO_PEERCRED: ::c_int = 0x11; +pub const SO_PRIORITY: ::c_int = 0xc; +pub const SO_PROTOCOL: ::c_int = 0x26; +pub const SO_RCVBUF: ::c_int = 0x8; +pub const SO_RCVLOWAT: ::c_int = 0x12; +pub const SO_RCVTIMEO: ::c_int = 0x14; +pub const SO_REUSEADDR: ::c_int = 0x2; +pub const SO_RXQ_OVFL: ::c_int = 0x28; +pub const SO_SNDBUF: ::c_int = 0x7; +pub const SO_SNDBUFFORCE: ::c_int = 0x20; +pub const SO_SNDLOWAT: ::c_int = 0x13; +pub const SO_SNDTIMEO: ::c_int = 0x15; +pub const SO_TIMESTAMP: ::c_int = 0x1d; +pub const SO_TYPE: ::c_int = 0x3; +pub const SYS_gettid: ::c_int = 0xe0; +pub const TAB1: ::c_int = 0x800; +pub const TAB2: ::c_int = 0x1000; +pub const TAB3: ::c_int = 0x1800; +pub const TABDLY: ::c_int = 0x1800; +pub const TCSADRAIN: ::c_int = 0x1; +pub const TCSAFLUSH: ::c_int = 0x2; +pub const TCSANOW: ::c_int = 0; +pub const TOSTOP: ::tcflag_t = 0x100; +pub const VDISCARD: usize = 0xd; +pub const VEOF: usize = 0x4; +pub const VEOL: usize = 0xb; +pub const VEOL2: usize = 0x10; +pub const VMIN: usize = 0x6; +pub const VREPRINT: usize = 0xc; +pub const VSTART: usize = 0x8; +pub const VSTOP: usize = 0x9; +pub const VSUSP: usize = 0xa; +pub const VSWTC: usize = 0x7; +pub const VT1: ::c_int = 0x4000; +pub const VTDLY: ::c_int = 0x4000; +pub const VTIME: usize = 0x5; +pub const VWERASE: usize = 0xe; +pub const XTABS: ::tcflag_t = 0x1800; +pub const _PC_2_SYMLINKS: ::c_int = 0x14; +pub const _PC_ALLOC_SIZE_MIN: ::c_int = 0x12; +pub const _PC_ASYNC_IO: ::c_int = 0xa; +pub const _PC_FILESIZEBITS: ::c_int = 0xd; +pub const _PC_PRIO_IO: ::c_int = 0xb; +pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 0xe; +pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 0xf; +pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 0x10; +pub const _PC_REC_XFER_ALIGN: ::c_int = 0x11; +pub const _PC_SYMLINK_MAX: ::c_int = 0x13; +pub const _PC_SYNC_IO: ::c_int = 0x9; +pub const _SC_2_PBS: ::c_int = 0xa8; +pub const _SC_2_PBS_ACCOUNTING: ::c_int = 0xa9; +pub const _SC_2_PBS_CHECKPOINT: ::c_int = 0xaf; +pub const _SC_2_PBS_LOCATE: ::c_int = 0xaa; +pub const _SC_2_PBS_MESSAGE: ::c_int = 0xab; +pub const _SC_2_PBS_TRACK: ::c_int = 0xac; +pub const _SC_ADVISORY_INFO: ::c_int = 0x84; +pub const _SC_BARRIERS: ::c_int = 0x85; +pub const _SC_CLOCK_SELECTION: ::c_int = 0x89; +pub const _SC_CPUTIME: ::c_int = 0x8a; +pub const _SC_IPV6: ::c_int = 0xeb; +pub const _SC_MONOTONIC_CLOCK: ::c_int = 0x95; +pub const _SC_RAW_SOCKETS: ::c_int = 0xec; +pub const _SC_READER_WRITER_LOCKS: ::c_int = 0x99; +pub const _SC_REGEXP: ::c_int = 0x9b; +pub const _SC_SHELL: ::c_int = 0x9d; +pub const _SC_SPAWN: ::c_int = 0x9f; +pub const _SC_SPIN_LOCKS: ::c_int = 0x9a; +pub const _SC_SPORADIC_SERVER: ::c_int = 0xa0; +pub const _SC_SS_REPL_MAX: ::c_int = 0xf1; +pub const _SC_SYMLOOP_MAX: ::c_int = 0xad; +pub const _SC_THREAD_CPUTIME: ::c_int = 0x8b; +pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 0x52; +pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 0xf7; +pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 0xf8; +pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 0xa1; +pub const _SC_TIMEOUTS: ::c_int = 0xa4; +pub const _SC_TRACE: ::c_int = 0xb5; +pub const _SC_TRACE_EVENT_FILTER: ::c_int = 0xb6; +pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 0xf2; +pub const _SC_TRACE_INHERIT: ::c_int = 0xb7; +pub const _SC_TRACE_LOG: ::c_int = 0xb8; +pub const _SC_TRACE_NAME_MAX: ::c_int = 0xf3; +pub const _SC_TRACE_SYS_MAX: ::c_int = 0xf4; +pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 0xf5; +pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 0xa5; +pub const _SC_V6_ILP32_OFF32: ::c_int = 0xb0; +pub const _SC_V6_ILP32_OFFBIG: ::c_int = 0xb1; +pub const _SC_V6_LP64_OFF64: ::c_int = 0xb2; +pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 0xb3; +pub const _SC_XOPEN_STREAMS: ::c_int = 0xf6; + +fn CMSG_ALIGN(len: usize) -> usize { + len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1) +} + +f! { + pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { + if (*mhdr).msg_controllen as usize >= ::mem::size_of::<cmsghdr>() { + (*mhdr).msg_control as *mut cmsghdr + } else { + 0 as *mut cmsghdr + } + } + + pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut ::c_uchar { + cmsg.offset(1) as *mut ::c_uchar + } + + pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + (CMSG_ALIGN(length as usize) + CMSG_ALIGN(::mem::size_of::<cmsghdr>())) + as ::c_uint + } + + pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { + CMSG_ALIGN(::mem::size_of::<cmsghdr>()) as ::c_uint + length + } + + pub fn CMSG_NXTHDR(mhdr: *const msghdr, + cmsg: *const cmsghdr) -> *mut cmsghdr { + if ((*cmsg).cmsg_len as usize) < ::mem::size_of::<cmsghdr>() { + return 0 as *mut cmsghdr; + }; + let next = (cmsg as usize + + CMSG_ALIGN((*cmsg).cmsg_len as usize)) + as *mut cmsghdr; + let max = (*mhdr).msg_control as usize + + (*mhdr).msg_controllen as usize; + if (next.offset(1)) as usize > max || + next as usize + CMSG_ALIGN((*next).cmsg_len as usize) > max + { + 0 as *mut cmsghdr + } else { + next as *mut cmsghdr + } + } + +} + +extern { + pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; + pub fn openpty(amaster: *mut ::c_int, + aslave: *mut ::c_int, + name: *mut ::c_char, + termp: *mut termios, + winp: *mut ::winsize) -> ::c_int; + pub fn setns(fd: ::c_int, nstype: ::c_int) -> ::c_int; + pub fn pwritev(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int, + offset: ::off_t) -> ::ssize_t; + pub fn preadv(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int, + offset: ::off_t) -> ::ssize_t; +} + +cfg_if! { + if #[cfg(libc_align)] { + mod align; + pub use self::align::*; + } else { + mod no_align; + pub use self::no_align::*; + } +} diff --git a/libc/src/unix/uclibc/arm/no_align.rs b/libc/src/unix/uclibc/arm/no_align.rs new file mode 100644 index 0000000..e32bf67 --- /dev/null +++ b/libc/src/unix/uclibc/arm/no_align.rs @@ -0,0 +1,10 @@ +s! { + // FIXME this is actually a union + pub struct sem_t { + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + __align: [::c_long; 0], + } +} diff --git a/libc/src/unix/uclibc/mips/mips32/align.rs b/libc/src/unix/uclibc/mips/mips32/align.rs new file mode 100644 index 0000000..4a0e074 --- /dev/null +++ b/libc/src/unix/uclibc/mips/mips32/align.rs @@ -0,0 +1,13 @@ +s! { + // FIXME this is actually a union + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct sem_t { + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + } +} diff --git a/libc/src/unix/uclibc/mips/mips32.rs b/libc/src/unix/uclibc/mips/mips32/mod.rs index dcbfcf8..410ab70 100644 --- a/libc/src/unix/uclibc/mips/mips32.rs +++ b/libc/src/unix/uclibc/mips/mips32/mod.rs @@ -220,20 +220,6 @@ s! { pub mem_unit: ::c_uint, pub _f: [::c_char; 8], } - - // FIXME this is actually a union - #[cfg_attr(all(feature = "align", target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", target_pointer_width = "64"), - repr(align(8)))] - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - #[cfg(not(feature = "align"))] - __align: [::c_long; 0], - } } pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; @@ -261,7 +247,6 @@ pub const SYS_mknod: ::c_long = 4000 + 14; pub const SYS_chmod: ::c_long = 4000 + 15; pub const SYS_lchown: ::c_long = 4000 + 16; pub const SYS_break: ::c_long = 4000 + 17; -pub const SYS_unused18: ::c_long = 4000 + 18; pub const SYS_lseek: ::c_long = 4000 + 19; pub const SYS_getpid: ::c_long = 4000 + 20; pub const SYS_mount: ::c_long = 4000 + 21; @@ -271,7 +256,6 @@ pub const SYS_getuid: ::c_long = 4000 + 24; pub const SYS_stime: ::c_long = 4000 + 25; pub const SYS_ptrace: ::c_long = 4000 + 26; pub const SYS_alarm: ::c_long = 4000 + 27; -pub const SYS_unused28: ::c_long = 4000 + 28; pub const SYS_pause: ::c_long = 4000 + 29; pub const SYS_utime: ::c_long = 4000 + 30; pub const SYS_stty: ::c_long = 4000 + 31; @@ -302,7 +286,6 @@ pub const SYS_fcntl: ::c_long = 4000 + 55; pub const SYS_mpx: ::c_long = 4000 + 56; pub const SYS_setpgid: ::c_long = 4000 + 57; pub const SYS_ulimit: ::c_long = 4000 + 58; -pub const SYS_unused59: ::c_long = 4000 + 59; pub const SYS_umask: ::c_long = 4000 + 60; pub const SYS_chroot: ::c_long = 4000 + 61; pub const SYS_ustat: ::c_long = 4000 + 62; @@ -325,9 +308,7 @@ pub const SYS_gettimeofday: ::c_long = 4000 + 78; pub const SYS_settimeofday: ::c_long = 4000 + 79; pub const SYS_getgroups: ::c_long = 4000 + 80; pub const SYS_setgroups: ::c_long = 4000 + 81; -pub const SYS_reserved82: ::c_long = 4000 + 82; pub const SYS_symlink: ::c_long = 4000 + 83; -pub const SYS_unused84: ::c_long = 4000 + 84; pub const SYS_readlink: ::c_long = 4000 + 85; pub const SYS_uselib: ::c_long = 4000 + 86; pub const SYS_swapon: ::c_long = 4000 + 87; @@ -352,7 +333,6 @@ pub const SYS_getitimer: ::c_long = 4000 + 105; pub const SYS_stat: ::c_long = 4000 + 106; pub const SYS_lstat: ::c_long = 4000 + 107; pub const SYS_fstat: ::c_long = 4000 + 108; -pub const SYS_unused109: ::c_long = 4000 + 109; pub const SYS_iopl: ::c_long = 4000 + 110; pub const SYS_vhangup: ::c_long = 4000 + 111; pub const SYS_idle: ::c_long = 4000 + 112; @@ -393,7 +373,6 @@ pub const SYS_writev: ::c_long = 4000 + 146; pub const SYS_cacheflush: ::c_long = 4000 + 147; pub const SYS_cachectl: ::c_long = 4000 + 148; pub const SYS_sysmips: ::c_long = 4000 + 149; -pub const SYS_unused150: ::c_long = 4000 + 150; pub const SYS_getsid: ::c_long = 4000 + 151; pub const SYS_fdatasync: ::c_long = 4000 + 152; pub const SYS__sysctl: ::c_long = 4000 + 153; @@ -464,7 +443,6 @@ pub const SYS_mincore: ::c_long = 4000 + 217; pub const SYS_madvise: ::c_long = 4000 + 218; pub const SYS_getdents64: ::c_long = 4000 + 219; pub const SYS_fcntl64: ::c_long = 4000 + 220; -pub const SYS_reserved221: ::c_long = 4000 + 221; pub const SYS_gettid: ::c_long = 4000 + 222; pub const SYS_readahead: ::c_long = 4000 + 223; pub const SYS_setxattr: ::c_long = 4000 + 224; @@ -624,7 +602,7 @@ extern { sz: ::c_int) -> ::c_int; pub fn glob64(pattern: *const ::c_char, flags: ::c_int, - errfunc: ::dox::Option<extern fn(epath: *const ::c_char, + errfunc: ::Option<extern fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int>, pglob: *mut glob64_t) -> ::c_int; @@ -637,3 +615,13 @@ extern { cpusetsize: ::size_t, cpuset: *const ::cpu_set_t) -> ::c_int; } + +cfg_if! { + if #[cfg(libc_align)] { + mod align; + pub use self::align::*; + } else { + mod no_align; + pub use self::no_align::*; + } +} diff --git a/libc/src/unix/uclibc/mips/mips32/no_align.rs b/libc/src/unix/uclibc/mips/mips32/no_align.rs new file mode 100644 index 0000000..e32bf67 --- /dev/null +++ b/libc/src/unix/uclibc/mips/mips32/no_align.rs @@ -0,0 +1,10 @@ +s! { + // FIXME this is actually a union + pub struct sem_t { + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + __align: [::c_long; 0], + } +} diff --git a/libc/src/unix/uclibc/mips/mips64/align.rs b/libc/src/unix/uclibc/mips/mips64/align.rs new file mode 100644 index 0000000..21e2190 --- /dev/null +++ b/libc/src/unix/uclibc/mips/mips64/align.rs @@ -0,0 +1,10 @@ +s! { + // FIXME this is actually a union + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct sem_t { + __size: [::c_char; 32], + } +} diff --git a/libc/src/unix/uclibc/mips/mips64.rs b/libc/src/unix/uclibc/mips/mips64/mod.rs index e35938b..d80762e 100644 --- a/libc/src/unix/uclibc/mips/mips64.rs +++ b/libc/src/unix/uclibc/mips/mips64/mod.rs @@ -186,17 +186,6 @@ s! { pub mem_unit: ::c_uint, pub _f: [::c_char; 0], } - - // FIXME this is actually a union - #[cfg_attr(all(feature = "align", target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", target_pointer_width = "64"), - repr(align(8)))] - pub struct sem_t { - __size: [::c_char; 32], - #[cfg(not(feature = "align"))] - __align: [::c_long; 0], - } } pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; @@ -212,3 +201,13 @@ pub const SYS_gettid: ::c_long = 5178; // Valid for n64 extern { pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; } + +cfg_if! { + if #[cfg(libc_align)] { + mod align; + pub use self::align::*; + } else { + mod no_align; + pub use self::no_align::*; + } +} diff --git a/libc/src/unix/uclibc/mips/mips64/no_align.rs b/libc/src/unix/uclibc/mips/mips64/no_align.rs new file mode 100644 index 0000000..ee57ea8 --- /dev/null +++ b/libc/src/unix/uclibc/mips/mips64/no_align.rs @@ -0,0 +1,8 @@ +s! { + // FIXME this is actually a union + pub struct sem_t { + __size: [::c_char; 32], + __align: [::c_long; 0], + } +} + diff --git a/libc/src/unix/uclibc/mod.rs b/libc/src/unix/uclibc/mod.rs index c04c22a..e3baba0 100644 --- a/libc/src/unix/uclibc/mod.rs +++ b/libc/src/unix/uclibc/mod.rs @@ -1,5 +1,3 @@ -use dox::{mem, Option}; - pub type sa_family_t = u16; pub type pthread_key_t = ::c_uint; pub type speed_t = ::c_uint; @@ -24,11 +22,30 @@ pub type nfds_t = ::c_ulong; pub type nl_item = ::c_int; pub type idtype_t = ::c_uint; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos64_t {} // TODO: fill this out with a struct +impl ::Copy for fpos64_t {} +impl ::Clone for fpos64_t { + fn clone(&self) -> fpos64_t { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} s! { + pub struct in_addr { + pub s_addr: ::in_addr_t, + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + pub struct sockaddr { pub sa_family: sa_family_t, pub sa_data: [::c_char; 14], @@ -49,20 +66,6 @@ s! { pub sin6_scope_id: u32, } - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 108] - } - - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - __ss_align: ::size_t, - #[cfg(target_pointer_width = "32")] - __ss_pad2: [u8; 128 - 2 * 4], - #[cfg(target_pointer_width = "64")] - __ss_pad2: [u8; 128 - 2 * 8], - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -123,23 +126,6 @@ s! { pub dli_saddr: *mut ::c_void, } - #[cfg_attr(any(all(target_arch = "x86", - target_arch = "x86_64")), - repr(packed))] - pub struct epoll_event { - pub events: ::uint32_t, - pub u64: ::uint64_t, - } - - pub struct utsname { - pub sysname: [::c_char; 65], - pub nodename: [::c_char; 65], - pub release: [::c_char; 65], - pub version: [::c_char; 65], - pub machine: [::c_char; 65], - pub domainname: [::c_char; 65] - } - pub struct lconv { pub decimal_point: *mut ::c_char, pub thousands_sep: *mut ::c_char, @@ -180,22 +166,6 @@ s! { __unused1: [::c_int; 12] } - 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; 256], - } - - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - pub struct rlimit64 { pub rlim_cur: rlim64_t, pub rlim_max: rlim64_t, @@ -224,103 +194,11 @@ s! { pub ifa_data: *mut ::c_void } - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))), - repr(align(8)))] - pub struct pthread_mutex_t { - #[cfg(all(not(feature = "align"), - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))), - repr(align(8)))] - pub struct pthread_rwlock_t { - #[cfg(all(not(feature = "align"), - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCK_T], - } - - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "32", - target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(any(target_pointer_width = "32", - target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))), - repr(align(8)))] - pub struct pthread_mutexattr_t { - #[cfg(all(not(feature = "align"), - any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")))] - __align: [::c_int; 0], - #[cfg(all(not(feature = "align"), - not(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T], - } - pub struct pthread_rwlockattr_t { __lockkind: ::c_int, __pshared: ::c_int, } - #[cfg_attr(feature = "align", repr(align(8)))] - pub struct pthread_cond_t { - #[cfg(not(feature = "align"))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_condattr_t { - #[cfg(not(feature = "align"))] - __align: [::c_int; 0], - size: [u8; __SIZEOF_PTHREAD_CONDATTR_T], - } - pub struct passwd { pub pw_name: *mut ::c_char, pub pw_passwd: *mut ::c_char, @@ -436,6 +314,62 @@ s! { } } +s_no_extra_traits! { + #[cfg_attr( + any(target_arch = "x86", target_arch = "x86_64"), + repr(packed) + )] + #[allow(missing_debug_implementations)] + pub struct epoll_event { + pub events: ::uint32_t, + pub u64: ::uint64_t, + } + + #[allow(missing_debug_implementations)] + pub struct sockaddr_un { + pub sun_family: sa_family_t, + pub sun_path: [::c_char; 108] + } + + #[allow(missing_debug_implementations)] + pub struct sockaddr_storage { + pub ss_family: sa_family_t, + __ss_align: ::size_t, + #[cfg(target_pointer_width = "32")] + __ss_pad2: [u8; 128 - 2 * 4], + #[cfg(target_pointer_width = "64")] + __ss_pad2: [u8; 128 - 2 * 8], + } + + #[allow(missing_debug_implementations)] + pub struct utsname { + pub sysname: [::c_char; 65], + pub nodename: [::c_char; 65], + pub release: [::c_char; 65], + pub version: [::c_char; 65], + pub machine: [::c_char; 65], + pub domainname: [::c_char; 65] + } + + #[allow(missing_debug_implementations)] + 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; 256], + } + + #[allow(missing_debug_implementations)] + pub struct dirent64 { + pub d_ino: ::ino64_t, + pub d_off: ::off64_t, + pub d_reclen: ::c_ushort, + pub d_type: ::c_uchar, + pub d_name: [::c_char; 256], + } +} + // intentionally not public, only used for fd_set cfg_if! { if #[cfg(target_pointer_width = "32")] { @@ -1459,20 +1393,20 @@ pub const AF_MAX: ::c_int = 39; f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; (*set).fds_bits[fd / size] &= !(1 << (fd % size)); return } pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 } pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; - let size = mem::size_of_val(&(*set).fds_bits[0]) * 8; + let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; (*set).fds_bits[fd / size] |= 1 << (fd % size); return } @@ -1522,21 +1456,23 @@ f! { } pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc + let size_in_bits + = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); cpuset.bits[idx] |= 1 << offset; () } pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc + let size_in_bits + = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); cpuset.bits[idx] &= !(1 << offset); () } pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); + let size_in_bits = 8 * ::mem::size_of_val(&cpuset.bits[0]); let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); 0 != (cpuset.bits[idx] & (1 << offset)) } @@ -1551,6 +1487,12 @@ f! { } extern { + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; + pub fn sem_init(sem: *mut sem_t, + pshared: ::c_int, + value: ::c_uint) + -> ::c_int; + pub fn abs(i: ::c_int) -> ::c_int; pub fn atof(s: *const ::c_char) -> ::c_double; pub fn labs(i: ::c_long) -> ::c_long; @@ -1857,7 +1799,7 @@ extern { pub fn glob(pattern: *const c_char, flags: ::c_int, - errfunc: Option<extern fn(epath: *const c_char, + errfunc: ::Option<extern fn(epath: *const c_char, errno: ::c_int) -> ::c_int>, pglob: *mut ::glob_t) -> ::c_int; pub fn globfree(pglob: *mut ::glob_t); @@ -1895,7 +1837,7 @@ extern { pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t; #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r(uid: ::uid_t, + pub fn getgrgid_r(gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, @@ -1941,9 +1883,9 @@ extern { #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork(prepare: Option<unsafe extern fn()>, - parent: Option<unsafe extern fn()>, - child: Option<unsafe extern fn()>) -> ::c_int; + pub fn pthread_atfork(prepare: ::Option<unsafe extern fn()>, + parent: ::Option<unsafe extern fn()>, + child: ::Option<unsafe extern fn()>) -> ::c_int; pub fn pthread_create(native: *mut ::pthread_t, attr: *const ::pthread_attr_t, f: extern fn(*mut ::c_void) -> *mut ::c_void, @@ -1963,8 +1905,22 @@ cfg_if! { } else if #[cfg(target_arch = "x86_64")] { mod x86_64; pub use self::x86_64::*; + } else if #[cfg(target_arch = "arm")] { + mod arm; + pub use self::arm::*; } else { pub use unsupported_target; } } +cfg_if! { + if #[cfg(libc_align)] { + #[macro_use] + mod align; + } else { + #[macro_use] + mod no_align; + } +} + +expand_align!(); diff --git a/libc/src/unix/uclibc/no_align.rs b/libc/src/unix/uclibc/no_align.rs new file mode 100644 index 0000000..a73dbde --- /dev/null +++ b/libc/src/unix/uclibc/no_align.rs @@ -0,0 +1,53 @@ +macro_rules! expand_align { + () => { + s! { + pub struct pthread_mutex_t { + #[cfg(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))] + __align: [::c_long; 0], + #[cfg(any(libc_align, + target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + pub struct pthread_rwlock_t { + #[cfg(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))] + __align: [::c_long; 0], + #[cfg(not(any( + target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + + pub struct pthread_mutexattr_t { + #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64", + target_arch = "mips64", target_arch = "s390x", + target_arch = "sparc64"))] + __align: [::c_int; 0], + #[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64", + target_arch = "mips64", target_arch = "s390x", + target_arch = "sparc64")))] + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + pub struct pthread_cond_t { + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + + pub struct pthread_condattr_t { + __align: [::c_int; 0], + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + } +} diff --git a/libc/src/unix/uclibc/x86_64/align.rs b/libc/src/unix/uclibc/x86_64/align.rs new file mode 100644 index 0000000..8d4bbd5 --- /dev/null +++ b/libc/src/unix/uclibc/x86_64/align.rs @@ -0,0 +1,77 @@ +macro_rules! expand_align { + () => { + s! { + #[cfg_attr(target_pointer_width = "32", + repr(align(4)))] + #[cfg_attr(target_pointer_width = "64", + repr(align(8)))] + pub struct sem_t { // ToDo + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + } + + #[cfg_attr(any(target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64"), + repr(align(4)))] + #[cfg_attr(not(any(target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64")), + repr(align(8)))] + pub struct pthread_mutexattr_t { // ToDo + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + #[repr(align(4))] + pub struct pthread_condattr_t { // ToDo + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + } + + s_no_extra_traits! { + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")), + repr(align(4)))] + #[cfg_attr(all(any(target_pointer_width = "64", + not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")))), + repr(align(8)))] + #[allow(missing_debug_implementations)] + pub struct pthread_mutex_t { // ToDo + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + #[repr(align(8))] + #[allow(missing_debug_implementations)] + pub struct pthread_cond_t { // ToDo + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + + #[cfg_attr(all(target_pointer_width = "32", + any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")), + repr(align(4)))] + #[cfg_attr(any(target_pointer_width = "64", + not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))), + repr(align(8)))] + #[allow(missing_debug_implementations)] + pub struct pthread_rwlock_t { // ToDo + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + } + } +} diff --git a/libc/src/unix/uclibc/x86_64/l4re.rs b/libc/src/unix/uclibc/x86_64/l4re.rs index 4f5811d..16ec0ef 100644 --- a/libc/src/unix/uclibc/x86_64/l4re.rs +++ b/libc/src/unix/uclibc/x86_64/l4re.rs @@ -27,6 +27,7 @@ s! { } #[cfg(target_os = "l4re")] +#[allow(missing_debug_implementations)] pub struct pthread_attr_t { pub __detachstate: ::c_int, pub __schedpolicy: ::c_int, diff --git a/libc/src/unix/uclibc/x86_64/mod.rs b/libc/src/unix/uclibc/x86_64/mod.rs index bc6571a..a8bb079 100644 --- a/libc/src/unix/uclibc/x86_64/mod.rs +++ b/libc/src/unix/uclibc/x86_64/mod.rs @@ -1,5 +1,4 @@ //! Definitions for uclibc on 64bit systems -//! pub type blkcnt_t = i64; pub type blksize_t = i64; pub type clock_t = i64; @@ -20,25 +19,7 @@ pub type suseconds_t = ::c_long; pub type time_t = ::c_int; pub type wchar_t = ::c_int; -pub type nfds_t = ::c_ulong; - s! { - pub struct dirent { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: u16, - pub d_type: u8, - pub d_name: [::c_char; 256], - } - - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: u16, - pub d_type: u8, - pub d_name: [::c_char; 256], - } - pub struct ipc_perm { pub __key: ::key_t, pub uid: ::uid_t, @@ -133,7 +114,7 @@ s! { // // pub struct in6_addr { // pub s6_addr: [u8; 16], -// #[cfg(not(feature = "align"))] +// #[cfg(not(libc_align))] // __align: [u32; 0], // } @@ -205,111 +186,6 @@ s! { pub c_cc: [::cc_t; ::NCCS], } - #[cfg_attr(all(feature = "align", target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(feature = "align", target_pointer_width = "64"), - repr(align(8)))] - pub struct sem_t { // ToDo - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - #[cfg(not(feature = "align"))] - __align: [::c_long; 0], - } - - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))), - repr(align(8)))] - pub struct pthread_mutex_t { // ToDo - #[cfg(all(not(feature = "align"), - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "32", - target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - not(any(target_pointer_width = "32", - target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))), - repr(align(8)))] - pub struct pthread_mutexattr_t { // ToDo - #[cfg(all(not(feature = "align"), - any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")))] - __align: [::c_int; 0], - #[cfg(all(not(feature = "align"), - not(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))))] - __align: [::c_long; 0], - size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[cfg_attr(feature = "align", repr(align(8)))] - pub struct pthread_cond_t { // ToDo - #[cfg(not(feature = "align"))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(feature = "align", repr(align(4)))] - pub struct pthread_condattr_t { // ToDo - #[cfg(not(feature = "align"))] - __align: [::c_int; 0], - size: [u8; __SIZEOF_PTHREAD_CONDATTR_T], - } - - #[cfg_attr(all(feature = "align", - target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(all(feature = "align", - any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))), - repr(align(8)))] - pub struct pthread_rwlock_t { // ToDo - #[cfg(all(not(feature = "align"), - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_long; 0], - #[cfg(not(any(feature = "align", - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; __SIZEOF_PTHREAD_RWLOCK_T], - } - pub struct sigset_t { // ToDo __val: [::c_ulong; 16], } @@ -360,6 +236,25 @@ s! { } } +s_no_extra_traits! { + #[allow(missing_debug_implementations)] + pub struct dirent { + pub d_ino: ::ino64_t, + pub d_off: ::off64_t, + pub d_reclen: u16, + pub d_type: u8, + pub d_name: [::c_char; 256], + } + #[allow(missing_debug_implementations)] + pub struct dirent64 { + pub d_ino: ::ino64_t, + pub d_off: ::off64_t, + pub d_reclen: u16, + pub d_type: u8, + pub d_name: [::c_char; 256], + } +} + // constants pub const EADDRINUSE: ::c_int = 98; // Address already in use pub const EADDRNOTAVAIL: ::c_int = 99; // Cannot assign requested address @@ -380,7 +275,6 @@ pub const O_NONBLOCK: ::c_int = 04000; pub const O_TRUNC: ::c_int = 01000; pub const NCCS: usize = 32; pub const SIG_SETMASK: ::c_int = 2; // Set the set of blocked signals -pub const PTHREAD_STACK_MIN: usize = 16384; pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; pub const SO_BROADCAST: ::c_int = 6; @@ -391,19 +285,11 @@ pub const SOL_SOCKET: ::c_int = 1; pub const SO_RCVTIMEO: ::c_int = 20; pub const SO_REUSEADDR: ::c_int = 2; pub const SO_SNDTIMEO: ::c_int = 21; -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; pub const RLIM_INFINITY: u64 = 0xffffffffffffffff; pub const __SIZEOF_PTHREAD_COND_T: usize = 48; pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; -extern { - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; -} - cfg_if! { if #[cfg(target_os = "l4re")] { mod l4re; @@ -414,3 +300,13 @@ cfg_if! { } } +cfg_if! { + if #[cfg(libc_align)] { + #[macro_use] + mod align; + } else { + #[macro_use] + mod no_align; + } +} +expand_align!(); diff --git a/libc/src/unix/uclibc/x86_64/no_align.rs b/libc/src/unix/uclibc/x86_64/no_align.rs new file mode 100644 index 0000000..422d78f --- /dev/null +++ b/libc/src/unix/uclibc/x86_64/no_align.rs @@ -0,0 +1,59 @@ +macro_rules! expand_align { + () => { + s! { + pub struct sem_t { // ToDo + #[cfg(target_pointer_width = "32")] + __size: [::c_char; 16], + #[cfg(target_pointer_width = "64")] + __size: [::c_char; 32], + __align: [::c_long; 0], + } + + pub struct pthread_mutex_t { // ToDo + #[cfg(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))] + __align: [::c_long; 0], + #[cfg(not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + pub struct pthread_mutexattr_t { // ToDo + #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64", + target_arch = "mips64", target_arch = "s390x", + target_arch = "sparc64"))] + __align: [::c_int; 0], + #[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64", + target_arch = "mips64", target_arch = "s390x", + target_arch = "sparc64")))] + __align: [::c_long; 0], + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + pub struct pthread_cond_t { // ToDo + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_COND_T], + } + + pub struct pthread_condattr_t { // ToDo + __align: [::c_int; 0], + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + + pub struct pthread_rwlock_t { // ToDo + #[cfg(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc"))] + __align: [::c_long; 0], + #[cfg(not(any(target_arch = "mips", + target_arch = "arm", + target_arch = "powerpc")))] + __align: [::c_longlong; 0], + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + } + } +} diff --git a/libc/src/unix/uclibc/x86_64/other.rs b/libc/src/unix/uclibc/x86_64/other.rs index 1cc521d..481577c 100644 --- a/libc/src/unix/uclibc/x86_64/other.rs +++ b/libc/src/unix/uclibc/x86_64/other.rs @@ -2,3 +2,4 @@ // separate module pub type pthread_t = ::c_ulong; +pub const PTHREAD_STACK_MIN: usize = 16384; diff --git a/libc/src/wasi.rs b/libc/src/wasi.rs new file mode 100644 index 0000000..b934861 --- /dev/null +++ b/libc/src/wasi.rs @@ -0,0 +1,1336 @@ +pub use ffi::c_void; + +pub type c_char = i8; +pub type c_uchar = u8; +pub type c_int = i32; +pub type c_uint = u32; +pub type c_short = i16; +pub type c_ushort = u16; +pub type c_long = i32; +pub type c_ulong = u32; +pub type c_longlong = i64; +pub type c_ulonglong = u64; +pub type intmax_t = i64; +pub type uintmax_t = u64; +pub type size_t = usize; +pub type ssize_t = isize; +pub type ptrdiff_t = isize; +pub type intptr_t = isize; +pub type uintptr_t = usize; +pub type off_t = i64; +pub type pid_t = i32; +pub type int8_t = i8; +pub type uint8_t = u8; +pub type int16_t = i16; +pub type uint16_t = u16; +pub type int32_t = i32; +pub type uint32_t = u32; +pub type int64_t = i64; +pub type uint64_t = u64; +pub type clock_t = c_longlong; +pub type time_t = c_longlong; +pub type c_double = f64; +pub type c_float = f32; +pub type ino_t = u64; +pub type sigset_t = c_uchar; +pub type suseconds_t = c_longlong; +pub type mode_t = u32; +pub type dev_t = u64; +pub type uid_t = u32; +pub type gid_t = u32; +pub type nlink_t = u64; +pub type blksize_t = c_long; +pub type blkcnt_t = i64; +pub type nfds_t = c_ulong; + +pub type __wasi_advice_t = u8; +pub type __wasi_clockid_t = u32; +pub type __wasi_device_t = u64; +pub type __wasi_dircookie_t = u64; +pub type __wasi_errno_t = u16; +pub type __wasi_eventrwflags_t = u16; +pub type __wasi_eventtype_t = u8; +pub type __wasi_exitcode_t = u32; +pub type __wasi_fd_t = u32; +pub type __wasi_fdflags_t = u16; +pub type __wasi_filedelta_t = i64; +pub type __wasi_filesize_t = u64; +pub type __wasi_filetype_t = u8; +pub type __wasi_fstflags_t = u16; +pub type __wasi_inode_t = u64; +pub type __wasi_linkcount_t = u32; +pub type __wasi_lookupflags_t = u32; +pub type __wasi_oflags_t = u16; +pub type __wasi_riflags_t = u16; +pub type __wasi_rights_t = u64; +pub type __wasi_roflags_t = u16; +pub type __wasi_sdflags_t = u8; +pub type __wasi_siflags_t = u16; +pub type __wasi_signal_t = u8; +pub type __wasi_subclockflags_t = u16; +pub type __wasi_timestamp_t = u64; +pub type __wasi_userdata_t = u64; +pub type __wasi_whence_t = u8; +pub type __wasi_preopentype_t = u8; + +#[allow(missing_copy_implementations)] +#[cfg_attr(feature = "extra_traits", derive(Debug))] +pub enum FILE {} +#[allow(missing_copy_implementations)] +#[cfg_attr(feature = "extra_traits", derive(Debug))] +pub enum DIR {} +#[allow(missing_copy_implementations)] +#[cfg_attr(feature = "extra_traits", derive(Debug))] +pub enum __locale_struct {} + +pub type locale_t = *mut __locale_struct; + +s! { + #[repr(align(8))] + pub struct fpos_t { + data: [u8; 16], + } + + pub struct tm { + pub tm_sec: c_int, + pub tm_min: c_int, + pub tm_hour: c_int, + pub tm_mday: c_int, + pub tm_mon: c_int, + pub tm_year: c_int, + pub tm_wday: c_int, + pub tm_yday: c_int, + pub tm_isdst: c_int, + pub __tm_gmtoff: c_int, + pub __tm_zone: *const c_char, + pub __tm_nsec: c_int, + } + + pub struct timeval { + pub tv_sec: time_t, + pub tv_usec: suseconds_t, + } + + pub struct timespec { + pub tv_sec: time_t, + pub tv_nsec: c_long, + } + + pub struct tms { + pub tms_utime: clock_t, + pub tms_stime: clock_t, + pub tms_cutime: clock_t, + pub tms_cstime: clock_t, + } + + pub struct itimerspec { + pub it_interval: timespec, + pub it_value: timespec, + } + + pub struct iovec { + pub iov_base: *mut c_void, + pub iov_len: size_t, + } + + pub struct lconv { + pub decimal_point: *mut c_char, + pub thousands_sep: *mut c_char, + pub grouping: *mut c_char, + pub int_curr_symbol: *mut c_char, + pub currency_symbol: *mut c_char, + pub mon_decimal_point: *mut c_char, + pub mon_thousands_sep: *mut c_char, + pub mon_grouping: *mut c_char, + pub positive_sign: *mut c_char, + pub negative_sign: *mut c_char, + pub int_frac_digits: c_char, + pub frac_digits: c_char, + pub p_cs_precedes: c_char, + pub p_sep_by_space: c_char, + pub n_cs_precedes: c_char, + pub n_sep_by_space: c_char, + pub p_sign_posn: c_char, + pub n_sign_posn: c_char, + pub int_p_cs_precedes: c_char, + pub int_p_sep_by_space: c_char, + pub int_n_cs_precedes: c_char, + pub int_n_sep_by_space: c_char, + pub int_p_sign_posn: c_char, + pub int_n_sign_posn: c_char, + } + + pub struct pollfd { + pub fd: c_int, + pub events: c_short, + pub revents: c_short, + } + + pub struct rusage { + pub ru_utime: timeval, + pub ru_stime: timeval, + } + + pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_nlink: nlink_t, + pub st_mode: mode_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + __pad0: c_uint, + pub st_rdev: dev_t, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_atim: timespec, + pub st_mtim: timespec, + pub st_ctim: timespec, + __reserved: [c_longlong; 3], + } + + pub struct __wasi_dirent_t { + pub d_next: __wasi_dircookie_t, + pub d_ino: __wasi_inode_t, + pub d_namlen: u32, + pub d_type: __wasi_filetype_t, + } + + pub struct __wasi_event_u_fd_readwrite_t { + pub nbytes: __wasi_filesize_t, + pub flags: __wasi_eventrwflags_t, + } + + pub struct __wasi_fdstat_t { + pub fs_filetype: __wasi_filetype_t, + pub fs_flags: __wasi_fdflags_t, + pub fs_rights_base: __wasi_rights_t, + pub fs_rights_inheriting: __wasi_rights_t, + } + + pub struct __wasi_filestat_t { + pub st_dev: __wasi_device_t, + pub st_ino: __wasi_inode_t, + pub st_filetype: __wasi_filetype_t, + pub st_nlink: __wasi_linkcount_t, + pub st_size: __wasi_filesize_t, + pub st_atim: __wasi_timestamp_t, + pub st_mtim: __wasi_timestamp_t, + pub st_ctim: __wasi_timestamp_t, + } + + pub struct __wasi_ciovec_t { + pub buf: *const ::c_void, + pub buf_len: size_t, + } + + pub struct __wasi_iovec_t { + pub buf: *mut ::c_void, + pub buf_len: size_t, + } + + pub struct __wasi_subscription_u_clock_t { + pub identifier: __wasi_userdata_t, + pub clock_id: __wasi_clockid_t, + pub timeout: __wasi_timestamp_t, + pub precision: __wasi_timestamp_t, + pub flags: __wasi_subclockflags_t, + } + + pub struct __wasi_subscription_u_fd_readwrite_t { + pub fd: __wasi_fd_t, + } + + pub struct __wasi_prestat_u_dir_t { + pub pr_name_len: size_t, + } +} + +s_no_extra_traits! { + #[allow(missing_debug_implementations)] + pub struct __wasi_subscription_t { + pub userdata: __wasi_userdata_t, + pub type_: __wasi_eventtype_t, + pub u: __wasi_subscription_u, + } + + #[allow(missing_debug_implementations)] + pub struct __wasi_event_t { + pub userdata: __wasi_userdata_t, + pub error: __wasi_errno_t, + pub type_: __wasi_eventtype_t, + pub u: __wasi_event_u, + } + + #[allow(missing_debug_implementations)] + pub union __wasi_event_u { + pub fd_readwrite: __wasi_event_u_fd_readwrite_t, + _bindgen_union_align: [u64; 2], + } + + #[allow(missing_debug_implementations)] + pub union __wasi_subscription_u { + pub clock: __wasi_subscription_u_clock_t, + pub fd_readwrite: + __wasi_subscription_u_fd_readwrite_t, + _bindgen_union_align: [u64; 5], + } + + #[allow(missing_debug_implementations)] + pub struct __wasi_prestat_t { + pub pr_type: __wasi_preopentype_t, + pub u: __wasi_prestat_u, + } + + #[allow(missing_debug_implementations)] + pub union __wasi_prestat_u { + pub dir: __wasi_prestat_u_dir_t, + } + +} + +// Declare dirent outside of s! so that it doesn't implement Copy, Eq, Hash, +// etc., since it contains a flexible array member with a dynamic size. +#[repr(C)] +#[allow(missing_copy_implementations)] +#[cfg_attr(feature = "extra_traits", derive(Debug))] +pub struct dirent { + pub d_ino: ino_t, + pub d_type: c_uchar, + /// d_name is declared in WASI libc as a flexible array member, which + /// can't be directly expressed in Rust. As an imperfect workaround, + /// declare it as a zero-length array instead. + pub d_name: [c_char; 0], +} + +pub const EXIT_SUCCESS: c_int = 0; +pub const EXIT_FAILURE: c_int = 1; +pub const STDIN_FILENO: c_int = 0; +pub const STDOUT_FILENO: c_int = 1; +pub const STDERR_FILENO: c_int = 2; +pub const SEEK_SET: c_int = 2; +pub const SEEK_CUR: c_int = 0; +pub const SEEK_END: c_int = 1; +pub const _IOFBF: c_int = 0; +pub const _IONBF: c_int = 2; +pub const _IOLBF: c_int = 1; +pub const FD_SETSIZE: size_t = 1024; +pub const O_APPEND: c_int = __WASI_FDFLAG_APPEND as c_int; +pub const O_DSYNC: c_int = __WASI_FDFLAG_DSYNC as c_int; +pub const O_NONBLOCK: c_int = __WASI_FDFLAG_NONBLOCK as c_int; +pub const O_RSYNC: c_int = __WASI_FDFLAG_RSYNC as c_int; +pub const O_SYNC: c_int = __WASI_FDFLAG_SYNC as c_int; +pub const O_CREAT: c_int = (__WASI_O_CREAT as c_int) << 12; +pub const O_DIRECTORY: c_int = (__WASI_O_DIRECTORY as c_int) << 12; +pub const O_EXCL: c_int = (__WASI_O_EXCL as c_int) << 12; +pub const O_TRUNC: c_int = (__WASI_O_TRUNC as c_int) << 12; +pub const O_NOFOLLOW: c_int = 0x01000000; +pub const O_EXEC: c_int = 0x02000000; +pub const O_RDONLY: c_int = 0x04000000; +pub const O_SEARCH: c_int = 0x08000000; +pub const O_WRONLY: c_int = 0x10000000; +pub const O_RDWR: c_int = O_WRONLY | O_RDONLY; +pub const O_ACCMODE: c_int = O_EXEC | O_RDWR | O_SEARCH; +pub const POSIX_FADV_DONTNEED: c_int = __WASI_ADVICE_DONTNEED as c_int; +pub const POSIX_FADV_NOREUSE: c_int = __WASI_ADVICE_NOREUSE as c_int; +pub const POSIX_FADV_NORMAL: c_int = __WASI_ADVICE_NORMAL as c_int; +pub const POSIX_FADV_RANDOM: c_int = __WASI_ADVICE_RANDOM as c_int; +pub const POSIX_FADV_SEQUENTIAL: c_int = __WASI_ADVICE_SEQUENTIAL as c_int; +pub const POSIX_FADV_WILLNEED: c_int = __WASI_ADVICE_WILLNEED as c_int; +pub const AT_EACCESS: c_int = 0x0; +pub const AT_SYMLINK_NOFOLLOW: c_int = 0x1; +pub const AT_SYMLINK_FOLLOW: c_int = 0x2; +pub const AT_REMOVEDIR: c_int = 0x4; + +pub const E2BIG: c_int = __WASI_E2BIG as c_int; +pub const EACCES: c_int = __WASI_EACCES as c_int; +pub const EADDRINUSE: c_int = __WASI_EADDRINUSE as c_int; +pub const EADDRNOTAVAIL: c_int = __WASI_EADDRNOTAVAIL as c_int; +pub const EAFNOSUPPORT: c_int = __WASI_EAFNOSUPPORT as c_int; +pub const EAGAIN: c_int = __WASI_EAGAIN as c_int; +pub const EALREADY: c_int = __WASI_EALREADY as c_int; +pub const EBADF: c_int = __WASI_EBADF as c_int; +pub const EBADMSG: c_int = __WASI_EBADMSG as c_int; +pub const EBUSY: c_int = __WASI_EBUSY as c_int; +pub const ECANCELED: c_int = __WASI_ECANCELED as c_int; +pub const ECHILD: c_int = __WASI_ECHILD as c_int; +pub const ECONNABORTED: c_int = __WASI_ECONNABORTED as c_int; +pub const ECONNREFUSED: c_int = __WASI_ECONNREFUSED as c_int; +pub const ECONNRESET: c_int = __WASI_ECONNRESET as c_int; +pub const EDEADLK: c_int = __WASI_EDEADLK as c_int; +pub const EDESTADDRREQ: c_int = __WASI_EDESTADDRREQ as c_int; +pub const EDOM: c_int = __WASI_EDOM as c_int; +pub const EDQUOT: c_int = __WASI_EDQUOT as c_int; +pub const EEXIST: c_int = __WASI_EEXIST as c_int; +pub const EFAULT: c_int = __WASI_EFAULT as c_int; +pub const EFBIG: c_int = __WASI_EFBIG as c_int; +pub const EHOSTUNREACH: c_int = __WASI_EHOSTUNREACH as c_int; +pub const EIDRM: c_int = __WASI_EIDRM as c_int; +pub const EILSEQ: c_int = __WASI_EILSEQ as c_int; +pub const EINPROGRESS: c_int = __WASI_EINPROGRESS as c_int; +pub const EINTR: c_int = __WASI_EINTR as c_int; +pub const EINVAL: c_int = __WASI_EINVAL as c_int; +pub const EIO: c_int = __WASI_EIO as c_int; +pub const EISCONN: c_int = __WASI_EISCONN as c_int; +pub const EISDIR: c_int = __WASI_EISDIR as c_int; +pub const ELOOP: c_int = __WASI_ELOOP as c_int; +pub const EMFILE: c_int = __WASI_EMFILE as c_int; +pub const EMLINK: c_int = __WASI_EMLINK as c_int; +pub const EMSGSIZE: c_int = __WASI_EMSGSIZE as c_int; +pub const EMULTIHOP: c_int = __WASI_EMULTIHOP as c_int; +pub const ENAMETOOLONG: c_int = __WASI_ENAMETOOLONG as c_int; +pub const ENETDOWN: c_int = __WASI_ENETDOWN as c_int; +pub const ENETRESET: c_int = __WASI_ENETRESET as c_int; +pub const ENETUNREACH: c_int = __WASI_ENETUNREACH as c_int; +pub const ENFILE: c_int = __WASI_ENFILE as c_int; +pub const ENOBUFS: c_int = __WASI_ENOBUFS as c_int; +pub const ENODEV: c_int = __WASI_ENODEV as c_int; +pub const ENOENT: c_int = __WASI_ENOENT as c_int; +pub const ENOEXEC: c_int = __WASI_ENOEXEC as c_int; +pub const ENOLCK: c_int = __WASI_ENOLCK as c_int; +pub const ENOLINK: c_int = __WASI_ENOLINK as c_int; +pub const ENOMEM: c_int = __WASI_ENOMEM as c_int; +pub const ENOMSG: c_int = __WASI_ENOMSG as c_int; +pub const ENOPROTOOPT: c_int = __WASI_ENOPROTOOPT as c_int; +pub const ENOSPC: c_int = __WASI_ENOSPC as c_int; +pub const ENOSYS: c_int = __WASI_ENOSYS as c_int; +pub const ENOTCONN: c_int = __WASI_ENOTCONN as c_int; +pub const ENOTDIR: c_int = __WASI_ENOTDIR as c_int; +pub const ENOTEMPTY: c_int = __WASI_ENOTEMPTY as c_int; +pub const ENOTRECOVERABLE: c_int = __WASI_ENOTRECOVERABLE as c_int; +pub const ENOTSOCK: c_int = __WASI_ENOTSOCK as c_int; +pub const ENOTSUP: c_int = __WASI_ENOTSUP as c_int; +pub const ENOTTY: c_int = __WASI_ENOTTY as c_int; +pub const ENXIO: c_int = __WASI_ENXIO as c_int; +pub const EOVERFLOW: c_int = __WASI_EOVERFLOW as c_int; +pub const EOWNERDEAD: c_int = __WASI_EOWNERDEAD as c_int; +pub const EPERM: c_int = __WASI_EPERM as c_int; +pub const EPIPE: c_int = __WASI_EPIPE as c_int; +pub const EPROTO: c_int = __WASI_EPROTO as c_int; +pub const EPROTONOSUPPORT: c_int = __WASI_EPROTONOSUPPORT as c_int; +pub const EPROTOTYPE: c_int = __WASI_EPROTOTYPE as c_int; +pub const ERANGE: c_int = __WASI_ERANGE as c_int; +pub const EROFS: c_int = __WASI_EROFS as c_int; +pub const ESPIPE: c_int = __WASI_ESPIPE as c_int; +pub const ESRCH: c_int = __WASI_ESRCH as c_int; +pub const ESTALE: c_int = __WASI_ESTALE as c_int; +pub const ETIMEDOUT: c_int = __WASI_ETIMEDOUT as c_int; +pub const ETXTBSY: c_int = __WASI_ETXTBSY as c_int; +pub const EXDEV: c_int = __WASI_EXDEV as c_int; +pub const ENOTCAPABLE: c_int = __WASI_ENOTCAPABLE as c_int; +pub const EOPNOTSUPP: c_int = ENOTSUP; +pub const EWOULDBLOCK: c_int = EAGAIN; + +pub const __WASI_ADVICE_NORMAL: u8 = 0; +pub const __WASI_ADVICE_SEQUENTIAL: u8 = 1; +pub const __WASI_ADVICE_RANDOM: u8 = 2; +pub const __WASI_ADVICE_WILLNEED: u8 = 3; +pub const __WASI_ADVICE_DONTNEED: u8 = 4; +pub const __WASI_ADVICE_NOREUSE: u8 = 5; +pub const __WASI_CLOCK_REALTIME: u32 = 0; +pub const __WASI_CLOCK_MONOTONIC: u32 = 1; +pub const __WASI_CLOCK_PROCESS_CPUTIME_ID: u32 = 2; +pub const __WASI_CLOCK_THREAD_CPUTIME_ID: u32 = 3; +pub const __WASI_DIRCOOKIE_START: u64 = 0; +pub const __WASI_ESUCCESS: u16 = 0; +pub const __WASI_E2BIG: u16 = 1; +pub const __WASI_EACCES: u16 = 2; +pub const __WASI_EADDRINUSE: u16 = 3; +pub const __WASI_EADDRNOTAVAIL: u16 = 4; +pub const __WASI_EAFNOSUPPORT: u16 = 5; +pub const __WASI_EAGAIN: u16 = 6; +pub const __WASI_EALREADY: u16 = 7; +pub const __WASI_EBADF: u16 = 8; +pub const __WASI_EBADMSG: u16 = 9; +pub const __WASI_EBUSY: u16 = 10; +pub const __WASI_ECANCELED: u16 = 11; +pub const __WASI_ECHILD: u16 = 12; +pub const __WASI_ECONNABORTED: u16 = 13; +pub const __WASI_ECONNREFUSED: u16 = 14; +pub const __WASI_ECONNRESET: u16 = 15; +pub const __WASI_EDEADLK: u16 = 16; +pub const __WASI_EDESTADDRREQ: u16 = 17; +pub const __WASI_EDOM: u16 = 18; +pub const __WASI_EDQUOT: u16 = 19; +pub const __WASI_EEXIST: u16 = 20; +pub const __WASI_EFAULT: u16 = 21; +pub const __WASI_EFBIG: u16 = 22; +pub const __WASI_EHOSTUNREACH: u16 = 23; +pub const __WASI_EIDRM: u16 = 24; +pub const __WASI_EILSEQ: u16 = 25; +pub const __WASI_EINPROGRESS: u16 = 26; +pub const __WASI_EINTR: u16 = 27; +pub const __WASI_EINVAL: u16 = 28; +pub const __WASI_EIO: u16 = 29; +pub const __WASI_EISCONN: u16 = 30; +pub const __WASI_EISDIR: u16 = 31; +pub const __WASI_ELOOP: u16 = 32; +pub const __WASI_EMFILE: u16 = 33; +pub const __WASI_EMLINK: u16 = 34; +pub const __WASI_EMSGSIZE: u16 = 35; +pub const __WASI_EMULTIHOP: u16 = 36; +pub const __WASI_ENAMETOOLONG: u16 = 37; +pub const __WASI_ENETDOWN: u16 = 38; +pub const __WASI_ENETRESET: u16 = 39; +pub const __WASI_ENETUNREACH: u16 = 40; +pub const __WASI_ENFILE: u16 = 41; +pub const __WASI_ENOBUFS: u16 = 42; +pub const __WASI_ENODEV: u16 = 43; +pub const __WASI_ENOENT: u16 = 44; +pub const __WASI_ENOEXEC: u16 = 45; +pub const __WASI_ENOLCK: u16 = 46; +pub const __WASI_ENOLINK: u16 = 47; +pub const __WASI_ENOMEM: u16 = 48; +pub const __WASI_ENOMSG: u16 = 49; +pub const __WASI_ENOPROTOOPT: u16 = 50; +pub const __WASI_ENOSPC: u16 = 51; +pub const __WASI_ENOSYS: u16 = 52; +pub const __WASI_ENOTCONN: u16 = 53; +pub const __WASI_ENOTDIR: u16 = 54; +pub const __WASI_ENOTEMPTY: u16 = 55; +pub const __WASI_ENOTRECOVERABLE: u16 = 56; +pub const __WASI_ENOTSOCK: u16 = 57; +pub const __WASI_ENOTSUP: u16 = 58; +pub const __WASI_ENOTTY: u16 = 59; +pub const __WASI_ENXIO: u16 = 60; +pub const __WASI_EOVERFLOW: u16 = 61; +pub const __WASI_EOWNERDEAD: u16 = 62; +pub const __WASI_EPERM: u16 = 63; +pub const __WASI_EPIPE: u16 = 64; +pub const __WASI_EPROTO: u16 = 65; +pub const __WASI_EPROTONOSUPPORT: u16 = 66; +pub const __WASI_EPROTOTYPE: u16 = 67; +pub const __WASI_ERANGE: u16 = 68; +pub const __WASI_EROFS: u16 = 69; +pub const __WASI_ESPIPE: u16 = 70; +pub const __WASI_ESRCH: u16 = 71; +pub const __WASI_ESTALE: u16 = 72; +pub const __WASI_ETIMEDOUT: u16 = 73; +pub const __WASI_ETXTBSY: u16 = 74; +pub const __WASI_EXDEV: u16 = 75; +pub const __WASI_ENOTCAPABLE: u16 = 76; +pub const __WASI_EVENT_FD_READWRITE_HANGUP: u16 = 0x0001; +pub const __WASI_EVENTTYPE_CLOCK: u8 = 0; +pub const __WASI_EVENTTYPE_FD_READ: u8 = 1; +pub const __WASI_EVENTTYPE_FD_WRITE: u8 = 2; +pub const __WASI_FDFLAG_APPEND: u16 = 0x0001; +pub const __WASI_FDFLAG_DSYNC: u16 = 0x0002; +pub const __WASI_FDFLAG_NONBLOCK: u16 = 0x0004; +pub const __WASI_FDFLAG_RSYNC: u16 = 0x0008; +pub const __WASI_FDFLAG_SYNC: u16 = 0x0010; +pub const __WASI_FILETYPE_UNKNOWN: u8 = 0; +pub const __WASI_FILETYPE_BLOCK_DEVICE: u8 = 1; +pub const __WASI_FILETYPE_CHARACTER_DEVICE: u8 = 2; +pub const __WASI_FILETYPE_DIRECTORY: u8 = 3; +pub const __WASI_FILETYPE_REGULAR_FILE: u8 = 4; +pub const __WASI_FILETYPE_SOCKET_DGRAM: u8 = 5; +pub const __WASI_FILETYPE_SOCKET_STREAM: u8 = 6; +pub const __WASI_FILETYPE_SYMBOLIC_LINK: u8 = 7; +pub const __WASI_FILESTAT_SET_ATIM: u16 = 0x0001; +pub const __WASI_FILESTAT_SET_ATIM_NOW: u16 = 0x0002; +pub const __WASI_FILESTAT_SET_MTIM: u16 = 0x0004; +pub const __WASI_FILESTAT_SET_MTIM_NOW: u16 = 0x0008; +pub const __WASI_LOOKUP_SYMLINK_FOLLOW: u32 = 0x00000001; +pub const __WASI_O_CREAT: u16 = 0x0001; +pub const __WASI_O_DIRECTORY: u16 = 0x0002; +pub const __WASI_O_EXCL: u16 = 0x0004; +pub const __WASI_O_TRUNC: u16 = 0x0008; +pub const __WASI_PREOPENTYPE_DIR: u8 = 0; +pub const __WASI_SOCK_RECV_PEEK: u16 = 0x0001; +pub const __WASI_SOCK_RECV_WAITALL: u16 = 0x0002; +pub const __WASI_RIGHT_FD_DATASYNC: u64 = 0x0000000000000001; +pub const __WASI_RIGHT_FD_READ: u64 = 0x0000000000000002; +pub const __WASI_RIGHT_FD_SEEK: u64 = 0x0000000000000004; +pub const __WASI_RIGHT_FD_FDSTAT_SET_FLAGS: u64 = 0x0000000000000008; +pub const __WASI_RIGHT_FD_SYNC: u64 = 0x0000000000000010; +pub const __WASI_RIGHT_FD_TELL: u64 = 0x0000000000000020; +pub const __WASI_RIGHT_FD_WRITE: u64 = 0x0000000000000040; +pub const __WASI_RIGHT_FD_ADVISE: u64 = 0x0000000000000080; +pub const __WASI_RIGHT_FD_ALLOCATE: u64 = 0x0000000000000100; +pub const __WASI_RIGHT_PATH_CREATE_DIRECTORY: u64 = 0x0000000000000200; +pub const __WASI_RIGHT_PATH_CREATE_FILE: u64 = 0x0000000000000400; +pub const __WASI_RIGHT_PATH_LINK_SOURCE: u64 = 0x0000000000000800; +pub const __WASI_RIGHT_PATH_LINK_TARGET: u64 = 0x0000000000001000; +pub const __WASI_RIGHT_PATH_OPEN: u64 = 0x0000000000002000; +pub const __WASI_RIGHT_FD_READDIR: u64 = 0x0000000000004000; +pub const __WASI_RIGHT_PATH_READLINK: u64 = 0x0000000000008000; +pub const __WASI_RIGHT_PATH_RENAME_SOURCE: u64 = 0x0000000000010000; +pub const __WASI_RIGHT_PATH_RENAME_TARGET: u64 = 0x0000000000020000; +pub const __WASI_RIGHT_PATH_FILESTAT_GET: u64 = 0x0000000000040000; +pub const __WASI_RIGHT_PATH_FILESTAT_SET_SIZE: u64 = 0x0000000000080000; +pub const __WASI_RIGHT_PATH_FILESTAT_SET_TIMES: u64 = 0x0000000000100000; +pub const __WASI_RIGHT_FD_FILESTAT_GET: u64 = 0x0000000000200000; +pub const __WASI_RIGHT_FD_FILESTAT_SET_SIZE: u64 = 0x0000000000400000; +pub const __WASI_RIGHT_FD_FILESTAT_SET_TIMES: u64 = 0x0000000000800000; +pub const __WASI_RIGHT_PATH_SYMLINK: u64 = 0x0000000001000000; +pub const __WASI_RIGHT_PATH_REMOVE_DIRECTORY: u64 = 0x0000000002000000; +pub const __WASI_RIGHT_PATH_UNLINK_FILE: u64 = 0x0000000004000000; +pub const __WASI_RIGHT_POLL_FD_READWRITE: u64 = 0x0000000008000000; +pub const __WASI_RIGHT_SOCK_SHUTDOWN: u64 = 0x0000000010000000; +pub const __WASI_SOCK_RECV_DATA_TRUNCATED: u16 = 0x0001; +pub const __WASI_SHUT_RD: u8 = 0x01; +pub const __WASI_SHUT_WR: u8 = 0x02; +pub const __WASI_SIGHUP: u8 = 1; +pub const __WASI_SIGINT: u8 = 2; +pub const __WASI_SIGQUIT: u8 = 3; +pub const __WASI_SIGILL: u8 = 4; +pub const __WASI_SIGTRAP: u8 = 5; +pub const __WASI_SIGABRT: u8 = 6; +pub const __WASI_SIGBUS: u8 = 7; +pub const __WASI_SIGFPE: u8 = 8; +pub const __WASI_SIGKILL: u8 = 9; +pub const __WASI_SIGUSR1: u8 = 10; +pub const __WASI_SIGSEGV: u8 = 11; +pub const __WASI_SIGUSR2: u8 = 12; +pub const __WASI_SIGPIPE: u8 = 13; +pub const __WASI_SIGALRM: u8 = 14; +pub const __WASI_SIGTERM: u8 = 15; +pub const __WASI_SIGCHLD: u8 = 16; +pub const __WASI_SIGCONT: u8 = 17; +pub const __WASI_SIGSTOP: u8 = 18; +pub const __WASI_SIGTSTP: u8 = 19; +pub const __WASI_SIGTTIN: u8 = 20; +pub const __WASI_SIGTTOU: u8 = 21; +pub const __WASI_SIGURG: u8 = 22; +pub const __WASI_SIGXCPU: u8 = 23; +pub const __WASI_SIGXFSZ: u8 = 24; +pub const __WASI_SIGVTALRM: u8 = 25; +pub const __WASI_SIGPROF: u8 = 26; +pub const __WASI_SIGWINCH: u8 = 27; +pub const __WASI_SIGPOLL: u8 = 28; +pub const __WASI_SIGPWR: u8 = 29; +pub const __WASI_SIGSYS: u8 = 30; +pub const __WASI_SUBSCRIPTION_CLOCK_ABSTIME: u16 = 0x0001; +pub const __WASI_WHENCE_CUR: u8 = 0; +pub const __WASI_WHENCE_END: u8 = 1; +pub const __WASI_WHENCE_SET: u8 = 2; + +#[cfg_attr( + feature = "rustc-dep-of-std", + link(name = "c", kind = "static", cfg(target_feature = "crt-static")) +)] +#[cfg_attr( + feature = "rustc-dep-of-std", + link(name = "c", cfg(not(target_feature = "crt-static"))) +)] +extern { + pub fn _Exit(code: c_int) -> !; + pub fn _exit(code: c_int) -> !; + pub fn abort() -> !; + pub fn aligned_alloc(a: size_t, b: size_t) -> *mut c_void; + pub fn calloc(amt: size_t, amt2: size_t) -> *mut c_void; + pub fn exit(code: c_int) -> !; + pub fn free(ptr: *mut c_void); + pub fn getenv(s: *const c_char) -> *mut c_char; + pub fn malloc(amt: size_t) -> *mut c_void; + pub fn malloc_usable_size(ptr: *mut c_void) -> size_t; + pub fn sbrk(increment: ::intptr_t) -> *mut ::c_void; + pub fn rand() -> c_int; + pub fn read(fd: c_int, ptr: *mut c_void, size: size_t) -> ssize_t; + pub fn realloc(ptr: *mut c_void, amt: size_t) -> *mut c_void; + pub fn setenv(k: *const c_char, v: *const c_char, a: c_int) -> c_int; + pub fn unsetenv(k: *const c_char) -> c_int; + pub fn clearenv() -> ::c_int; + pub fn write(fd: c_int, ptr: *const c_void, size: size_t) -> ssize_t; + pub static mut environ: *mut *mut c_char; + pub fn fopen(a: *const c_char, b: *const c_char) -> *mut FILE; + pub fn freopen( + a: *const c_char, + b: *const c_char, + f: *mut FILE, + ) -> *mut FILE; + pub fn fclose(f: *mut FILE) -> c_int; + pub fn remove(a: *const c_char) -> c_int; + pub fn rename(a: *const c_char, b: *const c_char) -> c_int; + pub fn feof(f: *mut FILE) -> c_int; + pub fn ferror(f: *mut FILE) -> c_int; + pub fn fflush(f: *mut FILE) -> c_int; + pub fn clearerr(f: *mut FILE); + pub fn fseek(f: *mut FILE, b: c_long, c: c_int) -> c_int; + pub fn ftell(f: *mut FILE) -> c_long; + pub fn rewind(f: *mut FILE); + pub fn fgetpos(f: *mut FILE, pos: *mut fpos_t) -> c_int; + pub fn fsetpos(f: *mut FILE, pos: *const fpos_t) -> c_int; + pub fn fread( + buf: *mut c_void, + a: size_t, + b: size_t, + f: *mut FILE, + ) -> size_t; + pub fn fwrite( + buf: *const c_void, + a: size_t, + b: size_t, + f: *mut FILE, + ) -> size_t; + pub fn fgetc(f: *mut FILE) -> c_int; + pub fn getc(f: *mut FILE) -> c_int; + pub fn getchar() -> c_int; + pub fn ungetc(a: c_int, f: *mut FILE) -> c_int; + pub fn fputc(a: c_int, f: *mut FILE) -> c_int; + pub fn putc(a: c_int, f: *mut FILE) -> c_int; + pub fn putchar(a: c_int) -> c_int; + pub fn fputs(a: *const c_char, f: *mut FILE) -> c_int; + pub fn puts(a: *const c_char) -> c_int; + pub fn perror(a: *const c_char); + pub fn srand(a: c_uint); + pub fn atexit(a: extern fn()) -> c_int; + pub fn at_quick_exit(a: extern fn()) -> c_int; + pub fn quick_exit(a: c_int) -> !; + pub fn posix_memalign(a: *mut *mut c_void, b: size_t, c: size_t) -> c_int; + pub fn rand_r(a: *mut c_uint) -> c_int; + pub fn random() -> c_long; + pub fn srandom(a: c_uint); + pub fn putenv(a: *mut c_char) -> c_int; + pub fn clock() -> clock_t; + pub fn time(a: *mut time_t) -> time_t; + pub fn difftime(a: time_t, b: time_t) -> c_double; + pub fn mktime(a: *mut tm) -> time_t; + pub fn strftime( + a: *mut c_char, + b: size_t, + c: *const c_char, + d: *const tm, + ) -> size_t; + pub fn gmtime(a: *const time_t) -> *mut tm; + pub fn gmtime_r(a: *const time_t, b: *mut tm) -> *mut tm; + pub fn localtime_r(a: *const time_t, b: *mut tm) -> *mut tm; + pub fn asctime_r(a: *const tm, b: *mut c_char) -> *mut c_char; + pub fn ctime_r(a: *const time_t, b: *mut c_char) -> *mut c_char; + + pub fn nanosleep(a: *const timespec, b: *mut timespec) -> c_int; + // pub fn clock_getres(a: clockid_t, b: *mut timespec) -> c_int; + // pub fn clock_gettime(a: clockid_t, b: *mut timespec) -> c_int; + // pub fn clock_nanosleep( + // a: clockid_t, + // a2: c_int, + // b: *const timespec, + // c: *mut timespec, + // ) -> c_int; + + pub fn isalnum(c: c_int) -> c_int; + pub fn isalpha(c: c_int) -> c_int; + pub fn iscntrl(c: c_int) -> c_int; + pub fn isdigit(c: c_int) -> c_int; + pub fn isgraph(c: c_int) -> c_int; + pub fn islower(c: c_int) -> c_int; + pub fn isprint(c: c_int) -> c_int; + pub fn ispunct(c: c_int) -> c_int; + pub fn isspace(c: c_int) -> c_int; + pub fn isupper(c: c_int) -> c_int; + pub fn isxdigit(c: c_int) -> c_int; + pub fn tolower(c: c_int) -> c_int; + pub fn toupper(c: c_int) -> c_int; + pub fn setvbuf( + stream: *mut FILE, + buffer: *mut c_char, + mode: c_int, + size: size_t, + ) -> c_int; + pub fn setbuf(stream: *mut FILE, buf: *mut c_char); + pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) + -> *mut c_char; + pub fn atoi(s: *const c_char) -> c_int; + pub fn atof(s: *const c_char) -> c_double; + pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; + pub fn strtol( + s: *const c_char, + endp: *mut *mut c_char, + base: c_int, + ) -> c_long; + pub fn strtoul( + s: *const c_char, + endp: *mut *mut c_char, + base: c_int, + ) -> c_ulong; + + pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; + pub fn strncpy( + dst: *mut c_char, + src: *const c_char, + n: size_t, + ) -> *mut c_char; + pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; + pub fn strncat( + s: *mut c_char, + ct: *const c_char, + n: size_t, + ) -> *mut c_char; + pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; + pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; + pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; + pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; + pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; + pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; + pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; + pub fn strdup(cs: *const c_char) -> *mut c_char; + pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; + pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; + pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; + pub fn strncasecmp( + s1: *const c_char, + s2: *const c_char, + n: size_t, + ) -> c_int; + pub fn strlen(cs: *const c_char) -> size_t; + pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; + pub fn strerror(n: c_int) -> *mut c_char; + pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; + pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; + + pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; + pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; + pub fn memcpy( + dest: *mut c_void, + src: *const c_void, + n: size_t, + ) -> *mut c_void; + pub fn memmove( + dest: *mut c_void, + src: *const c_void, + n: size_t, + ) -> *mut c_void; + pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; + + pub fn fprintf( + stream: *mut ::FILE, + format: *const ::c_char, + ... + ) -> ::c_int; + pub fn printf(format: *const ::c_char, ...) -> ::c_int; + pub fn snprintf( + s: *mut ::c_char, + n: ::size_t, + format: *const ::c_char, + ... + ) -> ::c_int; + pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int; + pub fn fscanf( + stream: *mut ::FILE, + format: *const ::c_char, + ... + ) -> ::c_int; + pub fn scanf(format: *const ::c_char, ...) -> ::c_int; + pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) + -> ::c_int; + pub fn getchar_unlocked() -> ::c_int; + pub fn putchar_unlocked(c: ::c_int) -> ::c_int; + + pub fn shutdown(socket: ::c_int, how: ::c_int) -> ::c_int; + pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; + pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int; + pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; + pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; + pub fn fileno(stream: *mut ::FILE) -> ::c_int; + pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; + pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int; + pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int; + pub fn opendir(dirname: *const c_char) -> *mut ::DIR; + pub fn fdopendir(fd: ::c_int) -> *mut ::DIR; + pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; + pub fn closedir(dirp: *mut ::DIR) -> ::c_int; + pub fn rewinddir(dirp: *mut ::DIR); + pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; + + pub fn openat( + dirfd: ::c_int, + pathname: *const ::c_char, + flags: ::c_int, + ... + ) -> ::c_int; + pub fn fstatat( + dirfd: ::c_int, + pathname: *const ::c_char, + buf: *mut stat, + flags: ::c_int, + ) -> ::c_int; + pub fn linkat( + olddirfd: ::c_int, + oldpath: *const ::c_char, + newdirfd: ::c_int, + newpath: *const ::c_char, + flags: ::c_int, + ) -> ::c_int; + pub fn mkdirat( + dirfd: ::c_int, + pathname: *const ::c_char, + mode: ::mode_t, + ) -> ::c_int; + pub fn readlinkat( + dirfd: ::c_int, + pathname: *const ::c_char, + buf: *mut ::c_char, + bufsiz: ::size_t, + ) -> ::ssize_t; + pub fn renameat( + olddirfd: ::c_int, + oldpath: *const ::c_char, + newdirfd: ::c_int, + newpath: *const ::c_char, + ) -> ::c_int; + pub fn symlinkat( + target: *const ::c_char, + newdirfd: ::c_int, + linkpath: *const ::c_char, + ) -> ::c_int; + pub fn unlinkat( + dirfd: ::c_int, + pathname: *const ::c_char, + flags: ::c_int, + ) -> ::c_int; + + pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; + pub fn close(fd: ::c_int) -> ::c_int; + pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> c_long; + pub fn getopt( + argc: ::c_int, + argv: *const *mut c_char, + optstr: *const c_char, + ) -> ::c_int; + pub fn isatty(fd: ::c_int) -> ::c_int; + pub fn link(src: *const c_char, dst: *const c_char) -> ::c_int; + pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t; + pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long; + pub fn pause() -> ::c_int; + pub fn rmdir(path: *const c_char) -> ::c_int; + pub fn sleep(secs: ::c_uint) -> ::c_uint; + pub fn unlink(c: *const c_char) -> ::c_int; + pub fn pread( + fd: ::c_int, + buf: *mut ::c_void, + count: ::size_t, + offset: off_t, + ) -> ::ssize_t; + pub fn pwrite( + fd: ::c_int, + buf: *const ::c_void, + count: ::size_t, + offset: off_t, + ) -> ::ssize_t; + + pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int; + + pub fn fsync(fd: ::c_int) -> ::c_int; + pub fn fdatasync(fd: ::c_int) -> ::c_int; + + pub fn symlink(path1: *const c_char, path2: *const c_char) -> ::c_int; + + pub fn truncate(path: *const c_char, length: off_t) -> ::c_int; + pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int; + + pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int; + + pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; + pub fn times(buf: *mut ::tms) -> ::clock_t; + + pub fn strerror_r( + errnum: ::c_int, + buf: *mut c_char, + buflen: ::size_t, + ) -> ::c_int; + + pub fn usleep(secs: ::c_uint) -> ::c_int; + pub fn send( + socket: ::c_int, + buf: *const ::c_void, + len: ::size_t, + flags: ::c_int, + ) -> ::ssize_t; + pub fn recv( + socket: ::c_int, + buf: *mut ::c_void, + len: ::size_t, + flags: ::c_int, + ) -> ::ssize_t; + pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int; + pub fn setlocale( + category: ::c_int, + locale: *const ::c_char, + ) -> *mut ::c_char; + pub fn localeconv() -> *mut lconv; + + pub fn readlink( + path: *const c_char, + buf: *mut c_char, + bufsz: ::size_t, + ) -> ::ssize_t; + + pub fn timegm(tm: *mut ::tm) -> time_t; + + pub fn sysconf(name: ::c_int) -> ::c_long; + + pub fn fseeko( + stream: *mut ::FILE, + offset: ::off_t, + whence: ::c_int, + ) -> ::c_int; + pub fn ftello(stream: *mut ::FILE) -> ::off_t; + pub fn posix_fallocate( + fd: ::c_int, + offset: ::off_t, + len: ::off_t, + ) -> ::c_int; + + pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char; + pub fn getline( + lineptr: *mut *mut c_char, + n: *mut size_t, + stream: *mut FILE, + ) -> ssize_t; + + pub fn faccessat( + dirfd: ::c_int, + pathname: *const ::c_char, + mode: ::c_int, + flags: ::c_int, + ) -> ::c_int; + pub fn writev( + fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int, + ) -> ::ssize_t; + pub fn readv( + fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int, + ) -> ::ssize_t; + pub fn pwritev( + fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int, + offset: ::off_t, + ) -> ::ssize_t; + pub fn preadv( + fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int, + offset: ::off_t, + ) -> ::ssize_t; + pub fn posix_fadvise( + fd: ::c_int, + offset: ::off_t, + len: ::off_t, + advise: ::c_int, + ) -> ::c_int; + pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; + pub fn utimensat( + dirfd: ::c_int, + path: *const ::c_char, + times: *const ::timespec, + flag: ::c_int, + ) -> ::c_int; + pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int; + pub fn memrchr( + cx: *const ::c_void, + c: ::c_int, + n: ::size_t, + ) -> *mut ::c_void; + pub fn abs(i: c_int) -> c_int; + pub fn labs(i: c_long) -> c_long; + pub fn duplocale(base: ::locale_t) -> ::locale_t; + pub fn freelocale(loc: ::locale_t); + pub fn newlocale( + mask: ::c_int, + locale: *const ::c_char, + base: ::locale_t, + ) -> ::locale_t; + pub fn uselocale(loc: ::locale_t) -> ::locale_t; + pub fn sched_yield() -> ::c_int; + + pub fn __wasilibc_register_preopened_fd( + fd: c_int, + path: *const c_char, + ) -> c_int; + pub fn __wasilibc_fd_renumber(fd: c_int, newfd: c_int) -> c_int; + pub fn __wasilibc_unlinkat(fd: c_int, path: *const c_char) -> c_int; + pub fn __wasilibc_rmdirat(fd: c_int, path: *const c_char) -> c_int; + pub fn __wasilibc_init_preopen(); + pub fn __wasilibc_find_relpath( + path: *const c_char, + rights_base: __wasi_rights_t, + rights_inheriting: __wasi_rights_t, + relative_path: *mut *const c_char, + ) -> c_int; + pub fn __wasilibc_tell(fd: c_int) -> ::off_t; + + pub fn arc4random() -> u32; + pub fn arc4random_buf(a: *mut c_void, b: size_t); + pub fn arc4random_uniform(a: u32) -> u32; +} + +#[link(wasm_import_module = "wasi_unstable")] +extern { + #[link_name = "clock_res_get"] + pub fn __wasi_clock_res_get( + clock_id: __wasi_clockid_t, + resolution: *mut __wasi_timestamp_t, + ) -> __wasi_errno_t; + #[link_name = "clock_time_get"] + pub fn __wasi_clock_time_get( + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: *mut __wasi_timestamp_t, + ) -> __wasi_errno_t; + #[link_name = "fd_close"] + pub fn __wasi_fd_close(fd: __wasi_fd_t) -> __wasi_errno_t; + #[link_name = "fd_datasync"] + pub fn __wasi_fd_datasync(fd: __wasi_fd_t) -> __wasi_errno_t; + #[link_name = "fd_pread"] + pub fn __wasi_fd_pread( + fd: __wasi_fd_t, + iovs: *const __wasi_iovec_t, + iovs_len: size_t, + offset: __wasi_filesize_t, + nread: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "fd_pwrite"] + pub fn __wasi_fd_pwrite( + fd: __wasi_fd_t, + iovs: *const __wasi_ciovec_t, + iovs_len: size_t, + offset: __wasi_filesize_t, + nwritten: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "fd_read"] + pub fn __wasi_fd_read( + fd: __wasi_fd_t, + iovs: *const __wasi_iovec_t, + iovs_len: size_t, + nread: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "fd_renumber"] + pub fn __wasi_fd_renumber( + from: __wasi_fd_t, + to: __wasi_fd_t, + ) -> __wasi_errno_t; + #[link_name = "fd_seek"] + pub fn __wasi_fd_seek( + fd: __wasi_fd_t, + offset: __wasi_filedelta_t, + whence: __wasi_whence_t, + newoffset: *mut __wasi_filesize_t, + ) -> __wasi_errno_t; + #[link_name = "fd_tell"] + pub fn __wasi_fd_tell( + fd: __wasi_fd_t, + newoffset: *mut __wasi_filesize_t, + ) -> __wasi_errno_t; + #[link_name = "fd_fdstat_get"] + pub fn __wasi_fd_fdstat_get( + fd: __wasi_fd_t, + buf: *mut __wasi_fdstat_t, + ) -> __wasi_errno_t; + #[link_name = "fd_fdstat_set_flags"] + pub fn __wasi_fd_fdstat_set_flags( + fd: __wasi_fd_t, + flags: __wasi_fdflags_t, + ) -> __wasi_errno_t; + #[link_name = "fd_fdstat_set_rights"] + pub fn __wasi_fd_fdstat_set_rights( + fd: __wasi_fd_t, + fs_rights_base: __wasi_rights_t, + fs_rights_inheriting: __wasi_rights_t, + ) -> __wasi_errno_t; + #[link_name = "fd_sync"] + pub fn __wasi_fd_sync(fd: __wasi_fd_t) -> __wasi_errno_t; + #[link_name = "fd_write"] + pub fn __wasi_fd_write( + fd: __wasi_fd_t, + iovs: *const __wasi_ciovec_t, + iovs_len: size_t, + nwritten: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "fd_advise"] + pub fn __wasi_fd_advise( + fd: __wasi_fd_t, + offset: __wasi_filesize_t, + len: __wasi_filesize_t, + advice: __wasi_advice_t, + ) -> __wasi_errno_t; + #[link_name = "fd_allocate"] + pub fn __wasi_fd_allocate( + fd: __wasi_fd_t, + offset: __wasi_filesize_t, + len: __wasi_filesize_t, + ) -> __wasi_errno_t; + #[link_name = "path_create_directory"] + pub fn __wasi_path_create_directory( + fd: __wasi_fd_t, + path: *const ::c_char, + path_len: size_t, + ) -> __wasi_errno_t; + #[link_name = "path_link"] + pub fn __wasi_path_link( + old_fd: __wasi_fd_t, + old_flags: __wasi_lookupflags_t, + old_path: *const ::c_char, + old_path_len: size_t, + new_fd: __wasi_fd_t, + new_path: *const ::c_char, + new_path_len: size_t, + ) -> __wasi_errno_t; + #[link_name = "path_open"] + pub fn __wasi_path_open( + dirfd: __wasi_fd_t, + dirflags: __wasi_lookupflags_t, + path: *const ::c_char, + path_len: size_t, + oflags: __wasi_oflags_t, + fs_rights_base: __wasi_rights_t, + fs_rights_inheriting: __wasi_rights_t, + fs_flags: __wasi_fdflags_t, + fd: *mut __wasi_fd_t, + ) -> __wasi_errno_t; + #[link_name = "fd_readdir"] + pub fn __wasi_fd_readdir( + fd: __wasi_fd_t, + buf: *mut ::c_void, + buf_len: size_t, + cookie: __wasi_dircookie_t, + bufused: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "path_readlink"] + pub fn __wasi_path_readlink( + fd: __wasi_fd_t, + path: *const ::c_char, + path_len: size_t, + buf: *mut ::c_char, + buf_len: size_t, + bufused: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "path_rename"] + pub fn __wasi_path_rename( + old_fd: __wasi_fd_t, + old_path: *const ::c_char, + old_path_len: size_t, + new_fd: __wasi_fd_t, + new_path: *const ::c_char, + new_path_len: size_t, + ) -> __wasi_errno_t; + #[link_name = "fd_filestat_get"] + pub fn __wasi_fd_filestat_get( + fd: __wasi_fd_t, + buf: *mut __wasi_filestat_t, + ) -> __wasi_errno_t; + #[link_name = "fd_filestat_set_times"] + pub fn __wasi_fd_filestat_set_times( + fd: __wasi_fd_t, + st_atim: __wasi_timestamp_t, + st_mtim: __wasi_timestamp_t, + fstflags: __wasi_fstflags_t, + ) -> __wasi_errno_t; + #[link_name = "fd_filestat_set_size"] + pub fn __wasi_fd_filestat_set_size( + fd: __wasi_fd_t, + st_size: __wasi_filesize_t, + ) -> __wasi_errno_t; + #[link_name = "path_filestat_get"] + pub fn __wasi_path_filestat_get( + fd: __wasi_fd_t, + flags: __wasi_lookupflags_t, + path: *const ::c_char, + path_len: size_t, + buf: *mut __wasi_filestat_t, + ) -> __wasi_errno_t; + #[link_name = "path_filestat_set_times"] + pub fn __wasi_path_filestat_set_times( + fd: __wasi_fd_t, + flags: __wasi_lookupflags_t, + path: *const ::c_char, + path_len: size_t, + st_atim: __wasi_timestamp_t, + st_mtim: __wasi_timestamp_t, + fstflags: __wasi_fstflags_t, + ) -> __wasi_errno_t; + #[link_name = "path_symlink"] + pub fn __wasi_path_symlink( + old_path: *const ::c_char, + old_path_len: size_t, + fd: __wasi_fd_t, + new_path: *const ::c_char, + new_path_len: size_t, + ) -> __wasi_errno_t; + #[link_name = "path_unlink_file"] + pub fn __wasi_path_unlink_file( + fd: __wasi_fd_t, + path: *const ::c_char, + path_len: size_t, + ) -> __wasi_errno_t; + #[link_name = "path_remove_directory"] + pub fn __wasi_path_remove_directory( + fd: __wasi_fd_t, + path: *const ::c_char, + path_len: size_t, + ) -> __wasi_errno_t; + #[link_name = "poll_oneoff"] + pub fn __wasi_poll_oneoff( + in_: *const __wasi_subscription_t, + out: *mut __wasi_event_t, + nsubscriptions: size_t, + nevents: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "proc_exit"] + pub fn __wasi_proc_exit(rval: __wasi_exitcode_t); + #[link_name = "proc_raise"] + pub fn __wasi_proc_raise(sig: __wasi_signal_t) -> __wasi_errno_t; + #[link_name = "random_get"] + pub fn __wasi_random_get( + buf: *mut ::c_void, + buf_len: size_t, + ) -> __wasi_errno_t; + #[link_name = "sock_recv"] + pub fn __wasi_sock_recv( + sock: __wasi_fd_t, + ri_data: *const __wasi_iovec_t, + ri_data_len: size_t, + ri_flags: __wasi_riflags_t, + ro_datalen: *mut size_t, + ro_flags: *mut __wasi_roflags_t, + ) -> __wasi_errno_t; + #[link_name = "sock_send"] + pub fn __wasi_sock_send( + sock: __wasi_fd_t, + si_data: *const __wasi_ciovec_t, + si_data_len: size_t, + si_flags: __wasi_siflags_t, + so_datalen: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "sock_shutdown"] + pub fn __wasi_sock_shutdown( + sock: __wasi_fd_t, + how: __wasi_sdflags_t, + ) -> __wasi_errno_t; + #[link_name = "sched_yield"] + pub fn __wasi_sched_yield() -> __wasi_errno_t; + #[link_name = "args_get"] + pub fn __wasi_args_get( + argv: *mut *mut c_char, + argv_buf: *mut c_char, + ) -> __wasi_errno_t; + #[link_name = "args_sizes_get"] + pub fn __wasi_args_sizes_get( + argc: *mut size_t, + argv_buf_size: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "environ_get"] + pub fn __wasi_environ_get( + environ: *mut *mut c_char, + environ_buf: *mut c_char, + ) -> __wasi_errno_t; + #[link_name = "environ_sizes_get"] + pub fn __wasi_environ_sizes_get( + environ_count: *mut size_t, + environ_buf_size: *mut size_t, + ) -> __wasi_errno_t; + #[link_name = "fd_prestat_get"] + pub fn __wasi_fd_prestat_get( + fd: __wasi_fd_t, + buf: *mut __wasi_prestat_t, + ) -> __wasi_errno_t; + #[link_name = "fd_prestat_dir_name"] + pub fn __wasi_fd_prestat_dir_name( + fd: __wasi_fd_t, + path: *mut c_char, + path_len: size_t, + ) -> __wasi_errno_t; +} diff --git a/libc/src/windows/mod.rs b/libc/src/windows/mod.rs index 4bea459..70ca675 100644 --- a/libc/src/windows/mod.rs +++ b/libc/src/windows/mod.rs @@ -47,7 +47,12 @@ cfg_if! { pub type off_t = i32; pub type dev_t = u32; pub type ino_t = u16; +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum timezone {} +impl ::Copy for timezone {} +impl ::Clone for timezone { + fn clone(&self) -> timezone { *self } +} pub type time64_t = i64; pub type SOCKET = ::uintptr_t; @@ -201,8 +206,18 @@ pub const SIG_ERR: ::c_int = -1; #[link(name = "libcmt", cfg(target_feature = "crt-static"))] extern {} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum FILE {} +impl ::Copy for FILE {} +impl ::Clone for FILE { + fn clone(&self) -> FILE { *self } +} +#[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos_t {} // TODO: fill this out with a struct +impl ::Copy for fpos_t {} +impl ::Clone for fpos_t { + fn clone(&self) -> fpos_t { *self } +} extern { pub fn isalnum(c: c_int) -> c_int; @@ -419,13 +434,15 @@ extern "system" { } cfg_if! { - if #[cfg(core_cvoid)] { - pub use core::ffi::c_void; + if #[cfg(libc_core_cvoid)] { + pub use ::ffi::c_void; } else { // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help // enable more optimization opportunities around it recognizing things // like malloc/free. #[repr(u8)] + #[allow(missing_copy_implementations)] + #[allow(missing_debug_implementations)] pub enum c_void { // Two dummy variants so the #[repr] attribute can be used. #[doc(hidden)] @@ -446,4 +463,4 @@ cfg_if! { } else { // Unknown target_env } -}
\ No newline at end of file +} diff --git a/nitrocli/CHANGELOG.md b/nitrocli/CHANGELOG.md index 57f8894..5b0e1b9 100644 --- a/nitrocli/CHANGELOG.md +++ b/nitrocli/CHANGELOG.md @@ -3,7 +3,7 @@ Unreleased - Added the `reset` command to perform a factory reset - Added the `-V`/`--version` option to print the program's version - Check the status of a PWS slot before accessing it in `pws get` -- Bumped `libc` dependency to `0.2.48` +- Bumped `libc` dependency to `0.2.55` 0.2.3 diff --git a/nitrocli/Cargo.lock b/nitrocli/Cargo.lock index 44c9d45..4af411b 100644 --- a/nitrocli/Cargo.lock +++ b/nitrocli/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "aho-corasick" version = "0.6.9" @@ -57,7 +59,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.48" +version = "0.2.55" [[package]] name = "memchr" @@ -65,7 +67,7 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48", + "libc 0.2.55", ] [[package]] @@ -74,7 +76,7 @@ version = "0.2.3" dependencies = [ "argparse 0.2.2", "base32 0.4.0", - "libc 0.2.48", + "libc 0.2.55", "nitrokey 0.3.4", "nitrokey-test 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -84,7 +86,7 @@ dependencies = [ name = "nitrokey" version = "0.3.4" dependencies = [ - "libc 0.2.48", + "libc 0.2.55", "nitrokey-sys 3.4.3", "rand_core 0.3.0", "rand_os 0.1.1", @@ -133,7 +135,7 @@ version = "0.1.1" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48", + "libc 0.2.55", "rand_core 0.3.0", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", |