diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/mach | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/mach')
43 files changed, 2378 insertions, 0 deletions
diff --git a/third_party/rust/mach/.cargo-checksum.json b/third_party/rust/mach/.cargo-checksum.json new file mode 100644 index 0000000000..0158b060d2 --- /dev/null +++ b/third_party/rust/mach/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"6cf25dae1f0fd842fb63275ae47904879e66b36290f6fc7ed02090f3ac657b51","LICENSE.md":"399507a62fba271ddb3e24dc857e85b571fbb76435546f51b212cf04d8463f58","README.md":"8e5094a355def0f762dcc92fd68f475bb65016dd0fbeadc0d8a50303d6fb5381","ci/build_fail.sh":"6c2401edd356a43739ef6c27deccfc7703f883ff8d21f49395d8edb806542728","ci/deploy_and_run_on_ios_simulator.rs":"acde74c117544575b2e7ef7531759ec0a6e28bd65d69da16944c746f711ec27d","ci/run.sh":"2eef6140f5f53373f961c682d2b292f8d4b57b2124f1f0e53d5168db27f38d52","examples/dump_process_registers.rs":"e9d0d023cb2cc8272f239cd134152dfa0169017c2a454db1490d2f4548efe6c8","src/boolean.rs":"1d24ea9872748881cd7269a383a7c344e3a650df23f0e44e3b6c266fb8205d9a","src/bootstrap.rs":"a5ab69d74ad8bfb8fad1cb45c8c571977c0bf907a70e767309a437580cee184c","src/clock.rs":"a33c1bfb2f174abb695d164c469ee744be52fec4bc345656e6027d063e150d71","src/clock_priv.rs":"a8e6a96896a94eda67c9fb6e45c564581a711cc9fdcf7674251bb6c0c28b47c2","src/clock_reply.rs":"bac04b6602dcdd4daac8e3a0a1e56fa4b6de20cf2c3fe7bb583358166aca8a3b","src/clock_types.rs":"d55d1d2a953e477f9dd064bd684b118235aa7bd79de85cdeaf75e21510aaaefa","src/dyld_kernel.rs":"566a17f597aa29619a1ce15f6b22577fc70ac5356f96e00fddbcb28560a5c83c","src/exc.rs":"2246493bef2c596b92f115ab673a10d50c6003d11abb8e73d7707ebc19e8ae5a","src/exception_types.rs":"c7894831d73145adb1a4b5d2a5d0b346f2b2dc05382b97f2f3f0275d337f6dfc","src/kern_return.rs":"153339995674136ef05d9595bdcf831595db0d0714a737ecd1ccd45391c56657","src/lib.rs":"7570054fdec1fb73200cb1cf736c97bdeeb82f2aef78aec11e8498af769bba86","src/mach_init.rs":"df49bd287fd05fb74bc76254df7607fad0d6b90cb20da803e9f9a1dc2fcfe2fc","src/mach_port.rs":"07e300871eac4687ccc98d725e550482f136f9780f9f353a0f01f768bc58229b","src/mach_time.rs":"b9493e820acf21fee1f6e7e82a510d887925dc1117d6b71b681acc40cfa776af","src/mach_types.rs":"e2d17741ebcdcdff9686ec9ee5c90fb7a150ce990979507da01c351771fb3a19","src/memory_object_types.rs":"6fcb446c00ddd5ef4920efe618bd89df2e87f7ae3cf660a2bc1d25cf1f331dc2","src/message.rs":"501e743438342ea37cf7db81d6ebd17528da9d78e77d1f1643412e7dc569649f","src/port.rs":"36fc636e2cae2c1f69246b54eb3ca2b33d7e75846df50587fb14597d34b05594","src/structs.rs":"132e21e91313e6ec13e3ad5ed9c71852e8a55fbbaba449dbb1b3ca889bed4889","src/task.rs":"282ea602db2d08711785e0050a06b322a3fe4a4aac34b3c9116fe13e033898dd","src/task_info.rs":"cf87cffe567fee8871e0ce9762b7d8bbd5058dfbb309678d382149dedbe7f14a","src/thread_act.rs":"647198e0f9e3fe409a0610ee98560de3af4f152bcc4761f943e67723193b8a25","src/thread_status.rs":"3fe98fadd61ce01b4f9dc3bc0ef8c9496798f0147822a4ddffe5d0eaf2f32c0a","src/traps.rs":"a15d0dc206c53cf69cb9d11c6ed5477b7dd9937ea68b5a453011be9d004c44a9","src/vm.rs":"9edecf858dcd8e22efbc6ad1838cbfa6a0fc5b334bd21d87b3f05d24058b549e","src/vm_attributes.rs":"55fd9c1661a147a4e374051a6da1884f0c9629aabc514e01561f0e0c365aa18a","src/vm_behavior.rs":"a5d195a52602f5ebe2991774c2390a6f20f1bfa82168dd62e88f2804134da1f3","src/vm_inherit.rs":"dbc7432350869733d6e7cf1da8617d97aafbeb1afcb1bdc60ed7ab53e37abf61","src/vm_page_size.rs":"9e5333f750cd7380465cd34b4611c1f7b5251c11befca0d4482a323e0b1c20b2","src/vm_prot.rs":"15f8f82fbdd67ed31185abd5cc3418332f4371d39ecef6a7e47ddf17bdb5146c","src/vm_purgable.rs":"a39a9fcd85f0394cd169c888e2d7e461d56bf97cf9f81a384df06262e40c9f24","src/vm_region.rs":"d95de52828f28987fa95eb54327b2d278f31769091befb653d286b21d51efc73","src/vm_statistics.rs":"49b452bf56080200d6bf3c32ae8b6642b142fbb13560849ef6a2dc96b650ab4a","src/vm_sync.rs":"4897306cf6c57929830766253637c9adc475e472949a351efc8ada28c20e0d0f","src/vm_types.rs":"a47f71193172ce233018dfd40de2b9a56cdfcdfb18e04c1c0761cb6fc36f51b8"},"package":"b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa"}
\ No newline at end of file diff --git a/third_party/rust/mach/Cargo.toml b/third_party/rust/mach/Cargo.toml new file mode 100644 index 0000000000..ea6d375c2c --- /dev/null +++ b/third_party/rust/mach/Cargo.toml @@ -0,0 +1,46 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +edition = "2015" +name = "mach" +version = "0.3.2" +authors = ["Nick Fitzgerald <fitzgen@gmail.com>", "David Cuddeback <david.cuddeback@gmail.com>", "Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>"] +description = "A Rust interface to the user-space API of the Mach 3.0 kernel that underlies OSX." +readme = "README.md" +keywords = ["kernel", "macos", "darwin"] +categories = ["api-bindings", "external-ffi-bindings", "no-std", "os"] +license = "BSD-2-Clause" +repository = "https://github.com/fitzgen/mach" + +[features] +default = [] +deprecated = [] +rustc-dep-of-std = ["rustc-std-workspace-core", "libc/rustc-dep-of-std"] +[target."cfg(any(target_os = \"macos\", target_os = \"ios\"))".dependencies.libc] +version = "0.2" +default-features = false + +[target."cfg(any(target_os = \"macos\", target_os = \"ios\"))".dependencies.rustc-std-workspace-core] +version = "1.0.0" +optional = true +[badges.is-it-maintained-issue-resolution] +repository = "fitzgen/mach" + +[badges.is-it-maintained-open-issues] +repository = "fitzgen/mach" + +[badges.maintenance] +status = "passively-maintained" + +[badges.travis-ci] +repository = "fitzgen/mach" diff --git a/third_party/rust/mach/LICENSE.md b/third_party/rust/mach/LICENSE.md new file mode 100644 index 0000000000..ee1e887d14 --- /dev/null +++ b/third_party/rust/mach/LICENSE.md @@ -0,0 +1,23 @@ +Copyright (c) 2015, Nick Fitzgerald +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/third_party/rust/mach/README.md b/third_party/rust/mach/README.md new file mode 100644 index 0000000000..cb5f93b756 --- /dev/null +++ b/third_party/rust/mach/README.md @@ -0,0 +1,55 @@ +[![Build Status][travis_ci_badge]][travis_ci] [![Latest Version]][crates.io] [![docs]][docs.rs] + +A Rust interface to the **user-space** API of the Mach 3.0 kernel exposed in +`/usr/include/mach` that underlies macOS and is linked via `libSystem` (and +`libsystem_kernel`). + +This library does not expose the **kernel-space** API of the Mach 3.0 kernel +exposed in +`SDK/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/mach`. + +That is, if you are writing a kernel-resident device drivers or some other +kernel extensions you have to use something else. The user-space kernel API is +often API-incompatible with the kernel space one, and even in the cases where +they match, they are sometimes ABI incompatible such that using this library +would have **undefined behavior**. + +# Usage + +Add the following to your `Cargo.toml` to conditionally include mach on those +platforms that support it. + +```toml +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.mach] +version = "0.3" +``` + +The following crate features are available: + +* **deprecated** (disabled by default): exposes deprecated APIs that have been + removed from the latest versions of the MacOS SDKs. The behavior of using + these APIs on MacOS versions that do not support them is undefined (hopefully + a linker error). + +# Platform support + +The following table describes the current CI set-up: + +| Target | Min. Rust | XCode | build | ctest | run | +|-----------------------|-----------|---------------|-------|-------|-----| +| `x86_64-apple-darwin` | 1.33.0 | 6.4 - 10.0 | ✓ | ✓ | ✓ | +| `i686-apple-darwin` | 1.33.0 | 6.4 - 10.0 | ✓ | ✓ | ✓ | +| `i386-apple-ios` | 1.33.0 | 6.4 - 9.4 [0] | ✓ | - | - | +| `x86_64-apple-ios` | 1.33.0 | 6.4 - 10.0 | ✓ | - | - | +| `armv7-apple-ios` | nightly | 6.4 - 10.0 | ✓ | - | - | +| `aarch64-apple-ios` | nightly | 6.4 - 10.0 | ✓ | - | - | + +[0] `i386-apple-ios` is deprecated in XCode 10.0. + +[travis_ci]: https://travis-ci.org/fitzgen/mach +[travis_ci_badge]: https://travis-ci.org/fitzgen/mach.png?branch=master +[crates.io]: https://crates.io/crates/mach +[Latest Version]: https://img.shields.io/crates/v/mach.svg +[docs]: https://docs.rs/mach/badge.svg +[docs.rs]: https://docs.rs/mach/ + diff --git a/third_party/rust/mach/ci/build_fail.sh b/third_party/rust/mach/ci/build_fail.sh new file mode 100755 index 0000000000..ef35965468 --- /dev/null +++ b/third_party/rust/mach/ci/build_fail.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -ex + +: "${TARGET?The TARGET environment variable must be set.}" + +! cargo build --target "${TARGET}" diff --git a/third_party/rust/mach/ci/deploy_and_run_on_ios_simulator.rs b/third_party/rust/mach/ci/deploy_and_run_on_ios_simulator.rs new file mode 100644 index 0000000000..c0bc21dbc7 --- /dev/null +++ b/third_party/rust/mach/ci/deploy_and_run_on_ios_simulator.rs @@ -0,0 +1,175 @@ +// Copyright 2017 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. + +// This is a script to deploy and execute a binary on an iOS simulator. +// The primary use of this is to be able to run unit tests on the simulator and +// retrieve the results. +// +// To do this through Cargo instead, use Dinghy +// (https://github.com/snipsco/dinghy): cargo dinghy install, then cargo dinghy +// test. +// +// Source: this script is part of libc +// https://github.com/rust-lang/libc/blob/master/ci/ios/deploy_and_run_on_ios_simulator.rs +// and should be sync'ed with it when ci breaks (or periodically). + +use std::env; +use std::fs::{self, File}; +use std::io::Write; +use std::path::Path; +use std::process; +use std::process::Command; + +macro_rules! t { + ($e:expr) => (match $e { + Ok(e) => e, + Err(e) => panic!("{} failed with: {}", stringify!($e), e), + }) +} + +// Step one: Wrap as an app +fn package_as_simulator_app(crate_name: &str, test_binary_path: &Path) { + println!("Packaging simulator app"); + drop(fs::remove_dir_all("ios_simulator_app")); + t!(fs::create_dir("ios_simulator_app")); + t!(fs::copy(test_binary_path, + Path::new("ios_simulator_app").join(crate_name))); + + let mut f = t!(File::create("ios_simulator_app/Info.plist")); + t!(f.write_all(format!(r#" + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE plist PUBLIC + "-//Apple//DTD PLIST 1.0//EN" + "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> + <plist version="1.0"> + <dict> + <key>CFBundleExecutable</key> + <string>{}</string> + <key>CFBundleIdentifier</key> + <string>com.rust.unittests</string> + </dict> + </plist> + "#, crate_name).as_bytes())); +} + +// Step two: Start the iOS simulator +fn start_simulator() { + println!("Looking for iOS simulator"); + let output = t!(Command::new("xcrun").arg("simctl").arg("list").output()); + assert!(output.status.success()); + let mut simulator_exists = false; + let mut simulator_booted = false; + let mut found_rust_sim = false; + let stdout = t!(String::from_utf8(output.stdout)); + for line in stdout.lines() { + if line.contains("rust_ios") { + if found_rust_sim { + panic!("Duplicate rust_ios simulators found. Please \ + double-check xcrun simctl list."); + } + simulator_exists = true; + simulator_booted = line.contains("(Booted)"); + found_rust_sim = true; + } + } + + if simulator_exists == false { + println!("Creating iOS simulator"); + Command::new("xcrun") + .arg("simctl") + .arg("create") + .arg("rust_ios") + .arg("com.apple.CoreSimulator.SimDeviceType.iPhone-SE") + .arg("com.apple.CoreSimulator.SimRuntime.iOS-10-2") + .check_status(); + } else if simulator_booted == true { + println!("Shutting down already-booted simulator"); + Command::new("xcrun") + .arg("simctl") + .arg("shutdown") + .arg("rust_ios") + .check_status(); + } + + println!("Starting iOS simulator"); + // We can't uninstall the app (if present) as that will hang if the + // simulator isn't completely booted; just erase the simulator instead. + Command::new("xcrun").arg("simctl").arg("erase").arg("rust_ios").check_status(); + Command::new("xcrun").arg("simctl").arg("boot").arg("rust_ios").check_status(); +} + +// Step three: Install the app +fn install_app_to_simulator() { + println!("Installing app to simulator"); + Command::new("xcrun") + .arg("simctl") + .arg("install") + .arg("booted") + .arg("ios_simulator_app/") + .check_status(); +} + +// Step four: Run the app +fn run_app_on_simulator() { + println!("Running app"); + let output = t!(Command::new("xcrun") + .arg("simctl") + .arg("launch") + .arg("--console") + .arg("booted") + .arg("com.rust.unittests") + .output()); + + println!("stdout --\n{}\n", String::from_utf8_lossy(&output.stdout)); + println!("stderr --\n{}\n", String::from_utf8_lossy(&output.stderr)); + + let stdout = String::from_utf8_lossy(&output.stdout); + let passed = stdout.lines() + .find(|l| l.contains("PASSED")) + .map(|l| l.contains("tests")) + .unwrap_or(false); + + println!("Shutting down simulator"); + Command::new("xcrun") + .arg("simctl") + .arg("shutdown") + .arg("rust_ios") + .check_status(); + if !passed { + panic!("tests didn't pass"); + } +} + +trait CheckStatus { + fn check_status(&mut self); +} + +impl CheckStatus for Command { + fn check_status(&mut self) { + println!("\trunning: {:?}", self); + assert!(t!(self.status()).success()); + } +} + +fn main() { + let args: Vec<String> = env::args().collect(); + if args.len() != 2 { + println!("Usage: {} <executable>", args[0]); + process::exit(-1); + } + + let test_binary_path = Path::new(&args[1]); + let crate_name = test_binary_path.file_name().unwrap(); + + package_as_simulator_app(crate_name.to_str().unwrap(), test_binary_path); + start_simulator(); + install_app_to_simulator(); + run_app_on_simulator(); +} diff --git a/third_party/rust/mach/ci/run.sh b/third_party/rust/mach/ci/run.sh new file mode 100755 index 0000000000..9d814705c9 --- /dev/null +++ b/third_party/rust/mach/ci/run.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env sh + +set -ex + +: "${TARGET?The TARGET environment variable must be set.}" +: "${TRAVIS_RUST_VERSION?The TRAVIS_RUST_VERSION environment variable must be set.}" + +echo "Running tests for target: ${TARGET}" +export RUST_BACKTRACE=1 +export RUST_TEST_THREADS=1 +export RUST_TEST_NOCAPTURE=1 +export CARGO_INCREMENTAL=0 +export CARGO_CODEGEN_UNITS=1 +export RUSTFLAGS="-C codegen-units=1 " + +case "${TARGET}" in + *"ios"*) + export RUSTFLAGS="${RUSTFLAGS} -C link-args=-mios-simulator-version-min=7.0" + rustc ./ci/deploy_and_run_on_ios_simulator.rs -o ios_cargo_runner --verbose + if [ "${TARGET}" = "x86_64-apple-ios" ]; then + export CARGO_TARGET_X86_64_APPLE_IOS_RUNNER + CARGO_TARGET_X86_64_APPLE_IOS_RUNNER="$(pwd)/ios_cargo_runner" + fi + if [ "${TARGET}" = "i386-apple-ios" ]; then + export CARGO_TARGET_I386_APPLE_IOS_RUNNER + CARGO_TARGET_I386_APPLE_IOS_RUNNER="$(pwd)/ios_cargo_runner" + fi + ;; + *) + ;; +esac + +# Build w/o std +cargo clean +cargo build --no-default-features --target "${TARGET}" -vv 2>&1 | tee build_no_std.txt + +# Check that the no-std builds are not linked against a libc with default +# features or the std feature enabled: +! grep -q "default" build_no_std.txt +! grep -q "std" build_no_std.txt +# Make sure that the resulting build contains no std symbols +! find target/ -name "*.rlib" -exec nm {} \; | grep "std" + +# Runs mach's run-time tests: +if [ -z "$NORUN" ]; then + cargo test --target "${TARGET}" -vv + cargo test --target "${TARGET}" -vv --features deprecated + cargo test --no-default-features --target "${TARGET}" -vv +fi + +# Runs ctest to verify mach's ABI against the system libraries: +if [ -z "$NOCTEST" ]; then + if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then + cargo test --manifest-path mach-test/Cargo.toml --target "${TARGET}" -vv + cargo test --no-default-features --manifest-path mach-test/Cargo.toml --target "${TARGET}" -vv + fi +fi diff --git a/third_party/rust/mach/examples/dump_process_registers.rs b/third_party/rust/mach/examples/dump_process_registers.rs new file mode 100644 index 0000000000..c426e583e0 --- /dev/null +++ b/third_party/rust/mach/examples/dump_process_registers.rs @@ -0,0 +1,136 @@ +//! A script to read and dump to stdout the current register values of a +//! process. + +extern crate libc; +extern crate mach; + +use std::io; +use std::mem; +use std::ptr; + +use mach::kern_return::KERN_SUCCESS; +use mach::mach_types::{task_t, thread_act_array_t}; +use mach::message::mach_msg_type_number_t; +use mach::port::mach_port_name_t; +use mach::structs::x86_thread_state64_t; +use mach::task::{task_resume, task_suspend, task_threads}; +use mach::thread_act::thread_get_state; +use mach::thread_status::x86_THREAD_STATE64; +use mach::traps::{mach_task_self, task_for_pid}; + +use std::io::prelude::*; + +fn read_int() -> Result<::libc::c_int, ()> { + let stdin = io::stdin(); + let mut line = String::new(); + + stdin.read_line(&mut line).ok().unwrap(); + let mut value: ::libc::c_int = 0; + + for c in line.chars().take_while(|&c| c != '\n') { + if let Some(d) = c.to_digit(10) { + value = value * 10 + (d as ::libc::c_int); + } else { + return Err(()); + } + } + return Ok(value); +} + +fn resume(task: task_t) { + unsafe { + let kret = task_resume(task); + if kret != KERN_SUCCESS { + println!("Did not succeed in resuming task."); + println!("kern_return_t error {}", kret); + panic!(); + } + } +} + +fn main() { + print!("Enter pid: "); + io::stdout().flush().ok(); + + let pid = match read_int() { + Ok(v) => v, + Err(_) => { + println!("Bad pid!"); + return; + } + }; + + println!("pid = {}", &pid); + + let task: mach_port_name_t = 0; + unsafe { + let kret = task_for_pid( + mach_task_self() as mach_port_name_t, + pid, + mem::transmute(&task), + ); + if kret != KERN_SUCCESS { + println!("Did not succeed in getting task for pid {}", pid); + println!("kern_return_t error {}", kret); + println!(""); + println!("Did you forget to run with 'sudo'? This script will"); + println!("probably fail without it."); + return; + } + } + + println!("task = 0x{:x}", &task); + + unsafe { + let kret = task_suspend(task as task_t); + if kret != KERN_SUCCESS { + println!("Did not succeed in suspending task."); + println!("kern_return_t error {}", kret); + return; + } + } + + let thread_list: thread_act_array_t = ptr::null_mut(); + let thread_count: mach_msg_type_number_t = 0; + unsafe { + let kret = task_threads( + task as task_t, + mem::transmute(&thread_list), + mem::transmute(&thread_count), + ); + if kret != KERN_SUCCESS { + println!("Did not succeed in getting task's threads"); + println!("kern_return_t error {}", kret); + resume(task as task_t); + return; + } + } + + println!("Task is running {} threads", &thread_count); + + unsafe { + let threads = + Vec::from_raw_parts(thread_list, thread_count as usize, thread_count as usize); + let state = x86_thread_state64_t::new(); + let state_count = x86_thread_state64_t::count(); + for (idx, &thread) in threads.iter().enumerate() { + println!("Thread {}:", idx); + let kret = thread_get_state( + thread, + x86_THREAD_STATE64, + mem::transmute(&state), + mem::transmute(&state_count), + ); + if kret != KERN_SUCCESS { + println!("Did not succeed in getting task's thread state"); + println!("kern_return_t error {}", kret); + continue; + } + + println!("{:?}", state); + } + } + + resume(task as task_t); + println!("Success!"); +} diff --git a/third_party/rust/mach/src/boolean.rs b/third_party/rust/mach/src/boolean.rs new file mode 100644 index 0000000000..cedffa1220 --- /dev/null +++ b/third_party/rust/mach/src/boolean.rs @@ -0,0 +1,7 @@ +//! This module corresponds to `mach/i386/boolean.h`. + +#[cfg(target_arch = "x86_64")] +pub type boolean_t = ::libc::c_uint; + +#[cfg(not(target_arch = "x86_64"))] +pub type boolean_t = ::libc::c_int; diff --git a/third_party/rust/mach/src/bootstrap.rs b/third_party/rust/mach/src/bootstrap.rs new file mode 100644 index 0000000000..3642b94627 --- /dev/null +++ b/third_party/rust/mach/src/bootstrap.rs @@ -0,0 +1,76 @@ +//! This module corresponds to `bootstrap.h` + +use boolean::boolean_t; +use kern_return::kern_return_t; +use port::mach_port_t; + +pub const BOOTSTRAP_MAX_NAME_LEN: ::libc::c_uint = 128; +pub const BOOTSTRAP_MAX_CMD_LEN: ::libc::c_uint = 512; + +pub const BOOTSTRAP_MAX_LOOKUP_COUNT: ::libc::c_uint = 20; + +pub const BOOTSTRAP_SUCCESS: ::libc::c_uint = 0; +pub const BOOTSTRAP_NOT_PRIVILEGED: ::libc::c_uint = 1100; +pub const BOOTSTRAP_NAME_IN_USE: ::libc::c_uint = 1101; +pub const BOOTSTRAP_UNKNOWN_SERVICE: ::libc::c_uint = 1102; +pub const BOOTSTRAP_SERVICE_ACTIVE: ::libc::c_uint = 1103; +pub const BOOTSTRAP_BAD_COUNT: ::libc::c_uint = 1104; +pub const BOOTSTRAP_NO_MEMORY: ::libc::c_uint = 1105; +pub const BOOTSTRAP_NO_CHILDREN: ::libc::c_uint = 1106; + +pub const BOOTSTRAP_STATUS_INACTIVE: ::libc::c_uint = 0; +pub const BOOTSTRAP_STATUS_ACTIVE: ::libc::c_uint = 1; +pub const BOOTSTRAP_STATUS_ON_DEMAND: ::libc::c_uint = 2; + +pub type name_t = [::libc::c_char; 128]; +pub type cmd_t = [::libc::c_char; 512]; +pub type name_array_t = *mut name_t; +pub type bootstrap_status_t = ::libc::c_int; +pub type bootstrap_status_array_t = *mut bootstrap_status_t; +pub type bootstrap_property_t = ::libc::c_uint; +pub type bootstrap_property_array_t = *mut bootstrap_property_t; +pub type bool_array_t = *mut boolean_t; + +extern "C" { + pub static bootstrap_port: mach_port_t; + pub fn bootstrap_create_server( + bp: mach_port_t, + server_cmd: *mut ::libc::c_char, + server_uid: ::libc::uid_t, + on_demand: boolean_t, + server_port: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_subset( + bp: mach_port_t, + requestor_port: mach_port_t, + subset_port: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_unprivileged(bp: mach_port_t, unpriv_port: *mut mach_port_t) -> kern_return_t; + pub fn bootstrap_parent(bp: mach_port_t, parent_port: *mut mach_port_t) -> kern_return_t; + pub fn bootstrap_register( + bp: mach_port_t, + service_name: *mut ::libc::c_char, + sp: mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_create_service( + bp: mach_port_t, + service_name: *mut ::libc::c_char, + sp: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_check_in( + bp: mach_port_t, + service_name: *const ::libc::c_char, + sp: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_look_up( + bp: mach_port_t, + service_name: *const ::libc::c_char, + sp: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_status( + bp: mach_port_t, + service_name: *mut ::libc::c_char, + service_active: *mut bootstrap_status_t, + ) -> kern_return_t; + pub fn bootstrap_strerror(r: kern_return_t) -> *const ::libc::c_char; +} diff --git a/third_party/rust/mach/src/clock.rs b/third_party/rust/mach/src/clock.rs new file mode 100644 index 0000000000..1d5437951d --- /dev/null +++ b/third_party/rust/mach/src/clock.rs @@ -0,0 +1,27 @@ +//! This module roughly corresponds to `mach/clock.h`. + +pub const clock_MSG_COUNT: ::libc::c_uint = 3; + +use clock_types::{alarm_type_t, clock_attr_t, clock_flavor_t, mach_timespec_t}; +use kern_return::kern_return_t; +use mach_types::{clock_reply_t, clock_serv_t}; +use message::mach_msg_type_number_t; + +extern "C" { + pub fn clock_get_time( + clock_serv: clock_serv_t, + cur_time: *mut mach_timespec_t, + ) -> kern_return_t; + pub fn clock_get_attributes( + clock_serv: clock_serv_t, + flavor: clock_flavor_t, + clock_attr: clock_attr_t, + clock_attrCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + pub fn clock_alarm( + clock_serv: clock_serv_t, + alarm_type: alarm_type_t, + alarm_time: mach_timespec_t, + alarm_port: clock_reply_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/clock_priv.rs b/third_party/rust/mach/src/clock_priv.rs new file mode 100644 index 0000000000..d534e79a3c --- /dev/null +++ b/third_party/rust/mach/src/clock_priv.rs @@ -0,0 +1,16 @@ +//! This module roughly corresponds to `mach/clock_priv.h`. + +use clock_types::{clock_attr_t, clock_flavor_t, mach_timespec_t}; +use kern_return::kern_return_t; +use mach_types::clock_ctrl_t; +use message::mach_msg_type_number_t; + +extern "C" { + pub fn clock_set_time(clock_ctrl: clock_ctrl_t, new_time: mach_timespec_t) -> kern_return_t; + pub fn clock_set_attributes( + clock_ctrl: clock_ctrl_t, + flavor: clock_flavor_t, + clock_attr: clock_attr_t, + clock_attrCnt: mach_msg_type_number_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/clock_reply.rs b/third_party/rust/mach/src/clock_reply.rs new file mode 100644 index 0000000000..854eb22bf5 --- /dev/null +++ b/third_party/rust/mach/src/clock_reply.rs @@ -0,0 +1,16 @@ +//! This module roughly corresponds to `mach/clock_reply.h`. + +use clock_types::{alarm_type_t, mach_timespec_t}; +use kern_return::kern_return_t; +use mach_types::clock_reply_t; +use message::mach_msg_type_name_t; + +extern "C" { + pub fn clock_alarm_reply( + alarm_port: clock_reply_t, + alarm_portPoly: mach_msg_type_name_t, + alarm_code: kern_return_t, + alarm_type: alarm_type_t, + alarm_time: mach_timespec_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/clock_types.rs b/third_party/rust/mach/src/clock_types.rs new file mode 100644 index 0000000000..c0949c8315 --- /dev/null +++ b/third_party/rust/mach/src/clock_types.rs @@ -0,0 +1,75 @@ +//! This module roughly corresponds to `mach/clock_types.h`. + +pub type alarm_type_t = ::libc::c_int; +pub type sleep_type_t = ::libc::c_int; +pub type clock_id_t = ::libc::c_int; +pub type clock_flavor_t = ::libc::c_int; +pub type clock_attr_t = *mut ::libc::c_int; +pub type clock_res_t = ::libc::c_int; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_timespec { + pub tv_sec: ::libc::c_uint, + pub tv_nsec: clock_res_t, +} +pub type mach_timespec_t = mach_timespec; + +pub const SYSTEM_CLOCK: ::libc::c_uint = 0; +pub const CALENDAR_CLOCK: ::libc::c_uint = 1; +pub const REALTIME_CLOCK: ::libc::c_uint = 0; + +pub const CLOCK_GET_TIME_RES: ::libc::c_uint = 1; +pub const CLOCK_ALARM_CURRES: ::libc::c_uint = 3; +pub const CLOCK_ALARM_MINRES: ::libc::c_uint = 4; +pub const CLOCK_ALARM_MAXRES: ::libc::c_uint = 5; + +pub const NSEC_PER_USEC: ::libc::c_ulonglong = 1000; +pub const USEC_PER_SEC: ::libc::c_ulonglong = 1_000_000; +pub const NSEC_PER_SEC: ::libc::c_ulonglong = 1_000_000_000; +pub const NSEC_PER_MSEC: ::libc::c_ulonglong = 1_000_000; + +#[allow(non_snake_case)] +pub fn BAD_MACH_TIMESPEC(t: mach_timespec) -> bool { + t.tv_nsec < 0 || (t.tv_nsec as ::libc::c_ulonglong) >= NSEC_PER_SEC +} + +#[allow(non_snake_case)] +pub fn CMP_MACH_TIMESPEC(t1: &mach_timespec, t2: &mach_timespec) -> ::libc::c_ulonglong { + if t1.tv_sec > t2.tv_sec { + return NSEC_PER_SEC; + } + if t1.tv_sec < t2.tv_sec { + return !NSEC_PER_SEC; + } + (t1.tv_nsec as ::libc::c_ulonglong) - (t2.tv_nsec as ::libc::c_ulonglong) +} + +#[allow(non_snake_case)] +pub fn ADD_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec) { + t1.tv_nsec += t2.tv_nsec; + if (t1.tv_nsec as ::libc::c_ulonglong) >= NSEC_PER_SEC { + t1.tv_nsec = (t1.tv_nsec as ::libc::c_ulonglong - NSEC_PER_SEC) as clock_res_t; + t1.tv_sec += 1; + } + t1.tv_sec += t2.tv_sec; +} + +#[allow(non_snake_case)] +pub fn SUB_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec) { + t1.tv_nsec -= t2.tv_nsec; + if t1.tv_nsec < 0 { + t1.tv_nsec = (t1.tv_nsec as ::libc::c_ulonglong + NSEC_PER_SEC) as clock_res_t; + t1.tv_sec -= 1; + } + t1.tv_sec -= t2.tv_sec; +} + +pub const ALRMTYPE: ::libc::c_uint = 0xff; +pub const TIME_ABSOLUTE: ::libc::c_uint = 0x00; +pub const TIME_RELATIVE: ::libc::c_uint = 0x01; + +#[allow(non_snake_case)] +pub fn BAD_ALRMTYPE(t: ::libc::c_uint) -> bool { + t & (!TIME_RELATIVE) != 0 +} diff --git a/third_party/rust/mach/src/dyld_kernel.rs b/third_party/rust/mach/src/dyld_kernel.rs new file mode 100644 index 0000000000..9a264dfafd --- /dev/null +++ b/third_party/rust/mach/src/dyld_kernel.rs @@ -0,0 +1,30 @@ +//! This module roughly corresponds to `mach/dyld_kernel.h`. + +use boolean::boolean_t; +use mach_types::{fsid_t, fsobj_id_t, uuid_t}; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct dyld_kernel_image_info { + pub uuid: uuid_t, + pub fsobjid: fsobj_id_t, + pub fsid: fsid_t, + pub load_addr: u64, +} + +#[allow(non_snake_case)] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct dyld_kernel_process_info { + pub cache_image_info: dyld_kernel_image_info, + pub timestamp: u64, + pub imageCount: u32, + pub initialImageCount: u32, + pub dyldState: u8, + pub no_cache: boolean_t, + pub private_cache: boolean_t, +} + +pub type dyld_kernel_image_info_t = dyld_kernel_image_info; +pub type dyld_kernel_process_info_t = dyld_kernel_process_info; +pub type dyld_kernel_image_info_array_t = *mut dyld_kernel_image_info_t; diff --git a/third_party/rust/mach/src/exc.rs b/third_party/rust/mach/src/exc.rs new file mode 100644 index 0000000000..9330740c4e --- /dev/null +++ b/third_party/rust/mach/src/exc.rs @@ -0,0 +1,44 @@ +//! This module roughly corresponds to `mach/exc.h`. + +use exception_types::{exception_data_t, exception_type_t}; +use kern_return::kern_return_t; +use message::mach_msg_type_number_t; +use port::mach_port_t; +use thread_status::thread_state_t; + +pub const exc_MSG_COUNT: ::libc::c_uint = 3; + +extern "C" { + pub fn exception_raise( + exception_port: mach_port_t, + thread: mach_port_t, + task: mach_port_t, + exception: exception_type_t, + code: exception_data_t, + codeCnt: mach_msg_type_number_t, + ) -> kern_return_t; + pub fn exception_raise_state( + exception_port: mach_port_t, + exception: exception_type_t, + code: exception_data_t, + codeCnt: mach_msg_type_number_t, + flavor: *mut ::libc::c_int, + old_state: thread_state_t, + old_stateCnt: mach_msg_type_number_t, + new_state: thread_state_t, + new_stateCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + pub fn exception_raise_state_identity( + exception_port: mach_port_t, + thread: mach_port_t, + task: mach_port_t, + exception: exception_type_t, + code: exception_data_t, + codeCnt: mach_msg_type_number_t, + flavor: *mut ::libc::c_int, + old_state: thread_state_t, + old_stateCnt: mach_msg_type_number_t, + new_state: thread_state_t, + new_stateCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/exception_types.rs b/third_party/rust/mach/src/exception_types.rs new file mode 100644 index 0000000000..f042443d8a --- /dev/null +++ b/third_party/rust/mach/src/exception_types.rs @@ -0,0 +1,56 @@ +//! This module roughly corresponds to `mach/exception_types.h`. + +use port::mach_port_t; +use thread_status::thread_state_flavor_t; +use vm_types::integer_t; + +pub const EXC_BAD_ACCESS: ::libc::c_uint = 1; +pub const EXC_BAD_INSTRUCTION: ::libc::c_uint = 2; +pub const EXC_ARITHMETIC: ::libc::c_uint = 3; +pub const EXC_EMULATION: ::libc::c_uint = 4; +pub const EXC_SOFTWARE: ::libc::c_uint = 5; +pub const EXC_BREAKPOINT: ::libc::c_uint = 6; +pub const EXC_SYSCALL: ::libc::c_uint = 7; +pub const EXC_MACH_SYSCALL: ::libc::c_uint = 8; +pub const EXC_RPC_ALERT: ::libc::c_uint = 9; +pub const EXC_CRASH: ::libc::c_uint = 10; +pub const EXC_RESOURCE: ::libc::c_uint = 11; +pub const EXC_GUARD: ::libc::c_uint = 12; +pub const EXC_CORPSE_NOTIFY: ::libc::c_uint = 13; +pub const EXC_CORPSE_VARIANT_BIT: ::libc::c_uint = 256; +pub const EXCEPTION_DEFAULT: ::libc::c_uint = 1; +pub const EXCEPTION_STATE: ::libc::c_uint = 2; +pub const EXCEPTION_STATE_IDENTITY: ::libc::c_uint = 3; +pub const MACH_EXCEPTION_CODES: ::libc::c_uint = 2_147_483_648; +pub const EXC_MASK_BAD_ACCESS: ::libc::c_uint = 2; +pub const EXC_MASK_BAD_INSTRUCTION: ::libc::c_uint = 4; +pub const EXC_MASK_ARITHMETIC: ::libc::c_uint = 8; +pub const EXC_MASK_EMULATION: ::libc::c_uint = 16; +pub const EXC_MASK_SOFTWARE: ::libc::c_uint = 32; +pub const EXC_MASK_BREAKPOINT: ::libc::c_uint = 64; +pub const EXC_MASK_SYSCALL: ::libc::c_uint = 128; +pub const EXC_MASK_MACH_SYSCALL: ::libc::c_uint = 256; +pub const EXC_MASK_RPC_ALERT: ::libc::c_uint = 512; +pub const EXC_MASK_CRASH: ::libc::c_uint = 1024; +pub const EXC_MASK_RESOURCE: ::libc::c_uint = 2048; +pub const EXC_MASK_GUARD: ::libc::c_uint = 4096; +pub const EXC_MASK_CORPSE_NOTIFY: ::libc::c_uint = 8192; +pub const EXC_MASK_ALL: ::libc::c_uint = 7166; +pub const FIRST_EXCEPTION: ::libc::c_uint = 1; +pub const EXC_SOFT_SIGNAL: ::libc::c_uint = 65_539; +pub const EXC_MACF_MIN: ::libc::c_uint = 131_072; +pub const EXC_MACF_MAX: ::libc::c_uint = 196_607; + +pub type exception_type_t = ::libc::c_int; +pub type exception_data_type_t = integer_t; +pub type mach_exception_data_type_t = i64; +pub type exception_behavior_t = ::libc::c_int; +pub type exception_data_t = *mut exception_data_type_t; +pub type mach_exception_data_t = *mut mach_exception_data_type_t; +pub type exception_mask_t = ::libc::c_uint; +pub type exception_mask_array_t = *mut exception_mask_t; +pub type exception_behavior_array_t = *mut exception_behavior_t; +pub type exception_flavor_array_t = *mut thread_state_flavor_t; +pub type exception_port_array_t = *mut mach_port_t; +pub type mach_exception_code_t = mach_exception_data_type_t; +pub type mach_exception_subcode_t = mach_exception_data_type_t; diff --git a/third_party/rust/mach/src/kern_return.rs b/third_party/rust/mach/src/kern_return.rs new file mode 100644 index 0000000000..3d447b4026 --- /dev/null +++ b/third_party/rust/mach/src/kern_return.rs @@ -0,0 +1,58 @@ +//! This module corresponds to `mach/kern_return.h` and +//! `mach/i386/kern_return.h`. + +pub type kern_return_t = ::libc::c_int; + +pub const KERN_SUCCESS: kern_return_t = 0; +pub const KERN_INVALID_ADDRESS: kern_return_t = 1; +pub const KERN_PROTECTION_FAILURE: kern_return_t = 2; +pub const KERN_NO_SPACE: kern_return_t = 3; +pub const KERN_INVALID_ARGUMENT: kern_return_t = 4; +pub const KERN_FAILURE: kern_return_t = 5; +pub const KERN_RESOURCE_SHORTAGE: kern_return_t = 6; +pub const KERN_NOT_RECEIVER: kern_return_t = 7; +pub const KERN_NO_ACCESS: kern_return_t = 8; +pub const KERN_MEMORY_FAILURE: kern_return_t = 9; +pub const KERN_MEMORY_ERROR: kern_return_t = 10; +pub const KERN_ALREADY_IN_SET: kern_return_t = 11; +pub const KERN_NOT_IN_SET: kern_return_t = 12; +pub const KERN_NAME_EXISTS: kern_return_t = 13; +pub const KERN_ABORTED: kern_return_t = 14; +pub const KERN_INVALID_NAME: kern_return_t = 15; +pub const KERN_INVALID_TASK: kern_return_t = 16; +pub const KERN_INVALID_RIGHT: kern_return_t = 17; +pub const KERN_INVALID_VALUE: kern_return_t = 18; +pub const KERN_UREFS_OVERFLOW: kern_return_t = 19; +pub const KERN_INVALID_CAPABILITY: kern_return_t = 20; +pub const KERN_RIGHT_EXISTS: kern_return_t = 21; +pub const KERN_INVALID_HOST: kern_return_t = 22; +pub const KERN_MEMORY_PRESENT: kern_return_t = 23; +pub const KERN_MEMORY_DATA_MOVED: kern_return_t = 24; +pub const KERN_MEMORY_RESTART_COPY: kern_return_t = 25; +pub const KERN_INVALID_PROCESSOR_SET: kern_return_t = 26; +pub const KERN_POLICY_LIMIT: kern_return_t = 27; +pub const KERN_INVALID_POLICY: kern_return_t = 28; +pub const KERN_INVALID_OBJECT: kern_return_t = 29; +pub const KERN_ALREADY_WAITING: kern_return_t = 30; +pub const KERN_DEFAULT_SET: kern_return_t = 31; +pub const KERN_EXCEPTION_PROTECTED: kern_return_t = 32; +pub const KERN_INVALID_LEDGER: kern_return_t = 33; +pub const KERN_INVALID_MEMORY_CONTROL: kern_return_t = 34; +pub const KERN_INVALID_SECURITY: kern_return_t = 35; +pub const KERN_NOT_DEPRESSED: kern_return_t = 36; +pub const KERN_TERMINATED: kern_return_t = 37; +pub const KERN_LOCK_SET_DESTROYED: kern_return_t = 38; +pub const KERN_LOCK_UNSTABLE: kern_return_t = 39; +pub const KERN_LOCK_OWNED: kern_return_t = 40; +pub const KERN_LOCK_OWNED_SELF: kern_return_t = 41; +pub const KERN_SEMAPHORE_DESTROYED: kern_return_t = 42; +pub const KERN_RPC_SERVER_TERMINATED: kern_return_t = 43; +pub const KERN_RPC_TERMINATE_ORPHAN: kern_return_t = 44; +pub const KERN_RPC_CONTINUE_ORPHAN: kern_return_t = 45; +pub const KERN_NOT_SUPPORTED: kern_return_t = 46; +pub const KERN_NODE_DOWN: kern_return_t = 47; +pub const KERN_NOT_WAITING: kern_return_t = 48; +pub const KERN_OPERATION_TIMED_OUT: kern_return_t = 49; +pub const KERN_CODESIGN_ERROR: kern_return_t = 50; +pub const KERN_POLICY_STATIC: kern_return_t = 51; +pub const KERN_RETURN_MAX: kern_return_t = 0x100; diff --git a/third_party/rust/mach/src/lib.rs b/third_party/rust/mach/src/lib.rs new file mode 100644 index 0000000000..faec2cbfa5 --- /dev/null +++ b/third_party/rust/mach/src/lib.rs @@ -0,0 +1,60 @@ +#![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] +#![deny(missing_debug_implementations)] +#![deny(missing_copy_implementations)] +#![cfg_attr(feature = "rustc-dep-of-std", feature(no_core))] +#![cfg_attr(feature = "rustc-dep-of-std", no_core)] +#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)] +#![allow( + clippy::module_name_repetitions, + clippy::cast_sign_loss, + clippy::cast_possible_truncation, + clippy::trivially_copy_pass_by_ref +)] + +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +compile_error!("mach requires MacOSX or iOS"); + +#[cfg(feature = "rustc-dep-of-std")] +extern crate rustc_std_workspace_core as core; + +extern crate libc; + +#[allow(unused_imports)] +use core::{clone, cmp, default, fmt, hash, marker, mem, option}; + +pub mod boolean; +pub mod bootstrap; +pub mod clock; +pub mod clock_priv; +pub mod clock_reply; +pub mod clock_types; // TODO: test +pub mod dyld_kernel; +// pub mod error; // TODO +pub mod exc; +pub mod exception_types; +pub mod kern_return; +pub mod mach_init; +pub mod mach_port; +pub mod mach_time; +pub mod mach_types; +pub mod memory_object_types; +pub mod message; +pub mod port; +pub mod structs; +pub mod task; +pub mod task_info; +pub mod thread_act; +pub mod thread_status; +pub mod traps; +pub mod vm; +pub mod vm_attributes; +pub mod vm_behavior; +pub mod vm_inherit; +pub mod vm_page_size; +pub mod vm_prot; +pub mod vm_purgable; +pub mod vm_region; +pub mod vm_statistics; +pub mod vm_sync; +pub mod vm_types; diff --git a/third_party/rust/mach/src/mach_init.rs b/third_party/rust/mach/src/mach_init.rs new file mode 100644 index 0000000000..5776988cb5 --- /dev/null +++ b/third_party/rust/mach/src/mach_init.rs @@ -0,0 +1,22 @@ +//! This module corresponds to `mach/mach_init.h`. + +use mach_types::thread_port_t; + +extern "C" { + pub fn mach_thread_self() -> thread_port_t; +} + +#[cfg(test)] +mod tests { + use mach_init::*; + use port::*; + + #[test] + fn mach_thread_self_test() { + unsafe { + let this_thread = mach_thread_self(); + assert!(this_thread != MACH_PORT_NULL); + assert!(this_thread != MACH_PORT_DEAD); + } + } +} diff --git a/third_party/rust/mach/src/mach_port.rs b/third_party/rust/mach/src/mach_port.rs new file mode 100644 index 0000000000..76a34001df --- /dev/null +++ b/third_party/rust/mach/src/mach_port.rs @@ -0,0 +1,29 @@ +//! This module corresponds to `mach/mach_port.h` + +use kern_return::kern_return_t; +use mach_types::ipc_space_t; +use message::mach_msg_type_name_t; +use port::{mach_port_name_t, mach_port_right_t, mach_port_t}; + +extern "C" { + pub fn mach_port_allocate( + task: ipc_space_t, + right: mach_port_right_t, + name: *mut mach_port_name_t, + ) -> kern_return_t; + pub fn mach_port_destroy(task: ipc_space_t, name: mach_port_name_t) -> kern_return_t; + pub fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) -> kern_return_t; + pub fn mach_port_insert_right( + task: ipc_space_t, + name: mach_port_name_t, + poly: mach_port_t, + polyPoly: mach_msg_type_name_t, + ) -> kern_return_t; + pub fn mach_port_extract_right( + task: ipc_space_t, + name: mach_port_name_t, + msgt_name: mach_msg_type_name_t, + poly: *mut mach_port_t, + polyPoly: *mut mach_msg_type_name_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/mach_time.rs b/third_party/rust/mach/src/mach_time.rs new file mode 100644 index 0000000000..9011c0c0af --- /dev/null +++ b/third_party/rust/mach/src/mach_time.rs @@ -0,0 +1,20 @@ +//! This module corresponds to `mach/mach_time.h` +use kern_return::kern_return_t; +pub type mach_timebase_info_t = *mut mach_timebase_info; +pub type mach_timebase_info_data_t = mach_timebase_info; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_timebase_info { + pub numer: u32, + pub denom: u32, +} + +extern "C" { + pub fn mach_timebase_info(info: mach_timebase_info_t) -> kern_return_t; + pub fn mach_wait_until(deadline: u64) -> kern_return_t; + pub fn mach_absolute_time() -> u64; + pub fn mach_approximate_time() -> u64; + pub fn mach_continuous_time() -> u64; + pub fn mach_continuous_approximate_time() -> u64; +} diff --git a/third_party/rust/mach/src/mach_types.rs b/third_party/rust/mach/src/mach_types.rs new file mode 100644 index 0000000000..fa257b2a53 --- /dev/null +++ b/third_party/rust/mach/src/mach_types.rs @@ -0,0 +1,106 @@ +//! This module corresponds to `mach/mach_types.h` + +use port::mach_port_t; + +pub type task_t = mach_port_t; +pub type task_name_t = mach_port_t; +pub type task_suspension_token_t = mach_port_t; +pub type thread_t = mach_port_t; +pub type thread_act_t = mach_port_t; +pub type ipc_space_t = mach_port_t; +pub type coalition_t = mach_port_t; +pub type host_t = mach_port_t; +pub type host_priv_t = mach_port_t; +pub type host_security_t = mach_port_t; +pub type processor_t = mach_port_t; +pub type processor_set_t = mach_port_t; +pub type processor_set_control_t = mach_port_t; +pub type semaphore_t = mach_port_t; +pub type lock_set_t = mach_port_t; +pub type ledger_t = mach_port_t; +pub type alarm_t = mach_port_t; +pub type clock_serv_t = mach_port_t; +pub type clock_ctrl_t = mach_port_t; + +pub type processor_set_name_t = processor_set_t; + +pub type clock_reply_t = mach_port_t; +pub type bootstrap_t = mach_port_t; +pub type mem_entry_name_port_t = mach_port_t; +pub type exception_handler_t = mach_port_t; +pub type exception_handler_array_t = *mut exception_handler_t; +pub type vm_task_entry_t = mach_port_t; +pub type io_master_t = mach_port_t; +pub type UNDServerRef = mach_port_t; + +pub type task_array_t = *mut task_t; +pub type thread_array_t = *mut thread_t; +pub type processor_set_array_t = *mut processor_set_t; +pub type processor_set_name_array_t = *mut processor_set_t; +pub type processor_array_t = *mut processor_t; +pub type thread_act_array_t = *mut thread_act_t; +pub type ledger_array_t = *mut ledger_t; + +pub type task_port_t = task_t; +pub type task_port_array_t = task_array_t; +pub type thread_port_t = thread_t; +pub type thread_port_array_t = thread_array_t; +pub type ipc_space_port_t = ipc_space_t; +pub type host_name_t = host_t; +pub type host_name_port_t = host_t; +pub type processor_set_port_t = processor_set_t; +pub type processor_set_name_port_t = processor_set_t; +pub type processor_set_name_port_array_t = processor_set_array_t; +pub type processor_set_control_port_t = processor_set_t; +pub type processor_port_t = processor_t; +pub type processor_port_array_t = processor_array_t; +pub type thread_act_port_t = thread_act_t; +pub type thread_act_port_array_t = thread_act_array_t; +pub type semaphore_port_t = semaphore_t; +pub type lock_set_port_t = lock_set_t; +pub type ledger_port_t = ledger_t; +pub type ledger_port_array_t = ledger_array_t; +pub type alarm_port_t = alarm_t; +pub type clock_serv_port_t = clock_serv_t; +pub type clock_ctrl_port_t = clock_ctrl_t; +pub type exception_port_t = exception_handler_t; +pub type exception_port_arrary_t = exception_handler_array_t; + +pub const TASK_NULL: task_t = 0; +pub const TASK_NAME_NULL: task_name_t = 0; +pub const THREAD_NULL: thread_t = 0; +pub const TID_NULL: u64 = 0; +pub const THR_ACT_NULL: thread_act_t = 0; +pub const IPC_SPACE_NULL: ipc_space_t = 0; +pub const COALITION_NULL: coalition_t = 0; +pub const HOST_NULL: host_t = 0; +pub const HOST_PRIV_NULL: host_priv_t = 0; +pub const HOST_SECURITY_NULL: host_security_t = 0; +pub const PROCESSOR_SET_NULL: processor_set_t = 0; +pub const PROCESSOR_NULL: processor_t = 0; +pub const SEMAPHORE_NULL: semaphore_t = 0; +pub const LOCK_SET_NULL: lock_set_t = 0; +pub const LEDGER_NULL: ledger_t = 0; +pub const ALARM_NULL: alarm_t = 0; +pub const CLOCK_NULL: ::libc::clock_t = 0; +pub const UND_SERVER_NULL: UNDServerRef = 0; + +// <sys/_types.h>: typedef unsigned char __darwin_uuid_t[16]; +pub type uuid_t = [::libc::c_uchar; 16]; + +// <sys/_types/_fsid_t.h> +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct fsid { + pub val: [i32; 2], +} +pub type fsid_t = fsid; + +// <sys/_types/_fsobj_id_t.h> +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct fsobj_id { + pub fid_objno: u32, + pub fid_generation: u32, +} +pub type fsobj_id_t = fsobj_id; diff --git a/third_party/rust/mach/src/memory_object_types.rs b/third_party/rust/mach/src/memory_object_types.rs new file mode 100644 index 0000000000..8399e71676 --- /dev/null +++ b/third_party/rust/mach/src/memory_object_types.rs @@ -0,0 +1,9 @@ +//! This module roughly corresponds to `mach/memory_object_types.h`. + +use vm_types::natural_t; + +pub type memory_object_offset_t = ::libc::c_ulonglong; +pub type memory_object_size_t = ::libc::c_ulonglong; +pub type memory_object_cluster_size_t = natural_t; +pub type memory_object_fault_info_t = *mut natural_t; +pub type vm_object_id_t = ::libc::c_ulonglong; diff --git a/third_party/rust/mach/src/message.rs b/third_party/rust/mach/src/message.rs new file mode 100644 index 0000000000..4eafa5e9a4 --- /dev/null +++ b/third_party/rust/mach/src/message.rs @@ -0,0 +1,248 @@ +//! This module corresponds to `mach/message.h`. + +use kern_return::kern_return_t; +use port::{mach_port_name_t, mach_port_t}; +use vm_types::{integer_t, natural_t}; + +pub type mach_msg_timeout_t = natural_t; + +pub type mach_msg_bits_t = ::libc::c_uint; +pub type mach_msg_id_t = integer_t; +pub type mach_msg_size_t = natural_t; + +pub type mach_msg_copy_options_t = ::libc::c_uint; +pub type mach_msg_descriptor_type_t = ::libc::c_uint; +pub type mach_msg_type_name_t = ::libc::c_uint; + +pub type mach_msg_trailer_type_t = ::libc::c_uint; +pub type mach_msg_trailer_size_t = ::libc::c_uint; + +pub type mach_msg_option_t = integer_t; + +pub type mach_msg_type_number_t = natural_t; +pub type mach_msg_type_size_t = natural_t; + +pub type mach_msg_return_t = kern_return_t; + +pub const MACH_MSG_TIMEOUT_NONE: mach_msg_timeout_t = 0; + +pub const MACH_MSGH_BITS_ZERO: mach_msg_bits_t = 0x0000_0000; + +pub const MACH_MSGH_BITS_REMOTE_MASK: mach_msg_bits_t = 0x0000_001f; +pub const MACH_MSGH_BITS_LOCAL_MASK: mach_msg_bits_t = 0x0000_1f00; +pub const MACH_MSGH_BITS_VOUCHER_MASK: mach_msg_bits_t = 0x001f_0000; + +pub const MACH_MSGH_BITS_PORTS_MASK: mach_msg_bits_t = + MACH_MSGH_BITS_REMOTE_MASK | MACH_MSGH_BITS_LOCAL_MASK | MACH_MSGH_BITS_VOUCHER_MASK; + +pub const MACH_MSGH_BITS_COMPLEX: mach_msg_bits_t = 0x8000_0000; + +pub const MACH_MSGH_BITS_USER: mach_msg_bits_t = 0x801f_1f1f; + +#[allow(non_snake_case)] +pub fn MACH_MSGH_BITS(remote: mach_msg_bits_t, local: mach_msg_bits_t) -> mach_msg_bits_t { + remote | (local << 8) +} + +pub const MACH_MSG_TYPE_MOVE_RECEIVE: mach_msg_type_name_t = 16; +pub const MACH_MSG_TYPE_MOVE_SEND: mach_msg_type_name_t = 17; +pub const MACH_MSG_TYPE_MOVE_SEND_ONCE: mach_msg_type_name_t = 18; +pub const MACH_MSG_TYPE_COPY_SEND: mach_msg_type_name_t = 19; +pub const MACH_MSG_TYPE_MAKE_SEND: mach_msg_type_name_t = 20; +pub const MACH_MSG_TYPE_MAKE_SEND_ONCE: mach_msg_type_name_t = 21; +pub const MACH_MSG_TYPE_COPY_RECEIVE: mach_msg_type_name_t = 22; +pub const MACH_MSG_TYPE_DISPOSE_RECEIVE: mach_msg_type_name_t = 24; +pub const MACH_MSG_TYPE_DISPOSE_SEND: mach_msg_type_name_t = 25; +pub const MACH_MSG_TYPE_DISPOSE_SEND_ONCE: mach_msg_type_name_t = 26; + +pub const MACH_MSG_PHYSICAL_COPY: mach_msg_copy_options_t = 0; +pub const MACH_MSG_VIRTUAL_COPY: mach_msg_copy_options_t = 1; +pub const MACH_MSG_ALLOCATE: mach_msg_copy_options_t = 2; + +pub const MACH_MSG_PORT_DESCRIPTOR: mach_msg_descriptor_type_t = 0; +pub const MACH_MSG_OOL_DESCRIPTOR: mach_msg_descriptor_type_t = 1; +pub const MACH_MSG_OOL_PORTS_DESCRIPTOR: mach_msg_descriptor_type_t = 2; +pub const MACH_MSG_OOL_VOLATILE_DESCRIPTOR: mach_msg_descriptor_type_t = 3; + +pub const MACH_MSG_OPTION_NONE: mach_msg_option_t = 0x0000_0000; + +pub const MACH_SEND_MSG: mach_msg_option_t = 0x0000_0001; +pub const MACH_RCV_MSG: mach_msg_option_t = 0x0000_0002; + +pub const MACH_RCV_LARGE: mach_msg_option_t = 0x0000_0004; +pub const MACH_RCV_LARGE_IDENTITY: mach_msg_option_t = 0x0000_0008; + +pub const MACH_SEND_TIMEOUT: mach_msg_option_t = 0x0000_0010; +pub const MACH_SEND_INTERRUPT: mach_msg_option_t = 0x0000_0040; +pub const MACH_SEND_NOTIFY: mach_msg_option_t = 0x0000_0080; +pub const MACH_SEND_ALWAYS: mach_msg_option_t = 0x0001_0000; +pub const MACH_SEND_TRAILER: mach_msg_option_t = 0x0002_0000; +pub const MACH_SEND_NOIMPORTANCE: mach_msg_option_t = 0x0004_0000; +pub const MACH_SEND_NODENAP: mach_msg_option_t = MACH_SEND_NOIMPORTANCE; +pub const MACH_SEND_IMPORTANCE: mach_msg_option_t = 0x0008_0000; + +pub const MACH_RCV_TIMEOUT: mach_msg_option_t = 0x0000_0100; +pub const MACH_RCV_NOTIFY: mach_msg_option_t = 0x0000_0200; +pub const MACH_RCV_INTERRUPT: mach_msg_option_t = 0x0000_0400; +pub const MACH_RCV_VOUCHER: mach_msg_option_t = 0x0000_0800; +pub const MACH_RCV_OVERWRITE: mach_msg_option_t = 0x0000_1000; + +pub const MACH_MSG_SUCCESS: mach_msg_return_t = 0x0000_0000; + +pub const MACH_MSG_MASK: mach_msg_return_t = 0x0000_3e00; +pub const MACH_MSG_IPC_SPACE: mach_msg_return_t = 0x0000_2000; +pub const MACH_MSG_VM_SPACE: mach_msg_return_t = 0x0000_1000; +pub const MACH_MSG_IPC_KERNEL: mach_msg_return_t = 0x0000_0800; +pub const MACH_MSG_VM_KERNEL: mach_msg_return_t = 0x0000_0400; + +pub const MACH_SEND_IN_PROGRESS: mach_msg_return_t = 0x1000_0001; +pub const MACH_SEND_INVALID_DATA: mach_msg_return_t = 0x1000_0002; +pub const MACH_SEND_INVALID_DEST: mach_msg_return_t = 0x1000_0003; +pub const MACH_SEND_TIMED_OUT: mach_msg_return_t = 0x1000_0004; +pub const MACH_SEND_INVALID_VOUCHER: mach_msg_return_t = 0x1000_0005; +pub const MACH_SEND_INTERRUPTED: mach_msg_return_t = 0x1000_0007; +pub const MACH_SEND_MSG_TOO_SMALL: mach_msg_return_t = 0x1000_0008; +pub const MACH_SEND_INVALID_REPLY: mach_msg_return_t = 0x1000_0009; +pub const MACH_SEND_INVALID_RIGHT: mach_msg_return_t = 0x1000_000a; +pub const MACH_SEND_INVALID_NOTIFY: mach_msg_return_t = 0x1000_000b; +pub const MACH_SEND_INVALID_MEMORY: mach_msg_return_t = 0x1000_000c; +pub const MACH_SEND_NO_BUFFER: mach_msg_return_t = 0x1000_000d; +pub const MACH_SEND_TOO_LARGE: mach_msg_return_t = 0x1000_000e; +pub const MACH_SEND_INVALID_TYPE: mach_msg_return_t = 0x1000_000f; +pub const MACH_SEND_INVALID_HEADER: mach_msg_return_t = 0x1000_0010; +pub const MACH_SEND_INVALID_TRAILER: mach_msg_return_t = 0x1000_0011; +pub const MACH_SEND_INVALID_RT_OOL_SIZE: mach_msg_return_t = 0x1000_0015; + +pub const MACH_RCV_IN_PROGRESS: mach_msg_return_t = 0x1000_4001; +pub const MACH_RCV_INVALID_NAME: mach_msg_return_t = 0x1000_4002; +pub const MACH_RCV_TIMED_OUT: mach_msg_return_t = 0x1000_4003; +pub const MACH_RCV_TOO_LARGE: mach_msg_return_t = 0x1000_4004; +pub const MACH_RCV_INTERRUPTED: mach_msg_return_t = 0x1000_4005; +pub const MACH_RCV_PORT_CHANGED: mach_msg_return_t = 0x1000_4006; +pub const MACH_RCV_INVALID_NOTIFY: mach_msg_return_t = 0x1000_4007; +pub const MACH_RCV_INVALID_DATA: mach_msg_return_t = 0x1000_4008; +pub const MACH_RCV_PORT_DIED: mach_msg_return_t = 0x1000_4009; +pub const MACH_RCV_IN_SET: mach_msg_return_t = 0x1000_400a; +pub const MACH_RCV_HEADER_ERROR: mach_msg_return_t = 0x1000_400b; +pub const MACH_RCV_BODY_ERROR: mach_msg_return_t = 0x1000_400c; +pub const MACH_RCV_INVALID_TYPE: mach_msg_return_t = 0x1000_400d; +pub const MACH_RCV_SCATTER_SMALL: mach_msg_return_t = 0x1000_400e; +pub const MACH_RCV_INVALID_TRAILER: mach_msg_return_t = 0x1000_400f; +pub const MACH_RCV_IN_PROGRESS_TIMED: mach_msg_return_t = 0x1000_4011; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_header_t { + pub msgh_bits: mach_msg_bits_t, + pub msgh_size: mach_msg_size_t, + pub msgh_remote_port: mach_port_t, + pub msgh_local_port: mach_port_t, + pub msgh_voucher_port: mach_port_name_t, + pub msgh_id: mach_msg_id_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_body_t { + pub msgh_descriptor_count: mach_msg_size_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_base_t { + pub header: mach_msg_header_t, + pub body: mach_msg_body_t, +} + +pub const MACH_MSG_TRAILER_FORMAT_0: mach_msg_trailer_type_t = 0; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_trailer_t { + pub msgh_trailer_type: mach_msg_trailer_type_t, + pub msgh_trailer_size: mach_msg_trailer_size_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_port_descriptor_t { + pub name: mach_port_t, + pub pad1: mach_msg_size_t, + pub pad2: u16, + pub disposition: u8, // mach_msg_type_name_t bitfield + pub type_: u8, // mach_msg_descriptor_type_t bitfield +} + +impl mach_msg_port_descriptor_t { + pub fn new(name: mach_port_t, disposition: mach_msg_type_name_t) -> Self { + Self { + name, + pad1: 0, + pad2: 0, + disposition: disposition as u8, + type_: MACH_MSG_PORT_DESCRIPTOR as u8, + } + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_ool_descriptor_t { + pub address: *mut ::libc::c_void, + #[cfg(not(target_pointer_width = "64"))] + pub size: mach_msg_size_t, + pub deallocate: u8, // boolean_t bitfield + pub copy: u8, // mach_msg_copy_options_t bitfield + pub pad1: u8, + pub type_: u8, // mach_msg_descriptor_type_t bitfield + #[cfg(target_pointer_width = "64")] + pub size: mach_msg_size_t, +} + +impl mach_msg_ool_descriptor_t { + pub fn new( + address: *mut ::libc::c_void, + deallocate: bool, + copy: mach_msg_copy_options_t, + size: u32, + ) -> Self { + Self { + address, + deallocate: if deallocate { 1 } else { 0 }, + copy: copy as u8, + pad1: 0, + type_: MACH_MSG_OOL_DESCRIPTOR as u8, + size, + } + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_ool_ports_descriptor_t { + pub address: *mut ::libc::c_void, + #[cfg(not(target_pointer_width = "64"))] + pub count: mach_msg_size_t, + pub deallocate: u8, // boolean_t bitfield + pub copy: u8, // mach_msg_copy_options_t bitfield + pub disposition: u8, // mach_msg_type_name_t bitfield + pub type_: u8, // mach_msg_descriptor_type_t bitfield + #[cfg(target_pointer_width = "64")] + pub count: mach_msg_size_t, +} + +extern "C" { + pub fn mach_msg( + msg: *mut mach_msg_header_t, + option: mach_msg_option_t, + send_size: mach_msg_size_t, + recv_size: mach_msg_size_t, + recv_name: mach_port_name_t, + timeout: mach_msg_timeout_t, + notify: mach_port_name_t, + ) -> mach_msg_return_t; + + // from mach/mach.h + pub fn mach_msg_send(msg: *mut mach_msg_header_t) -> mach_msg_return_t; + pub fn mach_msg_destroy(msg: *mut mach_msg_header_t); +} diff --git a/third_party/rust/mach/src/port.rs b/third_party/rust/mach/src/port.rs new file mode 100644 index 0000000000..e43e81d0d3 --- /dev/null +++ b/third_party/rust/mach/src/port.rs @@ -0,0 +1,26 @@ +//! This module corresponds to `mach/port.h` + +use vm_types::natural_t; + +pub type mach_port_name_t = natural_t; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct ipc_port; + +pub type ipc_port_t = *mut ipc_port; + +pub type mach_port_t = ::libc::c_uint; + +pub const MACH_PORT_NULL: mach_port_t = 0; +pub const MACH_PORT_DEAD: mach_port_t = !0; + +pub type mach_port_right_t = natural_t; + +pub const MACH_PORT_RIGHT_SEND: mach_port_right_t = 0; +pub const MACH_PORT_RIGHT_RECEIVE: mach_port_right_t = 1; +pub const MACH_PORT_RIGHT_SEND_ONCE: mach_port_right_t = 2; +pub const MACH_PORT_RIGHT_PORT_SET: mach_port_right_t = 3; +pub const MACH_PORT_RIGHT_DEAD_NAME: mach_port_right_t = 4; +pub const MACH_PORT_RIGHT_LABELH: mach_port_right_t = 5; +pub const MACH_PORT_RIGHT_NUMBER: mach_port_right_t = 6; diff --git a/third_party/rust/mach/src/structs.rs b/third_party/rust/mach/src/structs.rs new file mode 100644 index 0000000000..75dc0e8dba --- /dev/null +++ b/third_party/rust/mach/src/structs.rs @@ -0,0 +1,62 @@ +//! This module corresponds to `mach/_structs.h`. + +use mem; +use message::mach_msg_type_number_t; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct x86_thread_state64_t { + pub __rax: u64, + pub __rbx: u64, + pub __rcx: u64, + pub __rdx: u64, + pub __rdi: u64, + pub __rsi: u64, + pub __rbp: u64, + pub __rsp: u64, + pub __r8: u64, + pub __r9: u64, + pub __r10: u64, + pub __r11: u64, + pub __r12: u64, + pub __r13: u64, + pub __r14: u64, + pub __r15: u64, + pub __rip: u64, + pub __rflags: u64, + pub __cs: u64, + pub __fs: u64, + pub __gs: u64, +} + +impl x86_thread_state64_t { + pub fn new() -> Self { + Self { + __rax: 0, + __rbx: 0, + __rcx: 0, + __rdx: 0, + __rdi: 0, + __rsi: 0, + __rbp: 0, + __rsp: 0, + __r8: 0, + __r9: 0, + __r10: 0, + __r11: 0, + __r12: 0, + __r13: 0, + __r14: 0, + __r15: 0, + __rip: 0, + __rflags: 0, + __cs: 0, + __fs: 0, + __gs: 0, + } + } + + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} diff --git a/third_party/rust/mach/src/task.rs b/third_party/rust/mach/src/task.rs new file mode 100644 index 0000000000..1ca2280eb1 --- /dev/null +++ b/third_party/rust/mach/src/task.rs @@ -0,0 +1,41 @@ +//! This module corresponds to `mach/task.defs`. + +use kern_return::kern_return_t; +use mach_types::{task_name_t, task_t, thread_act_array_t}; +use message::mach_msg_type_number_t; +use port::mach_port_t; +use task_info::{task_flavor_t, task_info_t}; + +pub type task_special_port_t = ::libc::c_int; + +pub const TASK_KERNEL_PORT: task_special_port_t = 1; +pub const TASK_HOST_PORT: task_special_port_t = 2; +pub const TASK_NAME_PORT: task_special_port_t = 3; +pub const TASK_BOOTSTRAP_PORT: task_special_port_t = 4; + +extern "C" { + pub fn task_resume(target_task: task_t) -> kern_return_t; + pub fn task_suspend(target_task: task_t) -> kern_return_t; + pub fn task_get_special_port( + task: task_t, + which_port: task_special_port_t, + special_port: *mut mach_port_t, + ) -> kern_return_t; + pub fn task_threads( + target_task: task_t, + act_list: *mut thread_act_array_t, + act_list_cnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + pub fn task_info( + target_task: task_name_t, + flavor: task_flavor_t, + task_info_out: task_info_t, + task_info_outCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + pub fn task_set_info( + target_task: task_t, + flavor: task_flavor_t, + task_info_in: task_info_t, + task_info_inCnt: mach_msg_type_number_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/task_info.rs b/third_party/rust/mach/src/task_info.rs new file mode 100644 index 0000000000..4a3b8ed710 --- /dev/null +++ b/third_party/rust/mach/src/task_info.rs @@ -0,0 +1,44 @@ +//! This module roughly corresponds to `mach/task_info.h`. + +use vm_types::{integer_t, mach_vm_address_t, mach_vm_size_t, natural_t}; + +pub const TASK_INFO_MAX: ::libc::c_uint = 1024; +pub const TASK_BASIC_INFO_32: ::libc::c_uint = 4; +pub const TASK_BASIC2_INFO_32: ::libc::c_uint = 6; +pub const TASK_BASIC_INFO_64: ::libc::c_uint = 5; +#[cfg(target_arch = "x86_64")] +pub const TASK_BASIC_INFO: ::libc::c_uint = 5; +#[cfg(target_arch = "x86")] +pub const TASK_BASIC_INFO: ::libc::c_uint = 4; +pub const TASK_EVENTS_INFO: ::libc::c_uint = 2; +pub const TASK_THREAD_TIMES_INFO: ::libc::c_uint = 3; +pub const TASK_ABSOLUTETIME_INFO: ::libc::c_uint = 1; +pub const TASK_KERNELMEMORY_INFO: ::libc::c_uint = 7; +pub const TASK_SECURITY_TOKEN: ::libc::c_uint = 13; +pub const TASK_AUDIT_TOKEN: ::libc::c_uint = 15; +pub const TASK_AFFINITY_TAG_INFO: ::libc::c_uint = 16; +pub const TASK_DYLD_INFO: ::libc::c_uint = 17; +pub const TASK_DYLD_ALL_IMAGE_INFO_32: ::libc::c_uint = 0; +pub const TASK_DYLD_ALL_IMAGE_INFO_64: ::libc::c_uint = 1; +pub const TASK_EXTMOD_INFO: ::libc::c_uint = 19; +pub const MACH_TASK_BASIC_INFO: ::libc::c_uint = 20; +pub const TASK_POWER_INFO: ::libc::c_uint = 21; +pub const TASK_VM_INFO: ::libc::c_uint = 22; +pub const TASK_VM_INFO_PURGEABLE: ::libc::c_uint = 23; +pub const TASK_TRACE_MEMORY_INFO: ::libc::c_uint = 24; +pub const TASK_WAIT_STATE_INFO: ::libc::c_uint = 25; +pub const TASK_POWER_INFO_V2: ::libc::c_uint = 26; +pub const TASK_VM_INFO_PURGEABLE_ACCOUNT: ::libc::c_uint = 27; +pub const TASK_FLAGS_INFO: ::libc::c_uint = 28; +pub const TASK_DEBUG_INFO_INTERNAL: ::libc::c_uint = 29; + +pub type task_flavor_t = natural_t; +pub type task_info_t = *mut integer_t; + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct task_dyld_info { + pub all_image_info_addr: mach_vm_address_t, + pub all_image_info_size: mach_vm_size_t, + pub all_image_info_format: integer_t, +} diff --git a/third_party/rust/mach/src/thread_act.rs b/third_party/rust/mach/src/thread_act.rs new file mode 100644 index 0000000000..f2f9809a2b --- /dev/null +++ b/third_party/rust/mach/src/thread_act.rs @@ -0,0 +1,23 @@ +//! This module corresponds to `mach/thread_act.defs`. + +use kern_return::kern_return_t; +use mach_types::thread_act_t; +use message::mach_msg_type_number_t; +use thread_status::{thread_state_flavor_t, thread_state_t}; + +extern "C" { + pub fn thread_get_state( + target_act: thread_act_t, + flavor: thread_state_flavor_t, + new_state: thread_state_t, + new_state_count: *mut mach_msg_type_number_t, + ) -> kern_return_t; +} + +extern "C" { + pub fn thread_suspend(target_act: thread_act_t) -> kern_return_t; +} + +extern "C" { + pub fn thread_resume(target_act: thread_act_t) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/thread_status.rs b/third_party/rust/mach/src/thread_status.rs new file mode 100644 index 0000000000..951256622c --- /dev/null +++ b/third_party/rust/mach/src/thread_status.rs @@ -0,0 +1,23 @@ +//! This module corresponds to `mach/thread_status.h`. + +use vm_types::natural_t; + +pub type thread_state_t = *mut natural_t; +pub type thread_state_flavor_t = ::libc::c_int; + +pub static x86_THREAD_STATE32: thread_state_flavor_t = 1; +pub static x86_FLOAT_STATE32: thread_state_flavor_t = 2; +pub static x86_EXCEPTION_STATE32: thread_state_flavor_t = 3; +pub static x86_THREAD_STATE64: thread_state_flavor_t = 4; +pub static x86_FLOAT_STATE64: thread_state_flavor_t = 5; +pub static x86_EXCEPTION_STATE64: thread_state_flavor_t = 6; +pub static x86_THREAD_STATE: thread_state_flavor_t = 7; +pub static x86_FLOAT_STATE: thread_state_flavor_t = 8; +pub static x86_EXCEPTION_STATE: thread_state_flavor_t = 9; +pub static x86_DEBUG_STATE32: thread_state_flavor_t = 10; +pub static x86_DEBUG_STATE64: thread_state_flavor_t = 11; +pub static x86_DEBUG_STATE: thread_state_flavor_t = 12; +pub static THREAD_STATE_NONE: thread_state_flavor_t = 13; +pub static x86_AVX_STATE32: thread_state_flavor_t = 16; +pub static x86_AVX_STATE64: thread_state_flavor_t = 17; +pub static x86_AVX_STATE: thread_state_flavor_t = 18; diff --git a/third_party/rust/mach/src/traps.rs b/third_party/rust/mach/src/traps.rs new file mode 100644 index 0000000000..bc8694fcbf --- /dev/null +++ b/third_party/rust/mach/src/traps.rs @@ -0,0 +1,35 @@ +//! This module corresponds to `mach/mach_traps.h`. +use kern_return::kern_return_t; +use port::{mach_port_name_t, mach_port_t}; + +extern "C" { + static mach_task_self_: mach_port_t; + pub fn task_for_pid( + target_tport: mach_port_name_t, + pid: ::libc::c_int, + tn: *mut mach_port_name_t, + ) -> kern_return_t; +} + +pub unsafe fn mach_task_self() -> mach_port_t { + mach_task_self_ +} + +pub unsafe fn current_task() -> mach_port_t { + mach_task_self() +} + +#[cfg(test)] +mod tests { + use port::*; + use traps::*; + + #[test] + fn mach_task_self_sanity() { + unsafe { + let this_task = mach_task_self(); + assert!(this_task != MACH_PORT_NULL); + assert!(this_task != MACH_PORT_DEAD); + } + } +} diff --git a/third_party/rust/mach/src/vm.rs b/third_party/rust/mach/src/vm.rs new file mode 100644 index 0000000000..400ff2bf8a --- /dev/null +++ b/third_party/rust/mach/src/vm.rs @@ -0,0 +1,247 @@ +//! This module roughly corresponds to `mach/mach_vm.defs`. + +use boolean::boolean_t; +use kern_return::kern_return_t; +use mach_types::{mem_entry_name_port_t, vm_task_entry_t}; +use memory_object_types::{memory_object_offset_t, memory_object_size_t}; +use message::mach_msg_type_number_t; +use port::mach_port_t; +use vm_attributes::{vm_machine_attribute_t, vm_machine_attribute_val_t}; +use vm_behavior::vm_behavior_t; +use vm_inherit::vm_inherit_t; +use vm_prot::vm_prot_t; +use vm_purgable::vm_purgable_t; +use vm_region::mach_vm_read_entry_t; +use vm_region::{ + vm_page_info_flavor_t, vm_page_info_t, vm_region_flavor_t, vm_region_info_t, + vm_region_recurse_info_t, +}; +use vm_sync::vm_sync_t; +use vm_types::{ + integer_t, mach_vm_address_t, mach_vm_offset_t, mach_vm_size_t, natural_t, vm_map_t, + vm_offset_t, vm_size_t, +}; + +extern "C" { + pub fn mach_vm_allocate( + target: vm_task_entry_t, + address: *mut mach_vm_address_t, + size: mach_vm_size_t, + flags: ::libc::c_int, + ) -> kern_return_t; + + pub fn mach_vm_deallocate( + target: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + ) -> kern_return_t; + + pub fn mach_vm_protect( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + set_maximum: boolean_t, + new_protection: vm_prot_t, + ) -> kern_return_t; + + pub fn mach_vm_inherit( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + new_inheritance: vm_inherit_t, + ) -> kern_return_t; + + pub fn mach_vm_read( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + data: *mut vm_offset_t, + dataCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + + pub fn mach_vm_read_list( + target_task: vm_task_entry_t, + data_list: mach_vm_read_entry_t, + count: natural_t, + ) -> kern_return_t; + + pub fn mach_vm_write( + target_task: vm_map_t, + address: mach_vm_address_t, + data: vm_offset_t, + dataCnt: mach_msg_type_number_t, + ) -> kern_return_t; + + pub fn mach_vm_copy( + target_task: vm_task_entry_t, + source_address: mach_vm_address_t, + size: mach_vm_size_t, + dest_address: mach_vm_address_t, + ) -> kern_return_t; + + pub fn mach_vm_read_overwrite( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + data: mach_vm_address_t, + outsize: *mut mach_vm_size_t, + ) -> kern_return_t; + + pub fn mach_vm_msync( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + sync_flags: vm_sync_t, + ) -> kern_return_t; + + pub fn mach_vm_behavior_set( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + new_behavior: vm_behavior_t, + ) -> kern_return_t; + + pub fn mach_vm_map( + target_task: vm_task_entry_t, + inout: *mut mach_vm_address_t, + size: mach_vm_size_t, + mask: mach_vm_offset_t, + flags: ::libc::c_int, + object: mem_entry_name_port_t, + offset: memory_object_offset_t, + copy: boolean_t, + cur_protection: vm_prot_t, + max_protection: vm_prot_t, + inheritance: vm_inherit_t, + ) -> kern_return_t; + + pub fn mach_vm_machine_attribute( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + attribute: vm_machine_attribute_t, + value: *mut vm_machine_attribute_val_t, + ) -> kern_return_t; + + pub fn mach_vm_remap( + target_task: vm_task_entry_t, + target_address: *mut mach_vm_address_t, + size: mach_vm_size_t, + mask: mach_vm_offset_t, + flags: ::libc::c_int, + src_task: vm_task_entry_t, + src_address: mach_vm_address_t, + copy: boolean_t, + cur_protection: *mut vm_prot_t, + out: *mut vm_prot_t, + inheritance: vm_inherit_t, + ) -> kern_return_t; + + pub fn mach_vm_page_query( + target_map: vm_map_t, + offset: mach_vm_offset_t, + disposition: *mut integer_t, + ref_count: *mut integer_t, + ) -> kern_return_t; + + pub fn mach_vm_region_recurse( + target_task: vm_task_entry_t, + address: *mut mach_vm_address_t, + size: *mut mach_vm_size_t, + nesting_depth: *mut natural_t, + info: vm_region_recurse_info_t, + infoCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + + pub fn mach_vm_region( + target_task: vm_task_entry_t, + address: *mut mach_vm_address_t, + size: *mut mach_vm_size_t, + flavor: vm_region_flavor_t, + info: vm_region_info_t, + infoCnt: *mut mach_msg_type_number_t, + object_name: *mut mach_port_t, + ) -> kern_return_t; + + pub fn mach_make_memory_entry( + target_task: vm_map_t, + size: *mut vm_size_t, + offset: vm_offset_t, + permission: vm_prot_t, + object_handle: *mut mem_entry_name_port_t, + parent_handle: mem_entry_name_port_t, + ) -> kern_return_t; + + pub fn mach_make_memory_entry_64( + target_task: vm_map_t, + size: *mut memory_object_size_t, + offset: memory_object_offset_t, + permission: vm_prot_t, + object_handle: *mut mach_port_t, + parent_entry: mem_entry_name_port_t, + ) -> kern_return_t; + + pub fn mach_vm_purgable_control( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + control: vm_purgable_t, + state: *mut ::libc::c_int, + ) -> kern_return_t; + + pub fn mach_vm_page_info( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + flavor: vm_page_info_flavor_t, + info: vm_page_info_t, + infoCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; +} + +#[cfg(test)] +mod tests { + use super::*; + use kern_return::KERN_SUCCESS; + use traps::mach_task_self; + use vm_statistics::VM_FLAGS_ANYWHERE; + + #[test] + fn mach_vm_allocate_sanity() { + unsafe { + let size = 0x100; + let task = mach_task_self(); + + let mut address: mach_vm_address_t = 0; + assert_eq!( + mach_vm_allocate(task, &mut address, size, VM_FLAGS_ANYWHERE), + KERN_SUCCESS + ); + assert_eq!(mach_vm_deallocate(task, address, size), KERN_SUCCESS); + } + } + + #[test] + fn mach_vm_region_sanity() { + use mem; + use vm_prot::{VM_PROT_EXECUTE, VM_PROT_READ}; + use vm_region::{vm_region_basic_info_64, VM_REGION_BASIC_INFO_64}; + unsafe { + let mut size = 0x10; + let mut object_name = 0; + let mut address = mach_vm_region_sanity as mach_vm_address_t; + let mut info: vm_region_basic_info_64 = mem::zeroed(); + let mut info_size = vm_region_basic_info_64::count(); + + let result = mach_vm_region( + mach_task_self(), + &mut address, + &mut size, + VM_REGION_BASIC_INFO_64, + (&mut info as *mut _) as vm_region_info_t, + &mut info_size, + &mut object_name, + ); + assert_eq!(result, KERN_SUCCESS); + assert_eq!(info.protection, VM_PROT_READ | VM_PROT_EXECUTE); + } + } +} diff --git a/third_party/rust/mach/src/vm_attributes.rs b/third_party/rust/mach/src/vm_attributes.rs new file mode 100644 index 0000000000..9c484b1d17 --- /dev/null +++ b/third_party/rust/mach/src/vm_attributes.rs @@ -0,0 +1,18 @@ +//! This module corresponds to `mach/vm_attributes.h`. + +pub type vm_machine_attribute_t = ::libc::c_uint; + +pub const MATTR_CACHE: vm_machine_attribute_t = 1; +pub const MATTR_MIGRATE: vm_machine_attribute_t = (1 << 1); +pub const MATTR_REPLICATE: vm_machine_attribute_t = (1 << 2); + +pub type vm_machine_attribute_val_t = ::libc::c_int; + +pub const MATTR_VAL_OFF: vm_machine_attribute_val_t = 0; +pub const MATTR_VAL_ON: vm_machine_attribute_val_t = 1; +pub const MATTR_VAL_GET: vm_machine_attribute_val_t = 2; +pub const MATTR_VAL_CACHE_FLUSH: vm_machine_attribute_val_t = 6; +pub const MATTR_VAL_DCACHE_FLUSH: vm_machine_attribute_val_t = 7; +pub const MATTR_VAL_ICACHE_FLUSH: vm_machine_attribute_val_t = 8; +pub const MATTR_VAL_CACHE_SYNC: vm_machine_attribute_val_t = 9; +pub const MATTR_VAL_GET_INFO: vm_machine_attribute_val_t = 10; diff --git a/third_party/rust/mach/src/vm_behavior.rs b/third_party/rust/mach/src/vm_behavior.rs new file mode 100644 index 0000000000..8ab692e550 --- /dev/null +++ b/third_party/rust/mach/src/vm_behavior.rs @@ -0,0 +1,15 @@ +//! This module corresponds to `mach/vm_behavior.h`. + +pub type vm_behavior_t = ::libc::c_int; + +pub const VM_BEHAVIOR_DEFAULT: vm_behavior_t = 0; +pub const VM_BEHAVIOR_RANDOM: vm_behavior_t = 1; +pub const VM_BEHAVIOR_SEQUENTIAL: vm_behavior_t = 2; +pub const VM_BEHAVIOR_RSEQNTL: vm_behavior_t = 3; +pub const VM_BEHAVIOR_WILLNEED: vm_behavior_t = 4; +pub const VM_BEHAVIOR_DONTNEED: vm_behavior_t = 5; +pub const VM_BEHAVIOR_FREE: vm_behavior_t = 6; +pub const VM_BEHAVIOR_ZERO_WIRED_PAGES: vm_behavior_t = 7; +pub const VM_BEHAVIOR_REUSABLE: vm_behavior_t = 8; +pub const VM_BEHAVIOR_REUSE: vm_behavior_t = 9; +pub const VM_BEHAVIOR_CAN_REUSE: vm_behavior_t = 10; diff --git a/third_party/rust/mach/src/vm_inherit.rs b/third_party/rust/mach/src/vm_inherit.rs new file mode 100644 index 0000000000..4f4c9e5ef7 --- /dev/null +++ b/third_party/rust/mach/src/vm_inherit.rs @@ -0,0 +1,10 @@ +//! This module corresponds to `mach/vm_inherit.h`. + +pub type vm_inherit_t = ::libc::c_uint; + +pub const VM_INHERIT_SHARE: vm_inherit_t = 0; +pub const VM_INHERIT_COPY: vm_inherit_t = 1; +pub const VM_INHERIT_NONE: vm_inherit_t = 2; +pub const VM_INHERIT_DONATE_COPY: vm_inherit_t = 3; +pub const VM_INHERIT_DEFAULT: vm_inherit_t = VM_INHERIT_COPY; +pub const VM_INHERIT_LAST_VALID: vm_inherit_t = VM_INHERIT_NONE; diff --git a/third_party/rust/mach/src/vm_page_size.rs b/third_party/rust/mach/src/vm_page_size.rs new file mode 100644 index 0000000000..511932eb09 --- /dev/null +++ b/third_party/rust/mach/src/vm_page_size.rs @@ -0,0 +1,33 @@ +//! This module roughly corresponds to `mach/vm_page_size.h` + +use vm_types::{mach_vm_offset_t, mach_vm_size_t, vm_size_t}; + +extern "C" { + pub static vm_page_size: vm_size_t; + pub static vm_page_mask: vm_size_t; + pub static vm_page_shift: ::libc::c_int; +} + +pub unsafe fn mach_vm_trunc_page(x: mach_vm_offset_t) -> mach_vm_offset_t { + (x & !(vm_page_mask as mach_vm_size_t)) +} + +pub unsafe fn mach_vm_round_page(x: mach_vm_offset_t) -> mach_vm_offset_t { + ((x + vm_page_mask as mach_vm_size_t) & !(vm_page_mask as mach_vm_size_t)) +} + +#[cfg(test)] +mod tests { + use vm_page_size::*; + use vm_types::mach_vm_size_t; + + #[test] + fn page_size() { + unsafe { + assert!(vm_page_size > 0); + assert!(vm_page_size % 2 == 0); + assert_eq!(mach_vm_round_page(1), vm_page_size as mach_vm_size_t); + assert_eq!(vm_page_size, 4096); + } + } +} diff --git a/third_party/rust/mach/src/vm_prot.rs b/third_party/rust/mach/src/vm_prot.rs new file mode 100644 index 0000000000..8f7d3fbc53 --- /dev/null +++ b/third_party/rust/mach/src/vm_prot.rs @@ -0,0 +1,14 @@ +//! This module corresponds to `mach/vm_prot.h`. + +pub type vm_prot_t = ::libc::c_int; + +pub const VM_PROT_NONE: vm_prot_t = 0; +pub const VM_PROT_READ: vm_prot_t = 1; +pub const VM_PROT_WRITE: vm_prot_t = (1 << 1); +pub const VM_PROT_EXECUTE: vm_prot_t = (1 << 2); +pub const VM_PROT_NO_CHANGE: vm_prot_t = (1 << 3); +pub const VM_PROT_COPY: vm_prot_t = (1 << 4); +pub const VM_PROT_WANTS_COPY: vm_prot_t = (1 << 4); +pub const VM_PROT_TRUSTED: vm_prot_t = (1 << 5); +pub const VM_PROT_DEFAULT: vm_prot_t = VM_PROT_READ | VM_PROT_WRITE; +pub const VM_PROT_ALL: vm_prot_t = VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE; diff --git a/third_party/rust/mach/src/vm_purgable.rs b/third_party/rust/mach/src/vm_purgable.rs new file mode 100644 index 0000000000..622f3b8bb0 --- /dev/null +++ b/third_party/rust/mach/src/vm_purgable.rs @@ -0,0 +1,42 @@ +//! This module corresponds to `mach/vm_purgable.h`. + +pub type vm_purgable_t = ::libc::c_int; + +pub const VM_PURGABLE_SET_STATE: vm_purgable_t = 0; +pub const VM_PURGABLE_GET_STATE: vm_purgable_t = 1; + +pub const VM_VOLATILE_GROUP_SHIFT: ::libc::c_int = 8; +pub const VM_VOLATILE_GROUP_MASK: ::libc::c_int = (7 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_DEFAULT: ::libc::c_int = VM_VOLATILE_GROUP_0; + +pub const VM_VOLATILE_GROUP_0: ::libc::c_int = (0 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_1: ::libc::c_int = (1 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_2: ::libc::c_int = (2 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_3: ::libc::c_int = (3 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_4: ::libc::c_int = (4 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_5: ::libc::c_int = (5 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_6: ::libc::c_int = (6 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_7: ::libc::c_int = (7 << VM_VOLATILE_GROUP_SHIFT); + +pub const VM_PURGABLE_BEHAVIOR_SHIFT: ::libc::c_int = 6; +pub const VM_PURGABLE_BEHAVIOR_MASK: ::libc::c_int = (1 << VM_PURGABLE_BEHAVIOR_SHIFT); +pub const VM_PURGABLE_BEHAVIOR_FIFO: ::libc::c_int = (0 << VM_PURGABLE_BEHAVIOR_SHIFT); +pub const VM_PURGABLE_BEHAVIOR_LIFO: ::libc::c_int = (1 << VM_PURGABLE_BEHAVIOR_SHIFT); + +pub const VM_PURGABLE_ORDERING_SHIFT: ::libc::c_int = 5; +pub const VM_PURGABLE_ORDERING_MASK: ::libc::c_int = (1 << VM_PURGABLE_ORDERING_SHIFT); +pub const VM_PURGABLE_ORDERING_OBSOLETE: ::libc::c_int = (1 << VM_PURGABLE_ORDERING_SHIFT); +pub const VM_PURGABLE_ORDERING_NORMAL: ::libc::c_int = (0 << VM_PURGABLE_ORDERING_SHIFT); + +pub const VM_VOLATILE_ORDER_SHIFT: ::libc::c_int = 4; +pub const VM_VOLATILE_ORDER_MASK: ::libc::c_int = (1 << VM_VOLATILE_ORDER_SHIFT); +pub const VM_VOLATILE_MAKE_FIRST_IN_GROUP: ::libc::c_int = (1 << VM_VOLATILE_ORDER_SHIFT); +pub const VM_VOLATILE_MAKE_LAST_IN_GROUP: ::libc::c_int = (0 << VM_VOLATILE_ORDER_SHIFT); + +pub const VM_PURGABLE_STATE_MIN: ::libc::c_int = 0; +pub const VM_PURGABLE_STATE_MAX: ::libc::c_int = 3; +pub const VM_PURGABLE_STATE_MASK: ::libc::c_int = 3; +pub const VM_PURGABLE_NONVOLATILE: ::libc::c_int = 0; +pub const VM_PURGABLE_VOLATILE: ::libc::c_int = 1; +pub const VM_PURGABLE_EMPTY: ::libc::c_int = 2; +pub const VM_PURGABLE_DENY: ::libc::c_int = 3; diff --git a/third_party/rust/mach/src/vm_region.rs b/third_party/rust/mach/src/vm_region.rs new file mode 100644 index 0000000000..0586d4ea57 --- /dev/null +++ b/third_party/rust/mach/src/vm_region.rs @@ -0,0 +1,238 @@ +//! This module roughly corresponds to `mach/vm_region.h`. + +use boolean::boolean_t; +use mem; +use memory_object_types::{memory_object_offset_t, vm_object_id_t}; +use message::mach_msg_type_number_t; +use vm_behavior::vm_behavior_t; +use vm_inherit::vm_inherit_t; +use vm_prot::vm_prot_t; +use vm_types::{mach_vm_address_t, mach_vm_size_t}; + +pub type vm32_object_id_t = u32; + +pub type vm_region_info_t = *mut ::libc::c_int; +pub type vm_region_info_64_t = *mut ::libc::c_int; +pub type vm_region_recurse_info_t = *mut ::libc::c_int; +pub type vm_region_recurse_info_64_t = *mut ::libc::c_int; +pub type vm_region_flavor_t = ::libc::c_int; +pub type vm_region_info_data_t = [::libc::c_int; VM_REGION_INFO_MAX as usize]; + +pub type vm_region_basic_info_64_t = *mut vm_region_basic_info_64; +pub type vm_region_basic_info_data_64_t = vm_region_basic_info_64; +pub type vm_region_basic_info_t = *mut vm_region_basic_info; +pub type vm_region_basic_info_data_t = vm_region_basic_info; +pub type vm_region_extended_info_t = *mut vm_region_extended_info; +pub type vm_region_extended_info_data_t = vm_region_extended_info; +pub type vm_region_top_info_t = *mut vm_region_top_info; +pub type vm_region_top_info_data_t = vm_region_top_info; +pub type vm_region_submap_info_t = *mut vm_region_submap_info; +pub type vm_region_submap_info_data_t = vm_region_submap_info; +pub type vm_region_submap_info_64_t = *mut vm_region_submap_info_64; +pub type vm_region_submap_info_data_64_t = vm_region_submap_info_64; +pub type vm_region_submap_short_info_64_t = *mut vm_region_submap_short_info_64; +pub type vm_region_submap_short_info_data_64_t = vm_region_submap_short_info_64; +pub type vm_page_info_t = *mut ::libc::c_int; +pub type vm_page_info_flavor_t = ::libc::c_int; +pub type vm_page_info_basic_t = *mut vm_page_info_basic; +pub type vm_page_info_basic_data_t = vm_page_info_basic; +pub type mach_vm_read_entry_t = [mach_vm_read_entry; VM_MAP_ENTRY_MAX as usize]; + +pub const VM_REGION_INFO_MAX: ::libc::c_int = (1 << 10); +pub const VM_MAP_ENTRY_MAX: ::libc::c_int = (1 << 8); + +pub const VM_PAGE_INFO_BASIC: vm_page_info_flavor_t = 1; + +pub const VM_REGION_BASIC_INFO_64: vm_region_flavor_t = 9; +pub const VM_REGION_BASIC_INFO: vm_region_flavor_t = 10; +pub const VM_REGION_EXTENDED_INFO: vm_region_flavor_t = 13; +pub const VM_REGION_TOP_INFO: vm_region_flavor_t = 12; + +pub const SM_COW: ::libc::c_uchar = 1; +pub const SM_PRIVATE: ::libc::c_uchar = 2; +pub const SM_EMPTY: ::libc::c_uchar = 3; +pub const SM_SHARED: ::libc::c_uchar = 4; +pub const SM_TRUESHARED: ::libc::c_uchar = 5; +pub const SM_PRIVATE_ALIASED: ::libc::c_uchar = 6; +pub const SM_SHARED_ALIASED: ::libc::c_uchar = 7; + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_basic_info_64 { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub shared: boolean_t, + pub reserved: boolean_t, + pub offset: memory_object_offset_t, + pub behavior: vm_behavior_t, + pub user_wired_count: ::libc::c_ushort, +} + +impl vm_region_basic_info_64 { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_basic_info { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub shared: boolean_t, + pub reserved: boolean_t, + pub offset: u32, + pub behavior: vm_behavior_t, + pub user_wired_count: ::libc::c_ushort, +} + +impl vm_region_basic_info { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_extended_info { + pub protection: vm_prot_t, + pub user_tag: ::libc::c_uint, + pub pages_resident: ::libc::c_uint, + pub pages_shared_now_private: ::libc::c_uint, + pub pages_swapped_out: ::libc::c_uint, + pub pages_dirtied: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub shadow_depth: ::libc::c_ushort, + pub external_pager: ::libc::c_uchar, + pub share_mode: ::libc::c_uchar, + pub pages_reusable: ::libc::c_uint, +} + +impl vm_region_extended_info { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_top_info { + pub obj_id: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub private_pages_resident: ::libc::c_uint, + pub shared_pages_resident: ::libc::c_uint, + pub share_mode: ::libc::c_uchar, +} + +impl vm_region_top_info { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_submap_info { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub offset: u32, + pub user_tag: ::libc::c_uint, + pub pages_resident: ::libc::c_uint, + pub pages_shared_now_private: ::libc::c_uint, + pub pages_swapped_out: ::libc::c_uint, + pub pages_dirtied: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub shadow_depth: ::libc::c_ushort, + pub external_pager: ::libc::c_uchar, + pub share_mode: ::libc::c_uchar, + pub is_submap: boolean_t, + pub behavior: vm_behavior_t, + pub object_id: vm32_object_id_t, + pub user_wired_count: ::libc::c_ushort, +} + +impl vm_region_submap_info { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_submap_info_64 { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub offset: memory_object_offset_t, + pub user_tag: ::libc::c_uint, + pub pages_resident: ::libc::c_uint, + pub pages_shared_now_private: ::libc::c_uint, + pub pages_swapped_out: ::libc::c_uint, + pub pages_dirtied: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub shadow_depth: ::libc::c_ushort, + pub external_pager: ::libc::c_uchar, + pub share_mode: ::libc::c_uchar, + pub is_submap: boolean_t, + pub behavior: vm_behavior_t, + pub object_id: vm32_object_id_t, + pub user_wired_count: ::libc::c_ushort, + pub pages_reusable: ::libc::c_uint, +} + +impl vm_region_submap_info_64 { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_submap_short_info_64 { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub offset: memory_object_offset_t, + pub user_tag: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub shadow_depth: ::libc::c_ushort, + pub external_pager: ::libc::c_uchar, + pub share_mode: ::libc::c_uchar, + pub is_submap: boolean_t, + pub behavior: vm_behavior_t, + pub object_id: vm32_object_id_t, + pub user_wired_count: ::libc::c_ushort, +} + +impl vm_region_submap_short_info_64 { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_page_info_basic { + pub disposition: ::libc::c_int, + pub ref_count: ::libc::c_int, + pub object_id: vm_object_id_t, + pub offset: memory_object_offset_t, + pub depth: ::libc::c_int, + pub __pad: ::libc::c_int, +} + +impl vm_page_info_basic { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_vm_read_entry { + pub address: mach_vm_address_t, + pub size: mach_vm_size_t, +} diff --git a/third_party/rust/mach/src/vm_statistics.rs b/third_party/rust/mach/src/vm_statistics.rs new file mode 100644 index 0000000000..5cc3a15548 --- /dev/null +++ b/third_party/rust/mach/src/vm_statistics.rs @@ -0,0 +1,78 @@ +//! This module roughly corresponds to `mach/vm_statistics.h` + +use vm_types::{integer_t, natural_t}; + +pub type vm_statistics_t = *mut vm_statistics; +pub type vm_statistics_data_t = vm_statistics; +#[cfg(feature = "deprecated")] +#[deprecated( + since = "0.2.3", + note = "`pmap_statistics_t` was removed after MacOSX 10.3.9" +)] +#[allow(deprecated)] +pub type pmap_statistics_t = *mut pmap_statistics; + +pub const VM_PAGE_QUERY_PAGE_PRESENT: integer_t = 1; +pub const VM_PAGE_QUERY_PAGE_FICTITIOUS: integer_t = (1 << 1); +pub const VM_PAGE_QUERY_PAGE_REF: integer_t = (1 << 2); +pub const VM_PAGE_QUERY_PAGE_DIRTY: integer_t = (1 << 3); + +pub const VM_MEMORY_MALLOC: ::libc::c_uint = 1; +pub const VM_MEMORY_MALLOC_SMALL: ::libc::c_uint = 2; +pub const VM_MEMORY_MALLOC_LARGE: ::libc::c_uint = 3; +pub const VM_MEMORY_MALLOC_HUGE: ::libc::c_uint = 4; +pub const VM_MEMORY_SBRK: ::libc::c_uint = 5; +pub const VM_MEMORY_ANALYSIS_TOOL: ::libc::c_uint = 10; +pub const VM_MEMORY_MACH_MSG: ::libc::c_uint = 20; +pub const VM_MEMORY_IOKIT: ::libc::c_uint = 21; +pub const VM_MEMORY_STACK: ::libc::c_uint = 30; +pub const VM_MEMORY_GUARD: ::libc::c_uint = 31; +pub const VM_MEMORY_SHARED_PMAP: ::libc::c_uint = 32; +pub const VM_MEMORY_DYLIB: ::libc::c_uint = 33; +pub const VM_MEMORY_APPKIT: ::libc::c_uint = 40; +pub const VM_MEMORY_FOUNDATION: ::libc::c_uint = 41; +pub const VM_MEMORY_COREGRAPHICS: ::libc::c_uint = 42; +pub const VM_MEMORY_CARBON: ::libc::c_uint = 43; +pub const VM_MEMORY_JAVA: ::libc::c_uint = 44; +pub const VM_MEMORY_ATS: ::libc::c_uint = 50; +pub const VM_MEMORY_DYLD: ::libc::c_uint = 60; +pub const VM_MEMORY_DYLD_MALLOC: ::libc::c_uint = 61; +pub const VM_MEMORY_APPLICATION_SPECIFIC_1: ::libc::c_uint = 240; +pub const VM_MEMORY_APPLICATION_SPECIFIC_16: ::libc::c_uint = 255; + +pub const VM_FLAGS_FIXED: ::libc::c_int = 0x0; +pub const VM_FLAGS_ANYWHERE: ::libc::c_int = 0x1; +pub const VM_FLAGS_OVERWRITE: ::libc::c_int = 0x4000; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_statistics { + pub free_count: natural_t, + pub active_count: natural_t, + pub inactive_count: natural_t, + pub wire_count: natural_t, + pub zero_fill_count: natural_t, + pub reactivations: natural_t, + pub pageins: natural_t, + pub pageouts: natural_t, + pub faults: natural_t, + pub cow_faults: natural_t, + pub lookups: natural_t, + pub hits: natural_t, + pub purgeable_count: natural_t, + pub purges: natural_t, + pub speculative_count: natural_t, +} + +#[cfg(feature = "deprecated")] +#[deprecated( + since = "0.2.3", + note = "`pmap_statistics` was removed after MacOSX 10.3.9" +)] +#[cfg_attr(feature = "deprecated", allow(deprecated))] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct pmap_statistics { + pub resident_count: integer_t, + pub wired_count: integer_t, +} diff --git a/third_party/rust/mach/src/vm_sync.rs b/third_party/rust/mach/src/vm_sync.rs new file mode 100644 index 0000000000..b4e21c224a --- /dev/null +++ b/third_party/rust/mach/src/vm_sync.rs @@ -0,0 +1,11 @@ +//! This module corresponds to `mach/vm_sync.h`. + +pub type vm_sync_t = ::libc::c_uint; + +pub const VM_SYNC_ASYNCHRONOUS: vm_sync_t = 1; +pub const VM_SYNC_SYNCHRONOUS: vm_sync_t = (1 << 1); +pub const VM_SYNC_INVALIDATE: vm_sync_t = (1 << 2); +pub const VM_SYNC_KILLPAGES: vm_sync_t = (1 << 3); +pub const VM_SYNC_DEACTIVATE: vm_sync_t = (1 << 4); +pub const VM_SYNC_CONTIGUOUS: vm_sync_t = (1 << 5); +pub const VM_SYNC_REUSABLEPAGES: vm_sync_t = (1 << 6); diff --git a/third_party/rust/mach/src/vm_types.rs b/third_party/rust/mach/src/vm_types.rs new file mode 100644 index 0000000000..e37b9804c4 --- /dev/null +++ b/third_party/rust/mach/src/vm_types.rs @@ -0,0 +1,19 @@ +//! This module roughly corresponds to `mach/i386/vm_types.h`. + +pub type natural_t = ::libc::c_uint; +pub type integer_t = ::libc::c_int; + +pub type user_addr_t = u64; + +pub type mach_vm_address_t = u64; +pub type mach_vm_offset_t = u64; +pub type mach_vm_size_t = u64; +pub type vm_map_offset_t = u64; +pub type vm_map_address_t = u64; +pub type vm_map_size_t = u64; +pub type vm_map_t = ::port::mach_port_t; +pub type vm_offset_t = ::libc::uintptr_t; +pub type vm_size_t = ::libc::uintptr_t; +pub type vm_address_t = vm_offset_t; + +pub type mach_port_context_t = mach_vm_address_t; |