├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-BSD ├── LICENSE-MIT ├── README.md ├── ci ├── build_fail.sh ├── deploy_and_run_on_ios_simulator.rs └── run.sh ├── examples └── dump_process_registers.rs ├── mach-test ├── Cargo.toml ├── build.rs └── test │ └── main.rs └── src ├── boolean.rs ├── bootstrap.rs ├── clock.rs ├── clock_priv.rs ├── clock_reply.rs ├── clock_types.rs ├── dyld_kernel.rs ├── exc.rs ├── exception_types.rs ├── kern_return.rs ├── lib.rs ├── mach_init.rs ├── mach_port.rs ├── mach_time.rs ├── mach_types.rs ├── memory_object_types.rs ├── message.rs ├── port.rs ├── structs.rs ├── task.rs ├── task_info.rs ├── thread_act.rs ├── thread_status.rs ├── traps.rs ├── vm.rs ├── vm_attributes.rs ├── vm_behavior.rs ├── vm_inherit.rs ├── vm_page_size.rs ├── vm_prot.rs ├── vm_purgable.rs ├── vm_region.rs ├── vm_statistics.rs ├── vm_sync.rs └── vm_types.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | 3 | matrix: 4 | fast_finish: true 5 | include: 6 | # x86_64-unknown-linux-gnu 7 | - name: "x86_64-unknown-linux-gnu - fail" 8 | env: TARGET=x86_64-unknown-linux-gnu 9 | os: linux 10 | rust: nightly 11 | install: true 12 | script: ./ci/build_fail.sh 13 | 14 | # x86_64-apple-darwin 15 | - name: "x86_64-apple-darwin - Rust stable 1.33.0 - xcode10" 16 | env: TARGET=x86_64-apple-darwin 17 | rust: 1.33.0 18 | os: osx 19 | osx_image: xcode10 20 | install: true 21 | - name: "x86_64-apple-darwin - Rust beta - xcode10" 22 | env: TARGET=x86_64-apple-darwin 23 | rust: beta 24 | os: osx 25 | osx_image: xcode10 26 | install: true 27 | - name: "x86_64-apple-darwin - Rust nightly - xcode10" 28 | env: TARGET=x86_64-apple-darwin 29 | rust: nightly 30 | os: osx 31 | osx_image: xcode10 32 | install: true 33 | - name: "x86_64-apple-darwin - Rust nightly - xcode9.4" 34 | env: TARGET=x86_64-apple-darwin 35 | rust: nightly 36 | os: osx 37 | osx_image: xcode9.4 38 | install: true 39 | - name: "x86_64-apple-darwin - Rust nightly - xcode8.3" 40 | env: TARGET=x86_64-apple-darwin 41 | rust: nightly 42 | os: osx 43 | osx_image: xcode8.3 44 | install: true 45 | - name: "x86_64-apple-darwin - Rust nightly - xcode7.3" 46 | env: TARGET=x86_64-apple-darwin 47 | rust: nightly 48 | os: osx 49 | osx_image: xcode7.3 50 | install: true 51 | - name: "x86_64-apple-darwin - Rust nightly - xcode6.4" 52 | env: TARGET=x86_64-apple-darwin 53 | rust: nightly 54 | os: osx 55 | osx_image: xcode6.4 56 | install: true 57 | 58 | # i686-apple-darwin 59 | - name: "i686-apple-darwin - Rust stable 1.33.0 - xcode10" 60 | env: TARGET=i686-apple-darwin 61 | rust: 1.33.0 62 | os: osx 63 | osx_image: xcode10 64 | - name: "i686-apple-darwin - Rust beta - xcode10" 65 | env: TARGET=i686-apple-darwin 66 | rust: beta 67 | os: osx 68 | osx_image: xcode10 69 | - name: "i686-apple-darwin - Rust nightly - xcode10" 70 | env: TARGET=i686-apple-darwin 71 | rust: nightly 72 | os: osx 73 | osx_image: xcode10 74 | - name: "i686-apple-darwin - Rust nightly - xcode9.4" 75 | env: TARGET=i686-apple-darwin 76 | rust: nightly 77 | os: osx 78 | osx_image: xcode9.4 79 | - name: "i686-apple-darwin - Rust nightly - xcode8.3" 80 | env: TARGET=i686-apple-darwin 81 | rust: nightly 82 | os: osx 83 | osx_image: xcode8.3 84 | - name: "i686-apple-darwin - Rust nightly - xcode7.3" 85 | env: TARGET=i686-apple-darwin 86 | rust: nightly 87 | os: osx 88 | osx_image: xcode7.3 89 | - name: "i686-apple-darwin - Rust nightly - xcode6.4" 90 | env: TARGET=i686-apple-darwin 91 | rust: nightly 92 | os: osx 93 | osx_image: xcode6.4 94 | 95 | # x86_64-apple-ios 96 | - name: "x86_64-apple-ios - Rust stable 1.33.0 - xcode10 - no run/ffi tests" 97 | env: TARGET=x86_64-apple-ios NORUN=1 NOCTEST=1 98 | rust: 1.33.0 99 | os: osx 100 | osx_image: xcode10 101 | - name: "x86_64-apple-ios - Rust beta - xcode10 - no run/ffi tests" 102 | env: TARGET=x86_64-apple-ios NORUN=1 NOCTEST=1 103 | rust: beta 104 | os: osx 105 | osx_image: xcode10 106 | - name: "x86_64-apple-ios - Rust nightly - xcode10 - no run/ffi tests" 107 | env: TARGET=x86_64-apple-ios NORUN=1 NOCTEST=1 108 | rust: nightly 109 | os: osx 110 | osx_image: xcode10 111 | - name: "x86_64-apple-ios - Rust nightly - xcode9.4 - no run/ffi tests" 112 | env: TARGET=x86_64-apple-ios NORUN=1 NOCTEST=1 113 | rust: nightly 114 | os: osx 115 | osx_image: xcode9.4 116 | - name: "x86_64-apple-ios - Rust nightly - xcode8.3 - no run/ffi tests" 117 | env: TARGET=x86_64-apple-ios NORUN=1 NOCTEST=1 118 | rust: nightly 119 | os: osx 120 | osx_image: xcode8.3 121 | - name: "x86_64-apple-ios - Rust nightly - xcode7.3 - no run/ffi tests" 122 | env: TARGET=x86_64-apple-ios NORUN=1 NOCTEST=1 123 | rust: nightly 124 | os: osx 125 | osx_image: xcode7.3 126 | - name: "x86_64-apple-ios - Rust nightly - xcode6.4 - no run/ffi tests" 127 | env: TARGET=x86_64-apple-ios NORUN=1 NOCTEST=1 128 | rust: nightly 129 | os: osx 130 | osx_image: xcode6.4 131 | 132 | # i386-apple-ios (deprecated in xcode10) 133 | - name: "i386-apple-ios - Rust stable 1.33.0 - xcode9.4 - no run/ffi tests" 134 | env: TARGET=i386-apple-ios NORUN=1 NOCTEST=1 135 | rust: 1.33.0 136 | os: osx 137 | osx_image: xcode9.4 138 | - name: "i386-apple-ios - Rust beta - xcode9.4 - no run/ffi tests" 139 | env: TARGET=i386-apple-ios NORUN=1 NOCTEST=1 140 | rust: beta 141 | os: osx 142 | osx_image: xcode9.4 143 | - name: "i386-apple-ios - Rust nightly - xcode9.4 - no run/ffi tests" 144 | env: TARGET=i386-apple-ios NORUN=1 NOCTEST=1 145 | rust: nightly 146 | os: osx 147 | osx_image: xcode9.4 148 | - name: "i386-apple-ios - Rust nightly - xcode8.3 - no run/ffi tests" 149 | env: TARGET=i386-apple-ios NORUN=1 NOCTEST=1 150 | rust: nightly 151 | os: osx 152 | osx_image: xcode8.3 153 | - name: "i386-apple-ios - Rust nightly - xcode7.3 - no run/ffi tests" 154 | env: TARGET=i386-apple-ios NORUN=1 NOCTEST=1 155 | rust: nightly 156 | os: osx 157 | osx_image: xcode7.3 158 | - name: "i386-apple-ios - Rust nightly - xcode6.4 - no run/ffi tests" 159 | env: TARGET=i386-apple-ios NORUN=1 NOCTEST=1 160 | rust: nightly 161 | os: osx 162 | osx_image: xcode6.4 163 | 164 | # aarch64-apple-ios 165 | - name: "aarch64-apple-ios - Rust stable 1.33.0 - xcode10 - no run/ffi tests" 166 | env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 167 | rust: 1.33.0 168 | os: osx 169 | osx_image: xcode10 170 | - name: "aarch64-apple-ios - Rust beta - xcode10 - no run/ffi tests" 171 | env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 172 | rust: beta 173 | os: osx 174 | osx_image: xcode10 175 | - name: "aarch64-apple-ios - Rust nightly - xcode10 - no run/ffi tests" 176 | env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 177 | rust: nightly 178 | os: osx 179 | osx_image: xcode10 180 | - name: "aarch64-apple-ios - Rust nightly - xcode9.4 - no run/ffi tests" 181 | env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 182 | rust: nightly 183 | os: osx 184 | osx_image: xcode9.4 185 | - name: "aarch64-apple-ios - Rust nightly - xcode8.3 - no run/ffi tests" 186 | env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 187 | rust: nightly 188 | os: osx 189 | osx_image: xcode8.3 190 | - name: "aarch64-apple-ios - Rust nightly - xcode7.3 - no run/ffi tests" 191 | env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 192 | rust: nightly 193 | os: osx 194 | osx_image: xcode7.3 195 | - name: "aarch64-apple-ios - Rust nightly - xcode6.4 - no run/ffi tests" 196 | env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 197 | rust: nightly 198 | os: osx 199 | osx_image: xcode6.4 200 | 201 | # armv7-apple-ios 202 | - name: "armv7-apple-ios - Rust stable 1.33.0 - xcode10 - no run/ffi tests" 203 | env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 204 | rust: 1.33.0 205 | os: osx 206 | osx_image: xcode10 207 | - name: "armv7-apple-ios - Rust beta - xcode10 - no run/ffi tests" 208 | env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 209 | rust: beta 210 | os: osx 211 | osx_image: xcode10 212 | - name: "armv7-apple-ios - Rust nightly - xcode10 - no run/ffi tests" 213 | env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 214 | rust: nightly 215 | os: osx 216 | osx_image: xcode10 217 | - name: "armv7-apple-ios - Rust nightly - xcode9.4 - no run/ffi tests" 218 | env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 219 | rust: nightly 220 | os: osx 221 | osx_image: xcode9.4 222 | - name: "armv7-apple-ios - Rust nightly - xcode8.3 - no run/ffi tests" 223 | env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 224 | rust: nightly 225 | os: osx 226 | osx_image: xcode8.3 227 | - name: "armv7-apple-ios - Rust nightly - xcode7.3 - no run/ffi tests" 228 | env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 229 | rust: nightly 230 | os: osx 231 | osx_image: xcode7.3 232 | - name: "armv7-apple-ios - Rust nightly - xcode6.4 - no run/ffi tests" 233 | env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 234 | rust: nightly 235 | os: osx 236 | osx_image: xcode6.4 237 | 238 | # Tooling 239 | - name: "rustfmt" 240 | rust: nightly 241 | os: osx 242 | osx_image: xcode10 243 | install: rustup component add rustfmt-preview 244 | script: cargo fmt --all -- --check 245 | - name: "clippy" 246 | rust: nightly 247 | os: osx 248 | osx_image: xcode10 249 | install: rustup component add clippy-preview 250 | script: 251 | - cargo clippy --all -- -D clippy::pedantic 252 | - name: "Shellcheck" 253 | install: true 254 | script: 255 | - shellcheck --version 256 | - shellcheck ci/*.sh 257 | 258 | install: rustup target add "${TARGET}" 259 | script: ci/run.sh 260 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mach" 3 | version = "0.3.3" 4 | authors = [ 5 | "Nick Fitzgerald ", 6 | "David Cuddeback ", 7 | "Gonzalo Brito Gadeschi " 8 | ] 9 | license = "BSD-2-Clause/MIT/Apache-2.0" 10 | description = "A Rust interface to the user-space API of the Mach 3.0 kernel that underlies OSX." 11 | repository = "https://github.com/fitzgen/mach" 12 | readme = "README.md" 13 | keywords = ["kernel", "macos", "darwin"] 14 | categories = ["api-bindings", "external-ffi-bindings", "no-std", "os"] 15 | edition = "2015" 16 | 17 | [badges] 18 | travis-ci = { repository = "fitzgen/mach" } 19 | is-it-maintained-issue-resolution = { repository = "fitzgen/mach" } 20 | is-it-maintained-open-issues = { repository = "fitzgen/mach" } 21 | maintenance = { status = "passively-maintained" } 22 | 23 | [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] 24 | libc = { version = "0.2", default-features = false } 25 | rustc-std-workspace-core = { version = "1.0.0", optional = true } 26 | 27 | [features] 28 | default = [] 29 | # Enables deprecated and removed APIs. 30 | deprecated = [] 31 | rustc-dep-of-std = ['rustc-std-workspace-core', 'libc/rustc-dep-of-std'] 32 | 33 | [workspace] 34 | members = ["mach-test"] 35 | 36 | [package.metadata.docs.rs] 37 | default-target = "x86_64-apple-darwin" 38 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-BSD: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019, Nick Fitzgerald 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Nick Fitzgerald 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status][travis_ci_badge]][travis_ci] [![Latest Version]][crates.io] [![docs]][docs.rs] 2 | 3 | A Rust interface to the **user-space** API of the Mach 3.0 kernel exposed in 4 | `/usr/include/mach` that underlies macOS and is linked via `libSystem` (and 5 | `libsystem_kernel`). 6 | 7 | This library does not expose the **kernel-space** API of the Mach 3.0 kernel 8 | exposed in 9 | `SDK/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/mach`. 10 | 11 | That is, if you are writing a kernel-resident device drivers or some other 12 | kernel extensions you have to use something else. The user-space kernel API is 13 | often API-incompatible with the kernel space one, and even in the cases where 14 | they match, they are sometimes ABI incompatible such that using this library 15 | would have **undefined behavior**. 16 | 17 | # Usage 18 | 19 | Add the following to your `Cargo.toml` to conditionally include mach on those 20 | platforms that support it. 21 | 22 | ```toml 23 | [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.mach] 24 | version = "0.3" 25 | ``` 26 | 27 | The following crate features are available: 28 | 29 | * **deprecated** (disabled by default): exposes deprecated APIs that have been 30 | removed from the latest versions of the MacOS SDKs. The behavior of using 31 | these APIs on MacOS versions that do not support them is undefined (hopefully 32 | a linker error). 33 | 34 | # Platform support 35 | 36 | The following table describes the current CI set-up: 37 | 38 | | Target | Min. Rust | XCode | build | ctest | run | 39 | |-----------------------|-----------|---------------|-------|-------|-----| 40 | | `x86_64-apple-darwin` | 1.33.0 | 6.4 - 10.0 | ✓ | ✓ | ✓ | 41 | | `i686-apple-darwin` | 1.33.0 | 6.4 - 10.0 | ✓ | ✓ | ✓ | 42 | | `i386-apple-ios` | 1.33.0 | 6.4 - 9.4 [0] | ✓ | - | - | 43 | | `x86_64-apple-ios` | 1.33.0 | 6.4 - 10.0 | ✓ | - | - | 44 | | `armv7-apple-ios` | nightly | 6.4 - 10.0 | ✓ | - | - | 45 | | `aarch64-apple-ios` | nightly | 6.4 - 10.0 | ✓ | - | - | 46 | 47 | [0] `i386-apple-ios` is deprecated in XCode 10.0. 48 | 49 | # License 50 | 51 | This project is licensed under either of 52 | 53 | * A 2-clause BSD License ([LICENSE-BSD](LICENSE-BSD)), or 54 | * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or 55 | http://www.apache.org/licenses/LICENSE-2.0) 56 | * MIT license ([LICENSE-MIT](LICENSE-MIT) or 57 | http://opensource.org/licenses/MIT) 58 | 59 | at your option. 60 | 61 | # Contribution 62 | 63 | Unless you explicitly state otherwise, any contribution intentionally submitted 64 | for inclusion in `mach` by you, as defined in the Apache-2.0 license, shall be 65 | triple licensed as above, without any additional terms or conditions. 66 | 67 | To locally test the library, run: 68 | 69 | ``` 70 | TARGET=x86_64-apple-darwin TRAVIS_RUST_VERSION=nightly ./ci/run.sh 71 | ``` 72 | 73 | where you can replace the `TARGET` and `TRAVIS_RUST_VERSION` with the target you 74 | want to test (e.g. `i686-apple-darwin`) and the Rust version you want to use for 75 | the tests (e.g. `stable`, `1.33.0`, etc.). 76 | 77 | [travis_ci]: https://travis-ci.org/fitzgen/mach 78 | [travis_ci_badge]: https://travis-ci.org/fitzgen/mach.png?branch=master 79 | [crates.io]: https://crates.io/crates/mach 80 | [Latest Version]: https://img.shields.io/crates/v/mach.svg 81 | [docs]: https://docs.rs/mach/badge.svg 82 | [docs.rs]: https://docs.rs/mach/ 83 | -------------------------------------------------------------------------------- /ci/build_fail.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | : "${TARGET?The TARGET environment variable must be set.}" 6 | 7 | ! cargo build --target "${TARGET}" 8 | -------------------------------------------------------------------------------- /ci/deploy_and_run_on_ios_simulator.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | // This is a script to deploy and execute a binary on an iOS simulator. 12 | // The primary use of this is to be able to run unit tests on the simulator and 13 | // retrieve the results. 14 | // 15 | // To do this through Cargo instead, use Dinghy 16 | // (https://github.com/snipsco/dinghy): cargo dinghy install, then cargo dinghy 17 | // test. 18 | // 19 | // Source: this script is part of libc 20 | // https://github.com/rust-lang/libc/blob/master/ci/ios/deploy_and_run_on_ios_simulator.rs 21 | // and should be sync'ed with it when ci breaks (or periodically). 22 | 23 | use std::env; 24 | use std::fs::{self, File}; 25 | use std::io::Write; 26 | use std::path::Path; 27 | use std::process; 28 | use std::process::Command; 29 | 30 | macro_rules! t { 31 | ($e:expr) => (match $e { 32 | Ok(e) => e, 33 | Err(e) => panic!("{} failed with: {}", stringify!($e), e), 34 | }) 35 | } 36 | 37 | // Step one: Wrap as an app 38 | fn package_as_simulator_app(crate_name: &str, test_binary_path: &Path) { 39 | println!("Packaging simulator app"); 40 | drop(fs::remove_dir_all("ios_simulator_app")); 41 | t!(fs::create_dir("ios_simulator_app")); 42 | t!(fs::copy(test_binary_path, 43 | Path::new("ios_simulator_app").join(crate_name))); 44 | 45 | let mut f = t!(File::create("ios_simulator_app/Info.plist")); 46 | t!(f.write_all(format!(r#" 47 | 48 | 51 | 52 | 53 | CFBundleExecutable 54 | {} 55 | CFBundleIdentifier 56 | com.rust.unittests 57 | 58 | 59 | "#, crate_name).as_bytes())); 60 | } 61 | 62 | // Step two: Start the iOS simulator 63 | fn start_simulator() { 64 | println!("Looking for iOS simulator"); 65 | let output = t!(Command::new("xcrun").arg("simctl").arg("list").output()); 66 | assert!(output.status.success()); 67 | let mut simulator_exists = false; 68 | let mut simulator_booted = false; 69 | let mut found_rust_sim = false; 70 | let stdout = t!(String::from_utf8(output.stdout)); 71 | for line in stdout.lines() { 72 | if line.contains("rust_ios") { 73 | if found_rust_sim { 74 | panic!("Duplicate rust_ios simulators found. Please \ 75 | double-check xcrun simctl list."); 76 | } 77 | simulator_exists = true; 78 | simulator_booted = line.contains("(Booted)"); 79 | found_rust_sim = true; 80 | } 81 | } 82 | 83 | if simulator_exists == false { 84 | println!("Creating iOS simulator"); 85 | Command::new("xcrun") 86 | .arg("simctl") 87 | .arg("create") 88 | .arg("rust_ios") 89 | .arg("com.apple.CoreSimulator.SimDeviceType.iPhone-SE") 90 | .arg("com.apple.CoreSimulator.SimRuntime.iOS-10-2") 91 | .check_status(); 92 | } else if simulator_booted == true { 93 | println!("Shutting down already-booted simulator"); 94 | Command::new("xcrun") 95 | .arg("simctl") 96 | .arg("shutdown") 97 | .arg("rust_ios") 98 | .check_status(); 99 | } 100 | 101 | println!("Starting iOS simulator"); 102 | // We can't uninstall the app (if present) as that will hang if the 103 | // simulator isn't completely booted; just erase the simulator instead. 104 | Command::new("xcrun").arg("simctl").arg("erase").arg("rust_ios").check_status(); 105 | Command::new("xcrun").arg("simctl").arg("boot").arg("rust_ios").check_status(); 106 | } 107 | 108 | // Step three: Install the app 109 | fn install_app_to_simulator() { 110 | println!("Installing app to simulator"); 111 | Command::new("xcrun") 112 | .arg("simctl") 113 | .arg("install") 114 | .arg("booted") 115 | .arg("ios_simulator_app/") 116 | .check_status(); 117 | } 118 | 119 | // Step four: Run the app 120 | fn run_app_on_simulator() { 121 | println!("Running app"); 122 | let output = t!(Command::new("xcrun") 123 | .arg("simctl") 124 | .arg("launch") 125 | .arg("--console") 126 | .arg("booted") 127 | .arg("com.rust.unittests") 128 | .output()); 129 | 130 | println!("stdout --\n{}\n", String::from_utf8_lossy(&output.stdout)); 131 | println!("stderr --\n{}\n", String::from_utf8_lossy(&output.stderr)); 132 | 133 | let stdout = String::from_utf8_lossy(&output.stdout); 134 | let passed = stdout.lines() 135 | .find(|l| l.contains("PASSED")) 136 | .map(|l| l.contains("tests")) 137 | .unwrap_or(false); 138 | 139 | println!("Shutting down simulator"); 140 | Command::new("xcrun") 141 | .arg("simctl") 142 | .arg("shutdown") 143 | .arg("rust_ios") 144 | .check_status(); 145 | if !passed { 146 | panic!("tests didn't pass"); 147 | } 148 | } 149 | 150 | trait CheckStatus { 151 | fn check_status(&mut self); 152 | } 153 | 154 | impl CheckStatus for Command { 155 | fn check_status(&mut self) { 156 | println!("\trunning: {:?}", self); 157 | assert!(t!(self.status()).success()); 158 | } 159 | } 160 | 161 | fn main() { 162 | let args: Vec = env::args().collect(); 163 | if args.len() != 2 { 164 | println!("Usage: {} ", args[0]); 165 | process::exit(-1); 166 | } 167 | 168 | let test_binary_path = Path::new(&args[1]); 169 | let crate_name = test_binary_path.file_name().unwrap(); 170 | 171 | package_as_simulator_app(crate_name.to_str().unwrap(), test_binary_path); 172 | start_simulator(); 173 | install_app_to_simulator(); 174 | run_app_on_simulator(); 175 | } 176 | -------------------------------------------------------------------------------- /ci/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -ex 4 | 5 | : "${TARGET?The TARGET environment variable must be set.}" 6 | : "${TRAVIS_RUST_VERSION?The TRAVIS_RUST_VERSION environment variable must be set.}" 7 | 8 | echo "Running tests for target: ${TARGET}" 9 | export RUST_BACKTRACE=1 10 | export RUST_TEST_THREADS=1 11 | export RUST_TEST_NOCAPTURE=1 12 | export CARGO_INCREMENTAL=0 13 | export CARGO_CODEGEN_UNITS=1 14 | export RUSTFLAGS="-C codegen-units=1 " 15 | 16 | case "${TARGET}" in 17 | *"ios"*) 18 | export RUSTFLAGS="${RUSTFLAGS} -C link-args=-mios-simulator-version-min=7.0" 19 | rustc ./ci/deploy_and_run_on_ios_simulator.rs -o ios_cargo_runner --verbose 20 | if [ "${TARGET}" = "x86_64-apple-ios" ]; then 21 | export CARGO_TARGET_X86_64_APPLE_IOS_RUNNER 22 | CARGO_TARGET_X86_64_APPLE_IOS_RUNNER="$(pwd)/ios_cargo_runner" 23 | fi 24 | if [ "${TARGET}" = "i386-apple-ios" ]; then 25 | export CARGO_TARGET_I386_APPLE_IOS_RUNNER 26 | CARGO_TARGET_I386_APPLE_IOS_RUNNER="$(pwd)/ios_cargo_runner" 27 | fi 28 | ;; 29 | *) 30 | ;; 31 | esac 32 | 33 | # Build w/o std 34 | cargo clean 35 | cargo build --no-default-features --target "${TARGET}" -vv 2>&1 | tee build_no_std.txt 36 | 37 | # Check that the no-std builds are not linked against a libc with default 38 | # features or the std feature enabled: 39 | ! grep -q "default" build_no_std.txt 40 | ! grep -q "std" build_no_std.txt 41 | # Make sure that the resulting build contains no std symbols 42 | ! find target/ -name "*.rlib" -exec nm {} \; | grep "std" 43 | 44 | # Runs mach's run-time tests: 45 | if [ -z "$NORUN" ]; then 46 | cargo test --target "${TARGET}" -vv 47 | cargo test --target "${TARGET}" -vv --features deprecated 48 | cargo test --no-default-features --target "${TARGET}" -vv 49 | fi 50 | 51 | # Runs ctest to verify mach's ABI against the system libraries: 52 | if [ -z "$NOCTEST" ]; then 53 | if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then 54 | cargo test --manifest-path mach-test/Cargo.toml --target "${TARGET}" -vv 55 | cargo test --no-default-features --manifest-path mach-test/Cargo.toml --target "${TARGET}" -vv 56 | fi 57 | fi 58 | -------------------------------------------------------------------------------- /examples/dump_process_registers.rs: -------------------------------------------------------------------------------- 1 | //! A script to read and dump to stdout the current register values of a 2 | //! process. 3 | 4 | extern crate libc; 5 | extern crate mach; 6 | 7 | use std::io; 8 | use std::mem; 9 | use std::ptr; 10 | 11 | use mach::kern_return::KERN_SUCCESS; 12 | use mach::mach_types::{task_t, thread_act_array_t}; 13 | use mach::message::mach_msg_type_number_t; 14 | use mach::port::mach_port_name_t; 15 | use mach::structs::x86_thread_state64_t; 16 | use mach::task::{task_resume, task_suspend, task_threads}; 17 | use mach::thread_act::thread_get_state; 18 | use mach::thread_status::x86_THREAD_STATE64; 19 | use mach::traps::{mach_task_self, task_for_pid}; 20 | 21 | use std::io::prelude::*; 22 | 23 | fn read_int() -> Result<::libc::c_int, ()> { 24 | let stdin = io::stdin(); 25 | let mut line = String::new(); 26 | 27 | stdin.read_line(&mut line).ok().unwrap(); 28 | let mut value: ::libc::c_int = 0; 29 | 30 | for c in line.chars().take_while(|&c| c != '\n') { 31 | if let Some(d) = c.to_digit(10) { 32 | value = value * 10 + (d as ::libc::c_int); 33 | } else { 34 | return Err(()); 35 | } 36 | } 37 | return Ok(value); 38 | } 39 | 40 | fn resume(task: task_t) { 41 | unsafe { 42 | let kret = task_resume(task); 43 | if kret != KERN_SUCCESS { 44 | println!("Did not succeed in resuming task."); 45 | println!("kern_return_t error {}", kret); 46 | panic!(); 47 | } 48 | } 49 | } 50 | 51 | fn main() { 52 | print!("Enter pid: "); 53 | io::stdout().flush().ok(); 54 | 55 | let pid = match read_int() { 56 | Ok(v) => v, 57 | Err(_) => { 58 | println!("Bad pid!"); 59 | return; 60 | } 61 | }; 62 | 63 | println!("pid = {}", &pid); 64 | 65 | let task: mach_port_name_t = 0; 66 | unsafe { 67 | let kret = task_for_pid( 68 | mach_task_self() as mach_port_name_t, 69 | pid, 70 | mem::transmute(&task), 71 | ); 72 | if kret != KERN_SUCCESS { 73 | println!("Did not succeed in getting task for pid {}", pid); 74 | println!("kern_return_t error {}", kret); 75 | println!(""); 76 | println!("Did you forget to run with 'sudo'? This script will"); 77 | println!("probably fail without it."); 78 | return; 79 | } 80 | } 81 | 82 | println!("task = 0x{:x}", &task); 83 | 84 | unsafe { 85 | let kret = task_suspend(task as task_t); 86 | if kret != KERN_SUCCESS { 87 | println!("Did not succeed in suspending task."); 88 | println!("kern_return_t error {}", kret); 89 | return; 90 | } 91 | } 92 | 93 | let thread_list: thread_act_array_t = ptr::null_mut(); 94 | let thread_count: mach_msg_type_number_t = 0; 95 | unsafe { 96 | let kret = task_threads( 97 | task as task_t, 98 | mem::transmute(&thread_list), 99 | mem::transmute(&thread_count), 100 | ); 101 | if kret != KERN_SUCCESS { 102 | println!("Did not succeed in getting task's threads"); 103 | println!("kern_return_t error {}", kret); 104 | resume(task as task_t); 105 | return; 106 | } 107 | } 108 | 109 | println!("Task is running {} threads", &thread_count); 110 | 111 | unsafe { 112 | let threads = 113 | Vec::from_raw_parts(thread_list, thread_count as usize, thread_count as usize); 114 | let state = x86_thread_state64_t::new(); 115 | let state_count = x86_thread_state64_t::count(); 116 | for (idx, &thread) in threads.iter().enumerate() { 117 | println!("Thread {}:", idx); 118 | let kret = thread_get_state( 119 | thread, 120 | x86_THREAD_STATE64, 121 | mem::transmute(&state), 122 | mem::transmute(&state_count), 123 | ); 124 | if kret != KERN_SUCCESS { 125 | println!("Did not succeed in getting task's thread state"); 126 | println!("kern_return_t error {}", kret); 127 | continue; 128 | } 129 | 130 | println!("{:?}", state); 131 | } 132 | } 133 | 134 | resume(task as task_t); 135 | println!("Success!"); 136 | } 137 | -------------------------------------------------------------------------------- /mach-test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mach-test" 3 | version = "0.1.0" 4 | authors = ["gnzlbg "] 5 | build = "build.rs" 6 | 7 | [dependencies] 8 | mach = { path = ".." } 9 | libc = "0.2" 10 | 11 | [build-dependencies] 12 | ctest = "0.2" 13 | 14 | [[test]] 15 | name = "main" 16 | path = "test/main.rs" 17 | harness = false 18 | -------------------------------------------------------------------------------- /mach-test/build.rs: -------------------------------------------------------------------------------- 1 | extern crate ctest; 2 | 3 | #[derive(Eq, Ord, PartialEq, PartialOrd, Copy, Clone, Debug)] 4 | struct Xcode(pub u32, pub u32); 5 | 6 | impl Xcode { 7 | fn version() -> Xcode { 8 | use std::process::Command; 9 | let out = Command::new("/usr/bin/xcodebuild") 10 | .arg("-version") 11 | .output() 12 | .expect("failed to execute xcodebuild"); 13 | let stdout = ::std::str::from_utf8(&out.stdout).expect("couldn't parse stdout as UTF8"); 14 | let stderr = ::std::str::from_utf8(&out.stderr).expect("couldn't parse stderr as UTF8"); 15 | 16 | if !out.status.success() { 17 | eprintln!("stdout: {}", stdout); 18 | eprintln!("stderr: {}", stderr); 19 | panic!("xcodebuild -version failed"); 20 | } 21 | 22 | // xcodebuild -version output looks like: 23 | // 24 | // Xcode 9.2 25 | // Build version 9C40b 26 | let mut iter = stdout 27 | .split(|c: char| c.is_whitespace() || c == '.') 28 | .skip(1) 29 | .map(|c| { 30 | c.parse() 31 | .expect("failed to parse Xcode version into number") 32 | }); 33 | let major: u32 = iter.next().expect("failed to parse Xcode major version"); 34 | let minor: u32 = iter.next().expect("failed to parse Xcode minor version"); 35 | 36 | Xcode(major, minor) 37 | } 38 | } 39 | 40 | fn main() { 41 | let xcode = Xcode::version(); 42 | // kept on purpose for debugging: 43 | // println!("cargo:warning=\"Xcode version: {:?}\"", xcode); 44 | 45 | let mut cfg = ctest::TestGenerator::new(); 46 | 47 | // Older Xcode versions fail with: 48 | // error: unknown warning option '-Wno-address-of-packed-member' 49 | if xcode.0 < 8 { 50 | cfg.flag("-Wno-unknown-warning-option"); 51 | } 52 | 53 | // Include the header files where the C APIs are defined 54 | cfg.header("mach/boolean.h") 55 | .header("bootstrap.h") 56 | .header("mach/bootstrap.h") 57 | .header("mach/clock.h") 58 | .header("mach/clock_priv.h") 59 | .header("mach/clock_reply.h") 60 | .header("mach/clock_types.h"); 61 | 62 | if xcode >= Xcode(8, 0) { 63 | cfg.header("mach/dyld_kernel.h"); 64 | } 65 | 66 | cfg.header("mach/error.h") 67 | .header("mach/exc.h") 68 | .header("mach/exception.h") 69 | .header("mach/exception_types.h") 70 | .header("mach/host_info.h") 71 | .header("mach/host_notify.h") 72 | .header("mach/host_priv.h") 73 | .header("mach/host_reboot.h") 74 | .header("mach/host_security.h") 75 | .header("mach/host_special_ports.h") 76 | .header("mach/kern_return.h") 77 | .header("mach/kmod.h") 78 | .header("mach/lock_set.h") 79 | .header("mach/mach.h") 80 | .header("mach/mach_error.h") 81 | .header("mach/mach_host.h") 82 | .header("mach/mach_init.h") 83 | .header("mach/mach_interface.h") 84 | .header("mach/mach_param.h") 85 | .header("mach/mach_port.h") 86 | .header("mach/mach_syscalls.h") 87 | .header("mach/mach_time.h") 88 | .header("mach/mach_traps.h") 89 | .header("mach/mach_types.h") 90 | .header("mach/mach_vm.h") 91 | .header("mach/mach_voucher.h") 92 | .header("mach/mach_voucher_types.h") 93 | .header("mach/machine.h") 94 | .header("mach/memory_object_types.h") 95 | .header("mach/message.h"); 96 | 97 | cfg.header("mach/ndr.h") 98 | .header("mach/notify.h") 99 | .header("mach/policy.h") 100 | .header("mach/port.h") 101 | .header("mach/port_obj.h") 102 | .header("mach/processor.h") 103 | .header("mach/processor_info.h") 104 | .header("mach/processor_set.h") 105 | .header("mach/rpc.h") 106 | .header("mach/sdt.h") 107 | .header("mach/semaphore.h") 108 | .header("mach/shared_region.h") 109 | .header("mach/std_types.h") 110 | .header("mach/sync.h") 111 | .header("mach/sync_policy.h") 112 | .header("mach/task.h") 113 | .header("mach/task_info.h") 114 | // .header("mach/task_inspect.h"); 115 | .header("mach/task_policy.h") 116 | .header("mach/task_special_ports.h") 117 | .header("mach/thread_act.h") 118 | .header("mach/thread_info.h") 119 | .header("mach/thread_policy.h") 120 | .header("mach/thread_special_ports.h"); 121 | 122 | if xcode >= Xcode(7, 0) { 123 | cfg.header("mach/thread_state.h"); 124 | } 125 | 126 | cfg.header("mach/thread_status.h") 127 | .header("mach/thread_switch.h") 128 | .header("mach/time_value.h") 129 | .header("mach/vm_attributes.h") 130 | .header("mach/vm_behavior.h") 131 | .header("mach/vm_inherit.h") 132 | .header("mach/vm_map.h") 133 | .header("mach/vm_page_size.h") 134 | .header("mach/vm_param.h") 135 | .header("mach/vm_prot.h") 136 | .header("mach/vm_purgable.h") 137 | .header("mach/vm_region.h") 138 | .header("mach/vm_statistics.h") 139 | .header("mach/vm_sync.h") 140 | .header("mach/vm_task.h") 141 | .header("mach/vm_types.h"); 142 | 143 | cfg.skip_struct(move |s| { 144 | match s { 145 | // TODO: this type is a bitfield and must be verified by hand 146 | "mach_msg_port_descriptor_t" | 147 | 148 | // TODO: this type is a bitfield and must be verified by hand 149 | "mach_msg_ool_descriptor_t" | 150 | 151 | // TODO: this type is a bitfield and must be verified by hand 152 | "mach_msg_ool_ports_descriptor_t" | 153 | 154 | // FIXME: this type is not exposed in /usr/include/mach 155 | // but seems to be exposed in 156 | // SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/mach 157 | "ipc_port" => true, 158 | 159 | // These are not available in previous MacOSX versions: 160 | "dyld_kernel_image_info" | 161 | "dyld_kernel_process_info" | 162 | "fsid" | 163 | "fsobj_id" 164 | if xcode < Xcode(8, 0) => true, 165 | _ => false, 166 | } 167 | }); 168 | 169 | cfg.skip_type(move |s| { 170 | match s { 171 | // FIXME: this type is not exposed in /usr/include/mach 172 | // but seems to be exposed in 173 | // SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/mach 174 | "ipc_port_t" => true, 175 | 176 | // These are not available in previous MacOSX versions 177 | "dyld_kernel_image_info_t" 178 | | "dyld_kernel_process_info_t" 179 | | "dyld_kernel_image_info_array_t" 180 | | "uuid_t" 181 | | "fsid_t" 182 | | "fsobj_id_t" 183 | if xcode < Xcode(8, 0) => 184 | { 185 | true 186 | } 187 | 188 | _ => false, 189 | } 190 | }); 191 | 192 | cfg.skip_fn(move |s| { 193 | match s { 194 | // mac_task_self and current_tasl are not functions, but macro that map to the 195 | // mask_task_self_ static variable: 196 | "mach_task_self" | "current_task" => true, 197 | 198 | // These are not available in previous MacOSX versions: 199 | "mach_continuous_time" | "mach_continuous_approximate_time" if xcode < Xcode(8, 0) => { 200 | true 201 | } 202 | _ => false, 203 | } 204 | }); 205 | 206 | cfg.skip_const(move |s| { 207 | match s { 208 | // Available only in MacOSX >= 10.13 209 | "EXC_CORPSE_VARIANT_BIT" => true, 210 | // Used to have a value of 11 until MacOSX 10.8 and changed to a 211 | // value of 13 in MacOSX 10.9 ~ Xcode 6.4 212 | "VM_REGION_EXTENDED_INFO" if xcode < Xcode(6, 4) => true, 213 | // Added in MacOSX 10.11.0 (Xcode 7.3) 214 | "TASK_VM_INFO_PURGEABLE_ACCOUNT" | "TASK_FLAGS_INFO" | "TASK_DEBUG_INFO_INTERNAL" 215 | if xcode < Xcode(7, 3) => 216 | { 217 | true 218 | } 219 | // Removed after MacOSX 10.6 (does not appear in MacOSX 10.7) 220 | "VM_PROT_TRUSTED" if xcode > Xcode(4, 3) => true, 221 | // Added after MacOSX 10.9 ~ Xcode 6.4 222 | "EXC_CORPSE_NOTIFY" | "EXC_MASK_CORPSE_NOTIFY" if xcode <= Xcode(7, 0) => true, 223 | _ => false, 224 | } 225 | }); 226 | 227 | cfg.fn_cname(|rust, _link_name| match rust { 228 | v => v.to_string(), 229 | }); 230 | 231 | cfg.skip_signededness(|c| { 232 | // signededness test does not make sense for these: 233 | match c { 234 | // struct types: 235 | "mach_timespec_t" | 236 | "ipc_port_t" | 237 | "vm_statistics_data_t" | 238 | "fsid_t" | 239 | "fsobj_id_t" | 240 | "dyld_kernel_image_info_t" | 241 | "dyld_kernel_process_info_t" | 242 | 243 | // array types: 244 | "vm_region_info_data_t" | 245 | "mach_vm_read_entry_t" | 246 | "name_t" | 247 | "cmd_t" | 248 | "name_array_t" | 249 | "bootstrap_status_array_t" | 250 | "bootstrap_property_array_t" | 251 | "bool_array_t" | 252 | "uuid_t" | 253 | 254 | // pointer types: 255 | "clock_attr_t" | 256 | "dyld_kernel_image_info_array_t" | 257 | "memory_object_fault_info_t" | 258 | "exception_data_t" | 259 | "exception_flavor_array_t" | 260 | "exception_mask_array_t" | 261 | "exception_port_arrary_t" | 262 | "exception_handler_array_t" | 263 | "thread_state_t" | 264 | "thread_array_t" | 265 | "thread_port_array_t" | 266 | "thread_act_array_t" | 267 | "thread_act_port_array_t" | 268 | "ledger_array_t" | 269 | "ledger_port_array_t" | 270 | "mach_exception_data_t" | 271 | "exception_behavior_array_t" | 272 | "exception_port_array_t" | 273 | "task_info_t" | 274 | "task_array_t" | 275 | "task_port_array_t" | 276 | "processor_array_t" | 277 | "processor_port_array_t" | 278 | "processor_set_array_t" | 279 | "processor_set_name_array_t" | 280 | "processor_set_name_port_array_t" | 281 | "vm_region_t" | 282 | "vm_region_info_t" | 283 | "vm_region_info_64_t" | 284 | "vm_region_recurse_info_t" | 285 | "vm_region_recurse_info_64_t" | 286 | "vm_region_basic_info_64_t" | 287 | "vm_region_basic_info_t" | 288 | "vm_region_basic_info_data_t" | 289 | "vm_region_basic_info_data_64_t" | 290 | "vm_region_extended_info_t" | 291 | "vm_region_extended_info_data_t" | 292 | "vm_region_top_info_t" | 293 | "vm_region_top_info_data_t" | 294 | "vm_region_submap_info_t" | 295 | "vm_region_submap_info_64_t" | 296 | "vm_region_submap_info_data_t" | 297 | "vm_region_submap_info_data_64_t" | 298 | "vm_region_submap_short_info_64_t" | 299 | "vm_region_submap_short_info_data_64_t" | 300 | "vm_page_info_t" | 301 | "vm_page_info_basic_t" | 302 | "vm_page_info_basic_data_t" | 303 | "vm_statistics_t" 304 | => true, 305 | _ => false, 306 | } 307 | }); 308 | 309 | cfg.type_name(|ty, is_struct, _is_union| match ty { 310 | // struct foo in Rust should translate to struct foo in C: 311 | "vm_region_basic_info_64" 312 | | "vm_region_basic_info" 313 | | "vm_region_extended_info" 314 | | "vm_region_top_info" 315 | | "vm_region_submap_info" 316 | | "vm_region_submap_info_64" 317 | | "vm_region_submap_short_info_64" 318 | | "vm_page_info_basic" 319 | | "vm_statistics" 320 | | "task_dyld_info" 321 | | "fsid" 322 | | "fsobj_id" 323 | | "dyld_kernel_image_info" 324 | | "dyld_kernel_process_info" 325 | | "mach_timespec" 326 | | "mach_vm_read_entry" 327 | | "mach_timebase_info" => format!("struct {}", ty), 328 | _ if is_struct => format!("{}", ty), 329 | _ => ty.to_string(), 330 | }); 331 | 332 | cfg.skip_roundtrip(move |s| match s { 333 | // FIXME: TODO 334 | "name_t" | "uuid_t" | "vm_region_info_data_t" | "cmd_t" | "mach_vm_read_entry_t" => true, 335 | _ => false, 336 | }); 337 | 338 | // Include the directory where the header files are defined 339 | cfg.include("/usr/include"); 340 | 341 | // Generate the tests, passing the path to the `*-sys` library as well as 342 | // the module to generate. 343 | cfg.generate("../src/lib.rs", "all.rs"); 344 | } 345 | -------------------------------------------------------------------------------- /mach-test/test/main.rs: -------------------------------------------------------------------------------- 1 | #![allow(bad_style)] 2 | 3 | extern crate libc; 4 | extern crate mach; 5 | 6 | use mach::boolean::*; 7 | use mach::bootstrap::*; 8 | use mach::clock::*; 9 | use mach::clock_priv::*; 10 | use mach::clock_reply::*; 11 | use mach::clock_types::*; 12 | use mach::dyld_kernel::*; 13 | use mach::exc::*; 14 | use mach::exception_types::*; 15 | use mach::kern_return::*; 16 | use mach::mach_init::*; 17 | use mach::mach_port::*; 18 | use mach::mach_time::*; 19 | use mach::mach_types::*; 20 | use mach::memory_object_types::*; 21 | use mach::message::*; 22 | use mach::port::*; 23 | use mach::structs::*; 24 | use mach::task::*; 25 | use mach::task_info::*; 26 | use mach::thread_act::*; 27 | use mach::thread_status::*; 28 | use mach::traps::*; 29 | use mach::vm::*; 30 | use mach::vm_attributes::*; 31 | use mach::vm_behavior::*; 32 | use mach::vm_inherit::*; 33 | // FIXME: vm_page_size is not used => not tested? 34 | #[allow(unused_imports)] 35 | use mach::vm_page_size::*; 36 | use mach::vm_prot::*; 37 | use mach::vm_purgable::*; 38 | use mach::vm_region::*; 39 | use mach::vm_statistics::*; 40 | use mach::vm_sync::*; 41 | use mach::vm_types::*; 42 | 43 | // These types are not re-exported by mach::types but they are required. 44 | use libc::{c_int, c_uchar, c_uint, c_ulonglong, clock_t}; 45 | 46 | // Imported by mach, but kept private: 47 | extern "C" { 48 | static mach_task_self_: mach_port_t; 49 | } 50 | 51 | include!(concat!(env!("OUT_DIR"), "/all.rs")); 52 | -------------------------------------------------------------------------------- /src/boolean.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/i386/boolean.h`. 2 | 3 | #[cfg(target_arch = "x86_64")] 4 | pub type boolean_t = ::libc::c_uint; 5 | 6 | #[cfg(not(target_arch = "x86_64"))] 7 | pub type boolean_t = ::libc::c_int; 8 | -------------------------------------------------------------------------------- /src/bootstrap.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `bootstrap.h` 2 | 3 | use boolean::boolean_t; 4 | use kern_return::kern_return_t; 5 | use port::mach_port_t; 6 | 7 | pub const BOOTSTRAP_MAX_NAME_LEN: ::libc::c_uint = 128; 8 | pub const BOOTSTRAP_MAX_CMD_LEN: ::libc::c_uint = 512; 9 | 10 | pub const BOOTSTRAP_MAX_LOOKUP_COUNT: ::libc::c_uint = 20; 11 | 12 | pub const BOOTSTRAP_SUCCESS: ::libc::c_uint = 0; 13 | pub const BOOTSTRAP_NOT_PRIVILEGED: ::libc::c_uint = 1100; 14 | pub const BOOTSTRAP_NAME_IN_USE: ::libc::c_uint = 1101; 15 | pub const BOOTSTRAP_UNKNOWN_SERVICE: ::libc::c_uint = 1102; 16 | pub const BOOTSTRAP_SERVICE_ACTIVE: ::libc::c_uint = 1103; 17 | pub const BOOTSTRAP_BAD_COUNT: ::libc::c_uint = 1104; 18 | pub const BOOTSTRAP_NO_MEMORY: ::libc::c_uint = 1105; 19 | pub const BOOTSTRAP_NO_CHILDREN: ::libc::c_uint = 1106; 20 | 21 | pub const BOOTSTRAP_STATUS_INACTIVE: ::libc::c_uint = 0; 22 | pub const BOOTSTRAP_STATUS_ACTIVE: ::libc::c_uint = 1; 23 | pub const BOOTSTRAP_STATUS_ON_DEMAND: ::libc::c_uint = 2; 24 | 25 | pub type name_t = [::libc::c_char; 128]; 26 | pub type cmd_t = [::libc::c_char; 512]; 27 | pub type name_array_t = *mut name_t; 28 | pub type bootstrap_status_t = ::libc::c_int; 29 | pub type bootstrap_status_array_t = *mut bootstrap_status_t; 30 | pub type bootstrap_property_t = ::libc::c_uint; 31 | pub type bootstrap_property_array_t = *mut bootstrap_property_t; 32 | pub type bool_array_t = *mut boolean_t; 33 | 34 | extern "C" { 35 | pub static bootstrap_port: mach_port_t; 36 | pub fn bootstrap_create_server( 37 | bp: mach_port_t, 38 | server_cmd: *mut ::libc::c_char, 39 | server_uid: ::libc::uid_t, 40 | on_demand: boolean_t, 41 | server_port: *mut mach_port_t, 42 | ) -> kern_return_t; 43 | pub fn bootstrap_subset( 44 | bp: mach_port_t, 45 | requestor_port: mach_port_t, 46 | subset_port: *mut mach_port_t, 47 | ) -> kern_return_t; 48 | pub fn bootstrap_unprivileged(bp: mach_port_t, unpriv_port: *mut mach_port_t) -> kern_return_t; 49 | pub fn bootstrap_parent(bp: mach_port_t, parent_port: *mut mach_port_t) -> kern_return_t; 50 | pub fn bootstrap_register( 51 | bp: mach_port_t, 52 | service_name: *mut ::libc::c_char, 53 | sp: mach_port_t, 54 | ) -> kern_return_t; 55 | pub fn bootstrap_create_service( 56 | bp: mach_port_t, 57 | service_name: *mut ::libc::c_char, 58 | sp: *mut mach_port_t, 59 | ) -> kern_return_t; 60 | pub fn bootstrap_check_in( 61 | bp: mach_port_t, 62 | service_name: *const ::libc::c_char, 63 | sp: *mut mach_port_t, 64 | ) -> kern_return_t; 65 | pub fn bootstrap_look_up( 66 | bp: mach_port_t, 67 | service_name: *const ::libc::c_char, 68 | sp: *mut mach_port_t, 69 | ) -> kern_return_t; 70 | pub fn bootstrap_status( 71 | bp: mach_port_t, 72 | service_name: *mut ::libc::c_char, 73 | service_active: *mut bootstrap_status_t, 74 | ) -> kern_return_t; 75 | pub fn bootstrap_strerror(r: kern_return_t) -> *const ::libc::c_char; 76 | } 77 | -------------------------------------------------------------------------------- /src/clock.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/clock.h`. 2 | 3 | pub const clock_MSG_COUNT: ::libc::c_uint = 3; 4 | 5 | use clock_types::{alarm_type_t, clock_attr_t, clock_flavor_t, mach_timespec_t}; 6 | use kern_return::kern_return_t; 7 | use mach_types::{clock_reply_t, clock_serv_t}; 8 | use message::mach_msg_type_number_t; 9 | 10 | extern "C" { 11 | pub fn clock_get_time( 12 | clock_serv: clock_serv_t, 13 | cur_time: *mut mach_timespec_t, 14 | ) -> kern_return_t; 15 | pub fn clock_get_attributes( 16 | clock_serv: clock_serv_t, 17 | flavor: clock_flavor_t, 18 | clock_attr: clock_attr_t, 19 | clock_attrCnt: *mut mach_msg_type_number_t, 20 | ) -> kern_return_t; 21 | pub fn clock_alarm( 22 | clock_serv: clock_serv_t, 23 | alarm_type: alarm_type_t, 24 | alarm_time: mach_timespec_t, 25 | alarm_port: clock_reply_t, 26 | ) -> kern_return_t; 27 | } 28 | -------------------------------------------------------------------------------- /src/clock_priv.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/clock_priv.h`. 2 | 3 | use clock_types::{clock_attr_t, clock_flavor_t, mach_timespec_t}; 4 | use kern_return::kern_return_t; 5 | use mach_types::clock_ctrl_t; 6 | use message::mach_msg_type_number_t; 7 | 8 | extern "C" { 9 | pub fn clock_set_time(clock_ctrl: clock_ctrl_t, new_time: mach_timespec_t) -> kern_return_t; 10 | pub fn clock_set_attributes( 11 | clock_ctrl: clock_ctrl_t, 12 | flavor: clock_flavor_t, 13 | clock_attr: clock_attr_t, 14 | clock_attrCnt: mach_msg_type_number_t, 15 | ) -> kern_return_t; 16 | } 17 | -------------------------------------------------------------------------------- /src/clock_reply.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/clock_reply.h`. 2 | 3 | use clock_types::{alarm_type_t, mach_timespec_t}; 4 | use kern_return::kern_return_t; 5 | use mach_types::clock_reply_t; 6 | use message::mach_msg_type_name_t; 7 | 8 | extern "C" { 9 | pub fn clock_alarm_reply( 10 | alarm_port: clock_reply_t, 11 | alarm_portPoly: mach_msg_type_name_t, 12 | alarm_code: kern_return_t, 13 | alarm_type: alarm_type_t, 14 | alarm_time: mach_timespec_t, 15 | ) -> kern_return_t; 16 | } 17 | -------------------------------------------------------------------------------- /src/clock_types.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/clock_types.h`. 2 | 3 | pub type alarm_type_t = ::libc::c_int; 4 | pub type sleep_type_t = ::libc::c_int; 5 | pub type clock_id_t = ::libc::c_int; 6 | pub type clock_flavor_t = ::libc::c_int; 7 | pub type clock_attr_t = *mut ::libc::c_int; 8 | pub type clock_res_t = ::libc::c_int; 9 | 10 | #[repr(C)] 11 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 12 | pub struct mach_timespec { 13 | pub tv_sec: ::libc::c_uint, 14 | pub tv_nsec: clock_res_t, 15 | } 16 | pub type mach_timespec_t = mach_timespec; 17 | 18 | pub const SYSTEM_CLOCK: ::libc::c_uint = 0; 19 | pub const CALENDAR_CLOCK: ::libc::c_uint = 1; 20 | pub const REALTIME_CLOCK: ::libc::c_uint = 0; 21 | 22 | pub const CLOCK_GET_TIME_RES: ::libc::c_uint = 1; 23 | pub const CLOCK_ALARM_CURRES: ::libc::c_uint = 3; 24 | pub const CLOCK_ALARM_MINRES: ::libc::c_uint = 4; 25 | pub const CLOCK_ALARM_MAXRES: ::libc::c_uint = 5; 26 | 27 | pub const NSEC_PER_USEC: ::libc::c_ulonglong = 1000; 28 | pub const USEC_PER_SEC: ::libc::c_ulonglong = 1_000_000; 29 | pub const NSEC_PER_SEC: ::libc::c_ulonglong = 1_000_000_000; 30 | pub const NSEC_PER_MSEC: ::libc::c_ulonglong = 1_000_000; 31 | 32 | #[allow(non_snake_case)] 33 | pub fn BAD_MACH_TIMESPEC(t: mach_timespec) -> bool { 34 | t.tv_nsec < 0 || (t.tv_nsec as ::libc::c_ulonglong) >= NSEC_PER_SEC 35 | } 36 | 37 | #[allow(non_snake_case)] 38 | pub fn CMP_MACH_TIMESPEC(t1: &mach_timespec, t2: &mach_timespec) -> ::libc::c_ulonglong { 39 | if t1.tv_sec > t2.tv_sec { 40 | return NSEC_PER_SEC; 41 | } 42 | if t1.tv_sec < t2.tv_sec { 43 | return !NSEC_PER_SEC; 44 | } 45 | (t1.tv_nsec as ::libc::c_ulonglong) - (t2.tv_nsec as ::libc::c_ulonglong) 46 | } 47 | 48 | #[allow(non_snake_case)] 49 | pub fn ADD_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec) { 50 | t1.tv_nsec += t2.tv_nsec; 51 | if (t1.tv_nsec as ::libc::c_ulonglong) >= NSEC_PER_SEC { 52 | t1.tv_nsec = (t1.tv_nsec as ::libc::c_ulonglong - NSEC_PER_SEC) as clock_res_t; 53 | t1.tv_sec += 1; 54 | } 55 | t1.tv_sec += t2.tv_sec; 56 | } 57 | 58 | #[allow(non_snake_case)] 59 | pub fn SUB_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec) { 60 | t1.tv_nsec -= t2.tv_nsec; 61 | if t1.tv_nsec < 0 { 62 | t1.tv_nsec = (t1.tv_nsec as ::libc::c_ulonglong + NSEC_PER_SEC) as clock_res_t; 63 | t1.tv_sec -= 1; 64 | } 65 | t1.tv_sec -= t2.tv_sec; 66 | } 67 | 68 | pub const ALRMTYPE: ::libc::c_uint = 0xff; 69 | pub const TIME_ABSOLUTE: ::libc::c_uint = 0x00; 70 | pub const TIME_RELATIVE: ::libc::c_uint = 0x01; 71 | 72 | #[allow(non_snake_case)] 73 | pub fn BAD_ALRMTYPE(t: ::libc::c_uint) -> bool { 74 | t & (!TIME_RELATIVE) != 0 75 | } 76 | -------------------------------------------------------------------------------- /src/dyld_kernel.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/dyld_kernel.h`. 2 | 3 | use boolean::boolean_t; 4 | use mach_types::{fsid_t, fsobj_id_t, uuid_t}; 5 | 6 | #[repr(C)] 7 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 8 | pub struct dyld_kernel_image_info { 9 | pub uuid: uuid_t, 10 | pub fsobjid: fsobj_id_t, 11 | pub fsid: fsid_t, 12 | pub load_addr: u64, 13 | } 14 | 15 | #[allow(non_snake_case)] 16 | #[repr(C)] 17 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 18 | pub struct dyld_kernel_process_info { 19 | pub cache_image_info: dyld_kernel_image_info, 20 | pub timestamp: u64, 21 | pub imageCount: u32, 22 | pub initialImageCount: u32, 23 | pub dyldState: u8, 24 | pub no_cache: boolean_t, 25 | pub private_cache: boolean_t, 26 | } 27 | 28 | pub type dyld_kernel_image_info_t = dyld_kernel_image_info; 29 | pub type dyld_kernel_process_info_t = dyld_kernel_process_info; 30 | pub type dyld_kernel_image_info_array_t = *mut dyld_kernel_image_info_t; 31 | -------------------------------------------------------------------------------- /src/exc.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/exc.h`. 2 | 3 | use exception_types::{exception_data_t, exception_type_t}; 4 | use kern_return::kern_return_t; 5 | use message::mach_msg_type_number_t; 6 | use port::mach_port_t; 7 | use thread_status::thread_state_t; 8 | 9 | pub const exc_MSG_COUNT: ::libc::c_uint = 3; 10 | 11 | extern "C" { 12 | pub fn exception_raise( 13 | exception_port: mach_port_t, 14 | thread: mach_port_t, 15 | task: mach_port_t, 16 | exception: exception_type_t, 17 | code: exception_data_t, 18 | codeCnt: mach_msg_type_number_t, 19 | ) -> kern_return_t; 20 | pub fn exception_raise_state( 21 | exception_port: mach_port_t, 22 | exception: exception_type_t, 23 | code: exception_data_t, 24 | codeCnt: mach_msg_type_number_t, 25 | flavor: *mut ::libc::c_int, 26 | old_state: thread_state_t, 27 | old_stateCnt: mach_msg_type_number_t, 28 | new_state: thread_state_t, 29 | new_stateCnt: *mut mach_msg_type_number_t, 30 | ) -> kern_return_t; 31 | pub fn exception_raise_state_identity( 32 | exception_port: mach_port_t, 33 | thread: mach_port_t, 34 | task: mach_port_t, 35 | exception: exception_type_t, 36 | code: exception_data_t, 37 | codeCnt: mach_msg_type_number_t, 38 | flavor: *mut ::libc::c_int, 39 | old_state: thread_state_t, 40 | old_stateCnt: mach_msg_type_number_t, 41 | new_state: thread_state_t, 42 | new_stateCnt: *mut mach_msg_type_number_t, 43 | ) -> kern_return_t; 44 | } 45 | -------------------------------------------------------------------------------- /src/exception_types.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/exception_types.h`. 2 | 3 | use port::mach_port_t; 4 | use thread_status::thread_state_flavor_t; 5 | use vm_types::integer_t; 6 | 7 | pub const EXC_BAD_ACCESS: ::libc::c_uint = 1; 8 | pub const EXC_BAD_INSTRUCTION: ::libc::c_uint = 2; 9 | pub const EXC_ARITHMETIC: ::libc::c_uint = 3; 10 | pub const EXC_EMULATION: ::libc::c_uint = 4; 11 | pub const EXC_SOFTWARE: ::libc::c_uint = 5; 12 | pub const EXC_BREAKPOINT: ::libc::c_uint = 6; 13 | pub const EXC_SYSCALL: ::libc::c_uint = 7; 14 | pub const EXC_MACH_SYSCALL: ::libc::c_uint = 8; 15 | pub const EXC_RPC_ALERT: ::libc::c_uint = 9; 16 | pub const EXC_CRASH: ::libc::c_uint = 10; 17 | pub const EXC_RESOURCE: ::libc::c_uint = 11; 18 | pub const EXC_GUARD: ::libc::c_uint = 12; 19 | pub const EXC_CORPSE_NOTIFY: ::libc::c_uint = 13; 20 | pub const EXC_CORPSE_VARIANT_BIT: ::libc::c_uint = 256; 21 | pub const EXCEPTION_DEFAULT: ::libc::c_uint = 1; 22 | pub const EXCEPTION_STATE: ::libc::c_uint = 2; 23 | pub const EXCEPTION_STATE_IDENTITY: ::libc::c_uint = 3; 24 | pub const MACH_EXCEPTION_CODES: ::libc::c_uint = 2_147_483_648; 25 | pub const EXC_MASK_BAD_ACCESS: ::libc::c_uint = 2; 26 | pub const EXC_MASK_BAD_INSTRUCTION: ::libc::c_uint = 4; 27 | pub const EXC_MASK_ARITHMETIC: ::libc::c_uint = 8; 28 | pub const EXC_MASK_EMULATION: ::libc::c_uint = 16; 29 | pub const EXC_MASK_SOFTWARE: ::libc::c_uint = 32; 30 | pub const EXC_MASK_BREAKPOINT: ::libc::c_uint = 64; 31 | pub const EXC_MASK_SYSCALL: ::libc::c_uint = 128; 32 | pub const EXC_MASK_MACH_SYSCALL: ::libc::c_uint = 256; 33 | pub const EXC_MASK_RPC_ALERT: ::libc::c_uint = 512; 34 | pub const EXC_MASK_CRASH: ::libc::c_uint = 1024; 35 | pub const EXC_MASK_RESOURCE: ::libc::c_uint = 2048; 36 | pub const EXC_MASK_GUARD: ::libc::c_uint = 4096; 37 | pub const EXC_MASK_CORPSE_NOTIFY: ::libc::c_uint = 8192; 38 | pub const EXC_MASK_ALL: ::libc::c_uint = 7166; 39 | pub const FIRST_EXCEPTION: ::libc::c_uint = 1; 40 | pub const EXC_SOFT_SIGNAL: ::libc::c_uint = 65_539; 41 | pub const EXC_MACF_MIN: ::libc::c_uint = 131_072; 42 | pub const EXC_MACF_MAX: ::libc::c_uint = 196_607; 43 | 44 | pub type exception_type_t = ::libc::c_int; 45 | pub type exception_data_type_t = integer_t; 46 | pub type mach_exception_data_type_t = i64; 47 | pub type exception_behavior_t = ::libc::c_int; 48 | pub type exception_data_t = *mut exception_data_type_t; 49 | pub type mach_exception_data_t = *mut mach_exception_data_type_t; 50 | pub type exception_mask_t = ::libc::c_uint; 51 | pub type exception_mask_array_t = *mut exception_mask_t; 52 | pub type exception_behavior_array_t = *mut exception_behavior_t; 53 | pub type exception_flavor_array_t = *mut thread_state_flavor_t; 54 | pub type exception_port_array_t = *mut mach_port_t; 55 | pub type mach_exception_code_t = mach_exception_data_type_t; 56 | pub type mach_exception_subcode_t = mach_exception_data_type_t; 57 | -------------------------------------------------------------------------------- /src/kern_return.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/kern_return.h` and 2 | //! `mach/i386/kern_return.h`. 3 | 4 | pub type kern_return_t = ::libc::c_int; 5 | 6 | pub const KERN_SUCCESS: kern_return_t = 0; 7 | pub const KERN_INVALID_ADDRESS: kern_return_t = 1; 8 | pub const KERN_PROTECTION_FAILURE: kern_return_t = 2; 9 | pub const KERN_NO_SPACE: kern_return_t = 3; 10 | pub const KERN_INVALID_ARGUMENT: kern_return_t = 4; 11 | pub const KERN_FAILURE: kern_return_t = 5; 12 | pub const KERN_RESOURCE_SHORTAGE: kern_return_t = 6; 13 | pub const KERN_NOT_RECEIVER: kern_return_t = 7; 14 | pub const KERN_NO_ACCESS: kern_return_t = 8; 15 | pub const KERN_MEMORY_FAILURE: kern_return_t = 9; 16 | pub const KERN_MEMORY_ERROR: kern_return_t = 10; 17 | pub const KERN_ALREADY_IN_SET: kern_return_t = 11; 18 | pub const KERN_NOT_IN_SET: kern_return_t = 12; 19 | pub const KERN_NAME_EXISTS: kern_return_t = 13; 20 | pub const KERN_ABORTED: kern_return_t = 14; 21 | pub const KERN_INVALID_NAME: kern_return_t = 15; 22 | pub const KERN_INVALID_TASK: kern_return_t = 16; 23 | pub const KERN_INVALID_RIGHT: kern_return_t = 17; 24 | pub const KERN_INVALID_VALUE: kern_return_t = 18; 25 | pub const KERN_UREFS_OVERFLOW: kern_return_t = 19; 26 | pub const KERN_INVALID_CAPABILITY: kern_return_t = 20; 27 | pub const KERN_RIGHT_EXISTS: kern_return_t = 21; 28 | pub const KERN_INVALID_HOST: kern_return_t = 22; 29 | pub const KERN_MEMORY_PRESENT: kern_return_t = 23; 30 | pub const KERN_MEMORY_DATA_MOVED: kern_return_t = 24; 31 | pub const KERN_MEMORY_RESTART_COPY: kern_return_t = 25; 32 | pub const KERN_INVALID_PROCESSOR_SET: kern_return_t = 26; 33 | pub const KERN_POLICY_LIMIT: kern_return_t = 27; 34 | pub const KERN_INVALID_POLICY: kern_return_t = 28; 35 | pub const KERN_INVALID_OBJECT: kern_return_t = 29; 36 | pub const KERN_ALREADY_WAITING: kern_return_t = 30; 37 | pub const KERN_DEFAULT_SET: kern_return_t = 31; 38 | pub const KERN_EXCEPTION_PROTECTED: kern_return_t = 32; 39 | pub const KERN_INVALID_LEDGER: kern_return_t = 33; 40 | pub const KERN_INVALID_MEMORY_CONTROL: kern_return_t = 34; 41 | pub const KERN_INVALID_SECURITY: kern_return_t = 35; 42 | pub const KERN_NOT_DEPRESSED: kern_return_t = 36; 43 | pub const KERN_TERMINATED: kern_return_t = 37; 44 | pub const KERN_LOCK_SET_DESTROYED: kern_return_t = 38; 45 | pub const KERN_LOCK_UNSTABLE: kern_return_t = 39; 46 | pub const KERN_LOCK_OWNED: kern_return_t = 40; 47 | pub const KERN_LOCK_OWNED_SELF: kern_return_t = 41; 48 | pub const KERN_SEMAPHORE_DESTROYED: kern_return_t = 42; 49 | pub const KERN_RPC_SERVER_TERMINATED: kern_return_t = 43; 50 | pub const KERN_RPC_TERMINATE_ORPHAN: kern_return_t = 44; 51 | pub const KERN_RPC_CONTINUE_ORPHAN: kern_return_t = 45; 52 | pub const KERN_NOT_SUPPORTED: kern_return_t = 46; 53 | pub const KERN_NODE_DOWN: kern_return_t = 47; 54 | pub const KERN_NOT_WAITING: kern_return_t = 48; 55 | pub const KERN_OPERATION_TIMED_OUT: kern_return_t = 49; 56 | pub const KERN_CODESIGN_ERROR: kern_return_t = 50; 57 | pub const KERN_POLICY_STATIC: kern_return_t = 51; 58 | pub const KERN_RETURN_MAX: kern_return_t = 0x100; 59 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | #![allow(non_upper_case_globals)] 3 | #![deny(missing_debug_implementations)] 4 | #![deny(missing_copy_implementations)] 5 | #![cfg_attr(feature = "rustc-dep-of-std", feature(no_core))] 6 | #![cfg_attr(feature = "rustc-dep-of-std", no_core)] 7 | #![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)] 8 | #![allow( 9 | clippy::module_name_repetitions, 10 | clippy::cast_sign_loss, 11 | clippy::cast_possible_truncation, 12 | clippy::trivially_copy_pass_by_ref 13 | )] 14 | 15 | #[cfg(not(any(target_os = "macos", target_os = "ios")))] 16 | compile_error!("mach requires MacOSX or iOS"); 17 | 18 | #[cfg(feature = "rustc-dep-of-std")] 19 | extern crate rustc_std_workspace_core as core; 20 | 21 | extern crate libc; 22 | 23 | #[allow(unused_imports)] 24 | use core::{clone, cmp, default, fmt, hash, marker, mem, option}; 25 | 26 | pub mod boolean; 27 | pub mod bootstrap; 28 | pub mod clock; 29 | pub mod clock_priv; 30 | pub mod clock_reply; 31 | pub mod clock_types; // TODO: test 32 | pub mod dyld_kernel; 33 | // pub mod error; // TODO 34 | pub mod exc; 35 | pub mod exception_types; 36 | pub mod kern_return; 37 | pub mod mach_init; 38 | pub mod mach_port; 39 | pub mod mach_time; 40 | pub mod mach_types; 41 | pub mod memory_object_types; 42 | pub mod message; 43 | pub mod port; 44 | pub mod structs; 45 | pub mod task; 46 | pub mod task_info; 47 | pub mod thread_act; 48 | pub mod thread_status; 49 | pub mod traps; 50 | pub mod vm; 51 | pub mod vm_attributes; 52 | pub mod vm_behavior; 53 | pub mod vm_inherit; 54 | pub mod vm_page_size; 55 | pub mod vm_prot; 56 | pub mod vm_purgable; 57 | pub mod vm_region; 58 | pub mod vm_statistics; 59 | pub mod vm_sync; 60 | pub mod vm_types; 61 | -------------------------------------------------------------------------------- /src/mach_init.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/mach_init.h`. 2 | 3 | use mach_types::thread_port_t; 4 | 5 | extern "C" { 6 | pub fn mach_thread_self() -> thread_port_t; 7 | } 8 | 9 | #[cfg(test)] 10 | mod tests { 11 | use mach_init::*; 12 | use port::*; 13 | 14 | #[test] 15 | fn mach_thread_self_test() { 16 | unsafe { 17 | let this_thread = mach_thread_self(); 18 | assert!(this_thread != MACH_PORT_NULL); 19 | assert!(this_thread != MACH_PORT_DEAD); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/mach_port.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/mach_port.h` 2 | 3 | use kern_return::kern_return_t; 4 | use mach_types::ipc_space_t; 5 | use message::mach_msg_type_name_t; 6 | use port::{mach_port_name_t, mach_port_right_t, mach_port_t}; 7 | 8 | extern "C" { 9 | pub fn mach_port_allocate( 10 | task: ipc_space_t, 11 | right: mach_port_right_t, 12 | name: *mut mach_port_name_t, 13 | ) -> kern_return_t; 14 | pub fn mach_port_destroy(task: ipc_space_t, name: mach_port_name_t) -> kern_return_t; 15 | pub fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) -> kern_return_t; 16 | pub fn mach_port_insert_right( 17 | task: ipc_space_t, 18 | name: mach_port_name_t, 19 | poly: mach_port_t, 20 | polyPoly: mach_msg_type_name_t, 21 | ) -> kern_return_t; 22 | pub fn mach_port_extract_right( 23 | task: ipc_space_t, 24 | name: mach_port_name_t, 25 | msgt_name: mach_msg_type_name_t, 26 | poly: *mut mach_port_t, 27 | polyPoly: *mut mach_msg_type_name_t, 28 | ) -> kern_return_t; 29 | } 30 | -------------------------------------------------------------------------------- /src/mach_time.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/mach_time.h` 2 | use kern_return::kern_return_t; 3 | pub type mach_timebase_info_t = *mut mach_timebase_info; 4 | pub type mach_timebase_info_data_t = mach_timebase_info; 5 | 6 | #[repr(C)] 7 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 8 | pub struct mach_timebase_info { 9 | pub numer: u32, 10 | pub denom: u32, 11 | } 12 | 13 | extern "C" { 14 | pub fn mach_timebase_info(info: mach_timebase_info_t) -> kern_return_t; 15 | pub fn mach_wait_until(deadline: u64) -> kern_return_t; 16 | pub fn mach_absolute_time() -> u64; 17 | pub fn mach_approximate_time() -> u64; 18 | pub fn mach_continuous_time() -> u64; 19 | pub fn mach_continuous_approximate_time() -> u64; 20 | } 21 | -------------------------------------------------------------------------------- /src/mach_types.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/mach_types.h` 2 | 3 | use port::mach_port_t; 4 | 5 | pub type task_t = mach_port_t; 6 | pub type task_name_t = mach_port_t; 7 | pub type task_suspension_token_t = mach_port_t; 8 | pub type thread_t = mach_port_t; 9 | pub type thread_act_t = mach_port_t; 10 | pub type ipc_space_t = mach_port_t; 11 | pub type coalition_t = mach_port_t; 12 | pub type host_t = mach_port_t; 13 | pub type host_priv_t = mach_port_t; 14 | pub type host_security_t = mach_port_t; 15 | pub type processor_t = mach_port_t; 16 | pub type processor_set_t = mach_port_t; 17 | pub type processor_set_control_t = mach_port_t; 18 | pub type semaphore_t = mach_port_t; 19 | pub type lock_set_t = mach_port_t; 20 | pub type ledger_t = mach_port_t; 21 | pub type alarm_t = mach_port_t; 22 | pub type clock_serv_t = mach_port_t; 23 | pub type clock_ctrl_t = mach_port_t; 24 | 25 | pub type processor_set_name_t = processor_set_t; 26 | 27 | pub type clock_reply_t = mach_port_t; 28 | pub type bootstrap_t = mach_port_t; 29 | pub type mem_entry_name_port_t = mach_port_t; 30 | pub type exception_handler_t = mach_port_t; 31 | pub type exception_handler_array_t = *mut exception_handler_t; 32 | pub type vm_task_entry_t = mach_port_t; 33 | pub type io_master_t = mach_port_t; 34 | pub type UNDServerRef = mach_port_t; 35 | 36 | pub type task_array_t = *mut task_t; 37 | pub type thread_array_t = *mut thread_t; 38 | pub type processor_set_array_t = *mut processor_set_t; 39 | pub type processor_set_name_array_t = *mut processor_set_t; 40 | pub type processor_array_t = *mut processor_t; 41 | pub type thread_act_array_t = *mut thread_act_t; 42 | pub type ledger_array_t = *mut ledger_t; 43 | 44 | pub type task_port_t = task_t; 45 | pub type task_port_array_t = task_array_t; 46 | pub type thread_port_t = thread_t; 47 | pub type thread_port_array_t = thread_array_t; 48 | pub type ipc_space_port_t = ipc_space_t; 49 | pub type host_name_t = host_t; 50 | pub type host_name_port_t = host_t; 51 | pub type processor_set_port_t = processor_set_t; 52 | pub type processor_set_name_port_t = processor_set_t; 53 | pub type processor_set_name_port_array_t = processor_set_array_t; 54 | pub type processor_set_control_port_t = processor_set_t; 55 | pub type processor_port_t = processor_t; 56 | pub type processor_port_array_t = processor_array_t; 57 | pub type thread_act_port_t = thread_act_t; 58 | pub type thread_act_port_array_t = thread_act_array_t; 59 | pub type semaphore_port_t = semaphore_t; 60 | pub type lock_set_port_t = lock_set_t; 61 | pub type ledger_port_t = ledger_t; 62 | pub type ledger_port_array_t = ledger_array_t; 63 | pub type alarm_port_t = alarm_t; 64 | pub type clock_serv_port_t = clock_serv_t; 65 | pub type clock_ctrl_port_t = clock_ctrl_t; 66 | pub type exception_port_t = exception_handler_t; 67 | pub type exception_port_arrary_t = exception_handler_array_t; 68 | 69 | pub const TASK_NULL: task_t = 0; 70 | pub const TASK_NAME_NULL: task_name_t = 0; 71 | pub const THREAD_NULL: thread_t = 0; 72 | pub const TID_NULL: u64 = 0; 73 | pub const THR_ACT_NULL: thread_act_t = 0; 74 | pub const IPC_SPACE_NULL: ipc_space_t = 0; 75 | pub const COALITION_NULL: coalition_t = 0; 76 | pub const HOST_NULL: host_t = 0; 77 | pub const HOST_PRIV_NULL: host_priv_t = 0; 78 | pub const HOST_SECURITY_NULL: host_security_t = 0; 79 | pub const PROCESSOR_SET_NULL: processor_set_t = 0; 80 | pub const PROCESSOR_NULL: processor_t = 0; 81 | pub const SEMAPHORE_NULL: semaphore_t = 0; 82 | pub const LOCK_SET_NULL: lock_set_t = 0; 83 | pub const LEDGER_NULL: ledger_t = 0; 84 | pub const ALARM_NULL: alarm_t = 0; 85 | pub const CLOCK_NULL: ::libc::clock_t = 0; 86 | pub const UND_SERVER_NULL: UNDServerRef = 0; 87 | 88 | // : typedef unsigned char __darwin_uuid_t[16]; 89 | pub type uuid_t = [::libc::c_uchar; 16]; 90 | 91 | // 92 | #[repr(C)] 93 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 94 | pub struct fsid { 95 | pub val: [i32; 2], 96 | } 97 | pub type fsid_t = fsid; 98 | 99 | // 100 | #[repr(C)] 101 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 102 | pub struct fsobj_id { 103 | pub fid_objno: u32, 104 | pub fid_generation: u32, 105 | } 106 | pub type fsobj_id_t = fsobj_id; 107 | -------------------------------------------------------------------------------- /src/memory_object_types.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/memory_object_types.h`. 2 | 3 | use vm_types::natural_t; 4 | 5 | pub type memory_object_offset_t = ::libc::c_ulonglong; 6 | pub type memory_object_size_t = ::libc::c_ulonglong; 7 | pub type memory_object_cluster_size_t = natural_t; 8 | pub type memory_object_fault_info_t = *mut natural_t; 9 | pub type vm_object_id_t = ::libc::c_ulonglong; 10 | -------------------------------------------------------------------------------- /src/message.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/message.h`. 2 | 3 | use kern_return::kern_return_t; 4 | use port::{mach_port_name_t, mach_port_t}; 5 | use vm_types::{integer_t, natural_t}; 6 | 7 | pub type mach_msg_timeout_t = natural_t; 8 | 9 | pub type mach_msg_bits_t = ::libc::c_uint; 10 | pub type mach_msg_id_t = integer_t; 11 | pub type mach_msg_size_t = natural_t; 12 | 13 | pub type mach_msg_copy_options_t = ::libc::c_uint; 14 | pub type mach_msg_descriptor_type_t = ::libc::c_uint; 15 | pub type mach_msg_type_name_t = ::libc::c_uint; 16 | 17 | pub type mach_msg_trailer_type_t = ::libc::c_uint; 18 | pub type mach_msg_trailer_size_t = ::libc::c_uint; 19 | 20 | pub type mach_msg_option_t = integer_t; 21 | 22 | pub type mach_msg_type_number_t = natural_t; 23 | pub type mach_msg_type_size_t = natural_t; 24 | 25 | pub type mach_msg_return_t = kern_return_t; 26 | 27 | pub const MACH_MSG_TIMEOUT_NONE: mach_msg_timeout_t = 0; 28 | 29 | pub const MACH_MSGH_BITS_ZERO: mach_msg_bits_t = 0x0000_0000; 30 | 31 | pub const MACH_MSGH_BITS_REMOTE_MASK: mach_msg_bits_t = 0x0000_001f; 32 | pub const MACH_MSGH_BITS_LOCAL_MASK: mach_msg_bits_t = 0x0000_1f00; 33 | pub const MACH_MSGH_BITS_VOUCHER_MASK: mach_msg_bits_t = 0x001f_0000; 34 | 35 | pub const MACH_MSGH_BITS_PORTS_MASK: mach_msg_bits_t = 36 | MACH_MSGH_BITS_REMOTE_MASK | MACH_MSGH_BITS_LOCAL_MASK | MACH_MSGH_BITS_VOUCHER_MASK; 37 | 38 | pub const MACH_MSGH_BITS_COMPLEX: mach_msg_bits_t = 0x8000_0000; 39 | 40 | pub const MACH_MSGH_BITS_USER: mach_msg_bits_t = 0x801f_1f1f; 41 | 42 | #[allow(non_snake_case)] 43 | pub fn MACH_MSGH_BITS(remote: mach_msg_bits_t, local: mach_msg_bits_t) -> mach_msg_bits_t { 44 | remote | (local << 8) 45 | } 46 | 47 | pub const MACH_MSG_TYPE_MOVE_RECEIVE: mach_msg_type_name_t = 16; 48 | pub const MACH_MSG_TYPE_MOVE_SEND: mach_msg_type_name_t = 17; 49 | pub const MACH_MSG_TYPE_MOVE_SEND_ONCE: mach_msg_type_name_t = 18; 50 | pub const MACH_MSG_TYPE_COPY_SEND: mach_msg_type_name_t = 19; 51 | pub const MACH_MSG_TYPE_MAKE_SEND: mach_msg_type_name_t = 20; 52 | pub const MACH_MSG_TYPE_MAKE_SEND_ONCE: mach_msg_type_name_t = 21; 53 | pub const MACH_MSG_TYPE_COPY_RECEIVE: mach_msg_type_name_t = 22; 54 | pub const MACH_MSG_TYPE_DISPOSE_RECEIVE: mach_msg_type_name_t = 24; 55 | pub const MACH_MSG_TYPE_DISPOSE_SEND: mach_msg_type_name_t = 25; 56 | pub const MACH_MSG_TYPE_DISPOSE_SEND_ONCE: mach_msg_type_name_t = 26; 57 | 58 | pub const MACH_MSG_PHYSICAL_COPY: mach_msg_copy_options_t = 0; 59 | pub const MACH_MSG_VIRTUAL_COPY: mach_msg_copy_options_t = 1; 60 | pub const MACH_MSG_ALLOCATE: mach_msg_copy_options_t = 2; 61 | 62 | pub const MACH_MSG_PORT_DESCRIPTOR: mach_msg_descriptor_type_t = 0; 63 | pub const MACH_MSG_OOL_DESCRIPTOR: mach_msg_descriptor_type_t = 1; 64 | pub const MACH_MSG_OOL_PORTS_DESCRIPTOR: mach_msg_descriptor_type_t = 2; 65 | pub const MACH_MSG_OOL_VOLATILE_DESCRIPTOR: mach_msg_descriptor_type_t = 3; 66 | 67 | pub const MACH_MSG_OPTION_NONE: mach_msg_option_t = 0x0000_0000; 68 | 69 | pub const MACH_SEND_MSG: mach_msg_option_t = 0x0000_0001; 70 | pub const MACH_RCV_MSG: mach_msg_option_t = 0x0000_0002; 71 | 72 | pub const MACH_RCV_LARGE: mach_msg_option_t = 0x0000_0004; 73 | pub const MACH_RCV_LARGE_IDENTITY: mach_msg_option_t = 0x0000_0008; 74 | 75 | pub const MACH_SEND_TIMEOUT: mach_msg_option_t = 0x0000_0010; 76 | pub const MACH_SEND_INTERRUPT: mach_msg_option_t = 0x0000_0040; 77 | pub const MACH_SEND_NOTIFY: mach_msg_option_t = 0x0000_0080; 78 | pub const MACH_SEND_ALWAYS: mach_msg_option_t = 0x0001_0000; 79 | pub const MACH_SEND_TRAILER: mach_msg_option_t = 0x0002_0000; 80 | pub const MACH_SEND_NOIMPORTANCE: mach_msg_option_t = 0x0004_0000; 81 | pub const MACH_SEND_NODENAP: mach_msg_option_t = MACH_SEND_NOIMPORTANCE; 82 | pub const MACH_SEND_IMPORTANCE: mach_msg_option_t = 0x0008_0000; 83 | 84 | pub const MACH_RCV_TIMEOUT: mach_msg_option_t = 0x0000_0100; 85 | pub const MACH_RCV_NOTIFY: mach_msg_option_t = 0x0000_0200; 86 | pub const MACH_RCV_INTERRUPT: mach_msg_option_t = 0x0000_0400; 87 | pub const MACH_RCV_VOUCHER: mach_msg_option_t = 0x0000_0800; 88 | pub const MACH_RCV_OVERWRITE: mach_msg_option_t = 0x0000_1000; 89 | 90 | pub const MACH_MSG_SUCCESS: mach_msg_return_t = 0x0000_0000; 91 | 92 | pub const MACH_MSG_MASK: mach_msg_return_t = 0x0000_3e00; 93 | pub const MACH_MSG_IPC_SPACE: mach_msg_return_t = 0x0000_2000; 94 | pub const MACH_MSG_VM_SPACE: mach_msg_return_t = 0x0000_1000; 95 | pub const MACH_MSG_IPC_KERNEL: mach_msg_return_t = 0x0000_0800; 96 | pub const MACH_MSG_VM_KERNEL: mach_msg_return_t = 0x0000_0400; 97 | 98 | pub const MACH_SEND_IN_PROGRESS: mach_msg_return_t = 0x1000_0001; 99 | pub const MACH_SEND_INVALID_DATA: mach_msg_return_t = 0x1000_0002; 100 | pub const MACH_SEND_INVALID_DEST: mach_msg_return_t = 0x1000_0003; 101 | pub const MACH_SEND_TIMED_OUT: mach_msg_return_t = 0x1000_0004; 102 | pub const MACH_SEND_INVALID_VOUCHER: mach_msg_return_t = 0x1000_0005; 103 | pub const MACH_SEND_INTERRUPTED: mach_msg_return_t = 0x1000_0007; 104 | pub const MACH_SEND_MSG_TOO_SMALL: mach_msg_return_t = 0x1000_0008; 105 | pub const MACH_SEND_INVALID_REPLY: mach_msg_return_t = 0x1000_0009; 106 | pub const MACH_SEND_INVALID_RIGHT: mach_msg_return_t = 0x1000_000a; 107 | pub const MACH_SEND_INVALID_NOTIFY: mach_msg_return_t = 0x1000_000b; 108 | pub const MACH_SEND_INVALID_MEMORY: mach_msg_return_t = 0x1000_000c; 109 | pub const MACH_SEND_NO_BUFFER: mach_msg_return_t = 0x1000_000d; 110 | pub const MACH_SEND_TOO_LARGE: mach_msg_return_t = 0x1000_000e; 111 | pub const MACH_SEND_INVALID_TYPE: mach_msg_return_t = 0x1000_000f; 112 | pub const MACH_SEND_INVALID_HEADER: mach_msg_return_t = 0x1000_0010; 113 | pub const MACH_SEND_INVALID_TRAILER: mach_msg_return_t = 0x1000_0011; 114 | pub const MACH_SEND_INVALID_RT_OOL_SIZE: mach_msg_return_t = 0x1000_0015; 115 | 116 | pub const MACH_RCV_IN_PROGRESS: mach_msg_return_t = 0x1000_4001; 117 | pub const MACH_RCV_INVALID_NAME: mach_msg_return_t = 0x1000_4002; 118 | pub const MACH_RCV_TIMED_OUT: mach_msg_return_t = 0x1000_4003; 119 | pub const MACH_RCV_TOO_LARGE: mach_msg_return_t = 0x1000_4004; 120 | pub const MACH_RCV_INTERRUPTED: mach_msg_return_t = 0x1000_4005; 121 | pub const MACH_RCV_PORT_CHANGED: mach_msg_return_t = 0x1000_4006; 122 | pub const MACH_RCV_INVALID_NOTIFY: mach_msg_return_t = 0x1000_4007; 123 | pub const MACH_RCV_INVALID_DATA: mach_msg_return_t = 0x1000_4008; 124 | pub const MACH_RCV_PORT_DIED: mach_msg_return_t = 0x1000_4009; 125 | pub const MACH_RCV_IN_SET: mach_msg_return_t = 0x1000_400a; 126 | pub const MACH_RCV_HEADER_ERROR: mach_msg_return_t = 0x1000_400b; 127 | pub const MACH_RCV_BODY_ERROR: mach_msg_return_t = 0x1000_400c; 128 | pub const MACH_RCV_INVALID_TYPE: mach_msg_return_t = 0x1000_400d; 129 | pub const MACH_RCV_SCATTER_SMALL: mach_msg_return_t = 0x1000_400e; 130 | pub const MACH_RCV_INVALID_TRAILER: mach_msg_return_t = 0x1000_400f; 131 | pub const MACH_RCV_IN_PROGRESS_TIMED: mach_msg_return_t = 0x1000_4011; 132 | 133 | #[repr(C)] 134 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 135 | pub struct mach_msg_header_t { 136 | pub msgh_bits: mach_msg_bits_t, 137 | pub msgh_size: mach_msg_size_t, 138 | pub msgh_remote_port: mach_port_t, 139 | pub msgh_local_port: mach_port_t, 140 | pub msgh_voucher_port: mach_port_name_t, 141 | pub msgh_id: mach_msg_id_t, 142 | } 143 | 144 | #[repr(C)] 145 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 146 | pub struct mach_msg_body_t { 147 | pub msgh_descriptor_count: mach_msg_size_t, 148 | } 149 | 150 | #[repr(C)] 151 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 152 | pub struct mach_msg_base_t { 153 | pub header: mach_msg_header_t, 154 | pub body: mach_msg_body_t, 155 | } 156 | 157 | pub const MACH_MSG_TRAILER_FORMAT_0: mach_msg_trailer_type_t = 0; 158 | 159 | #[repr(C)] 160 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 161 | pub struct mach_msg_trailer_t { 162 | pub msgh_trailer_type: mach_msg_trailer_type_t, 163 | pub msgh_trailer_size: mach_msg_trailer_size_t, 164 | } 165 | 166 | #[repr(C)] 167 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 168 | pub struct mach_msg_port_descriptor_t { 169 | pub name: mach_port_t, 170 | pub pad1: mach_msg_size_t, 171 | pub pad2: u16, 172 | pub disposition: u8, // mach_msg_type_name_t bitfield 173 | pub type_: u8, // mach_msg_descriptor_type_t bitfield 174 | } 175 | 176 | impl mach_msg_port_descriptor_t { 177 | pub fn new(name: mach_port_t, disposition: mach_msg_type_name_t) -> Self { 178 | Self { 179 | name, 180 | pad1: 0, 181 | pad2: 0, 182 | disposition: disposition as u8, 183 | type_: MACH_MSG_PORT_DESCRIPTOR as u8, 184 | } 185 | } 186 | } 187 | 188 | #[repr(C)] 189 | #[derive(Copy, Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Ord)] 190 | pub struct mach_msg_ool_descriptor_t { 191 | pub address: *mut ::libc::c_void, 192 | #[cfg(not(target_pointer_width = "64"))] 193 | pub size: mach_msg_size_t, 194 | pub deallocate: u8, // boolean_t bitfield 195 | pub copy: u8, // mach_msg_copy_options_t bitfield 196 | pub pad1: u8, 197 | pub type_: u8, // mach_msg_descriptor_type_t bitfield 198 | #[cfg(target_pointer_width = "64")] 199 | pub size: mach_msg_size_t, 200 | } 201 | 202 | impl mach_msg_ool_descriptor_t { 203 | pub fn new( 204 | address: *mut ::libc::c_void, 205 | deallocate: bool, 206 | copy: mach_msg_copy_options_t, 207 | size: u32, 208 | ) -> Self { 209 | Self { 210 | address, 211 | deallocate: if deallocate { 1 } else { 0 }, 212 | copy: copy as u8, 213 | pad1: 0, 214 | type_: MACH_MSG_OOL_DESCRIPTOR as u8, 215 | size, 216 | } 217 | } 218 | } 219 | 220 | #[repr(C)] 221 | #[derive(Copy, Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Ord)] 222 | pub struct mach_msg_ool_ports_descriptor_t { 223 | pub address: *mut ::libc::c_void, 224 | #[cfg(not(target_pointer_width = "64"))] 225 | pub count: mach_msg_size_t, 226 | pub deallocate: u8, // boolean_t bitfield 227 | pub copy: u8, // mach_msg_copy_options_t bitfield 228 | pub disposition: u8, // mach_msg_type_name_t bitfield 229 | pub type_: u8, // mach_msg_descriptor_type_t bitfield 230 | #[cfg(target_pointer_width = "64")] 231 | pub count: mach_msg_size_t, 232 | } 233 | 234 | extern "C" { 235 | pub fn mach_msg( 236 | msg: *mut mach_msg_header_t, 237 | option: mach_msg_option_t, 238 | send_size: mach_msg_size_t, 239 | recv_size: mach_msg_size_t, 240 | recv_name: mach_port_name_t, 241 | timeout: mach_msg_timeout_t, 242 | notify: mach_port_name_t, 243 | ) -> mach_msg_return_t; 244 | 245 | // from mach/mach.h 246 | pub fn mach_msg_send(msg: *mut mach_msg_header_t) -> mach_msg_return_t; 247 | pub fn mach_msg_destroy(msg: *mut mach_msg_header_t); 248 | } 249 | -------------------------------------------------------------------------------- /src/port.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/port.h` 2 | 3 | use vm_types::natural_t; 4 | 5 | pub type mach_port_name_t = natural_t; 6 | 7 | #[repr(C)] 8 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 9 | pub struct ipc_port; 10 | 11 | pub type ipc_port_t = *mut ipc_port; 12 | 13 | pub type mach_port_t = ::libc::c_uint; 14 | 15 | pub const MACH_PORT_NULL: mach_port_t = 0; 16 | pub const MACH_PORT_DEAD: mach_port_t = !0; 17 | 18 | pub type mach_port_right_t = natural_t; 19 | 20 | pub const MACH_PORT_RIGHT_SEND: mach_port_right_t = 0; 21 | pub const MACH_PORT_RIGHT_RECEIVE: mach_port_right_t = 1; 22 | pub const MACH_PORT_RIGHT_SEND_ONCE: mach_port_right_t = 2; 23 | pub const MACH_PORT_RIGHT_PORT_SET: mach_port_right_t = 3; 24 | pub const MACH_PORT_RIGHT_DEAD_NAME: mach_port_right_t = 4; 25 | pub const MACH_PORT_RIGHT_LABELH: mach_port_right_t = 5; 26 | pub const MACH_PORT_RIGHT_NUMBER: mach_port_right_t = 6; 27 | -------------------------------------------------------------------------------- /src/structs.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/_structs.h`. 2 | 3 | use mem; 4 | use message::mach_msg_type_number_t; 5 | 6 | #[repr(C)] 7 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 8 | pub struct x86_thread_state64_t { 9 | pub __rax: u64, 10 | pub __rbx: u64, 11 | pub __rcx: u64, 12 | pub __rdx: u64, 13 | pub __rdi: u64, 14 | pub __rsi: u64, 15 | pub __rbp: u64, 16 | pub __rsp: u64, 17 | pub __r8: u64, 18 | pub __r9: u64, 19 | pub __r10: u64, 20 | pub __r11: u64, 21 | pub __r12: u64, 22 | pub __r13: u64, 23 | pub __r14: u64, 24 | pub __r15: u64, 25 | pub __rip: u64, 26 | pub __rflags: u64, 27 | pub __cs: u64, 28 | pub __fs: u64, 29 | pub __gs: u64, 30 | } 31 | 32 | impl x86_thread_state64_t { 33 | pub fn new() -> Self { 34 | Self { 35 | __rax: 0, 36 | __rbx: 0, 37 | __rcx: 0, 38 | __rdx: 0, 39 | __rdi: 0, 40 | __rsi: 0, 41 | __rbp: 0, 42 | __rsp: 0, 43 | __r8: 0, 44 | __r9: 0, 45 | __r10: 0, 46 | __r11: 0, 47 | __r12: 0, 48 | __r13: 0, 49 | __r14: 0, 50 | __r15: 0, 51 | __rip: 0, 52 | __rflags: 0, 53 | __cs: 0, 54 | __fs: 0, 55 | __gs: 0, 56 | } 57 | } 58 | 59 | pub fn count() -> mach_msg_type_number_t { 60 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/task.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/task.defs`. 2 | 3 | use kern_return::kern_return_t; 4 | use mach_types::{task_name_t, task_t, thread_act_array_t}; 5 | use message::mach_msg_type_number_t; 6 | use port::mach_port_t; 7 | use task_info::{task_flavor_t, task_info_t}; 8 | 9 | pub type task_special_port_t = ::libc::c_int; 10 | 11 | pub const TASK_KERNEL_PORT: task_special_port_t = 1; 12 | pub const TASK_HOST_PORT: task_special_port_t = 2; 13 | pub const TASK_NAME_PORT: task_special_port_t = 3; 14 | pub const TASK_BOOTSTRAP_PORT: task_special_port_t = 4; 15 | 16 | extern "C" { 17 | pub fn task_resume(target_task: task_t) -> kern_return_t; 18 | pub fn task_suspend(target_task: task_t) -> kern_return_t; 19 | pub fn task_get_special_port( 20 | task: task_t, 21 | which_port: task_special_port_t, 22 | special_port: *mut mach_port_t, 23 | ) -> kern_return_t; 24 | pub fn task_threads( 25 | target_task: task_t, 26 | act_list: *mut thread_act_array_t, 27 | act_list_cnt: *mut mach_msg_type_number_t, 28 | ) -> kern_return_t; 29 | pub fn task_info( 30 | target_task: task_name_t, 31 | flavor: task_flavor_t, 32 | task_info_out: task_info_t, 33 | task_info_outCnt: *mut mach_msg_type_number_t, 34 | ) -> kern_return_t; 35 | pub fn task_set_info( 36 | target_task: task_t, 37 | flavor: task_flavor_t, 38 | task_info_in: task_info_t, 39 | task_info_inCnt: mach_msg_type_number_t, 40 | ) -> kern_return_t; 41 | } 42 | -------------------------------------------------------------------------------- /src/task_info.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/task_info.h`. 2 | 3 | use vm_types::{integer_t, mach_vm_address_t, mach_vm_size_t, natural_t}; 4 | 5 | pub const TASK_INFO_MAX: ::libc::c_uint = 1024; 6 | pub const TASK_BASIC_INFO_32: ::libc::c_uint = 4; 7 | pub const TASK_BASIC2_INFO_32: ::libc::c_uint = 6; 8 | pub const TASK_BASIC_INFO_64: ::libc::c_uint = 5; 9 | #[cfg(target_arch = "x86_64")] 10 | pub const TASK_BASIC_INFO: ::libc::c_uint = 5; 11 | #[cfg(target_arch = "x86")] 12 | pub const TASK_BASIC_INFO: ::libc::c_uint = 4; 13 | pub const TASK_EVENTS_INFO: ::libc::c_uint = 2; 14 | pub const TASK_THREAD_TIMES_INFO: ::libc::c_uint = 3; 15 | pub const TASK_ABSOLUTETIME_INFO: ::libc::c_uint = 1; 16 | pub const TASK_KERNELMEMORY_INFO: ::libc::c_uint = 7; 17 | pub const TASK_SECURITY_TOKEN: ::libc::c_uint = 13; 18 | pub const TASK_AUDIT_TOKEN: ::libc::c_uint = 15; 19 | pub const TASK_AFFINITY_TAG_INFO: ::libc::c_uint = 16; 20 | pub const TASK_DYLD_INFO: ::libc::c_uint = 17; 21 | pub const TASK_DYLD_ALL_IMAGE_INFO_32: ::libc::c_uint = 0; 22 | pub const TASK_DYLD_ALL_IMAGE_INFO_64: ::libc::c_uint = 1; 23 | pub const TASK_EXTMOD_INFO: ::libc::c_uint = 19; 24 | pub const MACH_TASK_BASIC_INFO: ::libc::c_uint = 20; 25 | pub const TASK_POWER_INFO: ::libc::c_uint = 21; 26 | pub const TASK_VM_INFO: ::libc::c_uint = 22; 27 | pub const TASK_VM_INFO_PURGEABLE: ::libc::c_uint = 23; 28 | pub const TASK_TRACE_MEMORY_INFO: ::libc::c_uint = 24; 29 | pub const TASK_WAIT_STATE_INFO: ::libc::c_uint = 25; 30 | pub const TASK_POWER_INFO_V2: ::libc::c_uint = 26; 31 | pub const TASK_VM_INFO_PURGEABLE_ACCOUNT: ::libc::c_uint = 27; 32 | pub const TASK_FLAGS_INFO: ::libc::c_uint = 28; 33 | pub const TASK_DEBUG_INFO_INTERNAL: ::libc::c_uint = 29; 34 | 35 | pub type task_flavor_t = natural_t; 36 | pub type task_info_t = *mut integer_t; 37 | 38 | #[repr(C, packed(4))] 39 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 40 | pub struct task_dyld_info { 41 | pub all_image_info_addr: mach_vm_address_t, 42 | pub all_image_info_size: mach_vm_size_t, 43 | pub all_image_info_format: integer_t, 44 | } 45 | -------------------------------------------------------------------------------- /src/thread_act.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/thread_act.defs`. 2 | 3 | use kern_return::kern_return_t; 4 | use mach_types::thread_act_t; 5 | use message::mach_msg_type_number_t; 6 | use thread_status::{thread_state_flavor_t, thread_state_t}; 7 | 8 | extern "C" { 9 | pub fn thread_get_state( 10 | target_act: thread_act_t, 11 | flavor: thread_state_flavor_t, 12 | new_state: thread_state_t, 13 | new_state_count: *mut mach_msg_type_number_t, 14 | ) -> kern_return_t; 15 | } 16 | 17 | extern "C" { 18 | pub fn thread_suspend(target_act: thread_act_t) -> kern_return_t; 19 | } 20 | 21 | extern "C" { 22 | pub fn thread_resume(target_act: thread_act_t) -> kern_return_t; 23 | } 24 | -------------------------------------------------------------------------------- /src/thread_status.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/thread_status.h`. 2 | 3 | use vm_types::natural_t; 4 | 5 | pub type thread_state_t = *mut natural_t; 6 | pub type thread_state_flavor_t = ::libc::c_int; 7 | 8 | pub static x86_THREAD_STATE32: thread_state_flavor_t = 1; 9 | pub static x86_FLOAT_STATE32: thread_state_flavor_t = 2; 10 | pub static x86_EXCEPTION_STATE32: thread_state_flavor_t = 3; 11 | pub static x86_THREAD_STATE64: thread_state_flavor_t = 4; 12 | pub static x86_FLOAT_STATE64: thread_state_flavor_t = 5; 13 | pub static x86_EXCEPTION_STATE64: thread_state_flavor_t = 6; 14 | pub static x86_THREAD_STATE: thread_state_flavor_t = 7; 15 | pub static x86_FLOAT_STATE: thread_state_flavor_t = 8; 16 | pub static x86_EXCEPTION_STATE: thread_state_flavor_t = 9; 17 | pub static x86_DEBUG_STATE32: thread_state_flavor_t = 10; 18 | pub static x86_DEBUG_STATE64: thread_state_flavor_t = 11; 19 | pub static x86_DEBUG_STATE: thread_state_flavor_t = 12; 20 | pub static THREAD_STATE_NONE: thread_state_flavor_t = 13; 21 | pub static x86_AVX_STATE32: thread_state_flavor_t = 16; 22 | pub static x86_AVX_STATE64: thread_state_flavor_t = 17; 23 | pub static x86_AVX_STATE: thread_state_flavor_t = 18; 24 | -------------------------------------------------------------------------------- /src/traps.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/mach_traps.h`. 2 | use kern_return::kern_return_t; 3 | use port::{mach_port_name_t, mach_port_t}; 4 | 5 | extern "C" { 6 | static mach_task_self_: mach_port_t; 7 | pub fn task_for_pid( 8 | target_tport: mach_port_name_t, 9 | pid: ::libc::c_int, 10 | tn: *mut mach_port_name_t, 11 | ) -> kern_return_t; 12 | } 13 | 14 | pub unsafe fn mach_task_self() -> mach_port_t { 15 | mach_task_self_ 16 | } 17 | 18 | pub unsafe fn current_task() -> mach_port_t { 19 | mach_task_self() 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests { 24 | use port::*; 25 | use traps::*; 26 | 27 | #[test] 28 | fn mach_task_self_sanity() { 29 | unsafe { 30 | let this_task = mach_task_self(); 31 | assert!(this_task != MACH_PORT_NULL); 32 | assert!(this_task != MACH_PORT_DEAD); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/vm.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/mach_vm.defs`. 2 | 3 | use boolean::boolean_t; 4 | use kern_return::kern_return_t; 5 | use mach_types::{mem_entry_name_port_t, vm_task_entry_t}; 6 | use memory_object_types::{memory_object_offset_t, memory_object_size_t}; 7 | use message::mach_msg_type_number_t; 8 | use port::mach_port_t; 9 | use vm_attributes::{vm_machine_attribute_t, vm_machine_attribute_val_t}; 10 | use vm_behavior::vm_behavior_t; 11 | use vm_inherit::vm_inherit_t; 12 | use vm_prot::vm_prot_t; 13 | use vm_purgable::vm_purgable_t; 14 | use vm_region::mach_vm_read_entry_t; 15 | use vm_region::{ 16 | vm_page_info_flavor_t, vm_page_info_t, vm_region_flavor_t, vm_region_info_t, 17 | vm_region_recurse_info_t, 18 | }; 19 | use vm_sync::vm_sync_t; 20 | use vm_types::{ 21 | integer_t, mach_vm_address_t, mach_vm_offset_t, mach_vm_size_t, natural_t, vm_map_t, 22 | vm_offset_t, vm_size_t, 23 | }; 24 | 25 | extern "C" { 26 | pub fn mach_vm_allocate( 27 | target: vm_task_entry_t, 28 | address: *mut mach_vm_address_t, 29 | size: mach_vm_size_t, 30 | flags: ::libc::c_int, 31 | ) -> kern_return_t; 32 | 33 | pub fn mach_vm_deallocate( 34 | target: vm_task_entry_t, 35 | address: mach_vm_address_t, 36 | size: mach_vm_size_t, 37 | ) -> kern_return_t; 38 | 39 | pub fn mach_vm_protect( 40 | target_task: vm_task_entry_t, 41 | address: mach_vm_address_t, 42 | size: mach_vm_size_t, 43 | set_maximum: boolean_t, 44 | new_protection: vm_prot_t, 45 | ) -> kern_return_t; 46 | 47 | pub fn mach_vm_inherit( 48 | target_task: vm_task_entry_t, 49 | address: mach_vm_address_t, 50 | size: mach_vm_size_t, 51 | new_inheritance: vm_inherit_t, 52 | ) -> kern_return_t; 53 | 54 | pub fn mach_vm_read( 55 | target_task: vm_task_entry_t, 56 | address: mach_vm_address_t, 57 | size: mach_vm_size_t, 58 | data: *mut vm_offset_t, 59 | dataCnt: *mut mach_msg_type_number_t, 60 | ) -> kern_return_t; 61 | 62 | pub fn mach_vm_read_list( 63 | target_task: vm_task_entry_t, 64 | data_list: mach_vm_read_entry_t, 65 | count: natural_t, 66 | ) -> kern_return_t; 67 | 68 | pub fn mach_vm_write( 69 | target_task: vm_map_t, 70 | address: mach_vm_address_t, 71 | data: vm_offset_t, 72 | dataCnt: mach_msg_type_number_t, 73 | ) -> kern_return_t; 74 | 75 | pub fn mach_vm_copy( 76 | target_task: vm_task_entry_t, 77 | source_address: mach_vm_address_t, 78 | size: mach_vm_size_t, 79 | dest_address: mach_vm_address_t, 80 | ) -> kern_return_t; 81 | 82 | pub fn mach_vm_read_overwrite( 83 | target_task: vm_task_entry_t, 84 | address: mach_vm_address_t, 85 | size: mach_vm_size_t, 86 | data: mach_vm_address_t, 87 | outsize: *mut mach_vm_size_t, 88 | ) -> kern_return_t; 89 | 90 | pub fn mach_vm_msync( 91 | target_task: vm_task_entry_t, 92 | address: mach_vm_address_t, 93 | size: mach_vm_size_t, 94 | sync_flags: vm_sync_t, 95 | ) -> kern_return_t; 96 | 97 | pub fn mach_vm_behavior_set( 98 | target_task: vm_task_entry_t, 99 | address: mach_vm_address_t, 100 | size: mach_vm_size_t, 101 | new_behavior: vm_behavior_t, 102 | ) -> kern_return_t; 103 | 104 | pub fn mach_vm_map( 105 | target_task: vm_task_entry_t, 106 | inout: *mut mach_vm_address_t, 107 | size: mach_vm_size_t, 108 | mask: mach_vm_offset_t, 109 | flags: ::libc::c_int, 110 | object: mem_entry_name_port_t, 111 | offset: memory_object_offset_t, 112 | copy: boolean_t, 113 | cur_protection: vm_prot_t, 114 | max_protection: vm_prot_t, 115 | inheritance: vm_inherit_t, 116 | ) -> kern_return_t; 117 | 118 | pub fn mach_vm_machine_attribute( 119 | target_task: vm_task_entry_t, 120 | address: mach_vm_address_t, 121 | size: mach_vm_size_t, 122 | attribute: vm_machine_attribute_t, 123 | value: *mut vm_machine_attribute_val_t, 124 | ) -> kern_return_t; 125 | 126 | pub fn mach_vm_remap( 127 | target_task: vm_task_entry_t, 128 | target_address: *mut mach_vm_address_t, 129 | size: mach_vm_size_t, 130 | mask: mach_vm_offset_t, 131 | flags: ::libc::c_int, 132 | src_task: vm_task_entry_t, 133 | src_address: mach_vm_address_t, 134 | copy: boolean_t, 135 | cur_protection: *mut vm_prot_t, 136 | out: *mut vm_prot_t, 137 | inheritance: vm_inherit_t, 138 | ) -> kern_return_t; 139 | 140 | pub fn mach_vm_page_query( 141 | target_map: vm_map_t, 142 | offset: mach_vm_offset_t, 143 | disposition: *mut integer_t, 144 | ref_count: *mut integer_t, 145 | ) -> kern_return_t; 146 | 147 | pub fn mach_vm_region_recurse( 148 | target_task: vm_task_entry_t, 149 | address: *mut mach_vm_address_t, 150 | size: *mut mach_vm_size_t, 151 | nesting_depth: *mut natural_t, 152 | info: vm_region_recurse_info_t, 153 | infoCnt: *mut mach_msg_type_number_t, 154 | ) -> kern_return_t; 155 | 156 | pub fn mach_vm_region( 157 | target_task: vm_task_entry_t, 158 | address: *mut mach_vm_address_t, 159 | size: *mut mach_vm_size_t, 160 | flavor: vm_region_flavor_t, 161 | info: vm_region_info_t, 162 | infoCnt: *mut mach_msg_type_number_t, 163 | object_name: *mut mach_port_t, 164 | ) -> kern_return_t; 165 | 166 | pub fn mach_make_memory_entry( 167 | target_task: vm_map_t, 168 | size: *mut vm_size_t, 169 | offset: vm_offset_t, 170 | permission: vm_prot_t, 171 | object_handle: *mut mem_entry_name_port_t, 172 | parent_handle: mem_entry_name_port_t, 173 | ) -> kern_return_t; 174 | 175 | pub fn mach_make_memory_entry_64( 176 | target_task: vm_map_t, 177 | size: *mut memory_object_size_t, 178 | offset: memory_object_offset_t, 179 | permission: vm_prot_t, 180 | object_handle: *mut mach_port_t, 181 | parent_entry: mem_entry_name_port_t, 182 | ) -> kern_return_t; 183 | 184 | pub fn mach_vm_purgable_control( 185 | target_task: vm_task_entry_t, 186 | address: mach_vm_address_t, 187 | control: vm_purgable_t, 188 | state: *mut ::libc::c_int, 189 | ) -> kern_return_t; 190 | 191 | pub fn mach_vm_page_info( 192 | target_task: vm_task_entry_t, 193 | address: mach_vm_address_t, 194 | flavor: vm_page_info_flavor_t, 195 | info: vm_page_info_t, 196 | infoCnt: *mut mach_msg_type_number_t, 197 | ) -> kern_return_t; 198 | } 199 | 200 | #[cfg(test)] 201 | mod tests { 202 | use super::*; 203 | use kern_return::KERN_SUCCESS; 204 | use traps::mach_task_self; 205 | use vm_statistics::VM_FLAGS_ANYWHERE; 206 | 207 | #[test] 208 | fn mach_vm_allocate_sanity() { 209 | unsafe { 210 | let size = 0x100; 211 | let task = mach_task_self(); 212 | 213 | let mut address: mach_vm_address_t = 0; 214 | assert_eq!( 215 | mach_vm_allocate(task, &mut address, size, VM_FLAGS_ANYWHERE), 216 | KERN_SUCCESS 217 | ); 218 | assert_eq!(mach_vm_deallocate(task, address, size), KERN_SUCCESS); 219 | } 220 | } 221 | 222 | #[test] 223 | fn mach_vm_region_sanity() { 224 | use mem; 225 | use vm_prot::{VM_PROT_EXECUTE, VM_PROT_READ}; 226 | use vm_region::{vm_region_basic_info_64, VM_REGION_BASIC_INFO_64}; 227 | unsafe { 228 | let mut size = 0x10; 229 | let mut object_name = 0; 230 | let mut address = mach_vm_region_sanity as mach_vm_address_t; 231 | let mut info: vm_region_basic_info_64 = mem::zeroed(); 232 | let mut info_size = vm_region_basic_info_64::count(); 233 | 234 | let result = mach_vm_region( 235 | mach_task_self(), 236 | &mut address, 237 | &mut size, 238 | VM_REGION_BASIC_INFO_64, 239 | (&mut info as *mut _) as vm_region_info_t, 240 | &mut info_size, 241 | &mut object_name, 242 | ); 243 | assert_eq!(result, KERN_SUCCESS); 244 | assert_eq!(info.protection, VM_PROT_READ | VM_PROT_EXECUTE); 245 | } 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /src/vm_attributes.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/vm_attributes.h`. 2 | 3 | pub type vm_machine_attribute_t = ::libc::c_uint; 4 | 5 | pub const MATTR_CACHE: vm_machine_attribute_t = 1; 6 | pub const MATTR_MIGRATE: vm_machine_attribute_t = (1 << 1); 7 | pub const MATTR_REPLICATE: vm_machine_attribute_t = (1 << 2); 8 | 9 | pub type vm_machine_attribute_val_t = ::libc::c_int; 10 | 11 | pub const MATTR_VAL_OFF: vm_machine_attribute_val_t = 0; 12 | pub const MATTR_VAL_ON: vm_machine_attribute_val_t = 1; 13 | pub const MATTR_VAL_GET: vm_machine_attribute_val_t = 2; 14 | pub const MATTR_VAL_CACHE_FLUSH: vm_machine_attribute_val_t = 6; 15 | pub const MATTR_VAL_DCACHE_FLUSH: vm_machine_attribute_val_t = 7; 16 | pub const MATTR_VAL_ICACHE_FLUSH: vm_machine_attribute_val_t = 8; 17 | pub const MATTR_VAL_CACHE_SYNC: vm_machine_attribute_val_t = 9; 18 | pub const MATTR_VAL_GET_INFO: vm_machine_attribute_val_t = 10; 19 | -------------------------------------------------------------------------------- /src/vm_behavior.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/vm_behavior.h`. 2 | 3 | pub type vm_behavior_t = ::libc::c_int; 4 | 5 | pub const VM_BEHAVIOR_DEFAULT: vm_behavior_t = 0; 6 | pub const VM_BEHAVIOR_RANDOM: vm_behavior_t = 1; 7 | pub const VM_BEHAVIOR_SEQUENTIAL: vm_behavior_t = 2; 8 | pub const VM_BEHAVIOR_RSEQNTL: vm_behavior_t = 3; 9 | pub const VM_BEHAVIOR_WILLNEED: vm_behavior_t = 4; 10 | pub const VM_BEHAVIOR_DONTNEED: vm_behavior_t = 5; 11 | pub const VM_BEHAVIOR_FREE: vm_behavior_t = 6; 12 | pub const VM_BEHAVIOR_ZERO_WIRED_PAGES: vm_behavior_t = 7; 13 | pub const VM_BEHAVIOR_REUSABLE: vm_behavior_t = 8; 14 | pub const VM_BEHAVIOR_REUSE: vm_behavior_t = 9; 15 | pub const VM_BEHAVIOR_CAN_REUSE: vm_behavior_t = 10; 16 | -------------------------------------------------------------------------------- /src/vm_inherit.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/vm_inherit.h`. 2 | 3 | pub type vm_inherit_t = ::libc::c_uint; 4 | 5 | pub const VM_INHERIT_SHARE: vm_inherit_t = 0; 6 | pub const VM_INHERIT_COPY: vm_inherit_t = 1; 7 | pub const VM_INHERIT_NONE: vm_inherit_t = 2; 8 | pub const VM_INHERIT_DONATE_COPY: vm_inherit_t = 3; 9 | pub const VM_INHERIT_DEFAULT: vm_inherit_t = VM_INHERIT_COPY; 10 | pub const VM_INHERIT_LAST_VALID: vm_inherit_t = VM_INHERIT_NONE; 11 | -------------------------------------------------------------------------------- /src/vm_page_size.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/vm_page_size.h` 2 | 3 | use vm_types::{mach_vm_offset_t, mach_vm_size_t, vm_size_t}; 4 | 5 | extern "C" { 6 | pub static vm_page_size: vm_size_t; 7 | pub static vm_page_mask: vm_size_t; 8 | pub static vm_page_shift: ::libc::c_int; 9 | } 10 | 11 | pub unsafe fn mach_vm_trunc_page(x: mach_vm_offset_t) -> mach_vm_offset_t { 12 | (x & !(vm_page_mask as mach_vm_size_t)) 13 | } 14 | 15 | pub unsafe fn mach_vm_round_page(x: mach_vm_offset_t) -> mach_vm_offset_t { 16 | ((x + vm_page_mask as mach_vm_size_t) & !(vm_page_mask as mach_vm_size_t)) 17 | } 18 | 19 | #[cfg(test)] 20 | mod tests { 21 | use vm_page_size::*; 22 | use vm_types::mach_vm_size_t; 23 | 24 | #[test] 25 | fn page_size() { 26 | unsafe { 27 | assert!(vm_page_size > 0); 28 | assert!(vm_page_size % 2 == 0); 29 | assert_eq!(mach_vm_round_page(1), vm_page_size as mach_vm_size_t); 30 | assert_eq!(vm_page_size, 4096); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/vm_prot.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/vm_prot.h`. 2 | 3 | pub type vm_prot_t = ::libc::c_int; 4 | 5 | pub const VM_PROT_NONE: vm_prot_t = 0; 6 | pub const VM_PROT_READ: vm_prot_t = 1; 7 | pub const VM_PROT_WRITE: vm_prot_t = (1 << 1); 8 | pub const VM_PROT_EXECUTE: vm_prot_t = (1 << 2); 9 | pub const VM_PROT_NO_CHANGE: vm_prot_t = (1 << 3); 10 | pub const VM_PROT_COPY: vm_prot_t = (1 << 4); 11 | pub const VM_PROT_WANTS_COPY: vm_prot_t = (1 << 4); 12 | pub const VM_PROT_TRUSTED: vm_prot_t = (1 << 5); 13 | pub const VM_PROT_DEFAULT: vm_prot_t = VM_PROT_READ | VM_PROT_WRITE; 14 | pub const VM_PROT_ALL: vm_prot_t = VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE; 15 | -------------------------------------------------------------------------------- /src/vm_purgable.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/vm_purgable.h`. 2 | 3 | pub type vm_purgable_t = ::libc::c_int; 4 | 5 | pub const VM_PURGABLE_SET_STATE: vm_purgable_t = 0; 6 | pub const VM_PURGABLE_GET_STATE: vm_purgable_t = 1; 7 | 8 | pub const VM_VOLATILE_GROUP_SHIFT: ::libc::c_int = 8; 9 | pub const VM_VOLATILE_GROUP_MASK: ::libc::c_int = (7 << VM_VOLATILE_GROUP_SHIFT); 10 | pub const VM_VOLATILE_GROUP_DEFAULT: ::libc::c_int = VM_VOLATILE_GROUP_0; 11 | 12 | pub const VM_VOLATILE_GROUP_0: ::libc::c_int = (0 << VM_VOLATILE_GROUP_SHIFT); 13 | pub const VM_VOLATILE_GROUP_1: ::libc::c_int = (1 << VM_VOLATILE_GROUP_SHIFT); 14 | pub const VM_VOLATILE_GROUP_2: ::libc::c_int = (2 << VM_VOLATILE_GROUP_SHIFT); 15 | pub const VM_VOLATILE_GROUP_3: ::libc::c_int = (3 << VM_VOLATILE_GROUP_SHIFT); 16 | pub const VM_VOLATILE_GROUP_4: ::libc::c_int = (4 << VM_VOLATILE_GROUP_SHIFT); 17 | pub const VM_VOLATILE_GROUP_5: ::libc::c_int = (5 << VM_VOLATILE_GROUP_SHIFT); 18 | pub const VM_VOLATILE_GROUP_6: ::libc::c_int = (6 << VM_VOLATILE_GROUP_SHIFT); 19 | pub const VM_VOLATILE_GROUP_7: ::libc::c_int = (7 << VM_VOLATILE_GROUP_SHIFT); 20 | 21 | pub const VM_PURGABLE_BEHAVIOR_SHIFT: ::libc::c_int = 6; 22 | pub const VM_PURGABLE_BEHAVIOR_MASK: ::libc::c_int = (1 << VM_PURGABLE_BEHAVIOR_SHIFT); 23 | pub const VM_PURGABLE_BEHAVIOR_FIFO: ::libc::c_int = (0 << VM_PURGABLE_BEHAVIOR_SHIFT); 24 | pub const VM_PURGABLE_BEHAVIOR_LIFO: ::libc::c_int = (1 << VM_PURGABLE_BEHAVIOR_SHIFT); 25 | 26 | pub const VM_PURGABLE_ORDERING_SHIFT: ::libc::c_int = 5; 27 | pub const VM_PURGABLE_ORDERING_MASK: ::libc::c_int = (1 << VM_PURGABLE_ORDERING_SHIFT); 28 | pub const VM_PURGABLE_ORDERING_OBSOLETE: ::libc::c_int = (1 << VM_PURGABLE_ORDERING_SHIFT); 29 | pub const VM_PURGABLE_ORDERING_NORMAL: ::libc::c_int = (0 << VM_PURGABLE_ORDERING_SHIFT); 30 | 31 | pub const VM_VOLATILE_ORDER_SHIFT: ::libc::c_int = 4; 32 | pub const VM_VOLATILE_ORDER_MASK: ::libc::c_int = (1 << VM_VOLATILE_ORDER_SHIFT); 33 | pub const VM_VOLATILE_MAKE_FIRST_IN_GROUP: ::libc::c_int = (1 << VM_VOLATILE_ORDER_SHIFT); 34 | pub const VM_VOLATILE_MAKE_LAST_IN_GROUP: ::libc::c_int = (0 << VM_VOLATILE_ORDER_SHIFT); 35 | 36 | pub const VM_PURGABLE_STATE_MIN: ::libc::c_int = 0; 37 | pub const VM_PURGABLE_STATE_MAX: ::libc::c_int = 3; 38 | pub const VM_PURGABLE_STATE_MASK: ::libc::c_int = 3; 39 | pub const VM_PURGABLE_NONVOLATILE: ::libc::c_int = 0; 40 | pub const VM_PURGABLE_VOLATILE: ::libc::c_int = 1; 41 | pub const VM_PURGABLE_EMPTY: ::libc::c_int = 2; 42 | pub const VM_PURGABLE_DENY: ::libc::c_int = 3; 43 | -------------------------------------------------------------------------------- /src/vm_region.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/vm_region.h`. 2 | 3 | use boolean::boolean_t; 4 | use mem; 5 | use memory_object_types::{memory_object_offset_t, vm_object_id_t}; 6 | use message::mach_msg_type_number_t; 7 | use vm_behavior::vm_behavior_t; 8 | use vm_inherit::vm_inherit_t; 9 | use vm_prot::vm_prot_t; 10 | use vm_types::{mach_vm_address_t, mach_vm_size_t}; 11 | 12 | pub type vm32_object_id_t = u32; 13 | 14 | pub type vm_region_info_t = *mut ::libc::c_int; 15 | pub type vm_region_info_64_t = *mut ::libc::c_int; 16 | pub type vm_region_recurse_info_t = *mut ::libc::c_int; 17 | pub type vm_region_recurse_info_64_t = *mut ::libc::c_int; 18 | pub type vm_region_flavor_t = ::libc::c_int; 19 | pub type vm_region_info_data_t = [::libc::c_int; VM_REGION_INFO_MAX as usize]; 20 | 21 | pub type vm_region_basic_info_64_t = *mut vm_region_basic_info_64; 22 | pub type vm_region_basic_info_data_64_t = vm_region_basic_info_64; 23 | pub type vm_region_basic_info_t = *mut vm_region_basic_info; 24 | pub type vm_region_basic_info_data_t = vm_region_basic_info; 25 | pub type vm_region_extended_info_t = *mut vm_region_extended_info; 26 | pub type vm_region_extended_info_data_t = vm_region_extended_info; 27 | pub type vm_region_top_info_t = *mut vm_region_top_info; 28 | pub type vm_region_top_info_data_t = vm_region_top_info; 29 | pub type vm_region_submap_info_t = *mut vm_region_submap_info; 30 | pub type vm_region_submap_info_data_t = vm_region_submap_info; 31 | pub type vm_region_submap_info_64_t = *mut vm_region_submap_info_64; 32 | pub type vm_region_submap_info_data_64_t = vm_region_submap_info_64; 33 | pub type vm_region_submap_short_info_64_t = *mut vm_region_submap_short_info_64; 34 | pub type vm_region_submap_short_info_data_64_t = vm_region_submap_short_info_64; 35 | pub type vm_page_info_t = *mut ::libc::c_int; 36 | pub type vm_page_info_flavor_t = ::libc::c_int; 37 | pub type vm_page_info_basic_t = *mut vm_page_info_basic; 38 | pub type vm_page_info_basic_data_t = vm_page_info_basic; 39 | pub type mach_vm_read_entry_t = [mach_vm_read_entry; VM_MAP_ENTRY_MAX as usize]; 40 | 41 | pub const VM_REGION_INFO_MAX: ::libc::c_int = (1 << 10); 42 | pub const VM_MAP_ENTRY_MAX: ::libc::c_int = (1 << 8); 43 | 44 | pub const VM_PAGE_INFO_BASIC: vm_page_info_flavor_t = 1; 45 | 46 | pub const VM_REGION_BASIC_INFO_64: vm_region_flavor_t = 9; 47 | pub const VM_REGION_BASIC_INFO: vm_region_flavor_t = 10; 48 | pub const VM_REGION_EXTENDED_INFO: vm_region_flavor_t = 13; 49 | pub const VM_REGION_TOP_INFO: vm_region_flavor_t = 12; 50 | 51 | pub const SM_COW: ::libc::c_uchar = 1; 52 | pub const SM_PRIVATE: ::libc::c_uchar = 2; 53 | pub const SM_EMPTY: ::libc::c_uchar = 3; 54 | pub const SM_SHARED: ::libc::c_uchar = 4; 55 | pub const SM_TRUESHARED: ::libc::c_uchar = 5; 56 | pub const SM_PRIVATE_ALIASED: ::libc::c_uchar = 6; 57 | pub const SM_SHARED_ALIASED: ::libc::c_uchar = 7; 58 | 59 | #[repr(C, packed(4))] 60 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 61 | pub struct vm_region_basic_info_64 { 62 | pub protection: vm_prot_t, 63 | pub max_protection: vm_prot_t, 64 | pub inheritance: vm_inherit_t, 65 | pub shared: boolean_t, 66 | pub reserved: boolean_t, 67 | pub offset: memory_object_offset_t, 68 | pub behavior: vm_behavior_t, 69 | pub user_wired_count: ::libc::c_ushort, 70 | } 71 | 72 | impl vm_region_basic_info_64 { 73 | pub fn count() -> mach_msg_type_number_t { 74 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 75 | } 76 | } 77 | 78 | #[repr(C)] 79 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 80 | pub struct vm_region_basic_info { 81 | pub protection: vm_prot_t, 82 | pub max_protection: vm_prot_t, 83 | pub inheritance: vm_inherit_t, 84 | pub shared: boolean_t, 85 | pub reserved: boolean_t, 86 | pub offset: u32, 87 | pub behavior: vm_behavior_t, 88 | pub user_wired_count: ::libc::c_ushort, 89 | } 90 | 91 | impl vm_region_basic_info { 92 | pub fn count() -> mach_msg_type_number_t { 93 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 94 | } 95 | } 96 | 97 | #[repr(C)] 98 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 99 | pub struct vm_region_extended_info { 100 | pub protection: vm_prot_t, 101 | pub user_tag: ::libc::c_uint, 102 | pub pages_resident: ::libc::c_uint, 103 | pub pages_shared_now_private: ::libc::c_uint, 104 | pub pages_swapped_out: ::libc::c_uint, 105 | pub pages_dirtied: ::libc::c_uint, 106 | pub ref_count: ::libc::c_uint, 107 | pub shadow_depth: ::libc::c_ushort, 108 | pub external_pager: ::libc::c_uchar, 109 | pub share_mode: ::libc::c_uchar, 110 | pub pages_reusable: ::libc::c_uint, 111 | } 112 | 113 | impl vm_region_extended_info { 114 | pub fn count() -> mach_msg_type_number_t { 115 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 116 | } 117 | } 118 | 119 | #[repr(C)] 120 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 121 | pub struct vm_region_top_info { 122 | pub obj_id: ::libc::c_uint, 123 | pub ref_count: ::libc::c_uint, 124 | pub private_pages_resident: ::libc::c_uint, 125 | pub shared_pages_resident: ::libc::c_uint, 126 | pub share_mode: ::libc::c_uchar, 127 | } 128 | 129 | impl vm_region_top_info { 130 | pub fn count() -> mach_msg_type_number_t { 131 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 132 | } 133 | } 134 | 135 | #[repr(C)] 136 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 137 | pub struct vm_region_submap_info { 138 | pub protection: vm_prot_t, 139 | pub max_protection: vm_prot_t, 140 | pub inheritance: vm_inherit_t, 141 | pub offset: u32, 142 | pub user_tag: ::libc::c_uint, 143 | pub pages_resident: ::libc::c_uint, 144 | pub pages_shared_now_private: ::libc::c_uint, 145 | pub pages_swapped_out: ::libc::c_uint, 146 | pub pages_dirtied: ::libc::c_uint, 147 | pub ref_count: ::libc::c_uint, 148 | pub shadow_depth: ::libc::c_ushort, 149 | pub external_pager: ::libc::c_uchar, 150 | pub share_mode: ::libc::c_uchar, 151 | pub is_submap: boolean_t, 152 | pub behavior: vm_behavior_t, 153 | pub object_id: vm32_object_id_t, 154 | pub user_wired_count: ::libc::c_ushort, 155 | } 156 | 157 | impl vm_region_submap_info { 158 | pub fn count() -> mach_msg_type_number_t { 159 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 160 | } 161 | } 162 | 163 | #[repr(C, packed(4))] 164 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 165 | pub struct vm_region_submap_info_64 { 166 | pub protection: vm_prot_t, 167 | pub max_protection: vm_prot_t, 168 | pub inheritance: vm_inherit_t, 169 | pub offset: memory_object_offset_t, 170 | pub user_tag: ::libc::c_uint, 171 | pub pages_resident: ::libc::c_uint, 172 | pub pages_shared_now_private: ::libc::c_uint, 173 | pub pages_swapped_out: ::libc::c_uint, 174 | pub pages_dirtied: ::libc::c_uint, 175 | pub ref_count: ::libc::c_uint, 176 | pub shadow_depth: ::libc::c_ushort, 177 | pub external_pager: ::libc::c_uchar, 178 | pub share_mode: ::libc::c_uchar, 179 | pub is_submap: boolean_t, 180 | pub behavior: vm_behavior_t, 181 | pub object_id: vm32_object_id_t, 182 | pub user_wired_count: ::libc::c_ushort, 183 | pub pages_reusable: ::libc::c_uint, 184 | } 185 | 186 | impl vm_region_submap_info_64 { 187 | pub fn count() -> mach_msg_type_number_t { 188 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 189 | } 190 | } 191 | 192 | #[repr(C, packed(4))] 193 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 194 | pub struct vm_region_submap_short_info_64 { 195 | pub protection: vm_prot_t, 196 | pub max_protection: vm_prot_t, 197 | pub inheritance: vm_inherit_t, 198 | pub offset: memory_object_offset_t, 199 | pub user_tag: ::libc::c_uint, 200 | pub ref_count: ::libc::c_uint, 201 | pub shadow_depth: ::libc::c_ushort, 202 | pub external_pager: ::libc::c_uchar, 203 | pub share_mode: ::libc::c_uchar, 204 | pub is_submap: boolean_t, 205 | pub behavior: vm_behavior_t, 206 | pub object_id: vm32_object_id_t, 207 | pub user_wired_count: ::libc::c_ushort, 208 | } 209 | 210 | impl vm_region_submap_short_info_64 { 211 | pub fn count() -> mach_msg_type_number_t { 212 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 213 | } 214 | } 215 | 216 | #[repr(C)] 217 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 218 | pub struct vm_page_info_basic { 219 | pub disposition: ::libc::c_int, 220 | pub ref_count: ::libc::c_int, 221 | pub object_id: vm_object_id_t, 222 | pub offset: memory_object_offset_t, 223 | pub depth: ::libc::c_int, 224 | pub __pad: ::libc::c_int, 225 | } 226 | 227 | impl vm_page_info_basic { 228 | pub fn count() -> mach_msg_type_number_t { 229 | (mem::size_of::() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t 230 | } 231 | } 232 | 233 | #[repr(C, packed(4))] 234 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 235 | pub struct mach_vm_read_entry { 236 | pub address: mach_vm_address_t, 237 | pub size: mach_vm_size_t, 238 | } 239 | -------------------------------------------------------------------------------- /src/vm_statistics.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/vm_statistics.h` 2 | 3 | use vm_types::{integer_t, natural_t}; 4 | 5 | pub type vm_statistics_t = *mut vm_statistics; 6 | pub type vm_statistics_data_t = vm_statistics; 7 | #[cfg(feature = "deprecated")] 8 | #[deprecated( 9 | since = "0.2.3", 10 | note = "`pmap_statistics_t` was removed after MacOSX 10.3.9" 11 | )] 12 | #[allow(deprecated)] 13 | pub type pmap_statistics_t = *mut pmap_statistics; 14 | 15 | pub const VM_PAGE_QUERY_PAGE_PRESENT: integer_t = 1; 16 | pub const VM_PAGE_QUERY_PAGE_FICTITIOUS: integer_t = (1 << 1); 17 | pub const VM_PAGE_QUERY_PAGE_REF: integer_t = (1 << 2); 18 | pub const VM_PAGE_QUERY_PAGE_DIRTY: integer_t = (1 << 3); 19 | 20 | pub const VM_MEMORY_MALLOC: ::libc::c_uint = 1; 21 | pub const VM_MEMORY_MALLOC_SMALL: ::libc::c_uint = 2; 22 | pub const VM_MEMORY_MALLOC_LARGE: ::libc::c_uint = 3; 23 | pub const VM_MEMORY_MALLOC_HUGE: ::libc::c_uint = 4; 24 | pub const VM_MEMORY_SBRK: ::libc::c_uint = 5; 25 | pub const VM_MEMORY_ANALYSIS_TOOL: ::libc::c_uint = 10; 26 | pub const VM_MEMORY_MACH_MSG: ::libc::c_uint = 20; 27 | pub const VM_MEMORY_IOKIT: ::libc::c_uint = 21; 28 | pub const VM_MEMORY_STACK: ::libc::c_uint = 30; 29 | pub const VM_MEMORY_GUARD: ::libc::c_uint = 31; 30 | pub const VM_MEMORY_SHARED_PMAP: ::libc::c_uint = 32; 31 | pub const VM_MEMORY_DYLIB: ::libc::c_uint = 33; 32 | pub const VM_MEMORY_APPKIT: ::libc::c_uint = 40; 33 | pub const VM_MEMORY_FOUNDATION: ::libc::c_uint = 41; 34 | pub const VM_MEMORY_COREGRAPHICS: ::libc::c_uint = 42; 35 | pub const VM_MEMORY_CARBON: ::libc::c_uint = 43; 36 | pub const VM_MEMORY_JAVA: ::libc::c_uint = 44; 37 | pub const VM_MEMORY_ATS: ::libc::c_uint = 50; 38 | pub const VM_MEMORY_DYLD: ::libc::c_uint = 60; 39 | pub const VM_MEMORY_DYLD_MALLOC: ::libc::c_uint = 61; 40 | pub const VM_MEMORY_APPLICATION_SPECIFIC_1: ::libc::c_uint = 240; 41 | pub const VM_MEMORY_APPLICATION_SPECIFIC_16: ::libc::c_uint = 255; 42 | 43 | pub const VM_FLAGS_FIXED: ::libc::c_int = 0x0; 44 | pub const VM_FLAGS_ANYWHERE: ::libc::c_int = 0x1; 45 | pub const VM_FLAGS_OVERWRITE: ::libc::c_int = 0x4000; 46 | 47 | #[repr(C)] 48 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 49 | pub struct vm_statistics { 50 | pub free_count: natural_t, 51 | pub active_count: natural_t, 52 | pub inactive_count: natural_t, 53 | pub wire_count: natural_t, 54 | pub zero_fill_count: natural_t, 55 | pub reactivations: natural_t, 56 | pub pageins: natural_t, 57 | pub pageouts: natural_t, 58 | pub faults: natural_t, 59 | pub cow_faults: natural_t, 60 | pub lookups: natural_t, 61 | pub hits: natural_t, 62 | pub purgeable_count: natural_t, 63 | pub purges: natural_t, 64 | pub speculative_count: natural_t, 65 | } 66 | 67 | #[cfg(feature = "deprecated")] 68 | #[deprecated( 69 | since = "0.2.3", 70 | note = "`pmap_statistics` was removed after MacOSX 10.3.9" 71 | )] 72 | #[cfg_attr(feature = "deprecated", allow(deprecated))] 73 | #[repr(C)] 74 | #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] 75 | pub struct pmap_statistics { 76 | pub resident_count: integer_t, 77 | pub wired_count: integer_t, 78 | } 79 | -------------------------------------------------------------------------------- /src/vm_sync.rs: -------------------------------------------------------------------------------- 1 | //! This module corresponds to `mach/vm_sync.h`. 2 | 3 | pub type vm_sync_t = ::libc::c_uint; 4 | 5 | pub const VM_SYNC_ASYNCHRONOUS: vm_sync_t = 1; 6 | pub const VM_SYNC_SYNCHRONOUS: vm_sync_t = (1 << 1); 7 | pub const VM_SYNC_INVALIDATE: vm_sync_t = (1 << 2); 8 | pub const VM_SYNC_KILLPAGES: vm_sync_t = (1 << 3); 9 | pub const VM_SYNC_DEACTIVATE: vm_sync_t = (1 << 4); 10 | pub const VM_SYNC_CONTIGUOUS: vm_sync_t = (1 << 5); 11 | pub const VM_SYNC_REUSABLEPAGES: vm_sync_t = (1 << 6); 12 | -------------------------------------------------------------------------------- /src/vm_types.rs: -------------------------------------------------------------------------------- 1 | //! This module roughly corresponds to `mach/i386/vm_types.h`. 2 | 3 | pub type natural_t = ::libc::c_uint; 4 | pub type integer_t = ::libc::c_int; 5 | 6 | pub type user_addr_t = u64; 7 | 8 | pub type mach_vm_address_t = u64; 9 | pub type mach_vm_offset_t = u64; 10 | pub type mach_vm_size_t = u64; 11 | pub type vm_map_offset_t = u64; 12 | pub type vm_map_address_t = u64; 13 | pub type vm_map_size_t = u64; 14 | pub type vm_map_t = ::port::mach_port_t; 15 | pub type vm_offset_t = ::libc::uintptr_t; 16 | pub type vm_size_t = ::libc::uintptr_t; 17 | pub type vm_address_t = vm_offset_t; 18 | 19 | pub type mach_port_context_t = mach_vm_address_t; 20 | --------------------------------------------------------------------------------