stacker-0.1.9/.github/workflows/psm.yml010064400017500000144000000224461365441035100163230ustar0000000000000000name: Test psm on: push: paths: - 'psm/**' - '.github/workflows/psm.yml' - '!psm/**.mkd' - '!psm/LICENSE-*' pull_request: types: [opened, repoened, synchronize] jobs: native-test: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: rust_toolchain: [nightly, stable, 1.38.0] os: [ubuntu-latest, windows-latest, macOS-latest] timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust ${{ matrix.rust_toolchain }} uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust_toolchain }} profile: minimal default: true - name: Update uses: actions-rs/cargo@v1 with: command: update args: --manifest-path=psm/Cargo.toml - name: Build uses: actions-rs/cargo@v1 with: command: build args: --manifest-path=psm/Cargo.toml - name: Test uses: actions-rs/cargo@v1 with: command: test args: --manifest-path=psm/Cargo.toml -- --nocapture - name: Test Examples uses: actions-rs/cargo@v1 with: command: test args: --manifest-path=psm/Cargo.toml --examples -- --nocapture - name: Test Release uses: actions-rs/cargo@v1 with: command: test args: --manifest-path=psm/Cargo.toml --release -- --nocapture - name: Test Release Examples uses: actions-rs/cargo@v1 with: command: test args: --manifest-path=psm/Cargo.toml --examples --release -- --nocapture windows-gnu-test: runs-on: windows-latest strategy: fail-fast: false matrix: rust_toolchain: [nightly, stable] rust_target: - x86_64-pc-windows-gnu # Only 64 bit GCC is preinstalled #- i686-pc-windows-gnu steps: - uses: actions/checkout@v2 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust_toolchain }} profile: minimal target: ${{ matrix.rust_target }} default: true # https://github.com/rust-lang/rust/issues/49078 - name: Fix windows-gnu rust-mingw run : | for i in crt2.o dllcrt2.o libmingwex.a libmsvcrt.a ; do cp -f "/C/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/lib/$i" "`rustc --print sysroot`/lib/rustlib/x86_64-pc-windows-gnu/lib" done shell: bash - uses: actions-rs/cargo@v1 with: command: build args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml - uses: actions-rs/cargo@v1 with: command: test args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml cross-linux-test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust_target: - aarch64-linux-android - arm-linux-androideabi - armv7-linux-androideabi - x86_64-linux-android - aarch64-unknown-linux-gnu - arm-unknown-linux-gnueabi - armv7-unknown-linux-gnueabihf - i686-unknown-linux-gnu - i686-unknown-linux-musl - mips-unknown-linux-gnu - mips64-unknown-linux-gnuabi64 - mips64el-unknown-linux-gnuabi64 - mipsel-unknown-linux-gnu - powerpc-unknown-linux-gnu - powerpc64-unknown-linux-gnu - x86_64-unknown-linux-musl timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal target: ${{ matrix.rust_target }} default: true - name: Update uses: actions-rs/cargo@v1 with: command: update args: --manifest-path=psm/Cargo.toml - name: Build ${{ matrix.rust_target }} uses: actions-rs/cargo@v1 with: use-cross: true command: build args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml - name: Test uses: actions-rs/cargo@v1 with: use-cross: true command: test args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml -- --test-threads=1 --nocapture - name: Test Examples uses: actions-rs/cargo@v1 with: use-cross: true command: test args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml --examples -- --test-threads=1 --nocapture - name: Test Release uses: actions-rs/cargo@v1 with: use-cross: true command: test args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml --release -- --test-threads=1 --nocapture - name: Test Release Examples uses: actions-rs/cargo@v1 with: use-cross: true command: test args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml --examples --release -- --test-threads=1 --nocapture cross-build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust_target: # https://github.com/rust-embedded/cross/issues/333 - powerpc64le-unknown-linux-gnu # FIXME: Testing hangs, should be verified once-in-a-while manually. # could be made work by using full system emulation # https://github.com/rust-embedded/cross/issues/242 # # Currently tested manually with full-system emulation. - s390x-unknown-linux-gnu # FIXME: tests could be made work by using full system emulation, maybe? # # Currently tested manually on real hardware. - sparc64-unknown-linux-gnu # BSDs: could be tested with full system emulation - x86_64-unknown-netbsd timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal target: ${{ matrix.rust_target }} default: true - name: Update uses: actions-rs/cargo@v1 with: command: update args: --manifest-path=psm/Cargo.toml - name: Build ${{ matrix.rust_target }} uses: actions-rs/cargo@v1 with: use-cross: true command: build args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml bare-cross-build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust_target: # BSDs: could be tested with full system emulation - i686-unknown-freebsd - x86_64-unknown-freebsd timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal target: ${{ matrix.rust_target }} default: true - name: Update uses: actions-rs/cargo@v1 with: command: update args: --manifest-path=psm/Cargo.toml - name: Build ${{ matrix.rust_target }} uses: actions-rs/cargo@v1 with: command: build args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml cross-ios-build: runs-on: macos-latest strategy: fail-fast: false matrix: rust_toolchain: [nightly, stable] rust_target: - aarch64-apple-ios - x86_64-apple-ios timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust ${{ matrix.rust_toolchain }} uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust_toolchain }} profile: minimal target: ${{ matrix.rust_target }} default: true - name: Update uses: actions-rs/cargo@v1 with: command: update args: --manifest-path=psm/Cargo.toml - name: Build ${{ matrix.rust_target }} uses: actions-rs/cargo@v1 with: command: build args: --target=${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml cross-build-without-std: runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust_target: - wasm32-wasi # cannot be built because cross-toolchains are not easily available and LLVM fails # generating code when building libcore anyway...? # - sparcv9-sun-solaris # - sparc-unknown-linux-gnu timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal default: true - name: Fix-up toolchain run: | rustup component add rust-src --toolchain nightly --target ${{ matrix.rust_target }} - name: Build ${{ matrix.rust_target }} uses: actions-rs/cargo@v1 with: command: build args: --target ${{ matrix.rust_target }} --manifest-path=psm/Cargo.toml -Zbuild-std=core stacker-0.1.9/.github/workflows/stacker.yml010064400017500000144000000131561365441035100171560ustar0000000000000000name: Test stacker on: push: paths-ignore: - '**.md' - '**.mkd' - 'LICENSE-*' pull_request: types: [opened, repoened, synchronize] jobs: native-test: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: rust_toolchain: [nightly, stable, 1.38.0] os: [ubuntu-latest, windows-latest, macOS-latest] timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust ${{ matrix.rust_toolchain }} uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust_toolchain }} profile: minimal default: true - name: Build uses: actions-rs/cargo@v1 with: command: build - name: Test uses: actions-rs/cargo@v1 with: command: test - name: Test Release uses: actions-rs/cargo@v1 with: command: test args: --release windows-gnu-test: runs-on: windows-latest strategy: fail-fast: false matrix: rust_toolchain: [nightly, stable] rust_target: - x86_64-pc-windows-gnu # Only 64 bit GCC is preinstalled #- i686-pc-windows-gnu steps: - uses: actions/checkout@v2 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust_toolchain }} profile: minimal target: ${{ matrix.rust_target }} default: true # https://github.com/rust-lang/rust/issues/49078 - name: Fix windows-gnu rust-mingw run : | for i in crt2.o dllcrt2.o libmingwex.a libmsvcrt.a ; do cp -f "/C/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/lib/$i" "`rustc --print sysroot`/lib/rustlib/x86_64-pc-windows-gnu/lib" done shell: bash - uses: actions-rs/cargo@v1 with: command: build args: --target ${{ matrix.rust_target }} - uses: actions-rs/cargo@v1 with: command: test args: --target ${{ matrix.rust_target }} cross-linux-test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust_target: - aarch64-linux-android - arm-linux-androideabi - armv7-linux-androideabi - x86_64-linux-android - aarch64-unknown-linux-gnu - arm-unknown-linux-gnueabi - armv7-unknown-linux-gnueabihf - i686-unknown-linux-gnu - i686-unknown-linux-musl - mips-unknown-linux-gnu - mips64-unknown-linux-gnuabi64 - mips64el-unknown-linux-gnuabi64 - mipsel-unknown-linux-gnu - powerpc-unknown-linux-gnu - powerpc64-unknown-linux-gnu - x86_64-unknown-linux-musl timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal target: ${{ matrix.rust_target }} default: true - name: Build uses: actions-rs/cargo@v1 with: use-cross: true command: build args: --target ${{ matrix.rust_target }} - name: Test uses: actions-rs/cargo@v1 with: use-cross: true command: test args: --target ${{ matrix.rust_target }} -- --test-threads=1 - name: Test Release uses: actions-rs/cargo@v1 with: use-cross: true command: test args: --target ${{ matrix.rust_target }} --release -- --test-threads=1 cross-build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust_target: # https://github.com/rust-embedded/cross/issues/333 - powerpc64le-unknown-linux-gnu # FIXME: Testing hangs, should be verified once-in-a-while manually. # could be made work by using full system emulation # https://github.com/rust-embedded/cross/issues/242 # # Currently tested manually with full-system emulation. - s390x-unknown-linux-gnu # FIXME: tests could be made work by using full system emulation, maybe? # # Currently tested manually on real hardware. - sparc64-unknown-linux-gnu # BSDs: could be tested with full system emulation - i686-unknown-freebsd - x86_64-unknown-freebsd - x86_64-unknown-netbsd - wasm32-wasi timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal target: ${{ matrix.rust_target }} default: true - uses: actions-rs/cargo@v1 with: use-cross: true command: build args: --target ${{ matrix.rust_target }} cross-ios-build: runs-on: macos-latest strategy: fail-fast: false matrix: rust_toolchain: [nightly, stable] rust_target: - aarch64-apple-ios - x86_64-apple-ios timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Install Rust ${{ matrix.rust_toolchain }} uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust_toolchain }} profile: minimal target: ${{ matrix.rust_target }} default: true - uses: actions-rs/cargo@v1 with: command: build args: --target=${{ matrix.rust_target }} stacker-0.1.9/.gitignore010064400017500000144000000000261365441035100133620ustar0000000000000000target Cargo.lock *.o stacker-0.1.9/Cargo.toml.orig010064400017500000144000000014401365552275400142760ustar0000000000000000[package] name = "stacker" version = "0.1.9" authors = ["Alex Crichton ", "Simonas Kazlauskas "] build = "build.rs" license = "MIT/Apache-2.0" readme = "README.md" repository = "https://github.com/rust-lang/stacker" homepage = "https://github.com/rust-lang/stacker" documentation = "https://docs.rs/stacker/0.1.9" description = """ A stack growth library useful when implementing deeply recursive algorithms that may accidentally blow the stack. """ [lib] name = "stacker" doctest = false test = false [dependencies] cfg-if = "0.1.6" libc = "0.2.45" psm = "0.1.7" [target.'cfg(windows)'.dependencies.winapi] version = "0.3.6" features = [ 'memoryapi', 'winbase', 'fibersapi', 'processthreadsapi', 'minwindef', ] [build-dependencies] cc = "1.0" stacker-0.1.9/Cargo.toml0000644000000025321365552345700106140ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "stacker" version = "0.1.9" authors = ["Alex Crichton ", "Simonas Kazlauskas "] build = "build.rs" description = "A stack growth library useful when implementing deeply recursive algorithms that\nmay accidentally blow the stack.\n" homepage = "https://github.com/rust-lang/stacker" documentation = "https://docs.rs/stacker/0.1.9" readme = "README.md" license = "MIT/Apache-2.0" repository = "https://github.com/rust-lang/stacker" [lib] name = "stacker" test = false doctest = false [dependencies.cfg-if] version = "0.1.6" [dependencies.libc] version = "0.2.45" [dependencies.psm] version = "0.1.7" [build-dependencies.cc] version = "1.0" [target."cfg(windows)".dependencies.winapi] version = "0.3.6" features = ["memoryapi", "winbase", "fibersapi", "processthreadsapi", "minwindef"] stacker-0.1.9/Cross.toml010064400017500000144000000001201365441035100133530ustar0000000000000000[target.x86_64-linux-android] image = "rustembedded/cross:x86_64-linux-android" stacker-0.1.9/LICENSE-APACHE010064400017500000144000000251371354641747600133470ustar0000000000000000 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 [yyyy] [name of copyright owner] 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. stacker-0.1.9/LICENSE-MIT010064400017500000144000000020411354641747600130440ustar0000000000000000Copyright (c) 2014 Alex Crichton 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. stacker-0.1.9/README.md010064400017500000144000000026131365441035100126550ustar0000000000000000# stacker [![Build Status](https://github.com/rust-lang/stacker/workflows/Test%20stacker/badge.svg)](https://github.com/rust-lang/stacker/actions) [Documentation](https://docs.rs/stacker) A stack-growth library for Rust. Enables annotating fixed points in programs where the stack may want to grow larger. Spills over to the heap if the stack has hit its limit. This library is intended on helping implement recursive algorithms. ```toml # Cargo.toml [dependencies] stacker = "0.1" ``` ## Platform Support This library currently uses psm for its cross platform capabilities, with a notable exception of Windows, which uses an implementation based on Fibers. See the README for psm for the support table. On all unsupported platforms this library is a noop. It should compile and run, but it won't actually grow the stack and code will continue to hit the guard pages typically in place. # License This project is licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. stacker-0.1.9/build.rs010064400017500000144000000015541365441035100130460ustar0000000000000000extern crate cc; use std::env; use std::path::PathBuf; fn main() { let target = env::var("TARGET").unwrap(); if target.starts_with("wasm32") { // wasm32 auxilary functions are provided as a precompiled object file. // this is because LLVM with wasm32 support isn't widespread. let mut link_dir = PathBuf::new(); link_dir.push(env!("CARGO_MANIFEST_DIR")); link_dir.push("src"); link_dir.push("arch"); link_dir.push("wasm32"); println!("cargo:rustc-link-search={}", link_dir.display()); println!("cargo:rustc-link-lib=stacker"); return; } let mut cfg = cc::Build::new(); if target.contains("windows") { cfg.define("WINDOWS", None); cfg.file("src/arch/windows.c"); cfg.include("src/arch").compile("libstacker.a"); } else { return; } } stacker-0.1.9/src/arch/asm.h010064400017500000144000000002361354641747700140520ustar0000000000000000#if defined(APPLE) || (defined(WINDOWS) && defined(X86)) #define GLOBAL(name) .globl _ ## name; _ ## name #else #define GLOBAL(name) .globl name; name #endif stacker-0.1.9/src/arch/windows.c010064400017500000144000000001411354641747700147520ustar0000000000000000#include PVOID __stacker_get_current_fiber() { return GetCurrentFiber(); } stacker-0.1.9/src/lib.rs010064400017500000144000000413051365552251400133100ustar0000000000000000//! A library to help grow the stack when it runs out of space. //! //! This is an implementation of manually instrumented segmented stacks where points in a program's //! control flow are annotated with "maybe grow the stack here". Each point of annotation indicates //! how far away from the end of the stack it's allowed to be, plus the amount of stack to allocate //! if it does reach the end. //! //! Once a program has reached the end of its stack, a temporary stack on the heap is allocated and //! is switched to for the duration of a closure. //! //! For a set of lower-level primitives, consider the `psm` crate. //! //! # Examples //! //! ``` //! // Grow the stack if we are within the "red zone" of 32K, and if we allocate //! // a new stack allocate 1MB of stack space. //! // //! // If we're already in bounds, just run the provided closure on current stack. //! stacker::maybe_grow(32 * 1024, 1024 * 1024, || { //! // guaranteed to have at least 32K of stack //! }); //! ``` #![allow(improper_ctypes)] #[macro_use] extern crate cfg_if; extern crate libc; #[cfg(windows)] extern crate winapi; #[macro_use] extern crate psm; use std::cell::Cell; /// Grows the call stack if necessary. /// /// This function is intended to be called at manually instrumented points in a program where /// recursion is known to happen quite a bit. This function will check to see if we're within /// `red_zone` bytes of the end of the stack, and if so it will allocate a new stack of at least /// `stack_size` bytes. /// /// The closure `f` is guaranteed to run on a stack with at least `red_zone` bytes, and it will be /// run on the current stack if there's space available. #[inline(always)] pub fn maybe_grow R>(red_zone: usize, stack_size: usize, callback: F) -> R { // if we can't guess the remaining stack (unsupported on some platforms) we immediately grow // the stack and then cache the new stack size (which we do know now because we allocated it. let enough_space = remaining_stack().map_or(false, |remaining| remaining >= red_zone); if enough_space { callback() } else { grow(stack_size, callback) } } /// Always creates a new stack for the passed closure to run on. /// The closure will still be on the same thread as the caller of `grow`. /// This will allocate a new stack with at least `stack_size` bytes. pub fn grow R>(stack_size: usize, callback: F) -> R { let mut ret = None; let ret_ref = &mut ret; _grow(stack_size, move || { *ret_ref = Some(callback()); }); ret.unwrap() } /// Queries the amount of remaining stack as interpreted by this library. /// /// This function will return the amount of stack space left which will be used /// to determine whether a stack switch should be made or not. pub fn remaining_stack() -> Option { let current_ptr = current_stack_ptr(); get_stack_limit().map(|limit| current_ptr - limit) } psm_stack_information! ( yes { fn current_stack_ptr() -> usize { psm::stack_pointer() as usize } } no { #[inline(always)] fn current_stack_ptr() -> usize { unsafe { let mut x = std::mem::MaybeUninit::::uninit(); // Unlikely to be ever exercised. As a fallback we execute a volatile read to a // local (to hopefully defeat the optimisations that would make this local a static // global) and take its address. This way we get a very approximate address of the // current frame. x.as_mut_ptr().write_volatile(42); x.as_ptr() as usize } } } ); thread_local! { static STACK_LIMIT: Cell> = Cell::new(unsafe { guess_os_stack_limit() }) } #[inline(always)] fn get_stack_limit() -> Option { STACK_LIMIT.with(|s| s.get()) } #[inline(always)] #[allow(unused)] fn set_stack_limit(l: Option) { STACK_LIMIT.with(|s| s.set(l)) } psm_stack_manipulation! { yes { struct StackRestoreGuard { new_stack: *mut libc::c_void, stack_bytes: usize, old_stack_limit: Option, } impl Drop for StackRestoreGuard { fn drop(&mut self) { unsafe { // FIXME: check the error code and decide what to do with it. // Perhaps a debug_assertion? libc::munmap(self.new_stack, self.stack_bytes); } set_stack_limit(self.old_stack_limit); } } fn _grow(stack_size: usize, callback: F) { // Calculate a number of pages we want to allocate for the new stack. // For maximum portability we want to produce a stack that is aligned to a page and has // a size that’s a multiple of page size. Furthermore we want to allocate two extras pages // for the stack guard. To achieve that we do our calculations in number of pages and // convert to bytes last. // FIXME: consider caching the page size. let page_size = unsafe { libc::sysconf(libc::_SC_PAGE_SIZE) } as usize; let requested_pages = stack_size .checked_add(page_size - 1) .expect("unreasonably large stack requested") / page_size; let stack_pages = std::cmp::max(1, requested_pages) + 2; let stack_bytes = stack_pages.checked_mul(page_size) .expect("unreasonably large stack requesteed"); // Next, there are a couple of approaches to how we allocate the new stack. We take the // most obvious path and use `mmap`. We also `mprotect` a guard page into our // allocation. // // We use a guard pattern to ensure we deallocate the allocated stack when we leave // this function and also try to uphold various safety invariants required by `psm` // (such as not unwinding from the callback we pass to it). // // Other than that this code has no meaningful gotchas. unsafe { let new_stack = libc::mmap( std::ptr::null_mut(), stack_bytes, libc::PROT_NONE, libc::MAP_PRIVATE | libc::MAP_ANON, -1, // Some implementations assert fd = -1 if MAP_ANON is specified 0 ); if new_stack == libc::MAP_FAILED { panic!("unable to allocate stack") } let guard = StackRestoreGuard { new_stack, stack_bytes, old_stack_limit: get_stack_limit(), }; let above_guard_page = new_stack.add(page_size); #[cfg(not(target_os = "openbsd"))] let result = libc::mprotect( above_guard_page, stack_bytes - page_size, libc::PROT_READ | libc::PROT_WRITE ); #[cfg(target_os = "openbsd")] let result = if libc::mmap( above_guard_page, stack_bytes - page_size, libc::PROT_READ | libc::PROT_WRITE, libc::MAP_FIXED | libc::MAP_PRIVATE | libc::MAP_ANON | libc::MAP_STACK, -1, 0) == above_guard_page { 0 } else { -1 }; if result == -1 { drop(guard); panic!("unable to set stack permissions") } set_stack_limit(Some(above_guard_page as usize)); let panic = psm::on_stack(above_guard_page as *mut _, stack_size, move || { std::panic::catch_unwind(std::panic::AssertUnwindSafe(callback)).err() }); drop(guard); if let Some(p) = panic { std::panic::resume_unwind(p); } } } } no { #[cfg(not(windows))] fn _grow(stack_size: usize, callback: F) { drop(stack_size); callback(); } } } cfg_if! { if #[cfg(windows)] { use std::ptr; use std::io; use winapi::shared::basetsd::*; use winapi::shared::minwindef::{LPVOID, BOOL}; use winapi::shared::ntdef::*; use winapi::um::fibersapi::*; use winapi::um::memoryapi::*; use winapi::um::processthreadsapi::*; use winapi::um::winbase::*; // Make sure the libstacker.a (implemented in C) is linked. // See https://github.com/rust-lang/rust/issues/65610 #[link(name="stacker")] extern { fn __stacker_get_current_fiber() -> PVOID; } struct FiberInfo { callback: std::mem::MaybeUninit, panic: Option>, parent_fiber: LPVOID, } unsafe extern "system" fn fiber_proc(data: LPVOID) { // This function is the entry point to our inner fiber, and as argument we get an // instance of `FiberInfo`. We will set-up the "runtime" for the callback and execute // it. let data = &mut *(data as *mut FiberInfo); let old_stack_limit = get_stack_limit(); set_stack_limit(guess_os_stack_limit()); let callback = data.callback.as_ptr(); data.panic = std::panic::catch_unwind(std::panic::AssertUnwindSafe(callback.read())).err(); // Restore to the previous Fiber set_stack_limit(old_stack_limit); SwitchToFiber(data.parent_fiber); return; } fn _grow(stack_size: usize, callback: F) { // Fibers (or stackful coroutines) is the only official way to create new stacks on the // same thread on Windows. So in order to extend the stack we create fiber and switch // to it so we can use it's stack. After running `callback` within our fiber, we switch // back to the current stack and destroy the fiber and its associated stack. unsafe { let was_fiber = IsThreadAFiber() == TRUE as BOOL; let mut data = FiberInfo { callback: std::mem::MaybeUninit::new(callback), panic: None, parent_fiber: { if was_fiber { // Get a handle to the current fiber. We need to use a C implementation // for this as GetCurrentFiber is an header only function. __stacker_get_current_fiber() } else { // Convert the current thread to a fiber, so we are able to switch back // to the current stack. Threads coverted to fibers still act like // regular threads, but they have associated fiber data. We later // convert it back to a regular thread and free the fiber data. ConvertThreadToFiber(ptr::null_mut()) } }, }; if data.parent_fiber.is_null() { panic!("unable to convert thread to fiber: {}", io::Error::last_os_error()); } let fiber = CreateFiber( stack_size as SIZE_T, Some(fiber_proc::), &mut data as *mut FiberInfo as *mut _, ); if fiber.is_null() { panic!("unable to allocate fiber: {}", io::Error::last_os_error()); } // Switch to the fiber we created. This changes stacks and starts executing // fiber_proc on it. fiber_proc will run `callback` and then switch back to run the // next statement. SwitchToFiber(fiber); DeleteFiber(fiber); // Clean-up. if !was_fiber { if ConvertFiberToThread() == 0 { // FIXME: Perhaps should not panic here? panic!("unable to convert back to thread: {}", io::Error::last_os_error()); } } if let Some(p) = data.panic { std::panic::resume_unwind(p); } } } #[inline(always)] fn get_thread_stack_guarantee() -> usize { let min_guarantee = if cfg!(target_pointer_width = "32") { 0x1000 } else { 0x2000 }; let mut stack_guarantee = 0; unsafe { // Read the current thread stack guarantee // This is the stack reserved for stack overflow // exception handling. // This doesn't return the true value so we need // some further logic to calculate the real stack // guarantee. This logic is what is used on x86-32 and // x86-64 Windows 10. Other versions and platforms may differ SetThreadStackGuarantee(&mut stack_guarantee) }; std::cmp::max(stack_guarantee, min_guarantee) as usize + 0x1000 } #[inline(always)] unsafe fn guess_os_stack_limit() -> Option { // Query the allocation which contains our stack pointer in order // to discover the size of the stack // // FIXME: we could read stack base from the TIB, specifically the 3rd element of it. type QueryT = winapi::um::winnt::MEMORY_BASIC_INFORMATION; let mut mi = std::mem::MaybeUninit::::uninit(); VirtualQuery( psm::stack_pointer() as *const _, mi.as_mut_ptr(), std::mem::size_of::() as SIZE_T, ); Some(mi.assume_init().AllocationBase as usize + get_thread_stack_guarantee() + 0x1000) } } else if #[cfg(any(target_os = "linux", target_os="solaris", target_os = "netbsd"))] { unsafe fn guess_os_stack_limit() -> Option { let mut attr = std::mem::MaybeUninit::::uninit(); assert_eq!(libc::pthread_attr_init(attr.as_mut_ptr()), 0); assert_eq!(libc::pthread_getattr_np(libc::pthread_self(), attr.as_mut_ptr()), 0); let mut stackaddr = std::ptr::null_mut(); let mut stacksize = 0; assert_eq!(libc::pthread_attr_getstack( attr.as_ptr(), &mut stackaddr, &mut stacksize ), 0); assert_eq!(libc::pthread_attr_destroy(attr.as_mut_ptr()), 0); Some(stackaddr as usize) } } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { unsafe fn guess_os_stack_limit() -> Option { let mut attr = std::mem::MaybeUninit::::uninit(); assert_eq!(libc::pthread_attr_init(attr.as_mut_ptr()), 0); assert_eq!(libc::pthread_attr_get_np(libc::pthread_self(), attr.as_mut_ptr()), 0); let mut stackaddr = std::ptr::null_mut(); let mut stacksize = 0; assert_eq!(libc::pthread_attr_getstack( attr.as_ptr(), &mut stackaddr, &mut stacksize ), 0); assert_eq!(libc::pthread_attr_destroy(attr.as_mut_ptr()), 0); Some(stackaddr as usize) } } else if #[cfg(target_os = "openbsd")] { unsafe fn guess_os_stack_limit() -> Option { let mut stackinfo = std::mem::MaybeUninit::::uninit(); assert_eq!(libc::pthread_stackseg_np(libc::pthread_self(), stackinfo.as_mut_ptr()), 0); Some(stackinfo.assume_init().ss_sp as usize - stackinfo.assume_init().ss_size) } } else if #[cfg(target_os = "macos")] { unsafe fn guess_os_stack_limit() -> Option { Some(libc::pthread_get_stackaddr_np(libc::pthread_self()) as usize - libc::pthread_get_stacksize_np(libc::pthread_self()) as usize) } } else { // fallback for other platforms is to always increase the stack if we're on // the root stack. After we increased the stack once, we know the new stack // size and don't need this pessimization anymore #[inline(always)] unsafe fn guess_os_stack_limit() -> Option { None } } } stacker-0.1.9/tests/simple.rs010064400017500000144000000007341365441035100144010ustar0000000000000000extern crate stacker; const RED_ZONE: usize = 100 * 1024; // 100k const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB pub fn ensure_sufficient_stack R + std::panic::UnwindSafe>(f: F) -> R { stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f) } #[inline(never)] fn recurse(n: usize) { let x = [42u8; 50000]; if n != 0 { ensure_sufficient_stack(|| recurse(n - 1)); } drop(x); } #[test] fn foo() { recurse(10000); } stacker-0.1.9/tests/smoke.rs010064400017500000144000000035131365441035100142240ustar0000000000000000extern crate stacker; use std::sync::mpsc; use std::thread; #[inline(never)] fn __stacker_black_box(_: *const u8) {} #[test] fn deep() { fn foo(n: usize, s: &mut [u8]) { __stacker_black_box(s.as_ptr()); if n > 0 { stacker::maybe_grow(64 * 1024, 1024 * 1024, || { let mut s = [0u8; 1024]; foo(n - 1, &mut s); __stacker_black_box(s.as_ptr()); }) } else { println!("bottom"); } } foo(256 * 1024, &mut []); } #[test] fn panic() { fn foo(n: usize, s: &mut [u8]) { __stacker_black_box(s.as_ptr()); if n > 0 { stacker::maybe_grow(64 * 1024, 1024 * 1024, || { let mut s = [0u8; 1024]; foo(n - 1, &mut s); __stacker_black_box(s.as_ptr()); }) } else { panic!("bottom"); } } let (tx, rx) = mpsc::channel::<()>(); thread::spawn(move || { foo(64 * 1024, &mut []); drop(tx); }) .join() .unwrap_err(); assert!(rx.recv().is_err()); } fn recursive(n: usize, f: F) -> usize { if n > 0 { stacker::grow(64 * 1024, || recursive(n - 1, f) + 1) } else { f(); 0 } } #[test] fn catch_panic() { let panic_result = std::panic::catch_unwind(|| { recursive(100, || panic!()); }); assert!(panic_result.is_err()); } #[test] fn catch_panic_inside() { stacker::grow(64 * 1024, || { let panic_result = std::panic::catch_unwind(|| { recursive(100, || panic!()); }); assert!(panic_result.is_err()); }); } #[test] fn catch_panic_leaf() { stacker::grow(64 * 1024, || { let panic_result = std::panic::catch_unwind(|| panic!()); assert!(panic_result.is_err()); }); } stacker-0.1.9/.cargo_vcs_info.json0000644000000001121365552345700126060ustar00{ "git": { "sha1": "9a01959e0d487a6de7b4b4d6a9cd2f046f00588c" } }