From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/mach2/.cargo-checksum.json | 1 + third_party/rust/mach2/Cargo.toml | 49 +++++ third_party/rust/mach2/LICENSE-APACHE | 176 +++++++++++++++ third_party/rust/mach2/LICENSE-BSD | 23 ++ third_party/rust/mach2/LICENSE-MIT | 25 +++ third_party/rust/mach2/README.md | 92 ++++++++ third_party/rust/mach2/src/boolean.rs | 7 + third_party/rust/mach2/src/bootstrap.rs | 76 +++++++ third_party/rust/mach2/src/clock.rs | 27 +++ third_party/rust/mach2/src/clock_priv.rs | 16 ++ third_party/rust/mach2/src/clock_reply.rs | 16 ++ third_party/rust/mach2/src/clock_types.rs | 75 +++++++ third_party/rust/mach2/src/dyld_kernel.rs | 30 +++ third_party/rust/mach2/src/exc.rs | 44 ++++ third_party/rust/mach2/src/exception_types.rs | 56 +++++ third_party/rust/mach2/src/kern_return.rs | 58 +++++ third_party/rust/mach2/src/lib.rs | 56 +++++ third_party/rust/mach2/src/mach_init.rs | 22 ++ third_party/rust/mach2/src/mach_port.rs | 35 +++ third_party/rust/mach2/src/mach_time.rs | 20 ++ third_party/rust/mach2/src/mach_types.rs | 106 +++++++++ third_party/rust/mach2/src/memory_object_types.rs | 9 + third_party/rust/mach2/src/message.rs | 248 ++++++++++++++++++++++ third_party/rust/mach2/src/port.rs | 28 +++ third_party/rust/mach2/src/structs.rs | 62 ++++++ third_party/rust/mach2/src/task.rs | 41 ++++ third_party/rust/mach2/src/task_info.rs | 44 ++++ third_party/rust/mach2/src/thread_act.rs | 23 ++ third_party/rust/mach2/src/thread_policy.rs | 121 +++++++++++ third_party/rust/mach2/src/thread_status.rs | 23 ++ third_party/rust/mach2/src/traps.rs | 37 ++++ third_party/rust/mach2/src/vm.rs | 248 ++++++++++++++++++++++ third_party/rust/mach2/src/vm_attributes.rs | 18 ++ third_party/rust/mach2/src/vm_behavior.rs | 15 ++ third_party/rust/mach2/src/vm_inherit.rs | 10 + third_party/rust/mach2/src/vm_page_size.rs | 40 ++++ third_party/rust/mach2/src/vm_prot.rs | 13 ++ third_party/rust/mach2/src/vm_purgable.rs | 42 ++++ third_party/rust/mach2/src/vm_region.rs | 238 +++++++++++++++++++++ third_party/rust/mach2/src/vm_statistics.rs | 58 +++++ third_party/rust/mach2/src/vm_sync.rs | 11 + third_party/rust/mach2/src/vm_types.rs | 19 ++ 42 files changed, 2358 insertions(+) create mode 100644 third_party/rust/mach2/.cargo-checksum.json create mode 100644 third_party/rust/mach2/Cargo.toml create mode 100644 third_party/rust/mach2/LICENSE-APACHE create mode 100644 third_party/rust/mach2/LICENSE-BSD create mode 100644 third_party/rust/mach2/LICENSE-MIT create mode 100644 third_party/rust/mach2/README.md create mode 100644 third_party/rust/mach2/src/boolean.rs create mode 100644 third_party/rust/mach2/src/bootstrap.rs create mode 100644 third_party/rust/mach2/src/clock.rs create mode 100644 third_party/rust/mach2/src/clock_priv.rs create mode 100644 third_party/rust/mach2/src/clock_reply.rs create mode 100644 third_party/rust/mach2/src/clock_types.rs create mode 100644 third_party/rust/mach2/src/dyld_kernel.rs create mode 100644 third_party/rust/mach2/src/exc.rs create mode 100644 third_party/rust/mach2/src/exception_types.rs create mode 100644 third_party/rust/mach2/src/kern_return.rs create mode 100644 third_party/rust/mach2/src/lib.rs create mode 100644 third_party/rust/mach2/src/mach_init.rs create mode 100644 third_party/rust/mach2/src/mach_port.rs create mode 100644 third_party/rust/mach2/src/mach_time.rs create mode 100644 third_party/rust/mach2/src/mach_types.rs create mode 100644 third_party/rust/mach2/src/memory_object_types.rs create mode 100644 third_party/rust/mach2/src/message.rs create mode 100644 third_party/rust/mach2/src/port.rs create mode 100644 third_party/rust/mach2/src/structs.rs create mode 100644 third_party/rust/mach2/src/task.rs create mode 100644 third_party/rust/mach2/src/task_info.rs create mode 100644 third_party/rust/mach2/src/thread_act.rs create mode 100644 third_party/rust/mach2/src/thread_policy.rs create mode 100644 third_party/rust/mach2/src/thread_status.rs create mode 100644 third_party/rust/mach2/src/traps.rs create mode 100644 third_party/rust/mach2/src/vm.rs create mode 100644 third_party/rust/mach2/src/vm_attributes.rs create mode 100644 third_party/rust/mach2/src/vm_behavior.rs create mode 100644 third_party/rust/mach2/src/vm_inherit.rs create mode 100644 third_party/rust/mach2/src/vm_page_size.rs create mode 100644 third_party/rust/mach2/src/vm_prot.rs create mode 100644 third_party/rust/mach2/src/vm_purgable.rs create mode 100644 third_party/rust/mach2/src/vm_region.rs create mode 100644 third_party/rust/mach2/src/vm_statistics.rs create mode 100644 third_party/rust/mach2/src/vm_sync.rs create mode 100644 third_party/rust/mach2/src/vm_types.rs (limited to 'third_party/rust/mach2') diff --git a/third_party/rust/mach2/.cargo-checksum.json b/third_party/rust/mach2/.cargo-checksum.json new file mode 100644 index 0000000000..1e9ae12f05 --- /dev/null +++ b/third_party/rust/mach2/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"e6cb1c9aa2b65d61801e0f03de848525a9f7104234db25d0b1c9fa337b372626","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-BSD":"044983df14c97f2f9570766aaf977b3cdfc4a06cf1f36b776331c5ff89b4fb89","LICENSE-MIT":"3f9f0f7e5a5911a8042e32c83ff5d061ce1ffd02e8a207ec2135a44ad73b4191","README.md":"c2cb79f8e79e22b13e4c25e43829bf578ef25a3a338d5553081a1e5f39556fa8","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":"4c8a9d906303a67246b32b6f96228bff6b045deb0a68073a7f8d1061c8d072bd","src/mach_init.rs":"df49bd287fd05fb74bc76254df7607fad0d6b90cb20da803e9f9a1dc2fcfe2fc","src/mach_port.rs":"d71ef4f4875824410d2d829474303926a56e3218a00fbe04024801a3245b67ad","src/mach_time.rs":"b9493e820acf21fee1f6e7e82a510d887925dc1117d6b71b681acc40cfa776af","src/mach_types.rs":"e2d17741ebcdcdff9686ec9ee5c90fb7a150ce990979507da01c351771fb3a19","src/memory_object_types.rs":"6fcb446c00ddd5ef4920efe618bd89df2e87f7ae3cf660a2bc1d25cf1f331dc2","src/message.rs":"126dfcdef0f690cd17f4403528403721b81f7e6a95821eff867d11dd6bfa9718","src/port.rs":"7ef8af905edd7d0de9c11813d6cf56ae82171e85efdde2c986622be0e7debf6f","src/structs.rs":"132e21e91313e6ec13e3ad5ed9c71852e8a55fbbaba449dbb1b3ca889bed4889","src/task.rs":"282ea602db2d08711785e0050a06b322a3fe4a4aac34b3c9116fe13e033898dd","src/task_info.rs":"cf87cffe567fee8871e0ce9762b7d8bbd5058dfbb309678d382149dedbe7f14a","src/thread_act.rs":"647198e0f9e3fe409a0610ee98560de3af4f152bcc4761f943e67723193b8a25","src/thread_policy.rs":"e8999b03a03d398a456056274ed8ebc4c38a1cbbbba2da931503885da0e9c2e3","src/thread_status.rs":"3fe98fadd61ce01b4f9dc3bc0ef8c9496798f0147822a4ddffe5d0eaf2f32c0a","src/traps.rs":"59a65e0cc3cf67d79180eabfe31248287afa7a2daa58ec367ebb6302ff39f4cb","src/vm.rs":"1e3fe55704dbbc0c287ad543f5642389a823539f72b337cbff726d6927566b23","src/vm_attributes.rs":"7f73f41572d1ca854b45199a17e9008197f3898cfe6a82dba6d14293d49269c6","src/vm_behavior.rs":"a5d195a52602f5ebe2991774c2390a6f20f1bfa82168dd62e88f2804134da1f3","src/vm_inherit.rs":"dbc7432350869733d6e7cf1da8617d97aafbeb1afcb1bdc60ed7ab53e37abf61","src/vm_page_size.rs":"1cd209f8f6fbc4d3b7a44b77f5a3c53c578f357199e3c616b2386a63e5bfe70a","src/vm_prot.rs":"65e5f7179e155c600cec1a1b3e030f2d0d6b446a6ec9ebad0d04f56ccd884a86","src/vm_purgable.rs":"e32963f20905c4edd1cfee364ad489ef646ad7d401967d0ed9e1e7ed6cd57e5d","src/vm_region.rs":"905daa12391c0c3bca9200ceaecbd02dd03550bbdc9c3342dceeeb6e4056184f","src/vm_statistics.rs":"abee2c810b13fa007a7e38dd2b3d6460005e9e78f5972e069d7fc3e0df80190e","src/vm_sync.rs":"e6006b66f0fa1a06c5e853d765a9366aab85009cc77a095b93f902330cf4ec81","src/vm_types.rs":"a47f71193172ce233018dfd40de2b9a56cdfcdfb18e04c1c0761cb6fc36f51b8"},"package":"6d0d1830bcd151a6fc4aea1369af235b36c1528fe976b8ff678683c9995eade8"} \ No newline at end of file diff --git a/third_party/rust/mach2/Cargo.toml b/third_party/rust/mach2/Cargo.toml new file mode 100644 index 0000000000..422e53094c --- /dev/null +++ b/third_party/rust/mach2/Cargo.toml @@ -0,0 +1,49 @@ +# 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 are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "mach2" +version = "0.4.1" +include = [ + "src/**/*", + "LICENSE-*", + "README.md", +] +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 OR MIT OR Apache-2.0" +repository = "https://github.com/JohnTitor/mach2" + +[package.metadata.docs.rs] +default-target = "x86_64-apple-darwin" + +[features] +default = [] +unstable = [] + +[target."cfg(any(target_os = \"macos\", target_os = \"ios\"))".dependencies.libc] +version = "0.2" +default-features = false + +[badges.maintenance] +status = "passively-maintained" diff --git a/third_party/rust/mach2/LICENSE-APACHE b/third_party/rust/mach2/LICENSE-APACHE new file mode 100644 index 0000000000..1b5ec8b78e --- /dev/null +++ b/third_party/rust/mach2/LICENSE-APACHE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/third_party/rust/mach2/LICENSE-BSD b/third_party/rust/mach2/LICENSE-BSD new file mode 100644 index 0000000000..e02a2d2cfc --- /dev/null +++ b/third_party/rust/mach2/LICENSE-BSD @@ -0,0 +1,23 @@ +Copyright (c) 2019 Nick Fitzgerald, 2021 Yuki Okushi +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/mach2/LICENSE-MIT b/third_party/rust/mach2/LICENSE-MIT new file mode 100644 index 0000000000..08bda86c65 --- /dev/null +++ b/third_party/rust/mach2/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2019 Nick Fitzgerald, 2021 Yuki Okushi + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/third_party/rust/mach2/README.md b/third_party/rust/mach2/README.md new file mode 100644 index 0000000000..f297ebe633 --- /dev/null +++ b/third_party/rust/mach2/README.md @@ -0,0 +1,92 @@ +# mach2 + +[![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.4" +``` + +Available crate feature: + +* **unstable** (disabled by default): Exposes newly changed APIs. Enabling this may + bring breaking changes (see the breaking change policy). + + +### Breaking change policy + +We do the following steps when an item is changed/removed on latest toolchain: + +1. Deprecate an existing one +2. Declare a new one under the `unstable` feature +3. After a month or more since releasing a new version that contains that change, + remove/change an older one + +For instance, if const `FOO` value is changed from `3` to `4`, +we expose the newer one, i.e. `4`, under `unstable` first. +So the `unstable` users should notice the change on the first release since deprecating. +After a month or more, all the users should notice it. + +## 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 | 10.3.0 - 13.1.0 | ✓ | ✓ | ✓ | +| `aarch64-apple-darwin` | nightly | 13.1.0 | ✓ | - | - | +| `aarch64-apple-ios` | nightly | 13.1.0 | ✓ | - | - | +| `aarch64-apple-ios-sim` | nightly | 13.1.0 | ✓ | - | - | +| `x86_64-apple-ios` | nightly | 13.1.0 | ✓ | - | - | + +## License + +This project is licensed under either of + +* A 2-clause BSD License ([LICENSE-BSD](LICENSE-BSD)), or +* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) +* MIT license ([LICENSE-MIT](LICENSE-MIT) or + http://opensource.org/licenses/MIT) + +at your option. + +## Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in `mach` by you, as defined in the Apache-2.0 license, shall be +triple licensed as above, without any additional terms or conditions. + +To locally test the library, run: + +``` +TARGET=x86_64-apple-darwin RUST_VERSION=nightly ./ci/run.sh +``` + +where you can replace the `TARGET` and `RUST_VERSION` with the target you +want to test (e.g. `aarch64-apple-darwin`) and the Rust version you want to use for +the tests (e.g. `stable`, `1.33.0`, etc.). + +[crates.io]: https://crates.io/crates/mach2 +[Latest Version]: https://img.shields.io/crates/v/mach2.svg +[docs]: https://docs.rs/mach2/badge.svg +[docs.rs]: https://docs.rs/mach2 diff --git a/third_party/rust/mach2/src/boolean.rs b/third_party/rust/mach2/src/boolean.rs new file mode 100644 index 0000000000..cedffa1220 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/bootstrap.rs b/third_party/rust/mach2/src/bootstrap.rs new file mode 100644 index 0000000000..3642b94627 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/clock.rs b/third_party/rust/mach2/src/clock.rs new file mode 100644 index 0000000000..1d5437951d --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/clock_priv.rs b/third_party/rust/mach2/src/clock_priv.rs new file mode 100644 index 0000000000..d534e79a3c --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/clock_reply.rs b/third_party/rust/mach2/src/clock_reply.rs new file mode 100644 index 0000000000..854eb22bf5 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/clock_types.rs b/third_party/rust/mach2/src/clock_types.rs new file mode 100644 index 0000000000..c0949c8315 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/dyld_kernel.rs b/third_party/rust/mach2/src/dyld_kernel.rs new file mode 100644 index 0000000000..9a264dfafd --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/exc.rs b/third_party/rust/mach2/src/exc.rs new file mode 100644 index 0000000000..9330740c4e --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/exception_types.rs b/third_party/rust/mach2/src/exception_types.rs new file mode 100644 index 0000000000..f042443d8a --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/kern_return.rs b/third_party/rust/mach2/src/kern_return.rs new file mode 100644 index 0000000000..3d447b4026 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/lib.rs b/third_party/rust/mach2/src/lib.rs new file mode 100644 index 0000000000..0b68a706aa --- /dev/null +++ b/third_party/rust/mach2/src/lib.rs @@ -0,0 +1,56 @@ +#![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] +#![deny(missing_debug_implementations)] +#![deny(missing_copy_implementations)] +#![allow( + clippy::module_name_repetitions, + clippy::cast_sign_loss, + clippy::cast_possible_truncation, + clippy::trivially_copy_pass_by_ref +)] +#![no_std] + +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +compile_error!("mach requires macOS or iOS"); + +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_policy; +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/mach2/src/mach_init.rs b/third_party/rust/mach2/src/mach_init.rs new file mode 100644 index 0000000000..5776988cb5 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/mach_port.rs b/third_party/rust/mach2/src/mach_port.rs new file mode 100644 index 0000000000..e14a08e957 --- /dev/null +++ b/third_party/rust/mach2/src/mach_port.rs @@ -0,0 +1,35 @@ +//! 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_delta_t, 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; + pub fn mach_port_mod_refs( + task: ipc_space_t, + name: mach_port_name_t, + right: mach_port_right_t, + delta: mach_port_delta_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach2/src/mach_time.rs b/third_party/rust/mach2/src/mach_time.rs new file mode 100644 index 0000000000..9011c0c0af --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/mach_types.rs b/third_party/rust/mach2/src/mach_types.rs new file mode 100644 index 0000000000..fa257b2a53 --- /dev/null +++ b/third_party/rust/mach2/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; + +// : typedef unsigned char __darwin_uuid_t[16]; +pub type uuid_t = [::libc::c_uchar; 16]; + +// +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct fsid { + pub val: [i32; 2], +} +pub type fsid_t = fsid; + +// +#[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/mach2/src/memory_object_types.rs b/third_party/rust/mach2/src/memory_object_types.rs new file mode 100644 index 0000000000..8399e71676 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/message.rs b/third_party/rust/mach2/src/message.rs new file mode 100644 index 0000000000..40114ad3ed --- /dev/null +++ b/third_party/rust/mach2/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_0000; +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_0000; + +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/mach2/src/port.rs b/third_party/rust/mach2/src/port.rs new file mode 100644 index 0000000000..151a3aa40c --- /dev/null +++ b/third_party/rust/mach2/src/port.rs @@ -0,0 +1,28 @@ +//! This module corresponds to `mach/port.h` + +use vm_types::{integer_t, 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; + +pub type mach_port_delta_t = integer_t; diff --git a/third_party/rust/mach2/src/structs.rs b/third_party/rust/mach2/src/structs.rs new file mode 100644 index 0000000000..75dc0e8dba --- /dev/null +++ b/third_party/rust/mach2/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::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} diff --git a/third_party/rust/mach2/src/task.rs b/third_party/rust/mach2/src/task.rs new file mode 100644 index 0000000000..1ca2280eb1 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/task_info.rs b/third_party/rust/mach2/src/task_info.rs new file mode 100644 index 0000000000..4a3b8ed710 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/thread_act.rs b/third_party/rust/mach2/src/thread_act.rs new file mode 100644 index 0000000000..f2f9809a2b --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/thread_policy.rs b/third_party/rust/mach2/src/thread_policy.rs new file mode 100644 index 0000000000..aa17e6ea31 --- /dev/null +++ b/third_party/rust/mach2/src/thread_policy.rs @@ -0,0 +1,121 @@ +//! This module corresponds to `mach/thread_policy.h`. + +use boolean::boolean_t; +use kern_return::kern_return_t; +use libc::thread_policy_t; +use mach_types::thread_t; +use message::mach_msg_type_number_t; +use vm_types::{integer_t, natural_t}; + +pub type thread_policy_flavor_t = natural_t; + +pub const THREAD_STANDARD_POLICY: thread_policy_flavor_t = 1; +pub const THREAD_EXTENDED_POLICY: thread_policy_flavor_t = 1; +pub const THREAD_TIME_CONSTRAINT_POLICY: thread_policy_flavor_t = 2; +pub const THREAD_PRECEDENCE_POLICY: thread_policy_flavor_t = 3; +pub const THREAD_AFFINITY_POLICY: thread_policy_flavor_t = 4; +pub const THREAD_BACKGROUND_POLICY: thread_policy_flavor_t = 5; +pub const THREAD_LATENCY_QOS_POLICY: thread_policy_flavor_t = 7; +pub const THREAD_THROUGHPUT_QOS_POLICY: thread_policy_flavor_t = 8; + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct thread_standard_policy { + pub no_data: natural_t, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct thread_extended_policy { + pub timeshare: boolean_t, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct thread_time_constraint_policy { + pub period: u32, + pub computation: u32, + pub constraint: u32, + pub preemptible: boolean_t, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct thread_precedence_policy { + pub importance: integer_t, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct thread_affinity_policy { + pub affinity_tag: integer_t, +} + +pub const THREAD_AFFINITY_TAG_NULL: integer_t = 0; + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct thread_background_policy { + pub priority: integer_t, +} + +pub type thread_latency_qos_t = integer_t; + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct thread_latency_qos_policy { + thread_latency_qos_tier: thread_latency_qos_t, +} + +pub type thread_throughput_qos_t = integer_t; + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct thread_throughput_qos_policy { + thread_throughput_qos_tier: thread_throughput_qos_t, +} + +pub type thread_standard_policy_data_t = thread_standard_policy; +pub type thread_extended_policy_data_t = thread_extended_policy; +pub type thread_time_constraint_policy_data_t = thread_time_constraint_policy; +pub type thread_precedence_policy_data_t = thread_precedence_policy; +pub type thread_affinity_policy_data_t = thread_affinity_policy; +pub type thread_background_policy_data_t = thread_background_policy; +pub type thread_latency_qos_policy_data_t = thread_latency_qos_policy; +pub type thread_throughput_qos_policy_data_t = thread_throughput_qos_policy; + +pub const THREAD_STANDARD_POLICY_COUNT: mach_msg_type_number_t = 0; +pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t = + (core::mem::size_of::() / core::mem::size_of::()) as _; +pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t = + (core::mem::size_of::() / core::mem::size_of::()) + as _; +pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t = + (core::mem::size_of::() / core::mem::size_of::()) as _; +pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t = + (core::mem::size_of::() / core::mem::size_of::()) as _; +pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t = + (core::mem::size_of::() / core::mem::size_of::()) as _; +pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t = + (core::mem::size_of::() / core::mem::size_of::()) as _; +pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t = + (core::mem::size_of::() / core::mem::size_of::()) as _; + +extern "C" { + pub fn thread_policy_set( + thread: thread_t, + flavor: thread_policy_flavor_t, + policy_info: thread_policy_t, + count: mach_msg_type_number_t, + ) -> kern_return_t; +} + +extern "C" { + pub fn thread_policy_get( + thread: thread_t, + flavor: thread_policy_flavor_t, + policy_info: thread_policy_t, + count: *mut mach_msg_type_number_t, + get_default: *mut boolean_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach2/src/thread_status.rs b/third_party/rust/mach2/src/thread_status.rs new file mode 100644 index 0000000000..951256622c --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/traps.rs b/third_party/rust/mach2/src/traps.rs new file mode 100644 index 0000000000..1d3bb93ea3 --- /dev/null +++ b/third_party/rust/mach2/src/traps.rs @@ -0,0 +1,37 @@ +//! 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; +} + +#[allow(clippy::missing_safety_doc)] // FIXME +pub unsafe fn mach_task_self() -> mach_port_t { + mach_task_self_ +} + +#[allow(clippy::missing_safety_doc)] // FIXME +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/mach2/src/vm.rs b/third_party/rust/mach2/src/vm.rs new file mode 100644 index 0000000000..d0bf6f23ab --- /dev/null +++ b/third_party/rust/mach2/src/vm.rs @@ -0,0 +1,248 @@ +//! 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; + + #[allow(improper_ctypes)] + 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/mach2/src/vm_attributes.rs b/third_party/rust/mach2/src/vm_attributes.rs new file mode 100644 index 0000000000..ba3b0d3c70 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/vm_behavior.rs b/third_party/rust/mach2/src/vm_behavior.rs new file mode 100644 index 0000000000..8ab692e550 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/vm_inherit.rs b/third_party/rust/mach2/src/vm_inherit.rs new file mode 100644 index 0000000000..4f4c9e5ef7 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/vm_page_size.rs b/third_party/rust/mach2/src/vm_page_size.rs new file mode 100644 index 0000000000..f1ab37fcb4 --- /dev/null +++ b/third_party/rust/mach2/src/vm_page_size.rs @@ -0,0 +1,40 @@ +//! 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; +} + +#[allow(clippy::missing_safety_doc)] // FIXME +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) +} + +#[allow(clippy::missing_safety_doc)] // FIXME +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); + + #[cfg(target_arch = "aarch64")] + assert_eq!(vm_page_size, 16384); + + #[cfg(not(target_arch = "aarch64"))] + assert_eq!(vm_page_size, 4096); + } + } +} diff --git a/third_party/rust/mach2/src/vm_prot.rs b/third_party/rust/mach2/src/vm_prot.rs new file mode 100644 index 0000000000..0397d25a1d --- /dev/null +++ b/third_party/rust/mach2/src/vm_prot.rs @@ -0,0 +1,13 @@ +//! 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_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/mach2/src/vm_purgable.rs b/third_party/rust/mach2/src/vm_purgable.rs new file mode 100644 index 0000000000..79fc297cb0 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/vm_region.rs b/third_party/rust/mach2/src/vm_region.rs new file mode 100644 index 0000000000..b88b59fc56 --- /dev/null +++ b/third_party/rust/mach2/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::() / 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::() / 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::() / 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::() / 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::() / 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::() / 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::() / 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::() / 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/mach2/src/vm_statistics.rs b/third_party/rust/mach2/src/vm_statistics.rs new file mode 100644 index 0000000000..bd138ca044 --- /dev/null +++ b/third_party/rust/mach2/src/vm_statistics.rs @@ -0,0 +1,58 @@ +//! 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; + +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, +} diff --git a/third_party/rust/mach2/src/vm_sync.rs b/third_party/rust/mach2/src/vm_sync.rs new file mode 100644 index 0000000000..c562397358 --- /dev/null +++ b/third_party/rust/mach2/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/mach2/src/vm_types.rs b/third_party/rust/mach2/src/vm_types.rs new file mode 100644 index 0000000000..e37b9804c4 --- /dev/null +++ b/third_party/rust/mach2/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; -- cgit v1.2.3