├── .cargo └── config ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE.txt ├── LICENSE-MIT.txt ├── README.md ├── backlight ├── Cargo.toml └── src │ ├── args.rs │ └── main.rs ├── backlight_lib ├── Cargo.toml └── src │ ├── lib.rs │ ├── resolved_function.rs │ └── syscall.rs └── test_support ├── Cargo.toml ├── README.md └── src └── bin ├── test_support_abs.rs └── test_support_exit.rs /.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | install-backlight = "install --force --path backlight --bin backlight --" 3 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Build 13 | run: cargo build 14 | - name: Clippy 15 | run: cargo clippy --all-targets --all-features -- -D warnings 16 | - name: Format 17 | run: cargo fmt --all -- --check 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "atty" 7 | version = "0.2.14" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 10 | dependencies = [ 11 | "hermit-abi", 12 | "libc", 13 | "winapi", 14 | ] 15 | 16 | [[package]] 17 | name = "autocfg" 18 | version = "1.0.1" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 21 | 22 | [[package]] 23 | name = "backlight" 24 | version = "0.1.0" 25 | dependencies = [ 26 | "backlight_lib", 27 | "clap", 28 | "expect-test", 29 | ] 30 | 31 | [[package]] 32 | name = "backlight_lib" 33 | version = "0.1.0" 34 | dependencies = [ 35 | "goblin", 36 | "nix", 37 | "procfs", 38 | ] 39 | 40 | [[package]] 41 | name = "bitflags" 42 | version = "1.3.2" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 45 | 46 | [[package]] 47 | name = "byteorder" 48 | version = "1.4.3" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 51 | 52 | [[package]] 53 | name = "cc" 54 | version = "1.0.72" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" 57 | 58 | [[package]] 59 | name = "cfg-if" 60 | version = "1.0.0" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 63 | 64 | [[package]] 65 | name = "clap" 66 | version = "3.0.10" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375" 69 | dependencies = [ 70 | "atty", 71 | "bitflags", 72 | "clap_derive", 73 | "indexmap", 74 | "lazy_static", 75 | "os_str_bytes", 76 | "strsim", 77 | "termcolor", 78 | "textwrap", 79 | ] 80 | 81 | [[package]] 82 | name = "clap_derive" 83 | version = "3.0.6" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153" 86 | dependencies = [ 87 | "heck", 88 | "proc-macro-error", 89 | "proc-macro2", 90 | "quote", 91 | "syn", 92 | ] 93 | 94 | [[package]] 95 | name = "dissimilar" 96 | version = "1.0.3" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "31ad93652f40969dead8d4bf897a41e9462095152eb21c56e5830537e41179dd" 99 | 100 | [[package]] 101 | name = "expect-test" 102 | version = "1.2.2" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "7e3e6b28dccda91d8742195c71fbda412112c0c77febf56bf3d895d68b19db16" 105 | dependencies = [ 106 | "dissimilar", 107 | "once_cell", 108 | ] 109 | 110 | [[package]] 111 | name = "goblin" 112 | version = "0.4.3" 113 | source = "registry+https://github.com/rust-lang/crates.io-index" 114 | checksum = "32401e89c6446dcd28185931a01b1093726d0356820ac744023e6850689bf926" 115 | dependencies = [ 116 | "log", 117 | "plain", 118 | "scroll", 119 | ] 120 | 121 | [[package]] 122 | name = "hashbrown" 123 | version = "0.11.2" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" 126 | 127 | [[package]] 128 | name = "heck" 129 | version = "0.4.0" 130 | source = "registry+https://github.com/rust-lang/crates.io-index" 131 | checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" 132 | 133 | [[package]] 134 | name = "hermit-abi" 135 | version = "0.1.19" 136 | source = "registry+https://github.com/rust-lang/crates.io-index" 137 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 138 | dependencies = [ 139 | "libc", 140 | ] 141 | 142 | [[package]] 143 | name = "hex" 144 | version = "0.4.3" 145 | source = "registry+https://github.com/rust-lang/crates.io-index" 146 | checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" 147 | 148 | [[package]] 149 | name = "indexmap" 150 | version = "1.8.0" 151 | source = "registry+https://github.com/rust-lang/crates.io-index" 152 | checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" 153 | dependencies = [ 154 | "autocfg", 155 | "hashbrown", 156 | ] 157 | 158 | [[package]] 159 | name = "lazy_static" 160 | version = "1.4.0" 161 | source = "registry+https://github.com/rust-lang/crates.io-index" 162 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 163 | 164 | [[package]] 165 | name = "libc" 166 | version = "0.2.112" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" 169 | 170 | [[package]] 171 | name = "log" 172 | version = "0.4.14" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 175 | dependencies = [ 176 | "cfg-if", 177 | ] 178 | 179 | [[package]] 180 | name = "memchr" 181 | version = "2.4.1" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" 184 | 185 | [[package]] 186 | name = "memoffset" 187 | version = "0.6.5" 188 | source = "registry+https://github.com/rust-lang/crates.io-index" 189 | checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" 190 | dependencies = [ 191 | "autocfg", 192 | ] 193 | 194 | [[package]] 195 | name = "nix" 196 | version = "0.23.1" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" 199 | dependencies = [ 200 | "bitflags", 201 | "cc", 202 | "cfg-if", 203 | "libc", 204 | "memoffset", 205 | ] 206 | 207 | [[package]] 208 | name = "once_cell" 209 | version = "1.9.0" 210 | source = "registry+https://github.com/rust-lang/crates.io-index" 211 | checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" 212 | 213 | [[package]] 214 | name = "os_str_bytes" 215 | version = "6.0.0" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" 218 | dependencies = [ 219 | "memchr", 220 | ] 221 | 222 | [[package]] 223 | name = "plain" 224 | version = "0.2.3" 225 | source = "registry+https://github.com/rust-lang/crates.io-index" 226 | checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" 227 | 228 | [[package]] 229 | name = "proc-macro-error" 230 | version = "1.0.4" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 233 | dependencies = [ 234 | "proc-macro-error-attr", 235 | "proc-macro2", 236 | "quote", 237 | "syn", 238 | "version_check", 239 | ] 240 | 241 | [[package]] 242 | name = "proc-macro-error-attr" 243 | version = "1.0.4" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 246 | dependencies = [ 247 | "proc-macro2", 248 | "quote", 249 | "version_check", 250 | ] 251 | 252 | [[package]] 253 | name = "proc-macro2" 254 | version = "1.0.36" 255 | source = "registry+https://github.com/rust-lang/crates.io-index" 256 | checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" 257 | dependencies = [ 258 | "unicode-xid", 259 | ] 260 | 261 | [[package]] 262 | name = "procfs" 263 | version = "0.12.0" 264 | source = "registry+https://github.com/rust-lang/crates.io-index" 265 | checksum = "0941606b9934e2d98a3677759a971756eb821f75764d0e0d26946d08e74d9104" 266 | dependencies = [ 267 | "bitflags", 268 | "byteorder", 269 | "hex", 270 | "lazy_static", 271 | "libc", 272 | ] 273 | 274 | [[package]] 275 | name = "quote" 276 | version = "1.0.14" 277 | source = "registry+https://github.com/rust-lang/crates.io-index" 278 | checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" 279 | dependencies = [ 280 | "proc-macro2", 281 | ] 282 | 283 | [[package]] 284 | name = "scroll" 285 | version = "0.10.2" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "fda28d4b4830b807a8b43f7b0e6b5df875311b3e7621d84577188c175b6ec1ec" 288 | dependencies = [ 289 | "scroll_derive", 290 | ] 291 | 292 | [[package]] 293 | name = "scroll_derive" 294 | version = "0.10.5" 295 | source = "registry+https://github.com/rust-lang/crates.io-index" 296 | checksum = "aaaae8f38bb311444cfb7f1979af0bc9240d95795f75f9ceddf6a59b79ceffa0" 297 | dependencies = [ 298 | "proc-macro2", 299 | "quote", 300 | "syn", 301 | ] 302 | 303 | [[package]] 304 | name = "strsim" 305 | version = "0.10.0" 306 | source = "registry+https://github.com/rust-lang/crates.io-index" 307 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 308 | 309 | [[package]] 310 | name = "syn" 311 | version = "1.0.85" 312 | source = "registry+https://github.com/rust-lang/crates.io-index" 313 | checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" 314 | dependencies = [ 315 | "proc-macro2", 316 | "quote", 317 | "unicode-xid", 318 | ] 319 | 320 | [[package]] 321 | name = "termcolor" 322 | version = "1.1.2" 323 | source = "registry+https://github.com/rust-lang/crates.io-index" 324 | checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" 325 | dependencies = [ 326 | "winapi-util", 327 | ] 328 | 329 | [[package]] 330 | name = "test_support" 331 | version = "0.1.0" 332 | 333 | [[package]] 334 | name = "textwrap" 335 | version = "0.14.2" 336 | source = "registry+https://github.com/rust-lang/crates.io-index" 337 | checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" 338 | 339 | [[package]] 340 | name = "unicode-xid" 341 | version = "0.2.2" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 344 | 345 | [[package]] 346 | name = "version_check" 347 | version = "0.9.4" 348 | source = "registry+https://github.com/rust-lang/crates.io-index" 349 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 350 | 351 | [[package]] 352 | name = "winapi" 353 | version = "0.3.9" 354 | source = "registry+https://github.com/rust-lang/crates.io-index" 355 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 356 | dependencies = [ 357 | "winapi-i686-pc-windows-gnu", 358 | "winapi-x86_64-pc-windows-gnu", 359 | ] 360 | 361 | [[package]] 362 | name = "winapi-i686-pc-windows-gnu" 363 | version = "0.4.0" 364 | source = "registry+https://github.com/rust-lang/crates.io-index" 365 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 366 | 367 | [[package]] 368 | name = "winapi-util" 369 | version = "0.1.5" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 372 | dependencies = [ 373 | "winapi", 374 | ] 375 | 376 | [[package]] 377 | name = "winapi-x86_64-pc-windows-gnu" 378 | version = "0.4.0" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 381 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | 3 | members = [ 4 | "backlight", 5 | "backlight_lib", 6 | "test_support", 7 | ] 8 | -------------------------------------------------------------------------------- /LICENSE-APACHE.txt: -------------------------------------------------------------------------------- 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 2022 Josh Mcguigan 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-MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Josh Mcguigan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Backlight 2 | 3 | Backlight is a dynamic binary tracing tool. 4 | 5 | ## Install 6 | 7 | ```sh 8 | $ git clone git@github.com:JoshMcguigan/backlight.git 9 | 10 | $ cd backlight 11 | 12 | $ cargo install-backlight 13 | ``` 14 | 15 | ## Usage 16 | 17 | ```sh 18 | # Trace all system calls, shared library function calls, etc 19 | $ backlight /bin/ls 20 | ... 21 | [lib] malloc 22 | [sys] sys_brk 23 | [sys] sys_brk 24 | [lib] free 25 | [sys] sys_openat 26 | [sys] sys_newfstatat 27 | [sys] sys_mmap 28 | [sys] sys_close 29 | [lib] malloc 30 | ... 31 | --- Child process exited --- 32 | 33 | # Trace specific system calls 34 | $ backlight -s sys_openat -s sys_close /bin/ls 35 | 36 | # Trace specific shared library function calls 37 | $ backlight -l malloc -l free /bin/ls 38 | 39 | # Add args after `--` and backlight will pass them along to the tracee 40 | $ backlight /bin/ls -- -a 41 | 42 | # Trace specific system calls and all shared library function calls 43 | $ backlight -s sys_openat --all-library-functions /bin/ls 44 | 45 | # Trace specific shared library function calls and all system calls 46 | $ backlight -l malloc --all-syscalls /bin/ls 47 | ``` 48 | 49 | I'm looking for feedback on the UX of backlight. Stop by [#3](https://github.com/JoshMcguigan/backlight/issues/3) and share your opinions! 50 | 51 | ## License 52 | 53 | Licensed under either of 54 | 55 | * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) 56 | * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. 57 | 58 | ### Contribution 59 | 60 | Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. 61 | -------------------------------------------------------------------------------- /backlight/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "backlight" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | backlight_lib = { path = "../backlight_lib" } 8 | clap = { version = "3", features = ["derive"] } 9 | 10 | [dev-dependencies] 11 | expect-test = "1" 12 | -------------------------------------------------------------------------------- /backlight/src/args.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | 3 | #[derive(clap::Parser)] 4 | #[clap(setting(clap::AppSettings::TrailingVarArg))] 5 | pub struct Args { 6 | pub binary_to_trace: PathBuf, 7 | #[clap(short = 'l')] 8 | pub library_functions_to_trace: Vec, 9 | #[clap(long = "all-library-functions")] 10 | pub trace_all_library_functions: bool, 11 | #[clap(short = 's')] 12 | pub syscalls_to_trace: Vec, 13 | #[clap(long = "all-syscalls")] 14 | pub trace_all_syscalls: bool, 15 | pub tracee_args: Vec, 16 | } 17 | 18 | /// Expresses the users request to trace a given trace-able thing. 19 | pub enum TraceRequest { 20 | All, 21 | /// Names of the syscall/function the user would like to trace. 22 | /// 23 | /// This can be empty, in which case we will not trace any of this thing. 24 | These(Vec), 25 | NoSpecificRequest, 26 | } 27 | 28 | impl Args { 29 | pub fn syscall_trace_request(&self) -> TraceRequest { 30 | if self.trace_all_syscalls { 31 | TraceRequest::All 32 | } else if !self.syscalls_to_trace.is_empty() { 33 | TraceRequest::These(self.syscalls_to_trace.clone()) 34 | } else { 35 | TraceRequest::NoSpecificRequest 36 | } 37 | } 38 | pub fn library_function_trace_request(&self) -> TraceRequest { 39 | if self.trace_all_library_functions { 40 | TraceRequest::All 41 | } else if !self.library_functions_to_trace.is_empty() { 42 | TraceRequest::These(self.library_functions_to_trace.clone()) 43 | } else { 44 | TraceRequest::NoSpecificRequest 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /backlight/src/main.rs: -------------------------------------------------------------------------------- 1 | use backlight_lib::{find_undefined_symbols, Result, Tracee, TraceeState}; 2 | use clap::Parser; 3 | 4 | mod args; 5 | use args::{Args, TraceRequest}; 6 | 7 | enum SyscallsToTrace { 8 | All, 9 | /// Names of the syscalls the user would like to trace. 10 | /// 11 | /// This can be empty, in which case we will not trace any syscalls. 12 | These(Vec), 13 | } 14 | 15 | fn main() -> Result<()> { 16 | let args = Args::parse(); 17 | 18 | let library_function_trace_request = args.library_function_trace_request(); 19 | let syscall_trace_request = args.syscall_trace_request(); 20 | 21 | let Args { 22 | binary_to_trace, 23 | tracee_args, 24 | .. 25 | } = args; 26 | 27 | let (library_functions_to_trace, syscalls_to_trace) = 28 | match (library_function_trace_request, syscall_trace_request) { 29 | (TraceRequest::All, TraceRequest::All) => ( 30 | find_undefined_symbols(&binary_to_trace)?, 31 | SyscallsToTrace::All, 32 | ), 33 | (TraceRequest::All, TraceRequest::These(syscalls_to_trace)) => ( 34 | find_undefined_symbols(&binary_to_trace)?, 35 | SyscallsToTrace::These(syscalls_to_trace), 36 | ), 37 | (TraceRequest::All, TraceRequest::NoSpecificRequest) => ( 38 | find_undefined_symbols(&binary_to_trace)?, 39 | SyscallsToTrace::These(vec![]), 40 | ), 41 | (TraceRequest::These(functions_to_trace), TraceRequest::All) => { 42 | (functions_to_trace, SyscallsToTrace::All) 43 | } 44 | (TraceRequest::These(functions_to_trace), TraceRequest::These(syscalls_to_trace)) => ( 45 | functions_to_trace, 46 | SyscallsToTrace::These(syscalls_to_trace), 47 | ), 48 | (TraceRequest::These(functions_to_trace), TraceRequest::NoSpecificRequest) => { 49 | (functions_to_trace, SyscallsToTrace::These(vec![])) 50 | } 51 | (TraceRequest::NoSpecificRequest, TraceRequest::All) => (vec![], SyscallsToTrace::All), 52 | (TraceRequest::NoSpecificRequest, TraceRequest::These(syscalls_to_trace)) => { 53 | (vec![], SyscallsToTrace::These(syscalls_to_trace)) 54 | } 55 | // If the user doesn't specify what they want to trace we trace everything. 56 | (TraceRequest::NoSpecificRequest, TraceRequest::NoSpecificRequest) => ( 57 | find_undefined_symbols(&binary_to_trace)?, 58 | SyscallsToTrace::All, 59 | ), 60 | }; 61 | 62 | let mut tracee = Tracee::init(&binary_to_trace, &tracee_args, library_functions_to_trace)?; 63 | 64 | loop { 65 | tracee = match tracee.step()? { 66 | TraceeState::Alive(t) => t, 67 | TraceeState::StoppedAtSystemCallEntrance(t, syscall_name) => { 68 | // We break at all system calls, so before logging that we hit 69 | // one we first check if we want to trace this particular system 70 | // call. 71 | let should_trace = match syscalls_to_trace { 72 | SyscallsToTrace::All => true, 73 | SyscallsToTrace::These(ref syscalls_to_trace) => { 74 | syscalls_to_trace.contains(&syscall_name) 75 | } 76 | }; 77 | if should_trace { 78 | println!("[sys] {}", syscall_name); 79 | } 80 | 81 | t 82 | } 83 | TraceeState::StoppedAtSystemCallExit(t) => t, 84 | TraceeState::StoppedAtFunctionEntrace(t, func_name) => { 85 | // Unlike system calls above, we only break at functions which 86 | // we have explicitly asked for, so we always want to log here. 87 | println!("[lib] {}", func_name); 88 | 89 | t 90 | } 91 | TraceeState::Exited(code) => { 92 | println!("--- Child process exited with status code {} ---", code); 93 | return Ok(()); 94 | } 95 | } 96 | } 97 | } 98 | 99 | #[cfg(test)] 100 | mod tests { 101 | use std::process::Command; 102 | 103 | use expect_test::{expect, Expect}; 104 | 105 | /// Used to assert on the exact output of backlight. 106 | fn test_trace(bin_name: &str, trace_args: &[&str], expected: Expect) { 107 | cargo_build("backlight"); 108 | cargo_build(bin_name); 109 | 110 | let output = Command::new("../target/debug/backlight") 111 | .arg(&format!("../target/debug/{}", bin_name)) 112 | .args(trace_args) 113 | .output() 114 | .unwrap(); 115 | 116 | let result = format!( 117 | "status code: {}\n\nstd out:\n{}\nstd err:\n{}\n", 118 | match output.status.code() { 119 | Some(c) => format!("{}", c), 120 | None => "None".into(), 121 | }, 122 | String::from_utf8_lossy(&output.stdout), 123 | String::from_utf8_lossy(&output.stderr), 124 | ); 125 | expected.assert_eq(&result); 126 | } 127 | 128 | /// Used to assert that the output of backlight contains some values. Useful 129 | /// to create tests which don't depend on the specifics of the environment 130 | /// they run in. 131 | fn assert_trace_contains(bin_name: &str, trace_args: &[&str], expected: &[&str]) { 132 | cargo_build("backlight"); 133 | cargo_build(bin_name); 134 | 135 | let output = Command::new("../target/debug/backlight") 136 | .arg(&format!("../target/debug/{}", bin_name)) 137 | .args(trace_args) 138 | .output() 139 | .unwrap(); 140 | 141 | assert_eq!(0, output.status.code().unwrap()); 142 | 143 | let stdout = String::from_utf8_lossy(&output.stdout); 144 | 145 | for expected_str in expected { 146 | assert!(stdout.contains(expected_str)); 147 | } 148 | } 149 | 150 | fn cargo_build(bin_name: &str) { 151 | let status = Command::new("cargo") 152 | // cargo test sets the current working directory to the package 153 | // root. We need to go up to the workspace root because this 154 | // bin could be in a different package. 155 | .current_dir("..") 156 | .args(&["build", "--bin", bin_name]) 157 | .status() 158 | .unwrap(); 159 | 160 | assert!(status.success()); 161 | } 162 | 163 | #[test] 164 | fn traces_single_library_call() { 165 | test_trace( 166 | "test_support_abs", 167 | &["-l", "abs"], 168 | expect![[r#" 169 | status code: 0 170 | 171 | std out: 172 | [lib] abs 173 | [lib] abs 174 | [lib] abs 175 | --- Child process exited with status code 0 --- 176 | 177 | std err: 178 | 179 | "#]], 180 | ); 181 | } 182 | 183 | #[test] 184 | fn traces_multiple_library_calls() { 185 | test_trace( 186 | "test_support_abs", 187 | &["-l", "abs", "-l", "labs"], 188 | expect![[r#" 189 | status code: 0 190 | 191 | std out: 192 | [lib] abs 193 | [lib] labs 194 | [lib] abs 195 | [lib] labs 196 | [lib] abs 197 | --- Child process exited with status code 0 --- 198 | 199 | std err: 200 | 201 | "#]], 202 | ); 203 | } 204 | 205 | #[test] 206 | fn traces_single_syscall() { 207 | test_trace( 208 | "test_support_abs", 209 | &["-s", "sys_exit_group"], 210 | expect![[r#" 211 | status code: 0 212 | 213 | std out: 214 | [sys] sys_exit_group 215 | --- Child process exited with status code 0 --- 216 | 217 | std err: 218 | 219 | "#]], 220 | ); 221 | } 222 | 223 | #[test] 224 | fn traces_multiple_syscalls() { 225 | assert_trace_contains( 226 | "test_support_abs", 227 | &["-s", "sys_brk", "-s", "sys_exit_group"], 228 | &["[sys] sys_brk", "[sys] sys_exit_group"], 229 | ); 230 | } 231 | 232 | #[test] 233 | fn traces_syscall_and_library_function() { 234 | test_trace( 235 | "test_support_abs", 236 | &["-s", "sys_exit_group", "-l", "abs"], 237 | expect![[r#" 238 | status code: 0 239 | 240 | std out: 241 | [lib] abs 242 | [lib] abs 243 | [lib] abs 244 | [sys] sys_exit_group 245 | --- Child process exited with status code 0 --- 246 | 247 | std err: 248 | 249 | "#]], 250 | ); 251 | } 252 | 253 | #[test] 254 | fn traces_syscall_and_all_library_functions() { 255 | assert_trace_contains( 256 | "test_support_abs", 257 | &["-s", "sys_exit_group", "--all-library-functions"], 258 | &["[sys] sys_exit_group", "[lib] abs"], 259 | ); 260 | } 261 | 262 | #[test] 263 | fn traces_library_function_and_all_syscalls() { 264 | assert_trace_contains( 265 | "test_support_abs", 266 | &["-l", "abs", "--all-syscalls"], 267 | &["[sys] sys_exit_group", "[lib] abs"], 268 | ); 269 | } 270 | 271 | #[test] 272 | fn traces_all_by_default() { 273 | // The expected behavior of backlight when not provided with any explicit 274 | // filters is to trace everything. The exact output of the trace will be 275 | // platform specific, so rather than asserting on the exact output 276 | // we just confirm we see some indication that each expected thing shows 277 | // up somewhere in the backlight output. 278 | assert_trace_contains("test_support_abs", &[], &["[sys]", "[lib]"]); 279 | } 280 | 281 | #[test] 282 | fn passes_along_args() { 283 | // This binary exits with the code given as its first arg. 284 | // 285 | // This test demonstrates that backlight will pass along args to 286 | // the tracee. 287 | for code in &["0", "47"] { 288 | assert_trace_contains( 289 | "test_support_exit", 290 | &["--", code], 291 | &[&format!("Child process exited with status code {}", code)], 292 | ); 293 | } 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /backlight_lib/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "backlight_lib" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | goblin = "0.4" 8 | nix = "0.23" 9 | procfs = { version = "0.12", default-features = false } 10 | -------------------------------------------------------------------------------- /backlight_lib/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | ffi::c_void, 3 | fs::read, 4 | io, 5 | os::unix::prelude::CommandExt, 6 | path::{Path, PathBuf}, 7 | process::Command, 8 | }; 9 | 10 | use goblin::elf::Elf; 11 | use nix::{ 12 | errno::Errno, 13 | libc::user_regs_struct, 14 | sys::{ 15 | mman::ProtFlags, 16 | ptrace, 17 | wait::{waitpid, WaitStatus}, 18 | }, 19 | unistd::Pid, 20 | }; 21 | use procfs::process::{FDTarget, Process}; 22 | 23 | const SYSCALL_ENTRY_MARKER: u64 = -(Errno::ENOSYS as i32) as u64; 24 | const SYS_CALL_MMAP: u64 = 9; 25 | 26 | /// TODO redefine this more strictly 27 | pub type Result = std::result::Result>; 28 | 29 | mod resolved_function; 30 | use resolved_function::ResolvedFunction; 31 | 32 | mod syscall; 33 | use syscall::syscall_name; 34 | 35 | pub struct Tracee { 36 | pid: Pid, 37 | procfs: procfs::process::Process, 38 | unresolved_functions: Vec, 39 | resolved_functions: Vec, 40 | /// If we've seen the entry to a mmap syscall but not the exit 41 | /// we store the args here. Upon exit we resolve functions 42 | /// and set this back to None. 43 | mmap_in_progress: Option, 44 | int3_trap_in_progress: Option, 45 | } 46 | 47 | struct MmapArgs { 48 | /// Path to the file being mmap'd. 49 | file_path: PathBuf, 50 | /// Offset into the file where the mapping starts. 51 | offset: u64, 52 | } 53 | 54 | struct Int3TrapInProgress { 55 | addr: u64, 56 | instruction: i64, 57 | } 58 | 59 | #[allow(clippy::large_enum_variant)] 60 | pub enum TraceeState { 61 | Alive(Tracee), 62 | StoppedAtSystemCallEntrance(Tracee, SysCall), 63 | StoppedAtSystemCallExit(Tracee), 64 | StoppedAtFunctionEntrace(Tracee, Func), 65 | Exited(i32), 66 | } 67 | 68 | /// TODO replace this with enumeration of all syscalls, with args mapped 69 | pub type SysCall = String; 70 | pub type Func = String; 71 | 72 | impl Tracee { 73 | pub fn init( 74 | binary_to_trace: &Path, 75 | tracee_args: &[String], 76 | library_functions_to_trace: Vec, 77 | ) -> Result { 78 | let pid = spawn_tracee(binary_to_trace, tracee_args)?; 79 | 80 | // This allows distinguishing traps for sys calls from other traps. 81 | ptrace::setoptions(pid, ptrace::Options::PTRACE_O_TRACESYSGOOD)?; 82 | 83 | // The tracee should signal a SIGTRAP here. 84 | match waitpid(pid, None)? { 85 | WaitStatus::Exited(_, code) => { 86 | Err(format!("Child process exited with status code {}", code).into()) 87 | } 88 | _ => Ok(Self { 89 | pid, 90 | procfs: Process::new(pid.as_raw())?, 91 | unresolved_functions: library_functions_to_trace, 92 | resolved_functions: vec![], 93 | mmap_in_progress: None, 94 | int3_trap_in_progress: None, 95 | }), 96 | } 97 | } 98 | pub fn step(mut self) -> Result { 99 | // If we are in the middle of the int3 trap process, then we've 100 | // written the original instruction and we want to single step 101 | // until we are past it so we can write the modified instruction 102 | // again. 103 | if self.int3_trap_in_progress.is_some() { 104 | ptrace::step(self.pid, None)?; 105 | } else { 106 | ptrace::syscall(self.pid, None)?; 107 | } 108 | match waitpid(self.pid, None)? { 109 | WaitStatus::Exited(_, code) => Ok(TraceeState::Exited(code)), 110 | WaitStatus::PtraceSyscall(_pid) => { 111 | let registers = ptrace::getregs(self.pid)?; 112 | 113 | if registers.rax == SYSCALL_ENTRY_MARKER 114 | && registers.orig_rax == SYS_CALL_MMAP 115 | && ProtFlags::from_bits_truncate(registers.rdx as i32) 116 | .contains(ProtFlags::PROT_EXEC) 117 | { 118 | self.handle_mmap_entrance(registers)?; 119 | } else { 120 | // If we are stopped on a syscall and we have a mmap 121 | // in progress, we know we are exiting that mmap. 122 | if let Some(mmap_args) = self.mmap_in_progress.take() { 123 | self.handle_mmap_exit(mmap_args)?; 124 | } 125 | } 126 | 127 | if registers.rax == SYSCALL_ENTRY_MARKER { 128 | if registers.orig_rax == SYS_CALL_MMAP 129 | && ProtFlags::from_bits_truncate(registers.rdx as i32) 130 | .contains(ProtFlags::PROT_EXEC) 131 | { 132 | self.handle_mmap_entrance(registers)?; 133 | } 134 | 135 | let name = syscall_name(registers.orig_rax) 136 | .map(|s| s.to_string()) 137 | .unwrap_or(format!("SYS_UNKNOWN_{}", registers.orig_rax)); 138 | Ok(TraceeState::StoppedAtSystemCallEntrance(self, name)) 139 | } else { 140 | // If we are stopped on a syscall exit and we have a mmap 141 | // in progress, we know we are exiting that mmap. 142 | if let Some(mmap_args) = self.mmap_in_progress.take() { 143 | self.handle_mmap_exit(mmap_args)?; 144 | } 145 | 146 | Ok(TraceeState::StoppedAtSystemCallExit(self)) 147 | } 148 | } 149 | _ => { 150 | let registers = ptrace::getregs(self.pid)?; 151 | if let Some(int3_trap_in_progress) = self.int3_trap_in_progress.take() { 152 | if registers.rip == int3_trap_in_progress.addr { 153 | // We haven't moved past this instruction yet. This is still 154 | // in progress so we put it back. 155 | self.int3_trap_in_progress = Some(int3_trap_in_progress); 156 | } else { 157 | // We have single stepped past the breakpoint, so we need 158 | // to write back the int3 for next time. 159 | unsafe { 160 | ptrace::write( 161 | self.pid, 162 | int3_trap_in_progress.addr as *mut c_void, 163 | int3_trap_in_progress.instruction as *mut c_void, 164 | )?; 165 | } 166 | // The fact that we stopped here is an implementation detail 167 | // of how functoin breakpoints are set, so there isn't likely 168 | // to be anything useful for users of this library to do here. 169 | return Ok(TraceeState::Alive(self)); 170 | } 171 | } 172 | if let Some(traced_function) = self 173 | .resolved_functions 174 | .iter() 175 | // When we stop, the instruction pointer will be on the instruction 176 | // after our int3, so we subtract one from the instruction pointer 177 | // before doing the comparison. 178 | .find(|f| f.virtual_addr == registers.rip - 1) 179 | { 180 | unsafe { 181 | ptrace::write( 182 | self.pid, 183 | traced_function.virtual_addr as *mut c_void, 184 | traced_function.original_instruction as *mut c_void, 185 | )?; 186 | } 187 | // need to move pc back by 1 here 188 | let mut registers = registers; 189 | registers.rip -= 1; 190 | ptrace::setregs(self.pid, registers)?; 191 | 192 | // Setting this trap in progress tells Self::step to single 193 | // step until we move past this address and can write the 194 | // modified instruction back into its place. 195 | self.int3_trap_in_progress = Some(Int3TrapInProgress { 196 | addr: traced_function.virtual_addr, 197 | instruction: traced_function.modified_instruction(), 198 | }); 199 | 200 | let traced_function_name = traced_function.name.clone(); 201 | return Ok(TraceeState::StoppedAtFunctionEntrace( 202 | self, 203 | traced_function_name, 204 | )); 205 | } 206 | 207 | // If we get here, we stopped for what is at this point an 208 | // unknown / unhandled reason. 209 | Ok(TraceeState::Alive(self)) 210 | } 211 | } 212 | } 213 | fn handle_mmap_entrance(&mut self, registers: user_regs_struct) -> Result<()> { 214 | let file_descriptor = registers.r8; 215 | let file_path = 216 | if let Some(file_path) = get_file_path_from_fd(&self.procfs, file_descriptor)? { 217 | file_path 218 | } else { 219 | return Ok(()); 220 | }; 221 | 222 | let offset = registers.r9; 223 | 224 | self.mmap_in_progress = Some(MmapArgs { file_path, offset }); 225 | 226 | Ok(()) 227 | } 228 | fn handle_mmap_exit(&mut self, mmap_args: MmapArgs) -> Result<()> { 229 | let registers = ptrace::getregs(self.pid)?; 230 | let mapped_virtual_address_base = registers.rax; 231 | 232 | self.unresolved_functions = self 233 | .unresolved_functions 234 | .drain(..) 235 | .filter(|library_function_to_trace| { 236 | // If this file doesn't have our symbol we want to skip it. 237 | let (library_function_base_file_offset, library_function_virtual_addr_offset) = 238 | match find_library_function_addr_info( 239 | &mmap_args.file_path, 240 | library_function_to_trace, 241 | ) { 242 | Ok(Some((a, b))) => (a, b), 243 | _ => return true, 244 | }; 245 | 246 | if library_function_base_file_offset == mmap_args.offset { 247 | let virtual_addr = 248 | library_function_virtual_addr_offset + mapped_virtual_address_base; 249 | let library_function = ResolvedFunction { 250 | name: library_function_to_trace.into(), 251 | virtual_addr, 252 | original_instruction: ptrace::read(self.pid, virtual_addr as *mut c_void) 253 | .unwrap(), 254 | }; 255 | unsafe { 256 | ptrace::write( 257 | self.pid, 258 | library_function.virtual_addr as *mut c_void, 259 | library_function.modified_instruction() as *mut c_void, 260 | ) 261 | .unwrap(); 262 | } 263 | self.resolved_functions.push(library_function); 264 | false 265 | } else { 266 | true 267 | } 268 | }) 269 | .collect(); 270 | 271 | Ok(()) 272 | } 273 | } 274 | 275 | fn spawn_tracee(binary_to_trace: &Path, tracee_args: &[String]) -> Result { 276 | let mut c = Command::new(&binary_to_trace); 277 | c.args(tracee_args); 278 | unsafe { 279 | c.pre_exec(|| ptrace::traceme().map_err(|err| io::Error::from_raw_os_error(err as i32))); 280 | } 281 | Ok(Pid::from_raw(c.spawn()?.id() as i32)) 282 | } 283 | 284 | /// If the library function is found in this library, this function returns a tuple of 285 | /// * base address in the file of the segment containing this function 286 | /// * virtual address offset - the number of bytes from the base virtual address 287 | /// where that segment is mapped to this function 288 | fn find_library_function_addr_info( 289 | path_to_library: &Path, 290 | library_function_to_trace: &str, 291 | ) -> Result> { 292 | let library_bytes = read(path_to_library)?; 293 | let elf = Elf::parse(&library_bytes)?; 294 | 295 | let mut text_section_info = None; 296 | for (index, section_header) in elf.section_headers.into_iter().enumerate() { 297 | let name = elf 298 | .shdr_strtab 299 | .get_at(section_header.sh_name) 300 | .ok_or("failed to map section name")?; 301 | if name == ".text" { 302 | text_section_info = Some(index); 303 | } 304 | } 305 | let text_section_index = text_section_info.ok_or("failed to find base addr")?; 306 | 307 | let mut library_function_addr_info = None; 308 | for symbol in elf.dynsyms.into_iter().filter(|s| { 309 | s.is_function() 310 | // For now we only handle functions in the text section. 311 | && s.st_shndx == text_section_index 312 | }) { 313 | let name = elf 314 | .dynstrtab 315 | .get_at(symbol.st_name) 316 | .ok_or("failed to map symbol name")?; 317 | 318 | if name == library_function_to_trace { 319 | let base_offset = elf 320 | .program_headers 321 | .iter() 322 | .find(|program_header| { 323 | program_header.p_offset < symbol.st_value 324 | && symbol.st_value < program_header.p_offset + program_header.p_memsz 325 | }) 326 | .map(|program_header| program_header.p_offset) 327 | .ok_or("didn't find mem mapped place")?; 328 | // This is the offset between the start of the executable section 329 | // where this library is mapped into memory and where this function 330 | // is located. 331 | let virtual_addr_offset = symbol.st_value - base_offset; 332 | library_function_addr_info = Some((base_offset, virtual_addr_offset)); 333 | } 334 | } 335 | 336 | Ok(library_function_addr_info) 337 | } 338 | 339 | /// This function returns all undefined symbols, representing functions, in the 340 | /// given elf. Undefined symbols in a binary will be dynamically linked. 341 | pub fn find_undefined_symbols(path_to_bin: &Path) -> Result> { 342 | let library_bytes = read(path_to_bin)?; 343 | let elf = Elf::parse(&library_bytes)?; 344 | let mut out = vec![]; 345 | for symbol in elf 346 | .dynsyms 347 | .into_iter() 348 | // The first entry is reserved and holds a default unitialized entry. 349 | .skip(1) 350 | .filter(|s| s.is_import()) 351 | .filter(|s| s.is_function()) 352 | { 353 | let name = elf 354 | .dynstrtab 355 | .get_at(symbol.st_name) 356 | .ok_or("failed to map symbol name")?; 357 | out.push(name.into()); 358 | } 359 | 360 | Ok(out) 361 | } 362 | 363 | fn get_file_path_from_fd( 364 | procfs_process: &Process, 365 | file_descriptor: u64, 366 | ) -> Result> { 367 | if let Some(FDTarget::Path(file_path)) = procfs_process 368 | .fd()? 369 | .into_iter() 370 | .find(|fd_info| fd_info.fd as u64 == file_descriptor) 371 | .map(|fd_info| fd_info.target) 372 | { 373 | Ok(Some(file_path)) 374 | } else { 375 | Ok(None) 376 | } 377 | } 378 | -------------------------------------------------------------------------------- /backlight_lib/src/resolved_function.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | /// Represents a function which has been mapped to a known location 3 | /// in virtual memory. 4 | pub struct ResolvedFunction { 5 | pub name: String, 6 | /// The virtual address where this function was loaded. 7 | pub virtual_addr: u64, 8 | /// This is the word which was originally stored at the virtual 9 | /// address where this function was loaded. It may contain more 10 | /// than a single instruction but we store the whole word because 11 | /// that is the granularity that the ptrace API allows us to read. 12 | pub original_instruction: i64, 13 | } 14 | 15 | impl ResolvedFunction { 16 | /// Returns the original instruction with the first byte replaced by int3 17 | /// to trigger a trap. 18 | pub fn modified_instruction(&self) -> i64 { 19 | let mut i = self.original_instruction.to_ne_bytes(); 20 | i[0] = 0xcc; 21 | 22 | i64::from_ne_bytes(i) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /backlight_lib/src/syscall.rs: -------------------------------------------------------------------------------- 1 | pub fn syscall_name(syscall: u64) -> Option<&'static str> { 2 | match syscall { 3 | 0 => Some("sys_read"), 4 | 1 => Some("sys_write"), 5 | 2 => Some("sys_open"), 6 | 3 => Some("sys_close"), 7 | 4 => Some("sys_stat"), 8 | 5 => Some("sys_fstat"), 9 | 6 => Some("sys_lstat"), 10 | 7 => Some("sys_poll"), 11 | 8 => Some("sys_lseek"), 12 | 9 => Some("sys_mmap"), 13 | 10 => Some("sys_mprotect"), 14 | 11 => Some("sys_munmap"), 15 | 12 => Some("sys_brk"), 16 | 13 => Some("sys_rt_sigaction"), 17 | 14 => Some("sys_rt_sigprocmask"), 18 | 15 => Some("sys_rt_sigreturn"), 19 | 16 => Some("sys_ioctl"), 20 | 17 => Some("sys_pread64"), 21 | 18 => Some("sys_pwrite64"), 22 | 19 => Some("sys_readv"), 23 | 20 => Some("sys_writev"), 24 | 21 => Some("sys_access"), 25 | 22 => Some("sys_pipe"), 26 | 23 => Some("sys_select"), 27 | 24 => Some("sys_sched_yield"), 28 | 25 => Some("sys_mremap"), 29 | 26 => Some("sys_msync"), 30 | 27 => Some("sys_mincore"), 31 | 28 => Some("sys_madvise"), 32 | 29 => Some("sys_shmget"), 33 | 30 => Some("sys_shmat"), 34 | 31 => Some("sys_shmctl"), 35 | 32 => Some("sys_dup"), 36 | 33 => Some("sys_dup2"), 37 | 34 => Some("sys_pause"), 38 | 35 => Some("sys_nanosleep"), 39 | 36 => Some("sys_getitimer"), 40 | 37 => Some("sys_alarm"), 41 | 38 => Some("sys_setitimer"), 42 | 39 => Some("sys_getpid"), 43 | 40 => Some("sys_sendfile"), 44 | 41 => Some("sys_socket"), 45 | 42 => Some("sys_connect"), 46 | 43 => Some("sys_accept"), 47 | 44 => Some("sys_sendto"), 48 | 45 => Some("sys_recvfrom"), 49 | 46 => Some("sys_sendmsg"), 50 | 47 => Some("sys_recvmsg"), 51 | 48 => Some("sys_shutdown"), 52 | 49 => Some("sys_bind"), 53 | 50 => Some("sys_listen"), 54 | 51 => Some("sys_getsockname"), 55 | 52 => Some("sys_getpeername"), 56 | 53 => Some("sys_socketpair"), 57 | 54 => Some("sys_setsockopt"), 58 | 55 => Some("sys_getsockopt"), 59 | 56 => Some("sys_clone"), 60 | 57 => Some("sys_fork"), 61 | 58 => Some("sys_vfork"), 62 | 59 => Some("sys_execve"), 63 | 60 => Some("sys_exit"), 64 | 61 => Some("sys_wait4"), 65 | 62 => Some("sys_kill"), 66 | 63 => Some("sys_uname"), 67 | 64 => Some("sys_semget"), 68 | 65 => Some("sys_semop"), 69 | 66 => Some("sys_semctl"), 70 | 67 => Some("sys_shmdt"), 71 | 68 => Some("sys_msgget"), 72 | 69 => Some("sys_msgsnd"), 73 | 70 => Some("sys_msgrcv"), 74 | 71 => Some("sys_msgctl"), 75 | 72 => Some("sys_fcntl"), 76 | 73 => Some("sys_flock"), 77 | 74 => Some("sys_fsync"), 78 | 75 => Some("sys_fdatasync"), 79 | 76 => Some("sys_truncate"), 80 | 77 => Some("sys_ftruncate"), 81 | 78 => Some("sys_getdents"), 82 | 79 => Some("sys_getcwd"), 83 | 80 => Some("sys_chdir"), 84 | 81 => Some("sys_fchdir"), 85 | 82 => Some("sys_rename"), 86 | 83 => Some("sys_mkdir"), 87 | 84 => Some("sys_rmdir"), 88 | 85 => Some("sys_creat"), 89 | 86 => Some("sys_link"), 90 | 87 => Some("sys_unlink"), 91 | 88 => Some("sys_symlink"), 92 | 89 => Some("sys_readlink"), 93 | 90 => Some("sys_chmod"), 94 | 91 => Some("sys_fchmod"), 95 | 92 => Some("sys_chown"), 96 | 93 => Some("sys_fchown"), 97 | 94 => Some("sys_lchown"), 98 | 95 => Some("sys_umask"), 99 | 96 => Some("sys_gettimeofday"), 100 | 97 => Some("sys_getrlimit"), 101 | 98 => Some("sys_getrusage"), 102 | 99 => Some("sys_sysinfo"), 103 | 100 => Some("sys_times"), 104 | 101 => Some("sys_ptrace"), 105 | 102 => Some("sys_getuid"), 106 | 103 => Some("sys_syslog"), 107 | 104 => Some("sys_getgid"), 108 | 105 => Some("sys_setuid"), 109 | 106 => Some("sys_setgid"), 110 | 107 => Some("sys_geteuid"), 111 | 108 => Some("sys_getegid"), 112 | 109 => Some("sys_setpgid"), 113 | 110 => Some("sys_getppid"), 114 | 111 => Some("sys_getpgrp"), 115 | 112 => Some("sys_setsid"), 116 | 113 => Some("sys_setreuid"), 117 | 114 => Some("sys_setregid"), 118 | 115 => Some("sys_getgroups"), 119 | 116 => Some("sys_setgroups"), 120 | 117 => Some("sys_setresuid"), 121 | 118 => Some("sys_getresuid"), 122 | 119 => Some("sys_setresgid"), 123 | 120 => Some("sys_getresgid"), 124 | 121 => Some("sys_getpgid"), 125 | 122 => Some("sys_setfsuid"), 126 | 123 => Some("sys_setfsgid"), 127 | 124 => Some("sys_getsid"), 128 | 125 => Some("sys_capget"), 129 | 126 => Some("sys_capset"), 130 | 127 => Some("sys_rt_sigpending"), 131 | 128 => Some("sys_rt_sigtimedwait"), 132 | 129 => Some("sys_rt_sigqueueinfo"), 133 | 130 => Some("sys_rt_sigsuspend"), 134 | 131 => Some("sys_sigaltstack"), 135 | 132 => Some("sys_utime"), 136 | 133 => Some("sys_mknod"), 137 | 134 => Some("sys_uselib"), 138 | 135 => Some("sys_personality"), 139 | 136 => Some("sys_ustat"), 140 | 137 => Some("sys_statfs"), 141 | 138 => Some("sys_fstatfs"), 142 | 139 => Some("sys_sysfs"), 143 | 140 => Some("sys_getpriority"), 144 | 141 => Some("sys_setpriority"), 145 | 142 => Some("sys_sched_setparam"), 146 | 143 => Some("sys_sched_getparam"), 147 | 144 => Some("sys_sched_setscheduler"), 148 | 145 => Some("sys_sched_getscheduler"), 149 | 146 => Some("sys_sched_get_priority_max"), 150 | 147 => Some("sys_sched_get_priority_min"), 151 | 148 => Some("sys_sched_rr_get_interval"), 152 | 149 => Some("sys_mlock"), 153 | 150 => Some("sys_munlock"), 154 | 151 => Some("sys_mlockall"), 155 | 152 => Some("sys_munlockall"), 156 | 153 => Some("sys_vhangup"), 157 | 154 => Some("sys_modify_ldt"), 158 | 155 => Some("sys_pivot_root"), 159 | 156 => Some("sys__sysctl"), 160 | 157 => Some("sys_prctl"), 161 | 158 => Some("sys_arch_prctl"), 162 | 159 => Some("sys_adjtimex"), 163 | 160 => Some("sys_setrlimit"), 164 | 161 => Some("sys_chroot"), 165 | 162 => Some("sys_sync"), 166 | 163 => Some("sys_acct"), 167 | 164 => Some("sys_settimeofday"), 168 | 165 => Some("sys_mount"), 169 | 166 => Some("sys_umount2"), 170 | 167 => Some("sys_swapon"), 171 | 168 => Some("sys_swapoff"), 172 | 169 => Some("sys_reboot"), 173 | 170 => Some("sys_sethostname"), 174 | 171 => Some("sys_setdomainname"), 175 | 172 => Some("sys_iopl"), 176 | 173 => Some("sys_ioperm"), 177 | 174 => Some("sys_create_module"), 178 | 175 => Some("sys_init_module"), 179 | 176 => Some("sys_delete_module"), 180 | 177 => Some("sys_get_kernel_syms"), 181 | 178 => Some("sys_query_module"), 182 | 179 => Some("sys_quotactl"), 183 | 180 => Some("sys_nfsservctl"), 184 | 181 => Some("sys_getpmsg"), 185 | 182 => Some("sys_putpmsg"), 186 | 183 => Some("sys_afs_syscall"), 187 | 184 => Some("sys_tuxcall"), 188 | 185 => Some("sys_security"), 189 | 186 => Some("sys_gettid"), 190 | 187 => Some("sys_readahead"), 191 | 188 => Some("sys_setxattr"), 192 | 189 => Some("sys_lsetxattr"), 193 | 190 => Some("sys_fsetxattr"), 194 | 191 => Some("sys_getxattr"), 195 | 192 => Some("sys_lgetxattr"), 196 | 193 => Some("sys_fgetxattr"), 197 | 194 => Some("sys_listxattr"), 198 | 195 => Some("sys_llistxattr"), 199 | 196 => Some("sys_flistxattr"), 200 | 197 => Some("sys_removexattr"), 201 | 198 => Some("sys_lremovexattr"), 202 | 199 => Some("sys_fremovexattr"), 203 | 200 => Some("sys_tkill"), 204 | 201 => Some("sys_time"), 205 | 202 => Some("sys_futex"), 206 | 203 => Some("sys_sched_setaffinity"), 207 | 204 => Some("sys_sched_getaffinity"), 208 | 205 => Some("sys_set_thread_area"), 209 | 206 => Some("sys_io_setup"), 210 | 207 => Some("sys_io_destroy"), 211 | 208 => Some("sys_io_getevents"), 212 | 209 => Some("sys_io_submit"), 213 | 210 => Some("sys_io_cancel"), 214 | 211 => Some("sys_get_thread_area"), 215 | 212 => Some("sys_lookup_dcookie"), 216 | 213 => Some("sys_epoll_create"), 217 | 214 => Some("sys_epoll_ctl_old"), 218 | 215 => Some("sys_epoll_wait_old"), 219 | 216 => Some("sys_remap_file_pages"), 220 | 217 => Some("sys_getdents64"), 221 | 218 => Some("sys_set_tid_address"), 222 | 219 => Some("sys_restart_syscall"), 223 | 220 => Some("sys_semtimedop"), 224 | 221 => Some("sys_fadvise64"), 225 | 222 => Some("sys_timer_create"), 226 | 223 => Some("sys_timer_settime"), 227 | 224 => Some("sys_timer_gettime"), 228 | 225 => Some("sys_timer_getoverrun"), 229 | 226 => Some("sys_timer_delete"), 230 | 227 => Some("sys_clock_settime"), 231 | 228 => Some("sys_clock_gettime"), 232 | 229 => Some("sys_clock_getres"), 233 | 230 => Some("sys_clock_nanosleep"), 234 | 231 => Some("sys_exit_group"), 235 | 232 => Some("sys_epoll_wait"), 236 | 233 => Some("sys_epoll_ctl"), 237 | 234 => Some("sys_tgkill"), 238 | 235 => Some("sys_utimes"), 239 | 236 => Some("sys_vserver"), 240 | 237 => Some("sys_mbind"), 241 | 238 => Some("sys_set_mempolicy"), 242 | 239 => Some("sys_get_mempolicy"), 243 | 240 => Some("sys_mq_open"), 244 | 241 => Some("sys_mq_unlink"), 245 | 242 => Some("sys_mq_timedsend"), 246 | 243 => Some("sys_mq_timedreceive"), 247 | 244 => Some("sys_mq_notify"), 248 | 245 => Some("sys_mq_getsetattr"), 249 | 246 => Some("sys_kexec_load"), 250 | 247 => Some("sys_waitid"), 251 | 248 => Some("sys_add_key"), 252 | 249 => Some("sys_request_key"), 253 | 250 => Some("sys_keyctl"), 254 | 251 => Some("sys_ioprio_set"), 255 | 252 => Some("sys_ioprio_get"), 256 | 253 => Some("sys_inotify_init"), 257 | 254 => Some("sys_inotify_add_watch"), 258 | 255 => Some("sys_inotify_rm_watch"), 259 | 256 => Some("sys_migrate_pages"), 260 | 257 => Some("sys_openat"), 261 | 258 => Some("sys_mkdirat"), 262 | 259 => Some("sys_mknodat"), 263 | 260 => Some("sys_fchownat"), 264 | 261 => Some("sys_futimesat"), 265 | 262 => Some("sys_newfstatat"), 266 | 263 => Some("sys_unlinkat"), 267 | 264 => Some("sys_renameat"), 268 | 265 => Some("sys_linkat"), 269 | 266 => Some("sys_symlinkat"), 270 | 267 => Some("sys_readlinkat"), 271 | 268 => Some("sys_fchmodat"), 272 | 269 => Some("sys_faccessat"), 273 | 270 => Some("sys_pselect6"), 274 | 271 => Some("sys_ppoll"), 275 | 272 => Some("sys_unshare"), 276 | 273 => Some("sys_set_robust_list"), 277 | 274 => Some("sys_get_robust_list"), 278 | 275 => Some("sys_splice"), 279 | 276 => Some("sys_tee"), 280 | 277 => Some("sys_sync_file_range"), 281 | 278 => Some("sys_vmsplice"), 282 | 279 => Some("sys_move_pages"), 283 | 280 => Some("sys_utimensat"), 284 | 281 => Some("sys_epoll_pwait"), 285 | 282 => Some("sys_signalfd"), 286 | 283 => Some("sys_timerfd_create"), 287 | 284 => Some("sys_eventfd"), 288 | 285 => Some("sys_fallocate"), 289 | 286 => Some("sys_timerfd_settime"), 290 | 287 => Some("sys_timerfd_gettime"), 291 | 288 => Some("sys_accept4"), 292 | 289 => Some("sys_signalfd4"), 293 | 290 => Some("sys_eventfd2"), 294 | 291 => Some("sys_epoll_create1"), 295 | 292 => Some("sys_dup3"), 296 | 293 => Some("sys_pipe2"), 297 | 294 => Some("sys_inotify_init1"), 298 | 295 => Some("sys_preadv"), 299 | 296 => Some("sys_pwritev"), 300 | 297 => Some("sys_rt_tgsigqueueinfo"), 301 | 298 => Some("sys_perf_event_open"), 302 | 299 => Some("sys_recvmmsg"), 303 | 300 => Some("sys_fanotify_init"), 304 | 301 => Some("sys_fanotify_mark"), 305 | 302 => Some("sys_prlimit64"), 306 | 303 => Some("sys_name_to_handle_at"), 307 | 304 => Some("sys_open_by_handle_at"), 308 | 305 => Some("sys_clock_adjtime"), 309 | 306 => Some("sys_syncfs"), 310 | 307 => Some("sys_sendmmsg"), 311 | 308 => Some("sys_setns"), 312 | 309 => Some("sys_getcpu"), 313 | 310 => Some("sys_process_vm_readv"), 314 | 311 => Some("sys_process_vm_writev"), 315 | 312 => Some("sys_kcmp"), 316 | 313 => Some("sys_finit_module"), 317 | 314 => Some("sys_sched_setattr"), 318 | 315 => Some("sys_sched_getattr"), 319 | 316 => Some("sys_renameat2"), 320 | 317 => Some("sys_seccomp"), 321 | 318 => Some("sys_getrandom"), 322 | 319 => Some("sys_memfd_create"), 323 | 320 => Some("sys_kexec_file_load"), 324 | 321 => Some("sys_bpf"), 325 | 322 => Some("stub_execveat"), 326 | 323 => Some("userfaultfd"), 327 | 324 => Some("membarrier"), 328 | 325 => Some("mlock2"), 329 | 326 => Some("copy_file_range"), 330 | 327 => Some("preadv2"), 331 | 328 => Some("pwritev2"), 332 | 329 => Some("pkey_mprotect"), 333 | 330 => Some("pkey_alloc"), 334 | 331 => Some("pkey_free"), 335 | 332 => Some("statx"), 336 | 333 => Some("io_pgetevents"), 337 | 334 => Some("rseq"), 338 | 335 => Some("pkey_mprotect"), 339 | _ => None, 340 | } 341 | } 342 | -------------------------------------------------------------------------------- /test_support/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_support" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /test_support/README.md: -------------------------------------------------------------------------------- 1 | # Test Support 2 | 3 | This crate contains libraries and binaries used to support testing backlight. 4 | -------------------------------------------------------------------------------- /test_support/src/bin/test_support_abs.rs: -------------------------------------------------------------------------------- 1 | //! This binary is built to act as a test tracing target for backlight. 2 | 3 | use std::os::raw::{c_int, c_long}; 4 | 5 | #[link(name = "c")] 6 | extern "C" { 7 | fn abs(i: c_int) -> c_int; 8 | fn labs(i: c_long) -> c_long; 9 | } 10 | 11 | fn main() { 12 | // This code is nonsensical, but we just want an example 13 | // of calling a couple different library functions with 14 | // different argument values. 15 | for i in 0..5 { 16 | if i % 2 == 0 { 17 | let _ = unsafe { abs(i as c_int) }; 18 | } else { 19 | let _ = unsafe { labs(i as c_long) }; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test_support/src/bin/test_support_exit.rs: -------------------------------------------------------------------------------- 1 | //! This binary is built to act as a test tracing target for backlight. 2 | 3 | fn main() { 4 | let code = std::env::args() 5 | .into_iter() 6 | .nth(1) 7 | .map(|arg_string| arg_string.parse().ok()) 8 | .flatten() 9 | .unwrap_or(0); 10 | 11 | std::process::exit(code); 12 | } 13 | --------------------------------------------------------------------------------