diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b33f195ff..57c10f7c4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -44,7 +44,9 @@ jobs: run: rustup install ${{ matrix.rust_version }} && rustup default ${{ matrix.rust_version }} && rustup component add clippy - name: Run clippy on ${{ matrix.platform }} ${{ matrix.rust_version }} shell: bash - run: cargo clippy --workspace --all-targets --all-features -- -D warnings "$([ ${{ matrix.rust_version }} = 1.71.1 ] && echo -Aunknown-lints)" + run: | + # shellcheck disable=SC2046 + cargo clippy --workspace --all-targets --all-features -- -D warnings $([ ${{ matrix.rust_version }} = 1.71.1 ] && echo -Aunknown-lints -Aclippy::cast_ref_to_mut) licensecheck: runs-on: ubuntu-latest name: "Presence of licence headers" diff --git a/Cargo.lock b/Cargo.lock index 0654c6eb3..194cbb80b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -593,7 +593,8 @@ checksum = "a1d084b0137aaa901caf9f1e8b21daa6aa24d41cd806e111335541eff9683bd6" [[package]] name = "blazesym" version = "0.2.0-rc.0" -source = "git+https://github.com/libbpf/blazesym.git?rev=v0.2.0-rc.0#2f393f66a448f46ea71889e81a8866799762463d" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "519a0f9df086d6c4f44576558523a777c984454daeb124bee79bde69227360c4" dependencies = [ "cpp_demangle", "gimli 0.30.0", @@ -604,8 +605,9 @@ dependencies = [ [[package]] name = "blazesym-c" -version = "0.1.0-alpha.1" -source = "git+https://github.com/libbpf/blazesym.git?rev=v0.2.0-rc.0#2f393f66a448f46ea71889e81a8866799762463d" +version = "0.1.0-rc.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f09c03df5c33f265a7ae6de11a81c9ebb69c4ca632afa45e9fcf7a96c1d8cca0" dependencies = [ "blazesym", "memoffset 0.9.1", @@ -935,7 +937,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.4", + "windows-targets 0.52.6", ] [[package]] @@ -1336,6 +1338,7 @@ version = "12.0.0" dependencies = [ "anyhow", "bytes", + "criterion", "datadog-ddsketch", "datadog-trace-normalization", "datadog-trace-protobuf", @@ -1434,6 +1437,7 @@ dependencies = [ "bytes", "criterion", "datadog-ipc-macros", + "ddcommon", "futures", "glibc_version", "io-lifetimes", @@ -1768,6 +1772,7 @@ dependencies = [ "hyper-util", "indexmap 2.2.6", "lazy_static", + "libc", "log", "maplit", "pin-project", @@ -1778,6 +1783,7 @@ dependencies = [ "static_assertions", "tokio", "tokio-rustls 0.26.0", + "windows-sys 0.52.0", ] [[package]] @@ -3021,7 +3027,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.4", + "windows-targets 0.48.5", ] [[package]] @@ -5774,7 +5780,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.6", ] [[package]] @@ -5807,7 +5813,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.6", ] [[package]] @@ -5827,17 +5833,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -5854,9 +5861,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -5872,9 +5879,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -5890,9 +5897,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -5908,9 +5921,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -5926,9 +5939,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -5944,9 +5957,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -5962,9 +5975,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" diff --git a/LICENSE-3rdparty.yml b/LICENSE-3rdparty.yml index c1099a10f..aca6acd97 100644 --- a/LICENSE-3rdparty.yml +++ b/LICENSE-3rdparty.yml @@ -4728,41 +4728,12 @@ third_party_libraries: OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - package_name: blazesym-c - package_version: 0.1.0-alpha.1 + package_version: 0.1.0-rc.0 repository: https://github.com/libbpf/blazesym license: BSD-3-Clause licenses: - license: BSD-3-Clause - text: | - BSD 3-Clause License - - Copyright (c) 2022, Kuifeng Lee - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + text: NOT FOUND - package_name: block-buffer package_version: 0.10.4 repository: https://github.com/RustCrypto/utils @@ -21660,9 +21631,9 @@ third_party_libraries: - package_name: ring package_version: 0.17.8 repository: https://github.com/briansmith/ring - license: License specified in file ($CARGO_HOME/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/LICENSE) + license: License specified in file ($CARGO_HOME/registry/src/github.com-1ecc6299db9ec823/ring-0.17.8/LICENSE) licenses: - - license: License specified in file ($CARGO_HOME/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/LICENSE) + - license: License specified in file ($CARGO_HOME/registry/src/github.com-1ecc6299db9ec823/ring-0.17.8/LICENSE) text: "Note that it is easy for this file to get out of sync with the licenses in the\nsource code files. It's recommended to compare the licenses in the source code\nwith what's mentioned here.\n\n*ring* is derived from BoringSSL, so the licensing situation in *ring* is\nsimilar to BoringSSL.\n\n*ring* uses an ISC-style license like BoringSSL for code in new files,\nincluding in particular all the Rust code:\n\n Copyright 2015-2016 Brian Smith.\n\n Permission to use, copy, modify, and/or distribute this software for any\n purpose with or without fee is hereby granted, provided that the above\n copyright notice and this permission notice appear in all copies.\n\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHORS DISCLAIM ALL WARRANTIES\n WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY\n SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN\n CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n\nBoringSSL is a fork of OpenSSL. As such, large parts of it fall under OpenSSL\nlicensing. Files that are completely new have a Google copyright and an ISC\nlicense. This license is reproduced at the bottom of this file.\n\nContributors to BoringSSL are required to follow the CLA rules for Chromium:\nhttps://cla.developers.google.com/clas\n\nFiles in third_party/ have their own licenses, as described therein. The MIT\nlicense, for third_party/fiat, which, unlike other third_party directories, is\ncompiled into non-test libraries, is included below.\n\nThe OpenSSL toolkit stays under a dual license, i.e. both the conditions of the\nOpenSSL License and the original SSLeay license apply to the toolkit. See below\nfor the actual license texts. Actually both licenses are BSD-style Open Source\nlicenses. In case of any license issues related to OpenSSL please contact\nopenssl-core@openssl.org.\n\nThe following are Google-internal bug numbers where explicit permission from\nsome authors is recorded for use of their work:\n 27287199\n 27287880\n 27287883\n\n OpenSSL License\n ---------------\n\n/* ====================================================================\n * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n *\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer. \n *\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in\n * the documentation and/or other materials provided with the\n * distribution.\n *\n * 3. All advertising materials mentioning features or use of this\n * software must display the following acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission, please contact\n * openssl-core@openssl.org.\n *\n * 5. Products derived from this software may not be called \"OpenSSL\"\n * nor may \"OpenSSL\" appear in their names without prior written\n * permission of the OpenSSL Project.\n *\n * 6. Redistributions of any form whatsoever must retain the following\n * acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n Original SSLeay License\n -----------------------\n\n/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\n * All rights reserved.\n *\n * This package is an SSL implementation written\n * by Eric Young (eay@cryptsoft.com).\n * The implementation was written so as to conform with Netscapes SSL.\n * \n * This library is free for commercial and non-commercial use as long as\n * the following conditions are aheared to. The following conditions\n * apply to all code found in this distribution, be it the RC4, RSA,\n * lhash, DES, etc., code; not just the SSL code. The SSL documentation\n * included with this distribution is covered by the same copyright terms\n * except that the holder is Tim Hudson (tjh@cryptsoft.com).\n * \n * Copyright remains Eric Young's, and as such any Copyright notices in\n * the code are not to be removed.\n * If this package is used in a product, Eric Young should be given attribution\n * as the author of the parts of the library used.\n * This can be in the form of a textual message at program startup or\n * in documentation (online or textual) provided with the package.\n * \n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. All advertising materials mentioning features or use of this software\n * must display the following acknowledgement:\n * \"This product includes cryptographic software written by\n * Eric Young (eay@cryptsoft.com)\"\n * The word 'cryptographic' can be left out if the rouines from the library\n * being used are not cryptographic related :-).\n * 4. If you include any Windows specific code (or a derivative thereof) from \n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n\nISC license used for completely new code in BoringSSL:\n\n/* Copyright (c) 2015, Google Inc.\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\n * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN\n * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */\n\n\nThe code in third_party/fiat carries the MIT license:\n\nCopyright (c) 2015-2016 the fiat-crypto authors (see\nhttps://github.com/mit-plv/fiat-crypto/blob/master/AUTHORS).\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" - package_name: rmp package_version: 0.8.14 @@ -32899,7 +32870,7 @@ third_party_libraries: See the License for the specific language governing permissions and limitations under the License. - package_name: windows-targets - package_version: 0.52.4 + package_version: 0.52.6 repository: https://github.com/microsoft/windows-rs license: MIT OR Apache-2.0 licenses: @@ -33592,7 +33563,7 @@ third_party_libraries: See the License for the specific language governing permissions and limitations under the License. - package_name: windows_aarch64_gnullvm - package_version: 0.52.4 + package_version: 0.52.6 repository: https://github.com/microsoft/windows-rs license: MIT OR Apache-2.0 licenses: @@ -34285,7 +34256,7 @@ third_party_libraries: See the License for the specific language governing permissions and limitations under the License. - package_name: windows_aarch64_msvc - package_version: 0.52.4 + package_version: 0.52.6 repository: https://github.com/microsoft/windows-rs license: MIT OR Apache-2.0 licenses: @@ -34978,7 +34949,238 @@ third_party_libraries: See the License for the specific language governing permissions and limitations under the License. - package_name: windows_i686_gnu - package_version: 0.52.4 + package_version: 0.52.6 + repository: https://github.com/microsoft/windows-rs + license: MIT OR Apache-2.0 + licenses: + - license: MIT + text: |2 + MIT License + + Copyright (c) Microsoft Corporation. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE + - license: Apache-2.0 + text: |2 + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright (c) Microsoft Corporation. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +- package_name: windows_i686_gnullvm + package_version: 0.52.6 repository: https://github.com/microsoft/windows-rs license: MIT OR Apache-2.0 licenses: @@ -35671,7 +35873,7 @@ third_party_libraries: See the License for the specific language governing permissions and limitations under the License. - package_name: windows_i686_msvc - package_version: 0.52.4 + package_version: 0.52.6 repository: https://github.com/microsoft/windows-rs license: MIT OR Apache-2.0 licenses: @@ -36364,7 +36566,7 @@ third_party_libraries: See the License for the specific language governing permissions and limitations under the License. - package_name: windows_x86_64_gnu - package_version: 0.52.4 + package_version: 0.52.6 repository: https://github.com/microsoft/windows-rs license: MIT OR Apache-2.0 licenses: @@ -37057,7 +37259,7 @@ third_party_libraries: See the License for the specific language governing permissions and limitations under the License. - package_name: windows_x86_64_gnullvm - package_version: 0.52.4 + package_version: 0.52.6 repository: https://github.com/microsoft/windows-rs license: MIT OR Apache-2.0 licenses: @@ -37750,7 +37952,7 @@ third_party_libraries: See the License for the specific language governing permissions and limitations under the License. - package_name: windows_x86_64_msvc - package_version: 0.52.4 + package_version: 0.52.6 repository: https://github.com/microsoft/windows-rs license: MIT OR Apache-2.0 licenses: diff --git a/crashtracker/Cargo.toml b/crashtracker/Cargo.toml index 1666adbd4..a760063ff 100644 --- a/crashtracker/Cargo.toml +++ b/crashtracker/Cargo.toml @@ -25,7 +25,7 @@ receiver = [] [target.'cfg(unix)'.dependencies] # Should be kept in sync with the libdatadog symbolizer crate (also using blasesym) -blazesym = { git = "https://github.com/libbpf/blazesym.git", rev = "v0.2.0-rc.0" } +blazesym = "0.2.0-rc.0" [dependencies] anyhow = "1.0" diff --git a/data-pipeline/Cargo.toml b/data-pipeline/Cargo.toml index 65cdc9a1f..556f38618 100644 --- a/data-pipeline/Cargo.toml +++ b/data-pipeline/Cargo.toml @@ -5,6 +5,7 @@ rust-version.workspace = true edition.workspace = true version.workspace = true license.workspace = true +autobenches = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -26,5 +27,11 @@ datadog-ddsketch = { path = "../ddsketch"} [lib] bench = false +[[bench]] +name = "main" +harness = false +path = "benches/main.rs" + [dev-dependencies] +criterion = "0.5.1" rand = "0.8.5" diff --git a/data-pipeline/benches/main.rs b/data-pipeline/benches/main.rs new file mode 100644 index 000000000..f91acce72 --- /dev/null +++ b/data-pipeline/benches/main.rs @@ -0,0 +1,7 @@ +// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 +use criterion::criterion_main; + +mod span_concentrator_bench; + +criterion_main!(span_concentrator_bench::benches); diff --git a/data-pipeline/benches/span_concentrator_bench.rs b/data-pipeline/benches/span_concentrator_bench.rs new file mode 100644 index 000000000..f956bc9ea --- /dev/null +++ b/data-pipeline/benches/span_concentrator_bench.rs @@ -0,0 +1,72 @@ +// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 +use std::{ + collections::HashMap, + time::{self, Duration, SystemTime}, +}; + +use criterion::{criterion_group, Criterion}; +use data_pipeline::span_concentrator::SpanConcentrator; +use datadog_trace_protobuf::pb; + +fn get_bucket_start(now: SystemTime, n: u64) -> i64 { + let start = now.duration_since(time::UNIX_EPOCH).unwrap() + Duration::from_secs(10 * n); + start.as_nanos() as i64 +} + +fn get_span(now: SystemTime, trace_id: u64, span_id: u64) -> pb::Span { + let mut metrics = HashMap::from([("_dd.measured".to_string(), 1.0)]); + if span_id == 1 { + metrics.insert("_dd.top_level".to_string(), 1.0); + } + let mut meta = HashMap::from([("db_name".to_string(), "postgres".to_string())]); + if span_id % 3 == 0 { + meta.insert("bucket_s3".to_string(), "aws_bucket".to_string()); + } + pb::Span { + trace_id, + span_id, + service: "test-service".to_string(), + name: "test-name".to_string(), + resource: format!("test-{trace_id}"), + error: (span_id % 2) as i32, + metrics, + meta, + parent_id: span_id - 1, + start: get_bucket_start(now, trace_id), + duration: span_id as i64 % Duration::from_secs(10).as_nanos() as i64, + ..Default::default() + } +} + +pub fn criterion_benchmark(c: &mut Criterion) { + let mut group = c.benchmark_group("concentrator"); + let now = SystemTime::now() - Duration::from_secs(10 * 100); + let concentrator = SpanConcentrator::new( + Duration::from_secs(10), + now, + true, + true, + vec!["db_name".to_string(), "bucket_s3".to_string()], + ); + let mut spans = vec![]; + for trace_id in 1..100 { + for span_id in 1..100 { + spans.push(get_span(now, trace_id, span_id)); + } + } + group.bench_function("add_spans_to_concentrator", |b| { + b.iter_batched_ref( + || (concentrator.clone(), spans.clone()), + |data| { + let concentrator = &mut data.0; + let spans = &data.1; + for span in spans { + concentrator.add_span(span); + } + }, + criterion::BatchSize::LargeInput, + ); + }); +} +criterion_group!(benches, criterion_benchmark); diff --git a/data-pipeline/src/lib.rs b/data-pipeline/src/lib.rs index 8640f6888..50daf7f41 100644 --- a/data-pipeline/src/lib.rs +++ b/data-pipeline/src/lib.rs @@ -1,5 +1,5 @@ // Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -mod span_concentrator; +pub mod span_concentrator; pub mod trace_exporter; diff --git a/data-pipeline/src/span_concentrator/aggregation.rs b/data-pipeline/src/span_concentrator/aggregation.rs index d1f0d7047..b117e8066 100644 --- a/data-pipeline/src/span_concentrator/aggregation.rs +++ b/data-pipeline/src/span_concentrator/aggregation.rs @@ -110,7 +110,7 @@ fn get_peer_tags(span: &pb::Span, peer_tag_keys: &[String]) -> Vec { } /// The stats computed from a group of span with the same AggregationKey -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub(super) struct GroupedStats { hits: u64, errors: u64, @@ -140,7 +140,7 @@ impl GroupedStats { /// A time bucket used for stats aggregation. It stores a map of GroupedStats storing the stats of /// spans aggregated on their AggregationKey. -#[derive(Debug)] +#[derive(Debug, Clone)] pub(super) struct StatsBucket { data: HashMap, start: u64, diff --git a/data-pipeline/src/span_concentrator/mod.rs b/data-pipeline/src/span_concentrator/mod.rs index 0b63f24ee..e42de140c 100644 --- a/data-pipeline/src/span_concentrator/mod.rs +++ b/data-pipeline/src/span_concentrator/mod.rs @@ -60,7 +60,7 @@ fn should_ignore_span(span: &pb::Span, compute_stats_by_span_kind: bool) -> bool /// When the SpanConcentrator is flushed it keeps the `buffer_len` most recent buckets and remove /// all older buckets returning their content. When using force flush all buckets are flushed /// regardless of their age. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct SpanConcentrator { /// Size of the time buckets used for aggregation in nanos bucket_size: u64, diff --git a/ddcommon/Cargo.toml b/ddcommon/Cargo.toml index bd458b36a..d5bd74f65 100644 --- a/ddcommon/Cargo.toml +++ b/ddcommon/Cargo.toml @@ -36,6 +36,14 @@ tokio = { version = "1.23", features = ["rt", "macros"] } tokio-rustls = { version = "0.26", default-features = false } serde = { version = "1.0", features = ["derive"] } static_assertions = "1.1.0" +libc = "0.2" + +[target.'cfg(windows)'.dependencies.windows-sys] +version = "0.52" +features = [ + "Win32_Foundation", + "Win32_System_Performance", +] [target.'cfg(unix)'.dependencies] hyper-rustls = { version = "0.27", default-features = false, features = [ diff --git a/ddcommon/src/entity_id/unix/container_id.rs b/ddcommon/src/entity_id/unix/container_id.rs index 374e48ca3..7031a79e6 100644 --- a/ddcommon/src/entity_id/unix/container_id.rs +++ b/ddcommon/src/entity_id/unix/container_id.rs @@ -51,6 +51,7 @@ mod tests { use super::*; use maplit::hashmap; + #[cfg_attr(miri, ignore)] #[test] fn test_container_id_line_parsing() { let test_lines = hashmap! { @@ -92,6 +93,7 @@ mod tests { } } + #[cfg_attr(miri, ignore)] #[test] fn test_container_id_file_parsing() { let test_root_dir = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests")); diff --git a/ddcommon/src/entity_id/unix/mod.rs b/ddcommon/src/entity_id/unix/mod.rs index 59dd68c78..611c1d7ee 100644 --- a/ddcommon/src/entity_id/unix/mod.rs +++ b/ddcommon/src/entity_id/unix/mod.rs @@ -149,21 +149,25 @@ mod tests { } } + #[cfg_attr(miri, ignore)] #[test] fn test_entity_id_for_v2() { test_entity_id("cgroup.v2", Some(&IN_REGEX)) } + #[cfg_attr(miri, ignore)] #[test] fn test_entity_id_for_v1() { test_entity_id("cgroup.linux", Some(&IN_REGEX)) } + #[cfg_attr(miri, ignore)] #[test] fn test_entity_id_for_container_id() { test_entity_id("cgroup.docker", Some(&CI_REGEX)) } + #[cfg_attr(miri, ignore)] #[test] fn test_entity_id_for_no_id() { test_entity_id("cgroup.no_memory", None) diff --git a/ddcommon/src/lib.rs b/ddcommon/src/lib.rs index 089de4252..03f5056ee 100644 --- a/ddcommon/src/lib.rs +++ b/ddcommon/src/lib.rs @@ -16,6 +16,7 @@ pub mod entity_id; #[macro_use] pub mod cstr; pub mod config; +pub mod rate_limiter; pub mod tag; pub mod header { diff --git a/ddcommon/src/rate_limiter.rs b/ddcommon/src/rate_limiter.rs new file mode 100644 index 000000000..fee7480d1 --- /dev/null +++ b/ddcommon/src/rate_limiter.rs @@ -0,0 +1,186 @@ +// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 + +use std::sync::atomic::{AtomicI64, AtomicU32, AtomicU64, Ordering}; + +pub trait Limiter { + /// Takes the limit per interval. + /// Returns false if the limit is exceeded, otherwise true. + fn inc(&self, limit: u32) -> bool; + /// Returns the effective rate per interval. + /// Note: The rate is only guaranteed to be accurate immediately after a call to inc(). + fn rate(&self) -> f64; +} + +/// A thread-safe limiter built on Atomics. +/// It's base unit is in seconds, i.e. the minimum allowed rate is 1 per second. +/// Internally the limiter works with the system time granularity, i.e. nanoseconds on unix and +/// milliseconds on windows. +/// The implementation is a sliding window: every time the limiter is increased, the amount of time +/// that has passed is also refilled. +#[repr(C)] +pub struct LocalLimiter { + hit_count: AtomicI64, + last_update: AtomicU64, + last_limit: AtomicU32, + granularity: i64, +} + +const TIME_PER_SECOND: i64 = 1_000_000_000; // nanoseconds + +fn now() -> u64 { + #[cfg(windows)] + let now = unsafe { + static FREQUENCY: AtomicU64 = AtomicU64::new(0); + + let mut frequency = FREQUENCY.load(Ordering::Relaxed); + if frequency == 0 { + windows_sys::Win32::System::Performance::QueryPerformanceFrequency( + &mut frequency as *mut u64 as *mut i64, + ); + FREQUENCY.store(frequency, Ordering::Relaxed); + } + + let mut perf_counter = 0; + windows_sys::Win32::System::Performance::QueryPerformanceCounter(&mut perf_counter); + perf_counter as u64 * frequency / TIME_PER_SECOND as u64 + }; + #[cfg(not(windows))] + let now = { + let mut ts: libc::timespec = libc::timespec { + tv_sec: 0, + tv_nsec: 0, + }; + unsafe { libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts) }; + (ts.tv_sec * TIME_PER_SECOND + ts.tv_nsec) as u64 + }; + now +} + +impl Default for LocalLimiter { + fn default() -> Self { + LocalLimiter { + hit_count: Default::default(), + last_update: AtomicU64::from(now()), + last_limit: Default::default(), + granularity: TIME_PER_SECOND, + } + } +} + +impl LocalLimiter { + /// Allows setting a custom time granularity. The default() implementation is 1 second. + pub fn with_granularity(seconds: u32) -> LocalLimiter { + let mut limiter = LocalLimiter::default(); + limiter.granularity *= seconds as i64; + limiter + } + + /// Resets, with a given granularity. + pub fn reset(&mut self, seconds: u32) { + self.last_update.store(now(), Ordering::Relaxed); + self.hit_count.store(0, Ordering::Relaxed); + self.last_limit.store(0, Ordering::Relaxed); + self.granularity = TIME_PER_SECOND * seconds as i64; + } +} + +impl Limiter for LocalLimiter { + fn inc(&self, limit: u32) -> bool { + let now = now(); + let last = self.last_update.swap(now, Ordering::SeqCst); + // Make sure reducing the limit doesn't stall for a long time + let clear_limit = limit.max(self.last_limit.load(Ordering::Relaxed)); + let clear_counter = (now as i64 - last as i64) * (clear_limit as i64); + let subtract = clear_counter - self.granularity; + let mut previous_hits = self.hit_count.fetch_sub(subtract, Ordering::SeqCst); + // Handle where the limiter goes below zero + if previous_hits < subtract { + let add = clear_counter - previous_hits.max(0); + self.hit_count.fetch_add(add, Ordering::Acquire); + previous_hits += add - clear_counter; + } + if previous_hits / self.granularity >= limit as i64 { + self.hit_count + .fetch_sub(self.granularity, Ordering::Acquire); + false + } else { + // We don't care about race conditions here: + // If the last limit was high enough to increase the previous_hits, we are anyway close + // to a number realistic to decrease the count quickly; i.e. we won't stall the limiter + // indefinitely when switching from a high to a low limit. + self.last_limit.store(limit, Ordering::Relaxed); + true + } + } + + fn rate(&self) -> f64 { + let last_limit = self.last_limit.load(Ordering::Relaxed); + let hit_count = self.hit_count.load(Ordering::Relaxed); + (hit_count as f64 / (last_limit as i64 * self.granularity) as f64).clamp(0., 1.) + } +} + +#[cfg(test)] +mod tests { + use crate::rate_limiter::{Limiter, LocalLimiter, TIME_PER_SECOND}; + use std::sync::atomic::Ordering; + use std::thread::sleep; + use std::time::Duration; + + #[test] + #[cfg_attr(miri, ignore)] + fn test_rate_limiter() { + let limiter = LocalLimiter::default(); + // Two are allowed, then one more because a small amount of time passed since the first one + assert!(limiter.inc(2)); + // Work around floating point precision issues + assert!(limiter.rate() > 0.49999 && limiter.rate() <= 0.5); + // Add a minimal amount of time to ensure the test doesn't run faster than timer precision + sleep(Duration::from_micros(100)); + assert!(limiter.inc(2)); + // We're close to 1, but not quite, due to the minimal time passed + assert!(limiter.rate() > 0.5 && limiter.rate() < 1.); + sleep(Duration::from_micros(100)); + assert!(limiter.inc(2)); + // Rate capped at 1 + assert_eq!(1., limiter.rate()); + sleep(Duration::from_micros(100)); + assert!(!limiter.inc(2)); + sleep(Duration::from_micros(100)); + assert!(!limiter.inc(2)); + sleep(Duration::from_micros(100)); + + // reduce 4 times, we're going into negative territory. Next increment will reset to zero. + limiter + .last_update + .fetch_sub(3 * TIME_PER_SECOND as u64, Ordering::Relaxed); + assert!(limiter.inc(2)); + // Work around floating point precision issues + assert!(limiter.rate() > 0.49999 && limiter.rate() <= 0.5); // We're starting from scratch + sleep(Duration::from_micros(100)); + assert!(limiter.inc(2)); + sleep(Duration::from_micros(100)); + assert!(limiter.inc(2)); + sleep(Duration::from_micros(100)); + assert!(!limiter.inc(2)); + sleep(Duration::from_micros(100)); + + // Test change to higher value + assert!(limiter.inc(3)); + sleep(Duration::from_micros(100)); + assert!(!limiter.inc(3)); + + // Then change to lower value - but we have no capacity + assert!(!limiter.inc(1)); + + // The counter is around 4 (because last limit was 3) + // We're keeping the highest successful limit stored, thus subtracting 3 twice will reset it + limiter + .last_update + .fetch_sub(2 * TIME_PER_SECOND as u64, Ordering::Relaxed); + + // And now 1 succeeds again. + assert!(limiter.inc(1)); + } +} diff --git a/ipc/Cargo.toml b/ipc/Cargo.toml index b702645a3..321e59615 100644 --- a/ipc/Cargo.toml +++ b/ipc/Cargo.toml @@ -21,6 +21,7 @@ libc = { version = "0.2" } # tarpc needed extensions to allow 1 way communication and to export some internal structs tarpc = { path = "tarpc/tarpc", default-features = false, features = ["serde-transport"], package = "tarpc" } +ddcommon = { path = "../ddcommon" } datadog-ipc-macros = { path = "macros" } [dev-dependencies] diff --git a/ipc/src/lib.rs b/ipc/src/lib.rs index b3dc197cf..a73a8c71d 100644 --- a/ipc/src/lib.rs +++ b/ipc/src/lib.rs @@ -6,6 +6,7 @@ pub mod handles; pub mod transport; pub mod platform; +pub mod rate_limiter; pub mod sequential; pub use tarpc; diff --git a/ipc/src/platform/mem_handle.rs b/ipc/src/platform/mem_handle.rs index 94bd62fe6..87714924b 100644 --- a/ipc/src/platform/mem_handle.rs +++ b/ipc/src/platform/mem_handle.rs @@ -215,7 +215,7 @@ mod tests { let shm = ShmHandle::new(5).unwrap(); let mut mapped = shm.map().unwrap(); _ = mapped.as_slice_mut().write(&[1, 2, 3, 4, 5]).unwrap(); - let mapped = mapped.ensure_space(100000); + mapped.ensure_space(100000); assert!(mapped.as_slice().len() >= 100000); let mut exp = vec![0u8; mapped.as_slice().len()]; _ = (&mut exp[..5]).write(&[1, 2, 3, 4, 5]).unwrap(); @@ -229,7 +229,7 @@ mod tests { let shm = NamedShmHandle::create(path.clone(), 5).unwrap(); let mut mapped = shm.map().unwrap(); _ = mapped.as_slice_mut().write(&[1, 2, 3, 4, 5]).unwrap(); - let mapped = mapped.ensure_space(100000); + mapped.ensure_space(100000); assert!(mapped.as_slice().len() >= 100000); let other = NamedShmHandle::open(&path).unwrap().map().unwrap(); diff --git a/ipc/src/platform/unix/mem_handle.rs b/ipc/src/platform/unix/mem_handle.rs index ea70ea4ab..a5aec0e9a 100644 --- a/ipc/src/platform/unix/mem_handle.rs +++ b/ipc/src/platform/unix/mem_handle.rs @@ -111,14 +111,15 @@ impl NamedShmHandle { } impl>> MappedMem { - pub fn ensure_space(self, expected_size: usize) -> MappedMem { + pub fn ensure_space(&mut self, expected_size: usize) { if expected_size <= self.mem.get_shm().size { - return self; + return; } - let mut handle: T = self.into(); + // SAFETY: we'll overwrite the original memory later + let mut handle: T = unsafe { std::ptr::read(self) }.into(); _ = handle.resize(expected_size); - handle.map().unwrap() + unsafe { std::ptr::write(self, handle.map().unwrap()) }; } } diff --git a/ipc/src/platform/unix/mem_handle_macos.rs b/ipc/src/platform/unix/mem_handle_macos.rs index 6a5930e0e..014c98833 100644 --- a/ipc/src/platform/unix/mem_handle_macos.rs +++ b/ipc/src/platform/unix/mem_handle_macos.rs @@ -126,9 +126,9 @@ impl NamedShmHandle { } impl>> MappedMem { - pub fn ensure_space(self, expected_size: usize) -> MappedMem { + pub fn ensure_space(&mut self, expected_size: usize) { if expected_size <= self.mem.get_shm().size { - return self; + return; } if expected_size > MAPPING_MAX_SIZE - page_size::get() { panic!( @@ -138,7 +138,9 @@ impl>> MappedMem { ); } - let mut handle: T = self.into(); + // SAFETY: we'll overwrite the original memory later + let mut handle: T = unsafe { std::ptr::read(self) }.into(); + let page_size = NonZeroUsize::try_from(page_size::get()).unwrap(); unsafe { _ = handle.set_mapping_size(expected_size); @@ -156,7 +158,8 @@ impl>> MappedMem { size.fetch_max(handle.get_size(), Ordering::SeqCst); _ = munmap(ptr, usize::from(page_size)); } - handle.map().unwrap() + + unsafe { std::ptr::write(self, handle.map().unwrap()) }; } } diff --git a/ipc/src/platform/windows/mem_handle.rs b/ipc/src/platform/windows/mem_handle.rs index b3d8fc8d8..474ccbbe7 100644 --- a/ipc/src/platform/windows/mem_handle.rs +++ b/ipc/src/platform/windows/mem_handle.rs @@ -151,10 +151,10 @@ impl NamedShmHandle { } impl>> MappedMem { - pub fn ensure_space(mut self, expected_size: usize) -> MappedMem { + pub fn ensure_space(&mut self, expected_size: usize) { let current_size = self.mem.get_shm().size; if expected_size <= current_size { - return self; + return; } if expected_size > MAPPING_MAX_SIZE { panic!( @@ -175,6 +175,5 @@ impl>> MappedMem { PAGE_READWRITE, ) }; - self } } diff --git a/ipc/src/rate_limiter.rs b/ipc/src/rate_limiter.rs new file mode 100644 index 000000000..f05439f39 --- /dev/null +++ b/ipc/src/rate_limiter.rs @@ -0,0 +1,259 @@ +// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 + +use crate::platform::{FileBackedHandle, MappedMem, NamedShmHandle}; +use ddcommon::rate_limiter::{Limiter, LocalLimiter}; +use std::ffi::CString; +use std::fmt::{Debug, Formatter}; +use std::io; +use std::marker::PhantomData; +use std::sync::atomic::{AtomicI32, AtomicU32, Ordering}; +use std::sync::{Arc, RwLock}; + +#[repr(C)] +#[derive(Default)] +struct ShmLimiterData<'a> { + next_free: AtomicU32, // free list + rc: AtomicI32, + limiter: LocalLimiter, + _phantom: PhantomData<&'a ShmLimiterMemory>, +} + +#[derive(Clone)] +pub struct ShmLimiterMemory(Arc>>); + +impl ShmLimiterMemory { + const START_OFFSET: u32 = std::mem::align_of::() as u32; + + pub fn create(path: CString) -> io::Result { + // Clean leftover shm + unsafe { libc::unlink(path.as_ptr()) }; + let mem = Self::new(NamedShmHandle::create(path, 0x1000)?.map()?); + mem.first_free_ref() + .store(Self::START_OFFSET, Ordering::Relaxed); + Ok(mem) + } + + /// Opens the shared limiter. Users are expected to re-open this if their sidecar connection + /// breaks. + pub fn open(path: &CString) -> io::Result { + Ok(Self::new(NamedShmHandle::open(path)?.map()?)) + } + + fn new(handle: MappedMem) -> Self { + Self(Arc::new(RwLock::new(handle))) + } + + /// The start of the ShmLimiter memory has 4 bytes indicating an offset to the first free + /// element in the free list. It is zero if there is no element on the free list. + fn first_free_ref(&self) -> &AtomicU32 { + unsafe { &*self.0.read().unwrap().as_slice().as_ptr().cast() } + } + + fn next_free(&mut self) -> u32 { + let mut first_free = self.first_free_ref().load(Ordering::Relaxed); + loop { + let mut target_next_free = ShmLimiter { + idx: first_free, + memory: self.clone(), + } + .limiter() + .next_free + .load(Ordering::Relaxed); + // Not yet used memory will always be 0. The next free entry will then be just above. + if target_next_free == 0 { + target_next_free = first_free + std::mem::size_of::() as u32; + // target_next_free is the end of the current entry - but we need one more + self.0.write().unwrap().ensure_space( + target_next_free as usize + std::mem::size_of::(), + ); + } + match self.first_free_ref().compare_exchange( + first_free, + target_next_free, + Ordering::Release, + Ordering::Relaxed, + ) { + Ok(_) => return first_free, + Err(found) => first_free = found, + } + } + } + + pub fn alloc(&mut self) -> ShmLimiter { + let reference = ShmLimiter { + idx: self.next_free(), + memory: self.clone(), + }; + let limiter = reference.limiter(); + limiter.rc.store(1, Ordering::Relaxed); + // SAFETY: we initialize the struct here + unsafe { + (*(limiter as *const _ as *mut ShmLimiterData)) + .limiter + .reset(1) + }; + reference + } + + pub fn get(&self, idx: u32) -> Option { + assert_eq!( + idx % std::mem::size_of::() as u32, + Self::START_OFFSET + ); + let reference = ShmLimiter { + idx, + memory: self.clone(), + }; + let limiter = reference.limiter(); + let mut rc = limiter.rc.load(Ordering::Relaxed); + loop { + if rc == 0 { + return None; + } + match limiter + .rc + .compare_exchange(rc, rc + 1, Ordering::Release, Ordering::Relaxed) + { + Ok(_) => return Some(reference), + Err(found) => rc = found, + } + } + } +} + +pub struct ShmLimiter { + idx: u32, + memory: ShmLimiterMemory, +} + +impl Debug for ShmLimiter { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + self.idx.fmt(f) + } +} + +impl ShmLimiter { + fn limiter(&self) -> &ShmLimiterData { + unsafe { + &*self + .memory + .0 + .read() + .unwrap() + .as_slice() + .as_ptr() + .offset(self.idx as isize) + .cast() + } + } + + pub fn index(&self) -> u32 { + self.idx + } +} + +impl Limiter for ShmLimiter { + fn inc(&self, limit: u32) -> bool { + self.limiter().limiter.inc(limit) + } + + fn rate(&self) -> f64 { + self.limiter().limiter.rate() + } +} + +impl Drop for ShmLimiter { + fn drop(&mut self) { + let limiter = self.limiter(); + if limiter.rc.fetch_sub(1, Ordering::SeqCst) == 1 { + let next_free_ref = self.memory.first_free_ref(); + let mut next_free = next_free_ref.load(Ordering::Relaxed); + loop { + limiter.next_free.store(next_free, Ordering::Relaxed); + match next_free_ref.compare_exchange( + next_free, + self.idx, + Ordering::SeqCst, + Ordering::Relaxed, + ) { + Ok(_) => return, + Err(found) => next_free = found, + } + } + } + } +} + +pub enum AnyLimiter { + Local(LocalLimiter), + Shm(ShmLimiter), +} + +impl AnyLimiter { + fn limiter(&self) -> &dyn Limiter { + match self { + AnyLimiter::Local(local) => local as &dyn Limiter, + AnyLimiter::Shm(shm) => shm as &dyn Limiter, + } + } +} + +impl Limiter for AnyLimiter { + fn inc(&self, limit: u32) -> bool { + self.limiter().inc(limit) + } + + fn rate(&self) -> f64 { + self.limiter().rate() + } +} + +#[cfg(test)] +mod tests { + use crate::rate_limiter::{ShmLimiterData, ShmLimiterMemory}; + use ddcommon::rate_limiter::Limiter; + use std::ffi::CString; + use std::thread::sleep; + use std::time::Duration; + + fn path() -> CString { + CString::new("/ddlimiters-test".to_string()).unwrap() + } + + #[test] + #[cfg_attr(miri, ignore)] + fn test_limiters() { + let mut limiters = ShmLimiterMemory::create(path()).unwrap(); + let limiter = limiters.alloc(); + let limiter_idx = limiter.idx; + // Two are allowed, then one more because a small amount of time passed since the first one + assert!(limiter.inc(2)); + // Add a minimal amount of time to ensure the test doesn't run faster than timer precision + sleep(Duration::from_micros(100)); + assert!(limiter.inc(2)); + sleep(Duration::from_micros(100)); + assert!(limiter.inc(2)); + sleep(Duration::from_micros(100)); + assert!(!limiter.inc(2)); + sleep(Duration::from_micros(100)); + assert!(!limiter.inc(2)); + + // Now test the free list + let limiter2 = limiters.alloc(); + assert_eq!( + limiter2.idx, + limiter_idx + std::mem::size_of::() as u32 + ); + drop(limiter); + + let limiter = limiters.alloc(); + assert_eq!(limiter.idx, limiter_idx); + + let limiter3 = limiters.alloc(); + assert_eq!( + limiter3.idx, + limiter2.idx + std::mem::size_of::() as u32 + ); + } +} diff --git a/ruby/Rakefile b/ruby/Rakefile index 003714f14..8a910100c 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -11,7 +11,7 @@ require "rubygems/package" RSpec::Core::RakeTask.new(:spec) -LIB_VERSION_TO_PACKAGE = "11.0.0" +LIB_VERSION_TO_PACKAGE = "12.0.0" unless LIB_VERSION_TO_PACKAGE.start_with?(Libdatadog::LIB_VERSION) raise "`LIB_VERSION_TO_PACKAGE` setting in (#{LIB_VERSION_TO_PACKAGE}) does not match " \ "`LIB_VERSION` setting in (#{Libdatadog::LIB_VERSION})" @@ -20,22 +20,22 @@ end LIB_GITHUB_RELEASES = [ { file: "libdatadog-aarch64-alpine-linux-musl.tar.gz", - sha256: "81017bdc4634163151272539e98700e5e0fb076d4aa88a004087c4a01be0cfc3", + sha256: "8e7b429fcd7476cd800c041d8196e908b3a85ce6817e852f18f57a200c89e22a", ruby_platform: "aarch64-linux-musl" }, { file: "libdatadog-aarch64-unknown-linux-gnu.tar.gz", - sha256: "9b06e0dced2cfa72279a1f50bf12bb485eaa54d54b6d09764cc297d79a7ce0da", + sha256: "a78da9ed45cb301dc9aa43e6ca16df789c9dd845417f0ac4feee895f4df63ad4", ruby_platform: "aarch64-linux" }, { file: "libdatadog-x86_64-alpine-linux-musl.tar.gz", - sha256: "96ed601629feb33ce3b1acf6ffd0c30eacb04c4353c8a52388eccd6b4027c2f1", + sha256: "67d518a17147ea29383c4a6d72805a542dca1cb94f9233b322b510254b93ac0f", ruby_platform: "x86_64-linux-musl" }, { file: "libdatadog-x86_64-unknown-linux-gnu.tar.gz", - sha256: "cac9b7c4c0f791d8618426bac81f14c0be40bfeecb2d01a98dcae67ba217eca5", + sha256: "d4fd8bc13042d6c3c78cc5526b969d1279b26021858a470e25d25599bffd4f5f", ruby_platform: "x86_64-linux" } ] diff --git a/ruby/lib/libdatadog/version.rb b/ruby/lib/libdatadog/version.rb index 4288f375c..7ca06dcbf 100644 --- a/ruby/lib/libdatadog/version.rb +++ b/ruby/lib/libdatadog/version.rb @@ -2,7 +2,7 @@ module Libdatadog # Current libdatadog version - LIB_VERSION = "11.0.0" + LIB_VERSION = "12.0.0" GEM_MAJOR_VERSION = "1" GEM_MINOR_VERSION = "0" diff --git a/sidecar/src/entry.rs b/sidecar/src/entry.rs index 7ade83392..6349c0cf2 100644 --- a/sidecar/src/entry.rs +++ b/sidecar/src/entry.rs @@ -139,16 +139,12 @@ where .map_err(|e| e.into()) } -pub fn daemonize(listener: IpcServer, cfg: Config) -> anyhow::Result<()> { +pub fn daemonize(listener: IpcServer, mut cfg: Config) -> anyhow::Result<()> { #[allow(unused_unsafe)] // the unix method is unsafe let mut spawn_cfg = unsafe { spawn_worker::SpawnWorker::new() }; spawn_cfg.target(entrypoint!(ddog_daemon_entry_point)); - for (env, val) in cfg.to_env().into_iter() { - spawn_cfg.append_env(env, val); - } - match cfg.log_method { config::LogMethod::File(ref path) => { match File::options() @@ -164,6 +160,7 @@ pub fn daemonize(listener: IpcServer, cfg: Config) -> anyhow::Result<()> { } Err(e) => { tracing::warn!("Failed to open logfile for sidecar: {:?}", e); + cfg.log_method = config::LogMethod::Disabled; spawn_cfg.stdout(Stdio::Null); spawn_cfg.stderr(Stdio::Null); } @@ -176,6 +173,11 @@ pub fn daemonize(listener: IpcServer, cfg: Config) -> anyhow::Result<()> { _ => {} } + for (env, val) in cfg.to_env().into_iter() { + spawn_cfg.append_env(env, val); + } + spawn_cfg.append_env("LSAN_OPTIONS", "detect_leaks=0"); + setup_daemon_process(listener, &mut spawn_cfg)?; let mut lib_deps = cfg.library_dependencies; diff --git a/sidecar/src/one_way_shared_memory.rs b/sidecar/src/one_way_shared_memory.rs index 5949e5db0..d5490dcba 100644 --- a/sidecar/src/one_way_shared_memory.rs +++ b/sidecar/src/one_way_shared_memory.rs @@ -11,7 +11,7 @@ pub struct OneWayShmWriter where T: FileBackedHandle + From>, { - handle: Mutex>>, + handle: Mutex>, } pub struct OneWayShmReader @@ -68,7 +68,7 @@ pub fn create_anon_pair() -> anyhow::Result<(OneWayShmWriter, ShmHand let handle = ShmHandle::new(0x1000)?; Ok(( OneWayShmWriter { - handle: Mutex::new(Some(handle.clone().map()?)), + handle: Mutex::new(handle.clone().map()?), }, handle, )) @@ -87,7 +87,7 @@ impl>, D> OneWayShmReader { impl>> OneWayShmWriter { pub fn new(path: CString) -> io::Result> { Ok(OneWayShmWriter { - handle: Mutex::new(Some(NamedShmHandle::create(path, 0x1000)?.map()?)), + handle: Mutex::new(NamedShmHandle::create(path, 0x1000)?.map()?), }) } } @@ -127,9 +127,8 @@ where let fetch_data = |reader: &'a mut OneWayShmReader| { let size = std::mem::size_of::() + source_data.meta.size; - let handle = reader.handle.take().unwrap().ensure_space(size); - reader.handle.replace(handle); - let handle = reader.handle.as_ref().unwrap(); + let handle = reader.handle.as_mut().unwrap(); + handle.ensure_space(size); // aligned on 8 byte boundary, round up to closest 8 byte boundary let mut new_mem = Vec::::with_capacity((size + 7) / 8); @@ -185,11 +184,10 @@ where impl>> OneWayShmWriter { pub fn write(&self, contents: &[u8]) { - let mut handle = self.handle.lock().unwrap(); - let mut mapped = handle.take().unwrap(); + let mut mapped = self.handle.lock().unwrap(); let size = contents.len() + 1; // trailing zero byte, to keep some C code happy - mapped = mapped.ensure_space(std::mem::size_of::() + size); + mapped.ensure_space(std::mem::size_of::() + size); // Safety: ShmHandle is always big enough // Actually &mut mapped.as_slice_mut() as RawData seems safe, but unsized locals are @@ -203,13 +201,10 @@ impl>> OneWayShmWriter { data.meta.generation.fetch_add(1, Ordering::SeqCst); data.meta.writing.store(false, Ordering::SeqCst); - - handle.replace(mapped); } pub fn as_slice(&self) -> &[u8] { - let handle = self.handle.lock().unwrap(); - let mapped = handle.as_ref().unwrap(); + let mapped = self.handle.lock().unwrap(); let data = unsafe { &*(mapped.as_slice() as *const [u8] as *const RawData) }; if data.meta.size > 0 { let slice = data.as_slice(); @@ -220,12 +215,6 @@ impl>> OneWayShmWriter { } pub fn size(&self) -> usize { - self.handle - .lock() - .unwrap() - .as_ref() - .unwrap() - .as_slice() - .len() + self.handle.lock().unwrap().as_slice().len() } } diff --git a/spawn_worker/src/unix/spawn.rs b/spawn_worker/src/unix/spawn.rs index f7fc0f7eb..d30ddc999 100644 --- a/spawn_worker/src/unix/spawn.rs +++ b/spawn_worker/src/unix/spawn.rs @@ -634,8 +634,8 @@ impl SpawnWorker { } unsafe { libc::close(skip_close_fd); + libc::_exit(0); } - std::process::exit(0); } } diff --git a/symbolizer-ffi/Cargo.toml b/symbolizer-ffi/Cargo.toml index c223f4e1e..e903b3e6a 100644 --- a/symbolizer-ffi/Cargo.toml +++ b/symbolizer-ffi/Cargo.toml @@ -16,4 +16,4 @@ bench = false [target.'cfg(not(target_os = "windows"))'.dependencies] # Should be kept in sync with the libdatadog crashtracker crate (also using blasesym) -blazesym-c = { git = "https://github.com/libbpf/blazesym.git", rev = "v0.2.0-rc.0" } +blazesym-c = "0.1.0-rc.0" diff --git a/symbolizer-ffi/src/blazesym.h b/symbolizer-ffi/src/blazesym.h index 31ddbe5a4..fc86271d8 100644 --- a/symbolizer-ffi/src/blazesym.h +++ b/symbolizer-ffi/src/blazesym.h @@ -1,11 +1,12 @@ // BSD-3-Clause License // Synchronized from blazesym repository - +// https://github.com/libbpf/blazesym/blob/capi-v0.1.0-rc.0/capi/include/blazesym.h /* -* Please refer to the documentation hosted at -* -* https://docs.rs/blazesym-c/0.1.0-alpha.1 -*/ + * Please refer to the documentation hosted at + * + * https://docs.rs/blazesym-c/0.1.0-rc.0 + */ + #ifndef __blazesym_h_ #define __blazesym_h_ @@ -17,834 +18,834 @@ #include /** -* An enum providing a rough classification of errors. -* -* C ABI compatible version of [`blazesym::ErrorKind`]. -*/ + * An enum providing a rough classification of errors. + * + * C ABI compatible version of [`blazesym::ErrorKind`]. + */ typedef enum blaze_err { - /** - * The operation was successful. - */ - BLAZE_ERR_OK = 0, - /** - * An entity was not found, often a file. - */ - BLAZE_ERR_NOT_FOUND = -2, - /** - * The operation lacked the necessary privileges to complete. - */ - BLAZE_ERR_PERMISSION_DENIED = -1, - /** - * An entity already exists, often a file. - */ - BLAZE_ERR_ALREADY_EXISTS = -17, - /** - * The operation needs to block to complete, but the blocking - * operation was requested to not occur. - */ - BLAZE_ERR_WOULD_BLOCK = -11, - /** - * Data not valid for the operation were encountered. - */ - BLAZE_ERR_INVALID_DATA = -22, - /** - * The I/O operation's timeout expired, causing it to be canceled. - */ - BLAZE_ERR_TIMED_OUT = -110, - /** - * This operation is unsupported on this platform. - */ - BLAZE_ERR_UNSUPPORTED = -95, - /** - * An operation could not be completed, because it failed - * to allocate enough memory. - */ - BLAZE_ERR_OUT_OF_MEMORY = -12, - /** - * A parameter was incorrect. - */ - BLAZE_ERR_INVALID_INPUT = -256, - /** - * An error returned when an operation could not be completed - * because a call to [`write`] returned [`Ok(0)`]. - */ - BLAZE_ERR_WRITE_ZERO = -257, - /** - * An error returned when an operation could not be completed - * because an "end of file" was reached prematurely. - */ - BLAZE_ERR_UNEXPECTED_EOF = -258, - /** - * DWARF input data was invalid. - */ - BLAZE_ERR_INVALID_DWARF = -259, - /** - * A custom error that does not fall under any other I/O error - * kind. - */ - BLAZE_ERR_OTHER = -260, + /** + * The operation was successful. + */ + BLAZE_ERR_OK = 0, + /** + * An entity was not found, often a file. + */ + BLAZE_ERR_NOT_FOUND = -2, + /** + * The operation lacked the necessary privileges to complete. + */ + BLAZE_ERR_PERMISSION_DENIED = -1, + /** + * An entity already exists, often a file. + */ + BLAZE_ERR_ALREADY_EXISTS = -17, + /** + * The operation needs to block to complete, but the blocking + * operation was requested to not occur. + */ + BLAZE_ERR_WOULD_BLOCK = -11, + /** + * Data not valid for the operation were encountered. + */ + BLAZE_ERR_INVALID_DATA = -22, + /** + * The I/O operation's timeout expired, causing it to be canceled. + */ + BLAZE_ERR_TIMED_OUT = -110, + /** + * This operation is unsupported on this platform. + */ + BLAZE_ERR_UNSUPPORTED = -95, + /** + * An operation could not be completed, because it failed + * to allocate enough memory. + */ + BLAZE_ERR_OUT_OF_MEMORY = -12, + /** + * A parameter was incorrect. + */ + BLAZE_ERR_INVALID_INPUT = -256, + /** + * An error returned when an operation could not be completed + * because a call to [`write`] returned [`Ok(0)`]. + */ + BLAZE_ERR_WRITE_ZERO = -257, + /** + * An error returned when an operation could not be completed + * because an "end of file" was reached prematurely. + */ + BLAZE_ERR_UNEXPECTED_EOF = -258, + /** + * DWARF input data was invalid. + */ + BLAZE_ERR_INVALID_DWARF = -259, + /** + * A custom error that does not fall under any other I/O error + * kind. + */ + BLAZE_ERR_OTHER = -260, } blaze_err; /** -* The reason why normalization failed. -* -* The reason is generally only meant as a hint. Reasons reported may change -* over time and, hence, should not be relied upon for the correctness of the -* application. -*/ + * The reason why normalization failed. + * + * The reason is generally only meant as a hint. Reasons reported may change + * over time and, hence, should not be relied upon for the correctness of the + * application. + */ enum blaze_normalize_reason #ifdef __cplusplus - : uint8_t + : uint8_t #endif // __cplusplus -{ - /** - * The absolute address was not found in the corresponding process' virtual - * memory map. - */ - BLAZE_NORMALIZE_REASON_UNMAPPED, - /** - * The `/proc//maps` entry corresponding to the address does not have - * a component (file system path, object, ...) associated with it. - */ - BLAZE_NORMALIZE_REASON_MISSING_COMPONENT, - /** - * The address belonged to an entity that is currently unsupported. - */ - BLAZE_NORMALIZE_REASON_UNSUPPORTED, + { + /** + * The absolute address was not found in the corresponding process' virtual + * memory map. + */ + BLAZE_NORMALIZE_REASON_UNMAPPED, + /** + * The `/proc//maps` entry corresponding to the address does not have + * a component (file system path, object, ...) associated with it. + */ + BLAZE_NORMALIZE_REASON_MISSING_COMPONENT, + /** + * The address belonged to an entity that is currently unsupported. + */ + BLAZE_NORMALIZE_REASON_UNSUPPORTED, }; #ifndef __cplusplus typedef uint8_t blaze_normalize_reason; #endif // __cplusplus /** -* The type of a symbol. -*/ + * The type of a symbol. + */ enum blaze_sym_type #ifdef __cplusplus - : uint8_t + : uint8_t #endif // __cplusplus -{ - /** - * The symbol type is unspecified or unknown. - * - * In input contexts this variant can be used to encompass all - * other variants (functions and variables), whereas in output - * contexts it means that the type is not known. - */ - BLAZE_SYM_UNDEF, - /** - * The symbol is a function. - */ - BLAZE_SYM_FUNC, - /** - * The symbol is a variable. - */ - BLAZE_SYM_VAR, + { + /** + * The symbol type is unspecified or unknown. + * + * In input contexts this variant can be used to encompass all + * other variants (functions and variables), whereas in output + * contexts it means that the type is not known. + */ + BLAZE_SYM_UNDEF, + /** + * The symbol is a function. + */ + BLAZE_SYM_FUNC, + /** + * The symbol is a variable. + */ + BLAZE_SYM_VAR, }; #ifndef __cplusplus typedef uint8_t blaze_sym_type; #endif // __cplusplus /** -* The reason why symbolization failed. -* -* The reason is generally only meant as a hint. Reasons reported may -* change over time and, hence, should not be relied upon for the -* correctness of the application. -*/ + * The reason why symbolization failed. + * + * The reason is generally only meant as a hint. Reasons reported may + * change over time and, hence, should not be relied upon for the + * correctness of the application. + */ enum blaze_symbolize_reason #ifdef __cplusplus - : uint8_t + : uint8_t #endif // __cplusplus -{ - /** - * Symbolization was successful. - */ - BLAZE_SYMBOLIZE_REASON_SUCCESS = 0, - /** - * The absolute address was not found in the corresponding process' - * virtual memory map. - */ - BLAZE_SYMBOLIZE_REASON_UNMAPPED, - /** - * The file offset does not map to a valid piece of code/data. - */ - BLAZE_SYMBOLIZE_REASON_INVALID_FILE_OFFSET, - /** - * The `/proc//maps` entry corresponding to the address does - * not have a component (file system path, object, ...) associated - * with it. - */ - BLAZE_SYMBOLIZE_REASON_MISSING_COMPONENT, - /** - * The symbolization source has no or no relevant symbols. - */ - BLAZE_SYMBOLIZE_REASON_MISSING_SYMS, - /** - * The address could not be found in the symbolization source. - */ - BLAZE_SYMBOLIZE_REASON_UNKNOWN_ADDR, - /** - * The address belonged to an entity that is currently unsupported. - */ - BLAZE_SYMBOLIZE_REASON_UNSUPPORTED, + { + /** + * Symbolization was successful. + */ + BLAZE_SYMBOLIZE_REASON_SUCCESS = 0, + /** + * The absolute address was not found in the corresponding process' + * virtual memory map. + */ + BLAZE_SYMBOLIZE_REASON_UNMAPPED, + /** + * The file offset does not map to a valid piece of code/data. + */ + BLAZE_SYMBOLIZE_REASON_INVALID_FILE_OFFSET, + /** + * The `/proc//maps` entry corresponding to the address does + * not have a component (file system path, object, ...) associated + * with it. + */ + BLAZE_SYMBOLIZE_REASON_MISSING_COMPONENT, + /** + * The symbolization source has no or no relevant symbols. + */ + BLAZE_SYMBOLIZE_REASON_MISSING_SYMS, + /** + * The address could not be found in the symbolization source. + */ + BLAZE_SYMBOLIZE_REASON_UNKNOWN_ADDR, + /** + * The address belonged to an entity that is currently unsupported. + */ + BLAZE_SYMBOLIZE_REASON_UNSUPPORTED, }; #ifndef __cplusplus typedef uint8_t blaze_symbolize_reason; #endif // __cplusplus /** -* The valid variant kind in [`blaze_user_meta`]. -*/ + * The valid variant kind in [`blaze_user_meta`]. + */ typedef enum blaze_user_meta_kind { - /** - * [`blaze_user_meta_variant::unknown`] is valid. - */ - BLAZE_USER_META_UNKNOWN, - /** - * [`blaze_user_meta_variant::apk`] is valid. - */ - BLAZE_USER_META_APK, - /** - * [`blaze_user_meta_variant::elf`] is valid. - */ - BLAZE_USER_META_ELF, + /** + * [`blaze_user_meta_variant::unknown`] is valid. + */ + BLAZE_USER_META_UNKNOWN, + /** + * [`blaze_user_meta_variant::apk`] is valid. + */ + BLAZE_USER_META_APK, + /** + * [`blaze_user_meta_variant::elf`] is valid. + */ + BLAZE_USER_META_ELF, } blaze_user_meta_kind; /** -* Information about a looked up symbol. -*/ + * Information about a looked up symbol. + */ typedef struct blaze_sym_info { - /** - * See [`inspect::SymInfo::name`]. - */ - const char *name; - /** - * See [`inspect::SymInfo::addr`]. - */ - uintptr_t addr; - /** - * See [`inspect::SymInfo::size`]. - */ - size_t size; - /** - * See [`inspect::SymInfo::file_offset`]. - */ - uint64_t file_offset; - /** - * See [`inspect::SymInfo::obj_file_name`]. - */ - const char *obj_file_name; - /** - * See [`inspect::SymInfo::sym_type`]. - */ - blaze_sym_type sym_type; - /** - * Unused member available for future expansion. - */ - uint8_t reserved[15]; + /** + * See [`inspect::SymInfo::name`]. + */ + const char *name; + /** + * See [`inspect::SymInfo::addr`]. + */ + uintptr_t addr; + /** + * See [`inspect::SymInfo::size`]. + */ + size_t size; + /** + * See [`inspect::SymInfo::file_offset`]. + */ + uint64_t file_offset; + /** + * See [`inspect::SymInfo::obj_file_name`]. + */ + const char *obj_file_name; + /** + * See [`inspect::SymInfo::sym_type`]. + */ + blaze_sym_type sym_type; + /** + * Unused member available for future expansion. + */ + uint8_t reserved[15]; } blaze_sym_info; /** -* C ABI compatible version of [`blazesym::inspect::Inspector`]. -*/ + * C ABI compatible version of [`blazesym::inspect::Inspector`]. + */ typedef struct blaze_inspector blaze_inspector; /** -* An object representing an ELF inspection source. -* -* C ABI compatible version of [`inspect::Elf`]. -*/ + * An object representing an ELF inspection source. + * + * C ABI compatible version of [`inspect::Elf`]. + */ typedef struct blaze_inspect_elf_src { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * The path to the ELF file. This member is always present. - */ - const char *path; - /** - * Whether or not to consult debug symbols to satisfy the request - * (if present). - */ - bool debug_syms; - /** - * Unused member available for future expansion. Must be initialized - * to zero. - */ - uint8_t reserved[7]; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * The path to the ELF file. This member is always present. + */ + const char *path; + /** + * Whether or not to consult debug symbols to satisfy the request + * (if present). + */ + bool debug_syms; + /** + * Unused member available for future expansion. Must be initialized + * to zero. + */ + uint8_t reserved[7]; } blaze_inspect_elf_src; /** -* C ABI compatible version of [`blazesym::normalize::Normalizer`]. -*/ + * C ABI compatible version of [`blazesym::normalize::Normalizer`]. + */ typedef struct blaze_normalizer blaze_normalizer; /** -* Options for configuring [`blaze_normalizer`] objects. -*/ + * Options for configuring [`blaze_normalizer`] objects. + */ typedef struct blaze_normalizer_opts { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * Whether or not to cache `/proc//maps` contents. - * - * Setting this flag to `true` is not generally recommended, because it - * could result in addresses corresponding to mappings added after caching - * may not be normalized successfully, as there is no reasonable way of - * detecting staleness. - */ - bool cache_maps; - /** - * Whether to read and report build IDs as part of the normalization - * process. - */ - bool build_ids; - /** - * Whether or not to cache build IDs. This flag only has an effect - * if build ID reading is enabled in the first place. - */ - bool cache_build_ids; - /** - * Unused member available for future expansion. Must be initialized - * to zero. - */ - uint8_t reserved[5]; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * Whether or not to cache `/proc//maps` contents. + * + * Setting this flag to `true` is not generally recommended, because it + * could result in addresses corresponding to mappings added after caching + * may not be normalized successfully, as there is no reasonable way of + * detecting staleness. + */ + bool cache_maps; + /** + * Whether to read and report build IDs as part of the normalization + * process. + */ + bool build_ids; + /** + * Whether or not to cache build IDs. This flag only has an effect + * if build ID reading is enabled in the first place. + */ + bool cache_build_ids; + /** + * Unused member available for future expansion. Must be initialized + * to zero. + */ + uint8_t reserved[5]; } blaze_normalizer_opts; /** -* C compatible version of [`Apk`]. -*/ + * C compatible version of [`Apk`]. + */ typedef struct blaze_user_meta_apk { - /** - * The canonical absolute path to the APK, including its name. - * This member is always present. - */ - char *path; - /** - * Unused member available for future expansion. - */ - uint8_t reserved[8]; + /** + * The canonical absolute path to the APK, including its name. + * This member is always present. + */ + char *path; + /** + * Unused member available for future expansion. + */ + uint8_t reserved[8]; } blaze_user_meta_apk; /** -* C compatible version of [`Elf`]. -*/ + * C compatible version of [`Elf`]. + */ typedef struct blaze_user_meta_elf { - /** - * The path to the ELF file. This member is always present. - */ - char *path; - /** - * The length of the build ID, in bytes. - */ - size_t build_id_len; - /** - * The optional build ID of the ELF file, if found. - */ - uint8_t *build_id; - /** - * Unused member available for future expansion. - */ - uint8_t reserved[8]; + /** + * The path to the ELF file. This member is always present. + */ + char *path; + /** + * The length of the build ID, in bytes. + */ + size_t build_id_len; + /** + * The optional build ID of the ELF file, if found. + */ + uint8_t *build_id; + /** + * Unused member available for future expansion. + */ + uint8_t reserved[8]; } blaze_user_meta_elf; /** -* C compatible version of [`Unknown`]. -*/ + * C compatible version of [`Unknown`]. + */ typedef struct blaze_user_meta_unknown { - /** - * The reason why normalization failed. - * - * The provided reason is a best guess, hinting at what ultimately - * prevented the normalization from being successful. - */ - blaze_normalize_reason reason; - /** - * Unused member available for future expansion. - */ - uint8_t reserved[7]; + /** + * The reason why normalization failed. + * + * The provided reason is a best guess, hinting at what ultimately + * prevented the normalization from being successful. + */ + blaze_normalize_reason reason; + /** + * Unused member available for future expansion. + */ + uint8_t reserved[7]; } blaze_user_meta_unknown; /** -* The actual variant data in [`blaze_user_meta`]. -*/ + * The actual variant data in [`blaze_user_meta`]. + */ typedef union blaze_user_meta_variant { - /** - * Valid on [`blaze_user_meta_kind::BLAZE_USER_META_APK`]. - */ - struct blaze_user_meta_apk apk; - /** - * Valid on [`blaze_user_meta_kind::BLAZE_USER_META_ELF`]. - */ - struct blaze_user_meta_elf elf; - /** - * Valid on [`blaze_user_meta_kind::BLAZE_USER_META_UNKNOWN`]. - */ - struct blaze_user_meta_unknown unknown; + /** + * Valid on [`blaze_user_meta_kind::BLAZE_USER_META_APK`]. + */ + struct blaze_user_meta_apk apk; + /** + * Valid on [`blaze_user_meta_kind::BLAZE_USER_META_ELF`]. + */ + struct blaze_user_meta_elf elf; + /** + * Valid on [`blaze_user_meta_kind::BLAZE_USER_META_UNKNOWN`]. + */ + struct blaze_user_meta_unknown unknown; } blaze_user_meta_variant; /** -* C ABI compatible version of [`UserMeta`]. -*/ + * C ABI compatible version of [`UserMeta`]. + */ typedef struct blaze_user_meta { - /** - * The variant kind that is present. - */ - enum blaze_user_meta_kind kind; - /** - * The actual variant with its data. - */ - union blaze_user_meta_variant variant; + /** + * The variant kind that is present. + */ + enum blaze_user_meta_kind kind; + /** + * The actual variant with its data. + */ + union blaze_user_meta_variant variant; } blaze_user_meta; /** -* A file offset or non-normalized address along with an index into the -* associated [`blaze_user_meta`] array (such as -* [`blaze_normalized_user_output::metas`]). -*/ + * A file offset or non-normalized address along with an index into the + * associated [`blaze_user_meta`] array (such as + * [`blaze_normalized_user_output::metas`]). + */ typedef struct blaze_normalized_output { - /** - * The file offset or non-normalized address. - */ - uint64_t output; - /** - * The index into the associated [`blaze_user_meta`] array. - */ - size_t meta_idx; + /** + * The file offset or non-normalized address. + */ + uint64_t output; + /** + * The index into the associated [`blaze_user_meta`] array. + */ + size_t meta_idx; } blaze_normalized_output; /** -* An object representing normalized user addresses. -* -* C ABI compatible version of [`UserOutput`]. -*/ + * An object representing normalized user addresses. + * + * C ABI compatible version of [`UserOutput`]. + */ typedef struct blaze_normalized_user_output { - /** - * The number of [`blaze_user_meta`] objects present in `metas`. - */ - size_t meta_cnt; - /** - * An array of `meta_cnt` objects. - */ - struct blaze_user_meta *metas; - /** - * The number of [`blaze_normalized_output`] objects present in `outputs`. - */ - size_t output_cnt; - /** - * An array of `output_cnt` objects. - */ - struct blaze_normalized_output *outputs; - /** - * Unused member available for future expansion. - */ - uint8_t reserved[8]; + /** + * The number of [`blaze_user_meta`] objects present in `metas`. + */ + size_t meta_cnt; + /** + * An array of `meta_cnt` objects. + */ + struct blaze_user_meta *metas; + /** + * The number of [`blaze_normalized_output`] objects present in `outputs`. + */ + size_t output_cnt; + /** + * An array of `output_cnt` objects. + */ + struct blaze_normalized_output *outputs; + /** + * Unused member available for future expansion. + */ + uint8_t reserved[8]; } blaze_normalized_user_output; /** -* Options influencing the address normalization process. -*/ + * Options influencing the address normalization process. + */ typedef struct blaze_normalize_opts { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * Whether or not addresses are sorted (in ascending order) already. - * - * Normalization always happens on sorted addresses and if the addresses - * are sorted already, the library does not need to sort and later restore - * original ordering, speeding up the normalization process. - */ - bool sorted_addrs; - /** - * Whether to report `/proc//map_files/` entry paths or work - * with symbolic paths mentioned in `/proc//maps` instead. - * - * Relying on `map_files` may make sense in cases where - * symbolization happens on the local system and the reported paths - * can be worked with directly. In most other cases where one wants - * to attach meaning to symbolic paths on a remote system (e.g., by - * using them for file look up) symbolic paths are probably the - * better choice. - */ - bool map_files; - /** - * Unused member available for future expansion. Must be initialized - * to zero. - */ - uint8_t reserved[6]; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * Whether or not addresses are sorted (in ascending order) already. + * + * Normalization always happens on sorted addresses and if the addresses + * are sorted already, the library does not need to sort and later restore + * original ordering, speeding up the normalization process. + */ + bool sorted_addrs; + /** + * Whether to report `/proc//map_files/` entry paths or work + * with symbolic paths mentioned in `/proc//maps` instead. + * + * Relying on `map_files` may make sense in cases where + * symbolization happens on the local system and the reported paths + * can be worked with directly. In most other cases where one wants + * to attach meaning to symbolic paths on a remote system (e.g., by + * using them for file look up) symbolic paths are probably the + * better choice. + */ + bool map_files; + /** + * Unused member available for future expansion. Must be initialized + * to zero. + */ + uint8_t reserved[6]; } blaze_normalize_opts; /** -* C ABI compatible version of [`blazesym::symbolize::Symbolizer`]. -* -* It is returned by [`blaze_symbolizer_new`] and should be free by -* [`blaze_symbolizer_free`]. -*/ + * C ABI compatible version of [`blazesym::symbolize::Symbolizer`]. + * + * It is returned by [`blaze_symbolizer_new`] and should be free by + * [`blaze_symbolizer_free`]. + */ typedef struct blaze_symbolizer blaze_symbolizer; /** -* Options for configuring [`blaze_symbolizer`] objects. -*/ + * Options for configuring [`blaze_symbolizer`] objects. + */ typedef struct blaze_symbolizer_opts { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * Array of debug directories to search for split debug information. - * - * These directories will be consulted (in given order) when resolving - * debug links in binaries. By default and when this member is NULL, - * `/usr/lib/debug` and `/lib/debug/` will be searched. Setting an array - * here will overwrite these defaults, so make sure to include these - * directories as desired. - * - * Note that the directory containing a symbolization source is always an - * implicit candidate target directory of the highest precedence. - */ - const char *const *debug_dirs; - /** - * The number of array elements in `debug_dirs`. - */ - size_t debug_dirs_len; - /** - * Whether or not to automatically reload file system based - * symbolization sources that were updated since the last - * symbolization operation. - */ - bool auto_reload; - /** - * Whether to attempt to gather source code location information. - * - * This setting implies `debug_syms` (and forces it to `true`). - */ - bool code_info; - /** - * Whether to report inlined functions as part of symbolization. - */ - bool inlined_fns; - /** - * Whether or not to transparently demangle symbols. - * - * Demangling happens on a best-effort basis. Currently supported - * languages are Rust and C++ and the flag will have no effect if - * the underlying language does not mangle symbols (such as C). - */ - bool demangle; - /** - * Unused member available for future expansion. Must be initialized - * to zero. - */ - uint8_t reserved[4]; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * Array of debug directories to search for split debug information. + * + * These directories will be consulted (in given order) when resolving + * debug links in binaries. By default and when this member is NULL, + * `/usr/lib/debug` and `/lib/debug/` will be searched. Setting an array + * here will overwrite these defaults, so make sure to include these + * directories as desired. + * + * Note that the directory containing a symbolization source is always an + * implicit candidate target directory of the highest precedence. + */ + const char *const *debug_dirs; + /** + * The number of array elements in `debug_dirs`. + */ + size_t debug_dirs_len; + /** + * Whether or not to automatically reload file system based + * symbolization sources that were updated since the last + * symbolization operation. + */ + bool auto_reload; + /** + * Whether to attempt to gather source code location information. + * + * This setting implies `debug_syms` (and forces it to `true`). + */ + bool code_info; + /** + * Whether to report inlined functions as part of symbolization. + */ + bool inlined_fns; + /** + * Whether or not to transparently demangle symbols. + * + * Demangling happens on a best-effort basis. Currently supported + * languages are Rust and C++ and the flag will have no effect if + * the underlying language does not mangle symbols (such as C). + */ + bool demangle; + /** + * Unused member available for future expansion. Must be initialized + * to zero. + */ + uint8_t reserved[4]; } blaze_symbolizer_opts; /** -* Source code location information for a symbol or inlined function. -*/ + * Source code location information for a symbol or inlined function. + */ typedef struct blaze_symbolize_code_info { - /** - * The directory in which the source file resides. - * - * This attribute is optional and may be NULL. - */ - const char *dir; - /** - * The file that defines the symbol. - * - * This attribute is optional and may be NULL. - */ - const char *file; - /** - * The line number on which the symbol is located in the source - * code. - */ - uint32_t line; - /** - * The column number of the symbolized instruction in the source - * code. - */ - uint16_t column; - /** - * Unused member available for future expansion. - */ - uint8_t reserved[10]; + /** + * The directory in which the source file resides. + * + * This attribute is optional and may be NULL. + */ + const char *dir; + /** + * The file that defines the symbol. + * + * This attribute is optional and may be NULL. + */ + const char *file; + /** + * The line number on which the symbol is located in the source + * code. + */ + uint32_t line; + /** + * The column number of the symbolized instruction in the source + * code. + */ + uint16_t column; + /** + * Unused member available for future expansion. + */ + uint8_t reserved[10]; } blaze_symbolize_code_info; /** -* Data about an inlined function call. -*/ + * Data about an inlined function call. + */ typedef struct blaze_symbolize_inlined_fn { - /** - * The symbol name of the inlined function. - */ - const char *name; - /** - * Source code location information for the inlined function. - */ - struct blaze_symbolize_code_info code_info; - /** - * Unused member available for future expansion. - */ - uint8_t reserved[8]; + /** + * The symbol name of the inlined function. + */ + const char *name; + /** + * Source code location information for the inlined function. + */ + struct blaze_symbolize_code_info code_info; + /** + * Unused member available for future expansion. + */ + uint8_t reserved[8]; } blaze_symbolize_inlined_fn; /** -* The result of symbolization of an address. -* -* A `blaze_sym` is the information of a symbol found for an -* address. -*/ + * The result of symbolization of an address. + * + * A `blaze_sym` is the information of a symbol found for an + * address. + */ typedef struct blaze_sym { - /** - * The symbol name is where the given address should belong to. - * - * If an address could not be symbolized, this member will be NULL. - */ - const char *name; - /** - * The address at which the symbol is located (i.e., its "start"). - * - * This is the "normalized" address of the symbol, as present in - * the file (and reported by tools such as `readelf(1)`, - * `llvm-gsymutil`, or similar). - */ - uintptr_t addr; - /** - * The byte offset of the address that got symbolized from the - * start of the symbol (i.e., from `addr`). - * - * E.g., when symbolizing address 0x1337 of a function that starts at - * 0x1330, the offset will be set to 0x07 (and `addr` will be 0x1330). This - * member is especially useful in contexts when input addresses are not - * already normalized, such as when symbolizing an address in a process - * context (which may have been relocated and/or have layout randomizations - * applied). - */ - size_t offset; - /** - * Source code location information for the symbol. - */ - struct blaze_symbolize_code_info code_info; - /** - * The number of symbolized inlined function calls present. - */ - size_t inlined_cnt; - /** - * An array of `inlined_cnt` symbolized inlined function calls. - */ - const struct blaze_symbolize_inlined_fn *inlined; - /** - * On error (i.e., if `name` is NULL), a reason trying to explain - * why symbolization failed. - */ - blaze_symbolize_reason reason; - /** - * Unused member available for future expansion. - */ - uint8_t reserved[7]; + /** + * The symbol name is where the given address should belong to. + * + * If an address could not be symbolized, this member will be NULL. + */ + const char *name; + /** + * The address at which the symbol is located (i.e., its "start"). + * + * This is the "normalized" address of the symbol, as present in + * the file (and reported by tools such as `readelf(1)`, + * `llvm-gsymutil`, or similar). + */ + uintptr_t addr; + /** + * The byte offset of the address that got symbolized from the + * start of the symbol (i.e., from `addr`). + * + * E.g., when symbolizing address 0x1337 of a function that starts at + * 0x1330, the offset will be set to 0x07 (and `addr` will be 0x1330). This + * member is especially useful in contexts when input addresses are not + * already normalized, such as when symbolizing an address in a process + * context (which may have been relocated and/or have layout randomizations + * applied). + */ + size_t offset; + /** + * Source code location information for the symbol. + */ + struct blaze_symbolize_code_info code_info; + /** + * The number of symbolized inlined function calls present. + */ + size_t inlined_cnt; + /** + * An array of `inlined_cnt` symbolized inlined function calls. + */ + const struct blaze_symbolize_inlined_fn *inlined; + /** + * On error (i.e., if `name` is NULL), a reason trying to explain + * why symbolization failed. + */ + blaze_symbolize_reason reason; + /** + * Unused member available for future expansion. + */ + uint8_t reserved[7]; } blaze_sym; /** -* `blaze_result` is the result of symbolization for C API. -* -* Instances of [`blaze_result`] are returned by any of the `blaze_symbolize_*` -* variants. They should be freed by calling [`blaze_result_free`]. -*/ + * `blaze_result` is the result of symbolization for C API. + * + * Instances of [`blaze_result`] are returned by any of the `blaze_symbolize_*` + * variants. They should be freed by calling [`blaze_result_free`]. + */ typedef struct blaze_result { - /** - * The number of symbols being reported. - */ - size_t cnt; - /** - * The symbols corresponding to input addresses. - * - * Symbolization happens based on the ordering of (input) addresses. - * Therefore, every input address has an associated symbol. - */ - struct blaze_sym syms[0]; + /** + * The number of symbols being reported. + */ + size_t cnt; + /** + * The symbols corresponding to input addresses. + * + * Symbolization happens based on the ordering of (input) addresses. + * Therefore, every input address has an associated symbol. + */ + struct blaze_sym syms[0]; } blaze_result; /** -* The parameters to load symbols and debug information from a process. -* -* Load all ELF files in a process as the sources of symbols and debug -* information. -*/ + * The parameters to load symbols and debug information from a process. + * + * Load all ELF files in a process as the sources of symbols and debug + * information. + */ typedef struct blaze_symbolize_src_process { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * It is the PID of a process to symbolize. - * - * blazesym will parse `/proc//maps` and load all the object - * files. - */ - uint32_t pid; - /** - * Whether or not to consult debug symbols to satisfy the request - * (if present). - */ - bool debug_syms; - /** - * Whether to incorporate a process' perf map file into the symbolization - * procedure. - */ - bool perf_map; - /** - * Whether to work with `/proc//map_files/` entries or with - * symbolic paths mentioned in `/proc//maps` instead. - * `map_files` usage is generally strongly encouraged, as symbolic - * path usage is unlikely to work reliably in mount namespace - * contexts or when files have been deleted from the file system. - * However, by using symbolic paths the need for requiring the - * `SYS_ADMIN` capability is eliminated. - */ - bool map_files; - /** - * Unused member available for future expansion. Must be initialized - * to zero. - */ - uint8_t reserved[1]; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * It is the PID of a process to symbolize. + * + * blazesym will parse `/proc//maps` and load all the object + * files. + */ + uint32_t pid; + /** + * Whether or not to consult debug symbols to satisfy the request + * (if present). + */ + bool debug_syms; + /** + * Whether to incorporate a process' perf map file into the symbolization + * procedure. + */ + bool perf_map; + /** + * Whether to work with `/proc//map_files/` entries or with + * symbolic paths mentioned in `/proc//maps` instead. + * `map_files` usage is generally strongly encouraged, as symbolic + * path usage is unlikely to work reliably in mount namespace + * contexts or when files have been deleted from the file system. + * However, by using symbolic paths the need for requiring the + * `SYS_ADMIN` capability is eliminated. + */ + bool map_files; + /** + * Unused member available for future expansion. Must be initialized + * to zero. + */ + uint8_t reserved[1]; } blaze_symbolize_src_process; /** -* The parameters to load symbols and debug information from a kernel. -* -* Use a kernel image and a snapshot of its kallsyms as a source of symbols and -* debug information. -*/ + * The parameters to load symbols and debug information from a kernel. + * + * Use a kernel image and a snapshot of its kallsyms as a source of symbols and + * debug information. + */ typedef struct blaze_symbolize_src_kernel { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * The path of a copy of kallsyms. - * - * It can be `"/proc/kallsyms"` for the running kernel on the - * device. However, you can make copies for later. In that situation, - * you should give the path of a copy. - * Passing a `NULL`, by default, will result in `"/proc/kallsyms"`. - */ - const char *kallsyms; - /** - * The path of a kernel image. - * - * The path of a kernel image should be, for instance, - * `"/boot/vmlinux-xxxx"`. For a `NULL` value, it will locate the - * kernel image of the running kernel in `"/boot/"` or - * `"/usr/lib/debug/boot/"`. - */ - const char *kernel_image; - /** - * Whether or not to consult debug symbols from `kernel_image` - * to satisfy the request (if present). - */ - bool debug_syms; - /** - * Unused member available for future expansion. Must be initialized - * to zero. - */ - uint8_t reserved[7]; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * The path of a copy of kallsyms. + * + * It can be `"/proc/kallsyms"` for the running kernel on the + * device. However, you can make copies for later. In that situation, + * you should give the path of a copy. + * Passing a `NULL`, by default, will result in `"/proc/kallsyms"`. + */ + const char *kallsyms; + /** + * The path of a kernel image. + * + * The path of a kernel image should be, for instance, + * `"/boot/vmlinux-xxxx"`. For a `NULL` value, it will locate the + * kernel image of the running kernel in `"/boot/"` or + * `"/usr/lib/debug/boot/"`. + */ + const char *kernel_image; + /** + * Whether or not to consult debug symbols from `kernel_image` + * to satisfy the request (if present). + */ + bool debug_syms; + /** + * Unused member available for future expansion. Must be initialized + * to zero. + */ + uint8_t reserved[7]; } blaze_symbolize_src_kernel; /** -* The parameters to load symbols and debug information from an ELF. -* -* Describes the path and address of an ELF file loaded in a -* process. -*/ + * The parameters to load symbols and debug information from an ELF. + * + * Describes the path and address of an ELF file loaded in a + * process. + */ typedef struct blaze_symbolize_src_elf { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * The path to the ELF file. - * - * The referenced file may be an executable or shared object. For example, - * passing "/bin/sh" will load symbols and debug information from `sh` and - * passing "/lib/libc.so.xxx" will load symbols and debug information from - * libc. - */ - const char *path; - /** - * Whether or not to consult debug symbols to satisfy the request - * (if present). - */ - bool debug_syms; - /** - * Unused member available for future expansion. Must be initialized - * to zero. - */ - uint8_t reserved[7]; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * The path to the ELF file. + * + * The referenced file may be an executable or shared object. For example, + * passing "/bin/sh" will load symbols and debug information from `sh` and + * passing "/lib/libc.so.xxx" will load symbols and debug information from + * libc. + */ + const char *path; + /** + * Whether or not to consult debug symbols to satisfy the request + * (if present). + */ + bool debug_syms; + /** + * Unused member available for future expansion. Must be initialized + * to zero. + */ + uint8_t reserved[7]; } blaze_symbolize_src_elf; /** -* The parameters to load symbols and debug information from "raw" Gsym data. -*/ + * The parameters to load symbols and debug information from "raw" Gsym data. + */ typedef struct blaze_symbolize_src_gsym_data { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * The Gsym data. - */ - const uint8_t *data; - /** - * The size of the Gsym data. - */ - size_t data_len; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * The Gsym data. + */ + const uint8_t *data; + /** + * The size of the Gsym data. + */ + size_t data_len; } blaze_symbolize_src_gsym_data; /** -* The parameters to load symbols and debug information from a Gsym file. -*/ + * The parameters to load symbols and debug information from a Gsym file. + */ typedef struct blaze_symbolize_src_gsym_file { - /** - * The size of this object's type. - * - * Make sure to initialize it to `sizeof()`. This member is used to - * ensure compatibility in the presence of member additions. - */ - size_t type_size; - /** - * The path to a gsym file. - */ - const char *path; + /** + * The size of this object's type. + * + * Make sure to initialize it to `sizeof()`. This member is used to + * ensure compatibility in the presence of member additions. + */ + size_t type_size; + /** + * The path to a gsym file. + */ + const char *path; } blaze_symbolize_src_gsym_file; #ifdef __cplusplus @@ -852,378 +853,378 @@ extern "C" { #endif // __cplusplus /** -* Retrieve the error reported by the last fallible API function invoked. -*/ + * Retrieve the error reported by the last fallible API function invoked. + */ enum blaze_err blaze_err_last(void); /** -* Retrieve a textual representation of the error code. -*/ + * Retrieve a textual representation of the error code. + */ const char *blaze_err_str(enum blaze_err err); /** -* Lookup symbol information in an ELF file. -* -* On success, returns an array with `name_cnt` elements. Each such element, in -* turn, is NULL terminated array comprised of each symbol found. The returned -* object should be released using [`blaze_inspect_syms_free`] once it is no -* longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `inspector` needs to point to an initialized [`blaze_inspector`] object -* - `src` needs to point to an initialized [`blaze_inspect_syms_elf`] object -* - `names` needs to be a valid pointer to `name_cnt` NUL terminated strings -*/ + * Lookup symbol information in an ELF file. + * + * On success, returns an array with `name_cnt` elements. Each such element, in + * turn, is NULL terminated array comprised of each symbol found. The returned + * object should be released using [`blaze_inspect_syms_free`] once it is no + * longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `inspector` needs to point to an initialized [`blaze_inspector`] object + * - `src` needs to point to an initialized [`blaze_inspect_syms_elf`] object + * - `names` needs to be a valid pointer to `name_cnt` NUL terminated strings + */ const struct blaze_sym_info *const *blaze_inspect_syms_elf(const blaze_inspector *inspector, - const struct blaze_inspect_elf_src *src, - const char *const *names, - size_t name_cnt); + const struct blaze_inspect_elf_src *src, + const char *const *names, + size_t name_cnt); /** -* Free an array returned by [`blaze_inspect_syms_elf`]. -* -* # Safety -* -* The pointer must be returned by [`blaze_inspect_syms_elf`]. -*/ + * Free an array returned by [`blaze_inspect_syms_elf`]. + * + * # Safety + * + * The pointer must be returned by [`blaze_inspect_syms_elf`]. + */ void blaze_inspect_syms_free(const struct blaze_sym_info *const *syms); /** -* Create an instance of a blazesym inspector. -* -* C ABI compatible version of [`blazesym::inspect::Inspector::new()`]. -* Please refer to its documentation for the default configuration in -* use. -* -* On success, the function creates a new [`blaze_inspector`] object -* and returns it. The resulting object should be released using -* [`blaze_inspector_free`] once it is no longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -*/ + * Create an instance of a blazesym inspector. + * + * C ABI compatible version of [`blazesym::inspect::Inspector::new()`]. + * Please refer to its documentation for the default configuration in + * use. + * + * On success, the function creates a new [`blaze_inspector`] object + * and returns it. The resulting object should be released using + * [`blaze_inspector_free`] once it is no longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + */ blaze_inspector *blaze_inspector_new(void); /** -* Free a blazesym inspector. -* -* Release resources associated with a inspector as created by -* [`blaze_inspector_new`], for example. -* -* # Safety -* The provided inspector should have been created by -* [`blaze_inspector_new`]. -*/ + * Free a blazesym inspector. + * + * Release resources associated with a inspector as created by + * [`blaze_inspector_new`], for example. + * + * # Safety + * The provided inspector should have been created by + * [`blaze_inspector_new`]. + */ void blaze_inspector_free(blaze_inspector *inspector); /** -* Create an instance of a blazesym normalizer in the default -* configuration. -* -* C ABI compatible version of [`blazesym::normalize::Normalizer::new()`]. -* Please refer to its documentation for the default configuration in use. -* -* On success, the function creates a new [`blaze_normalizer`] object and -* returns it. The resulting object should be released using -* [`blaze_normalizer_free`] once it is no longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -*/ + * Create an instance of a blazesym normalizer in the default + * configuration. + * + * C ABI compatible version of [`blazesym::normalize::Normalizer::new()`]. + * Please refer to its documentation for the default configuration in use. + * + * On success, the function creates a new [`blaze_normalizer`] object and + * returns it. The resulting object should be released using + * [`blaze_normalizer_free`] once it is no longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + */ blaze_normalizer *blaze_normalizer_new(void); /** -* Create an instance of a blazesym normalizer. -* -* On success, the function creates a new [`blaze_normalizer`] object and -* returns it. The resulting object should be released using -* [`blaze_normalizer_free`] once it is no longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `opts` needs to point to a valid [`blaze_normalizer_opts`] object -*/ + * Create an instance of a blazesym normalizer. + * + * On success, the function creates a new [`blaze_normalizer`] object and + * returns it. The resulting object should be released using + * [`blaze_normalizer_free`] once it is no longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `opts` needs to point to a valid [`blaze_normalizer_opts`] object + */ blaze_normalizer *blaze_normalizer_new_opts(const struct blaze_normalizer_opts *opts); /** -* Free a blazesym normalizer. -* -* Release resources associated with a normalizer as created by -* [`blaze_normalizer_new`], for example. -* -* # Safety -* The provided normalizer should have been created by -* [`blaze_normalizer_new`]. -*/ + * Free a blazesym normalizer. + * + * Release resources associated with a normalizer as created by + * [`blaze_normalizer_new`], for example. + * + * # Safety + * The provided normalizer should have been created by + * [`blaze_normalizer_new`]. + */ void blaze_normalizer_free(blaze_normalizer *normalizer); /** -* Retrieve a textual representation of the reason of a normalization failure. -*/ + * Retrieve a textual representation of the reason of a normalization failure. + */ const char *blaze_normalize_reason_str(blaze_normalize_reason err); /** -* Normalize a list of user space addresses. -* -* C ABI compatible version of [`Normalizer::normalize_user_addrs`]. -* -* `pid` should describe the PID of the process to which the addresses -* belongs. It may be `0` if they belong to the calling process. -* -* On success, the function creates a new [`blaze_normalized_user_output`] -* object and returns it. The resulting object should be released using -* [`blaze_user_output_free`] once it is no longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `addrs` needs to be a valid pointer to `addr_cnt` addresses -*/ + * Normalize a list of user space addresses. + * + * C ABI compatible version of [`Normalizer::normalize_user_addrs`]. + * + * `pid` should describe the PID of the process to which the addresses + * belongs. It may be `0` if they belong to the calling process. + * + * On success, the function creates a new [`blaze_normalized_user_output`] + * object and returns it. The resulting object should be released using + * [`blaze_user_output_free`] once it is no longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `addrs` needs to be a valid pointer to `addr_cnt` addresses + */ struct blaze_normalized_user_output *blaze_normalize_user_addrs(const blaze_normalizer *normalizer, - uint32_t pid, - const uintptr_t *addrs, - size_t addr_cnt); + uint32_t pid, + const uintptr_t *addrs, + size_t addr_cnt); /** -* Normalize a list of user space addresses. -* -* C ABI compatible version of [`Normalizer::normalize_user_addrs_opts`]. -* -* `pid` should describe the PID of the process to which the addresses -* belongs. It may be `0` if they belong to the calling process. -* -* `opts` should point to a valid [`blaze_normalize_opts`] object. -* -* On success, the function creates a new [`blaze_normalized_user_output`] -* object and returns it. The resulting object should be released using -* [`blaze_user_output_free`] once it is no longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `addrs` needs to be a valid pointer to `addr_cnt` addresses -*/ + * Normalize a list of user space addresses. + * + * C ABI compatible version of [`Normalizer::normalize_user_addrs_opts`]. + * + * `pid` should describe the PID of the process to which the addresses + * belongs. It may be `0` if they belong to the calling process. + * + * `opts` should point to a valid [`blaze_normalize_opts`] object. + * + * On success, the function creates a new [`blaze_normalized_user_output`] + * object and returns it. The resulting object should be released using + * [`blaze_user_output_free`] once it is no longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `addrs` needs to be a valid pointer to `addr_cnt` addresses + */ struct blaze_normalized_user_output *blaze_normalize_user_addrs_opts(const blaze_normalizer *normalizer, - uint32_t pid, - const uintptr_t *addrs, - size_t addr_cnt, - const struct blaze_normalize_opts *opts); + uint32_t pid, + const uintptr_t *addrs, + size_t addr_cnt, + const struct blaze_normalize_opts *opts); /** -* Free an object as returned by [`blaze_normalize_user_addrs`] or -* [`blaze_normalize_user_addrs_opts`]. -* -* # Safety -* The provided object should have been created by -* [`blaze_normalize_user_addrs`] or -* [`blaze_normalize_user_addrs_opts`]. -*/ + * Free an object as returned by [`blaze_normalize_user_addrs`] or + * [`blaze_normalize_user_addrs_opts`]. + * + * # Safety + * The provided object should have been created by + * [`blaze_normalize_user_addrs`] or + * [`blaze_normalize_user_addrs_opts`]. + */ void blaze_user_output_free(struct blaze_normalized_user_output *output); /** -* Retrieve a textual representation of the reason of a symbolization -* failure. -*/ + * Retrieve a textual representation of the reason of a symbolization + * failure. + */ const char *blaze_symbolize_reason_str(blaze_symbolize_reason err); /** -* Create an instance of a symbolizer. -* -* C ABI compatible version of [`blazesym::symbolize::Symbolizer::new()`]. -* Please refer to its documentation for the default configuration in use. -* -* On success, the function creates a new [`blaze_symbolizer`] object -* and returns it. The resulting object should be released using -* [`blaze_symbolizer_free`] once it is no longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -*/ + * Create an instance of a symbolizer. + * + * C ABI compatible version of [`blazesym::symbolize::Symbolizer::new()`]. + * Please refer to its documentation for the default configuration in use. + * + * On success, the function creates a new [`blaze_symbolizer`] object + * and returns it. The resulting object should be released using + * [`blaze_symbolizer_free`] once it is no longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + */ blaze_symbolizer *blaze_symbolizer_new(void); /** -* Create an instance of a symbolizer with configurable options. -* -* On success, the function creates a new [`blaze_symbolizer`] object -* and returns it. The resulting object should be released using -* [`blaze_symbolizer_free`] once it is no longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `opts` needs to point to a valid [`blaze_symbolizer_opts`] object -*/ + * Create an instance of a symbolizer with configurable options. + * + * On success, the function creates a new [`blaze_symbolizer`] object + * and returns it. The resulting object should be released using + * [`blaze_symbolizer_free`] once it is no longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `opts` needs to point to a valid [`blaze_symbolizer_opts`] object + */ blaze_symbolizer *blaze_symbolizer_new_opts(const struct blaze_symbolizer_opts *opts); /** -* Free an instance of blazesym a symbolizer for C API. -* -* # Safety -* -* The pointer must have been returned by [`blaze_symbolizer_new`] or -* [`blaze_symbolizer_new_opts`]. -*/ + * Free an instance of blazesym a symbolizer for C API. + * + * # Safety + * + * The pointer must have been returned by [`blaze_symbolizer_new`] or + * [`blaze_symbolizer_new_opts`]. + */ void blaze_symbolizer_free(blaze_symbolizer *symbolizer); /** -* Symbolize a list of process absolute addresses. -* -* On success, the function returns a [`blaze_result`] containing an -* array of `abs_addr_cnt` [`blaze_sym`] objects. The returned object -* should be released using [`blaze_result_free`] once it is no longer -* needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object -* - `src` needs to point to a valid [`blaze_symbolize_src_process`] object -* -`abs_addrs` point to an array of `abs_addr_cnt` addresses -*/ + * Symbolize a list of process absolute addresses. + * + * On success, the function returns a [`blaze_result`] containing an + * array of `abs_addr_cnt` [`blaze_sym`] objects. The returned object + * should be released using [`blaze_result_free`] once it is no longer + * needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object + * - `src` needs to point to a valid [`blaze_symbolize_src_process`] object + * -`abs_addrs` point to an array of `abs_addr_cnt` addresses + */ const struct blaze_result *blaze_symbolize_process_abs_addrs(blaze_symbolizer *symbolizer, - const struct blaze_symbolize_src_process *src, - const uintptr_t *abs_addrs, - size_t abs_addr_cnt); + const struct blaze_symbolize_src_process *src, + const uintptr_t *abs_addrs, + size_t abs_addr_cnt); /** -* Symbolize a list of kernel absolute addresses. -* -* On success, the function returns a [`blaze_result`] containing an -* array of `abs_addr_cnt` [`blaze_sym`] objects. The returned object -* should be released using [`blaze_result_free`] once it is no longer -* needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object -* - `src` needs to point to a valid [`blaze_symbolize_src_kernel`] object -* -`abs_addrs` point to an array of `abs_addr_cnt` addresses -*/ + * Symbolize a list of kernel absolute addresses. + * + * On success, the function returns a [`blaze_result`] containing an + * array of `abs_addr_cnt` [`blaze_sym`] objects. The returned object + * should be released using [`blaze_result_free`] once it is no longer + * needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object + * - `src` needs to point to a valid [`blaze_symbolize_src_kernel`] object + * -`abs_addrs` point to an array of `abs_addr_cnt` addresses + */ const struct blaze_result *blaze_symbolize_kernel_abs_addrs(blaze_symbolizer *symbolizer, - const struct blaze_symbolize_src_kernel *src, - const uintptr_t *abs_addrs, - size_t abs_addr_cnt); + const struct blaze_symbolize_src_kernel *src, + const uintptr_t *abs_addrs, + size_t abs_addr_cnt); /** -* Symbolize virtual offsets in an ELF file. -* -* On success, the function returns a [`blaze_result`] containing an -* array of `virt_offset_cnt` [`blaze_sym`] objects. The returned -* object should be released using [`blaze_result_free`] once it is no -* longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object -* - `src` needs to point to a valid [`blaze_symbolize_src_elf`] object -* -`virt_offsets` point to an array of `virt_offset_cnt` addresses -*/ + * Symbolize virtual offsets in an ELF file. + * + * On success, the function returns a [`blaze_result`] containing an + * array of `virt_offset_cnt` [`blaze_sym`] objects. The returned + * object should be released using [`blaze_result_free`] once it is no + * longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object + * - `src` needs to point to a valid [`blaze_symbolize_src_elf`] object + * -`virt_offsets` point to an array of `virt_offset_cnt` addresses + */ const struct blaze_result *blaze_symbolize_elf_virt_offsets(blaze_symbolizer *symbolizer, - const struct blaze_symbolize_src_elf *src, - const uintptr_t *virt_offsets, - size_t virt_offset_cnt); + const struct blaze_symbolize_src_elf *src, + const uintptr_t *virt_offsets, + size_t virt_offset_cnt); /** -* Symbolize file offsets in an ELF file. -* -* On success, the function returns a [`blaze_result`] containing an -* array of `file_offset_cnt` [`blaze_sym`] objects. The returned -* object should be released using [`blaze_result_free`] once it is no -* longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object -* - `src` needs to point to a valid [`blaze_symbolize_src_elf`] object -* -`file_offsets` point to an array of `file_offset_cnt` addresses -*/ + * Symbolize file offsets in an ELF file. + * + * On success, the function returns a [`blaze_result`] containing an + * array of `file_offset_cnt` [`blaze_sym`] objects. The returned + * object should be released using [`blaze_result_free`] once it is no + * longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object + * - `src` needs to point to a valid [`blaze_symbolize_src_elf`] object + * -`file_offsets` point to an array of `file_offset_cnt` addresses + */ const struct blaze_result *blaze_symbolize_elf_file_offsets(blaze_symbolizer *symbolizer, - const struct blaze_symbolize_src_elf *src, - const uintptr_t *file_offsets, - size_t file_offset_cnt); + const struct blaze_symbolize_src_elf *src, + const uintptr_t *file_offsets, + size_t file_offset_cnt); /** -* Symbolize virtual offsets using "raw" Gsym data. -* -* On success, the function returns a [`blaze_result`] containing an -* array of `virt_offset_cnt` [`blaze_sym`] objects. The returned -* object should be released using [`blaze_result_free`] once it is no -* longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object -* - `src` needs to point to a valid [`blaze_symbolize_src_gsym_data`] object -* -`virt_offsets` point to an array of `virt_offset_cnt` addresses -*/ + * Symbolize virtual offsets using "raw" Gsym data. + * + * On success, the function returns a [`blaze_result`] containing an + * array of `virt_offset_cnt` [`blaze_sym`] objects. The returned + * object should be released using [`blaze_result_free`] once it is no + * longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object + * - `src` needs to point to a valid [`blaze_symbolize_src_gsym_data`] object + * -`virt_offsets` point to an array of `virt_offset_cnt` addresses + */ const struct blaze_result *blaze_symbolize_gsym_data_virt_offsets(blaze_symbolizer *symbolizer, - const struct blaze_symbolize_src_gsym_data *src, - const uintptr_t *virt_offsets, - size_t virt_offset_cnt); + const struct blaze_symbolize_src_gsym_data *src, + const uintptr_t *virt_offsets, + size_t virt_offset_cnt); /** -* Symbolize virtual offsets in a Gsym file. -* -* On success, the function returns a [`blaze_result`] containing an -* array of `virt_offset_cnt` [`blaze_sym`] objects. The returned -* object should be released using [`blaze_result_free`] once it is no -* longer needed. -* -* On error, the function returns `NULL` and sets the thread's last error to -* indicate the problem encountered. Use [`blaze_err_last`] to retrieve this -* error. -* -* # Safety -* - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object -* - `src` needs to point to a valid [`blaze_symbolize_src_gsym_file`] object -* -`virt_offsets` point to an array of `virt_offset_cnt` addresses -*/ + * Symbolize virtual offsets in a Gsym file. + * + * On success, the function returns a [`blaze_result`] containing an + * array of `virt_offset_cnt` [`blaze_sym`] objects. The returned + * object should be released using [`blaze_result_free`] once it is no + * longer needed. + * + * On error, the function returns `NULL` and sets the thread's last error to + * indicate the problem encountered. Use [`blaze_err_last`] to retrieve this + * error. + * + * # Safety + * - `symbolizer` needs to point to a valid [`blaze_symbolizer`] object + * - `src` needs to point to a valid [`blaze_symbolize_src_gsym_file`] object + * -`virt_offsets` point to an array of `virt_offset_cnt` addresses + */ const struct blaze_result *blaze_symbolize_gsym_file_virt_offsets(blaze_symbolizer *symbolizer, - const struct blaze_symbolize_src_gsym_file *src, - const uintptr_t *virt_offsets, - size_t virt_offset_cnt); + const struct blaze_symbolize_src_gsym_file *src, + const uintptr_t *virt_offsets, + size_t virt_offset_cnt); /** -* Free an array returned by any of the `blaze_symbolize_*` variants. -* -* # Safety -* The pointer must have been returned by any of the `blaze_symbolize_*` -* variants. -*/ + * Free an array returned by any of the `blaze_symbolize_*` variants. + * + * # Safety + * The pointer must have been returned by any of the `blaze_symbolize_*` + * variants. + */ void blaze_result_free(const struct blaze_result *results); #ifdef __cplusplus } // extern "C" #endif // __cplusplus -#endif /* __blazesym_h_ */ \ No newline at end of file +#endif /* __blazesym_h_ */