chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

1
vendor/stacker/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{".cargo_vcs_info.json":"c7d506ab60cffbbb9fcb697a189038b36daa2398cff963d2101a252bc3a0cff8",".github/workflows/test.yml":"1fbabdc82a5f66ffca672eac608df08ef2baa02547b3005015f1522f05e9f8b7","Cargo.lock":"830308b3ebac8a7ecda345b56f9ee3dc27d0adb8fbd53ff984552ce1d8569193","Cargo.toml":"4a6c0ea5efb9d40c579b98a0f26fda5ffd39d44547954f5a8ea4cc1e14ed30cf","Cargo.toml.orig":"740449861b316e10ef4328f3573b60f0148dd07089a99aba4a3309e2056dea3f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"3b4db90523bcff7d1381367418fdbdb3c866d13c95f1c4aa8185f2280ae33abb","build.rs":"8a9274309128a737566386f2534a93c69d2991da19a4543113790bc819448a53","src/alloc_stack_restore_guard.rs":"5bc62493772e407494ad48b9bf316688b7eb1b9c85f1f7a8fc183c80903697b6","src/arch/asm.h":"4c4db945e854e4ce3f0b7ba8da3755613c0e4513a7aab0604bd6a67c0ff2192d","src/arch/windows.c":"e98e08f6b5102480b8fa4dfa7ee13441845202f5ba81c60b13da2800e0a8630c","src/backends/fallback.rs":"9314cb7646b0542bf7bafd576c4aa98d6e1dd0e0e0e3632618165487062f6f18","src/backends/macos.rs":"f6a504461e951c14e1cb7c4dc5153c516a2a62039e1293ad3e66cf38a660f878","src/backends/mod.rs":"1b1e61ee87546119e36cc232a7729a819c2ca944d9a62b1060b86beed5042c70","src/backends/openbsd.rs":"bf5f1f9ff35e8b514aadf430004dc5994a8c36a6ca445d30c02595c287d1bef8","src/backends/unix.rs":"5319b15a0de0408c466e9af2d8672205d26265afd25bae00c89453636a7b5bea","src/backends/windows.rs":"5224401ef6a157a1caaee4eda3d8a55f3337d73a31b7b0d36ba25ed1d62b66db","src/lib.rs":"483018446d61f6a917df6915f53ed319b0bda42edee17a3d6ab3408807418485","src/mmap_stack_restore_guard.rs":"a1e828008e7a123e8cc64f2aaee3757fdc0b698504dc1e96d781b22a9de71e6e","tests/simple.rs":"569efca91a64bde5c517f2ff03cc31b17501d8af86d13b1bffb1a45377d9bbe0","tests/smoke.rs":"7cd7772a971be4c20a1ff163c0bc1fe2c4203e62afa8ec7cdb4e63a5b8ea4a70"},"package":"08d74a23609d509411d10e2176dc2a4346e3b4aea2e7b1869f19fdedbc71c013"}

6
vendor/stacker/.cargo_vcs_info.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"git": {
"sha1": "93c7abc0c82c6c9f811298d0c02c3c132ffdbfa2"
},
"path_in_vcs": ""
}

View File

@@ -0,0 +1,421 @@
name: Test
on:
push:
branches:
- master
paths-ignore:
- "*.mkd"
- "LICENSE"
pull_request:
types: [opened, reopened, synchronize]
workflow_dispatch:
jobs:
native-test:
name: Test ${{ matrix.manifest }} on ${{ matrix.os }} with ${{ matrix.rust_toolchain }} and ${{ matrix.mode }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
rust_toolchain: [nightly, stable, 1.91.0]
os: [ubuntu-latest, windows-latest, macOS-latest, windows-11-arm]
mode: ["--release", "-Zminimal-versions", ""]
manifest: ["psm/Cargo.toml", "Cargo.toml"]
# Pedantic flags
cflags: ["-Werror -Wundef", ""]
exclude:
- rust_toolchain: stable
mode: -Zminimal-versions
- rust_toolchain: 1.91.0
mode: -Zminimal-versions
- os: windows-latest
cflags: "-Werror -Wundef"
- os: windows-11-arm
cflags: "-Werror -Wundef"
include:
- os: windows-latest
extra_target: i686-pc-windows-msvc
- os: windows-11-arm
rust_toolchain: nightly
extra_target: arm64ec-pc-windows-msvc
timeout-minutes: 10
env:
CFLAGS: ${{ matrix.cflags }}
steps:
- uses: actions/checkout@v4
- name: Install Rust ${{ matrix.rust_toolchain }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust_toolchain }}
profile: minimal
default: true
target: ${{ matrix.extra_target }}
- name: Test ${{ matrix.manifest}} with ${{ matrix.mode }}
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=${{ matrix.manifest }} ${{ matrix.mode }} -- --nocapture
- name: Test ${{ matrix.manifest}} examples with ${{ matrix.mode }}
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=${{ matrix.manifest }} ${{ matrix.mode }} --examples -- --nocapture
- if: ${{ matrix.extra_target }}
name: Test ${{ matrix.manifest}} with ${{ matrix.mode }} as ${{ matrix.extra_target }}
uses: actions-rs/cargo@v1
with:
command: test
args: --target=${{ matrix.extra_target }} --manifest-path=${{ matrix.manifest }} ${{ matrix.mode }} -- --nocapture
- if: ${{ matrix.extra_target }}
name: Test ${{ matrix.manifest}} examples with ${{ matrix.mode }} as ${{ matrix.extra_target }}
uses: actions-rs/cargo@v1
with:
command: test
args: --target=${{ matrix.extra_target }} --manifest-path=${{ matrix.manifest }} ${{ matrix.mode }} --examples -- --nocapture
clang-cl-test:
name: Test ${{ matrix.manifest }} on ${{ matrix.rust_target }} with ${{ matrix.clang_cl }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
manifest: ["psm/Cargo.toml", "Cargo.toml"]
rust_target:
- x86_64-pc-windows-msvc
- i686-pc-windows-msvc
include:
- rust_target: x86_64-pc-windows-msvc
clang_cl: C:/msys64/mingw64/bin/clang-cl.exe
package: mingw-w64-x86_64-clang
- rust_target: i686-pc-windows-msvc
clang_cl: C:/msys64/mingw32/bin/clang-cl.exe
package: mingw-w64-i686-clang
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
release: false
install: ${{ matrix.package }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true
target: ${{ matrix.rust_target }}
- uses: actions-rs/cargo@v1
with:
command: test
args: --target=${{ matrix.rust_target }} --manifest-path=${{ matrix.manifest }} -- --nocapture
env:
CC: ${{ matrix.clang_cl }}
CFLAGS: "-Werror -Wundef"
windows-gnu-test:
name: Test ${{ matrix.manifest }} on ${{ matrix.rust_target }} with ${{ matrix.rust_toolchain }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
rust_toolchain: [nightly, stable]
rust_target:
- x86_64-pc-windows-gnu
- i686-pc-windows-gnu
manifest: ["psm/Cargo.toml", "Cargo.toml"]
include:
- rust_target: x86_64-pc-windows-gnu
mingw_path: C:/msys64/mingw64/bin
package: mingw-w64-x86_64-gcc
- rust_target: i686-pc-windows-gnu
mingw_path: C:/msys64/mingw32/bin
package: mingw-w64-i686-gcc
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
release: false
install: ${{ matrix.package }}
- run: echo "c:/msys64/bin" | Out-File -FilePath $env:GITHUB_PATH -Append
- run: echo "${{ matrix.mingw_path }}" | Out-File -FilePath $env:GITHUB_PATH -Append
- name: Install Rust
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: test
args: --target ${{ matrix.rust_target }} --manifest-path=${{ matrix.manifest }}
env:
CFLAGS: "-Werror -Wundef"
cross-windows-gnullvm-check:
name: Check ${{ matrix.manifest }} to ${{ matrix.rust_target }} with stable
runs-on: ubuntu-22.04
env:
LLVM_MINGW_VERSION: "20250417"
strategy:
fail-fast: false
matrix:
rust_target:
- aarch64-pc-windows-gnullvm
- i686-pc-windows-gnullvm
- x86_64-pc-windows-gnullvm
manifest: ["psm/Cargo.toml", "Cargo.toml"]
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: llvm-mingw-version
key: ${{ env.LLVM_MINGW_VERSION }}
- name: Install llvm-mingw
if: steps.cache.outputs.cache-hit != 'true'
run: curl -L https://github.com/mstorsjo/llvm-mingw/releases/download/${{ env.LLVM_MINGW_VERSION }}/llvm-mingw-${{ env.LLVM_MINGW_VERSION }}-ucrt-ubuntu-22.04-x86_64.tar.xz | tar xJf -
- name: Add llvm-mingw to PATH
run: echo "${{ github.workspace }}/llvm-mingw-${{ env.LLVM_MINGW_VERSION }}-ucrt-ubuntu-22.04-x86_64/bin" >> $GITHUB_PATH
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
target: ${{ matrix.rust_target }}
- name: Check
uses: actions-rs/cargo@v1
with:
command: check
args: --target ${{ matrix.rust_target }} --manifest-path=${{ matrix.manifest }}
cross-linux-test:
name: Test ${{ matrix.manifest }} on ${{ matrix.rust_target }} with nightly ${{ matrix.mode }}
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
- loongarch64-unknown-linux-gnu
- i686-unknown-linux-gnu
- i686-unknown-linux-musl
# No libstd available :(
# - mips-unknown-linux-gnu
# - mips64-unknown-linux-gnuabi64
# - mips64el-unknown-linux-gnuabi64
# - mipsel-unknown-linux-gnu
- powerpc-unknown-linux-gnu
# https://github.com/rust-embedded/cross/pull/440
# - powerpc64-unknown-linux-gnu
- x86_64-unknown-linux-musl
manifest: ["psm/Cargo.toml", "Cargo.toml"]
mode: ["--release", "-Zminimal-versions", ""]
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
target: ${{ matrix.rust_target }}
default: true
- name: Install cross
run: |
cargo install cross --git https://github.com/cross-rs/cross
- name: Test
run: |
cross test --target ${{ matrix.rust_target }} --manifest-path=${{ matrix.manifest }} ${{ matrix.mode }} -- --test-threads=1 --nocapture
native-build:
name: Build ${{ matrix.manifest }} to ${{ matrix.rust_target }} on nightly
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
manifest: ["psm/Cargo.toml", "Cargo.toml"]
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
target: ${{ matrix.rust_target }}
default: true
- name: Build ${{ matrix.rust_target }}
uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.rust_target }} --manifest-path=${{ matrix.manifest }}
cross-build:
name: Cross-compile ${{ matrix.manifest }} to ${{ matrix.rust_target }} with cargo-cross
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.
# FIXME: https://github.com/rust-embedded/cross/pull/440
# - sparc64-unknown-linux-gnu
# BSDs: could be tested with full system emulation
- x86_64-unknown-netbsd
manifest: ["psm/Cargo.toml", "Cargo.toml"]
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Install Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
target: ${{ matrix.rust_target }}
default: true
- name: Build ${{ matrix.rust_target }}
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --target ${{ matrix.rust_target }} --manifest-path=${{ matrix.manifest }}
cross-ios-build:
name: Cross-compile ${{ matrix.manifest }} to ${{ matrix.rust_target }} on ${{ matrix.rust_toolchain }}
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
rust_toolchain: [nightly, stable]
rust_target:
- aarch64-apple-ios
- x86_64-apple-ios
manifest: ["psm/Cargo.toml", "Cargo.toml"]
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust_toolchain }}
profile: minimal
target: ${{ matrix.rust_target }}
default: true
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.rust_target }} --manifest-path=${{ matrix.manifest }}
cross-windows-build:
name: Cross-compile ${{ matrix.manifest }} for ${{ matrix.rust_target }} from x86_64-unknown-linux-gnu
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
rust_target:
- x86_64-pc-windows-msvc
- i686-pc-windows-msvc
manifest: ["psm/Cargo.toml", "Cargo.toml"]
xwin_version: ["0.1.6"]
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
target: ${{ matrix.rust_target }}
- name: Add toolchain shims
run: |
set -eux
sudo ln -s clang-14 /usr/bin/clang-cl
sudo ln -s llvm-ar-14 /usr/bin/llvm-lib
sudo ln -s lld-link-14 /usr/bin/lld-link
- name: Install Windows SDK
run: |
set -eux
xwin_version=${{ matrix.xwin_version }}
xwin_prefix="xwin-$xwin_version-x86_64-unknown-linux-musl"
# Install xwin to cargo/bin via github release. Note you could also just use `cargo install xwin`.
curl --fail -L https://github.com/Jake-Shadle/xwin/releases/download/$xwin_version/$xwin_prefix.tar.gz | tar -xzv -C /home/runner/.cargo/bin --strip-components=1 $xwin_prefix/xwin
# Splat the CRT and SDK files to /tmp/xwin/crt and /tmp/xwin/sdk respectively
xwin --accept-license 1 splat --output /tmp/xwin
- name: Test
env:
CC: "clang-cl"
CXX: "clang-cl"
AR: "llvm-lib"
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: "lld-link"
CARGO_TARGET_I686_PC_WINDOWS_MSVC_LINKER: "lld-link"
# Note that we only disable unused-command-line-argument here since clang-cl
# doesn't implement all of the options supported by cl, but the ones it doesn't
# are _generally_ not interesting.
CFLAGS: "-Wno-unused-command-line-argument -fuse-ld=lld-link /imsvc/tmp/xwin/crt/include /imsvc/tmp/xwin/sdk/include/ucrt /imsvc/tmp/xwin/sdk/include/um /imsvc/tmp/xwin/sdk/include/shared"
# Inform the linker where to search for libraries
RUSTFLAGS: "-Lnative=/tmp/xwin/crt/lib/x86_64 -Lnative=/tmp/xwin/sdk/lib/um/x86_64 -Lnative=/tmp/xwin/sdk/lib/ucrt/x86_64"
run: |
set -eux
cargo build --target ${{ matrix.rust_target }} --manifest-path ${{ matrix.manifest }}
wasm-test:
name: Test stacker on WASM
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Install Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
target: wasm32-wasip1
- run: |
curl -Lf https://github.com/bytecodealliance/wasmtime/releases/download/v24.0.0/wasmtime-v24.0.0-x86_64-linux.tar.xz | tar xJf - -C ${{ runner.tool_cache }}
echo "${{ runner.tool_cache }}/wasmtime-v24.0.0-x86_64-linux" >> $GITHUB_PATH
echo "CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime run --" >> $GITHUB_ENV
- run: cargo test --target wasm32-wasip1 --all -- --nocapture
miri-test:
name: Test stacker with Miri on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Install Rust nightly with Miri
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
components: miri
default: true
- name: Setup Miri
run: cargo miri setup
- name: Test with Miri
run: cargo miri test -- --nocapture

155
vendor/stacker/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,155 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "ar_archive_writer"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb93bbb63b9c227414f6eb3a0adfddca591a8ce1e9b60661bb08969b87e340b"
dependencies = [
"object",
]
[[package]]
name = "cc"
version = "1.2.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "find-msvc-tools"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]]
name = "libc"
version = "0.2.180"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
[[package]]
name = "memchr"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [
"memchr",
]
[[package]]
name = "psm"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3852766467df634d74f0b2d7819bf8dc483a0eb2e3b0f50f756f9cfe8b0d18d8"
dependencies = [
"ar_archive_writer",
"cc",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "stacker"
version = "0.1.23"
dependencies = [
"cc",
"cfg-if",
"libc",
"psm",
"windows-sys",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
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 = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

77
vendor/stacker/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,77 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
rust-version = "1.63"
name = "stacker"
version = "0.1.23"
authors = [
"Alex Crichton <alex@alexcrichton.com>",
"Simonas Kazlauskas <stacker@kazlauskas.me>",
]
build = "build.rs"
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = """
A stack growth library useful when implementing deeply recursive algorithms that
may accidentally blow the stack.
"""
homepage = "https://github.com/rust-lang/stacker"
documentation = "https://docs.rs/stacker/0.1.23"
readme = "README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/stacker"
[lib]
name = "stacker"
path = "src/lib.rs"
test = false
doctest = false
[[test]]
name = "simple"
path = "tests/simple.rs"
[[test]]
name = "smoke"
path = "tests/smoke.rs"
[dependencies.cfg-if]
version = "1.0.0"
[dependencies.libc]
version = "0.2.156"
[dependencies.psm]
version = "0.1.7"
[build-dependencies.cc]
version = "1.2.33"
[target.arm64ec-pc-windows-msvc.dependencies.windows-sys]
version = ">=0.59.0, <0.60.0"
features = [
"Win32_System_Memory",
"Win32_System_Threading",
"Win32_Foundation",
]
[target.'cfg(all(windows, not(target_arch = "arm64ec")))'.dependencies.windows-sys]
version = ">=0.52.0, <0.60.0"
features = [
"Win32_System_Memory",
"Win32_System_Threading",
"Win32_Foundation",
]

201
vendor/stacker/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,201 @@
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.

25
vendor/stacker/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,25 @@
Copyright (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.

44
vendor/stacker/README.md vendored Normal file
View File

@@ -0,0 +1,44 @@
# stacker
[![Build Status](https://github.com/rust-lang/stacker/actions/workflows/test.yml/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
https://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
https://opensource.org/license/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.

13
vendor/stacker/build.rs vendored Normal file
View File

@@ -0,0 +1,13 @@
use std::env;
fn main() {
let target = env::var("TARGET").unwrap();
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;
}
}

View File

@@ -0,0 +1,47 @@
use crate::{get_stack_limit, set_stack_limit};
pub struct StackRestoreGuard {
new_stack: *mut u8,
stack_bytes: usize,
old_stack_limit: Option<usize>,
}
const ALIGNMENT: usize = 16;
impl StackRestoreGuard {
pub fn new(stack_bytes: usize) -> StackRestoreGuard {
// On these platforms we do not use stack guards. this is very unfortunate,
// but there is not much we can do about it without OS support.
// We simply allocate the requested size from the global allocator with a suitable
// alignment.
let stack_bytes = stack_bytes
.checked_add(ALIGNMENT - 1)
.expect("unreasonably large stack requested")
/ ALIGNMENT
* ALIGNMENT;
let layout = std::alloc::Layout::from_size_align(stack_bytes, ALIGNMENT).unwrap();
let ptr = unsafe { std::alloc::alloc(layout) };
assert!(!ptr.is_null(), "unable to allocate stack");
StackRestoreGuard {
new_stack: ptr,
stack_bytes,
old_stack_limit: get_stack_limit(),
}
}
pub fn stack_area(&self) -> (*mut u8, usize) {
(self.new_stack, self.stack_bytes)
}
}
impl Drop for StackRestoreGuard {
fn drop(&mut self) {
unsafe {
std::alloc::dealloc(
self.new_stack,
std::alloc::Layout::from_size_align_unchecked(self.stack_bytes, ALIGNMENT),
);
}
set_stack_limit(self.old_stack_limit);
}
}

5
vendor/stacker/src/arch/asm.h vendored Normal file
View File

@@ -0,0 +1,5 @@
#if defined(APPLE) || (defined(WINDOWS) && defined(X86))
#define GLOBAL(name) .globl _ ## name; _ ## name
#else
#define GLOBAL(name) .globl name; name
#endif

5
vendor/stacker/src/arch/windows.c vendored Normal file
View File

@@ -0,0 +1,5 @@
#include <windows.h>
PVOID __stacker_get_current_fiber() {
return GetCurrentFiber();
}

View File

@@ -0,0 +1,4 @@
#[inline(always)]
pub unsafe fn guess_os_stack_limit() -> Option<usize> {
None
}

6
vendor/stacker/src/backends/macos.rs vendored Normal file
View File

@@ -0,0 +1,6 @@
pub unsafe fn guess_os_stack_limit() -> Option<usize> {
Some(
libc::pthread_get_stackaddr_np(libc::pthread_self()) as usize
- libc::pthread_get_stacksize_np(libc::pthread_self()) as usize,
)
}

29
vendor/stacker/src/backends/mod.rs vendored Normal file
View File

@@ -0,0 +1,29 @@
cfg_if! {
if #[cfg(miri)] {
mod fallback;
pub use fallback::guess_os_stack_limit;
} else if #[cfg(windows)] {
pub(crate) mod windows;
pub use windows::guess_os_stack_limit;
} else if #[cfg(any(
target_os = "linux",
target_os = "solaris",
target_os = "netbsd",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "illumos"
))] {
mod unix;
pub use unix::guess_os_stack_limit;
} else if #[cfg(target_os = "openbsd")] {
mod openbsd;
pub use openbsd::guess_os_stack_limit;
} else if #[cfg(target_os = "macos")] {
mod macos;
pub use macos::guess_os_stack_limit;
} else {
mod fallback;
pub use fallback::guess_os_stack_limit;
}
}

View File

@@ -0,0 +1,9 @@
pub unsafe fn guess_os_stack_limit() -> Option<usize> {
let mut stackinfo = std::mem::MaybeUninit::<libc::stack_t>::uninit();
let res = libc::pthread_stackseg_np(libc::pthread_self(), stackinfo.as_mut_ptr());
if res != 0 {
return None;
}
let stackinfo = stackinfo.assume_init();
Some(stackinfo.ss_sp as usize - stackinfo.ss_size)
}

40
vendor/stacker/src/backends/unix.rs vendored Normal file
View File

@@ -0,0 +1,40 @@
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "illumos"))]
use libc::pthread_attr_get_np as get_attr;
#[cfg(any(target_os = "linux", target_os = "solaris", target_os = "netbsd", target_os = "haiku"))]
use libc::pthread_getattr_np as get_attr;
pub unsafe fn guess_os_stack_limit() -> Option<usize> {
let mut attr = PthreadAttr::new()?;
(get_attr(libc::pthread_self(), &mut attr.0) == 0).then_some(())?;
let mut stackaddr = std::ptr::null_mut();
let mut stacksize = 0;
(libc::pthread_attr_getstack(&attr.0, &mut stackaddr, &mut stacksize) == 0).then_some(())?;
Some(stackaddr as usize)
}
struct PthreadAttr(libc::pthread_attr_t);
impl Drop for PthreadAttr {
fn drop(&mut self) {
unsafe {
let ret = libc::pthread_attr_destroy(&mut self.0);
if ret != 0 {
let err = std::io::Error::last_os_error();
panic!(
"pthread_attr_destroy failed with error code {}: {}",
ret, err
);
}
}
}
}
impl PthreadAttr {
unsafe fn new() -> Option<Self> {
let mut attr = std::mem::MaybeUninit::<libc::pthread_attr_t>::uninit();
if libc::pthread_attr_init(attr.as_mut_ptr()) != 0 {
return None;
}
Some(PthreadAttr(attr.assume_init()))
}
}

142
vendor/stacker/src/backends/windows.rs vendored Normal file
View File

@@ -0,0 +1,142 @@
use libc::c_void;
use std::io;
use std::ptr;
use windows_sys::Win32::Foundation::BOOL;
use windows_sys::Win32::System::Memory::VirtualQuery;
use windows_sys::Win32::System::Threading::{
ConvertFiberToThread, ConvertThreadToFiber, CreateFiber, DeleteFiber, IsThreadAFiber,
SetThreadStackGuarantee, SwitchToFiber,
};
// Make sure the libstacker.a (implemented in C) is linked.
// See https://github.com/rust-lang/rust/issues/65610
#[link(name = "stacker")]
extern "C" {
fn __stacker_get_current_fiber() -> *mut c_void;
}
struct FiberInfo<F> {
callback: std::mem::MaybeUninit<F>,
panic: Option<Box<dyn std::any::Any + Send + 'static>>,
parent_fiber: *mut c_void,
}
unsafe extern "system" fn fiber_proc<F: FnOnce()>(data: *mut c_void) {
// 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<F>);
let old_stack_limit = crate::get_stack_limit();
crate::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
crate::set_stack_limit(old_stack_limit);
SwitchToFiber(data.parent_fiber);
}
pub fn _grow(stack_size: usize, callback: &mut dyn FnMut()) {
// 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() == 1 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 usize,
Some(fiber_proc::<&mut dyn FnMut()>),
&mut data as *mut FiberInfo<&mut dyn FnMut()> 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 && 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() -> Option<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
let ret = SetThreadStackGuarantee(&mut stack_guarantee);
if ret == 0 {
return None;
}
};
Some(std::cmp::max(stack_guarantee, min_guarantee) as usize + 0x1000)
}
#[inline(always)]
pub unsafe fn guess_os_stack_limit() -> Option<usize> {
// 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 = windows_sys::Win32::System::Memory::MEMORY_BASIC_INFORMATION;
let mut mi = std::mem::MaybeUninit::<QueryT>::uninit();
let res = VirtualQuery(
psm::stack_pointer() as *const _,
mi.as_mut_ptr(),
std::mem::size_of::<QueryT>() as usize,
);
if res == 0 {
return None;
}
Some(mi.assume_init().AllocationBase as usize + get_thread_stack_guarantee()? + 0x1000)
}

180
vendor/stacker/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,180 @@
//! 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 windows_sys;
#[macro_use]
extern crate psm;
mod backends;
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, F: FnOnce() -> 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 = match remaining_stack() {
Some(remaining) => remaining >= red_zone,
None => false,
};
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, F: FnOnce() -> R>(stack_size: usize, callback: F) -> R {
// To avoid monomorphizing `_grow()` and everything it calls,
// we convert the generic callback to a dynamic one.
let mut opt_callback = Some(callback);
let mut ret = None;
let ret_ref = &mut ret;
// This wrapper around `callback` achieves two things:
// * It converts the `impl FnOnce` to a `dyn FnMut`.
// `dyn` because we want it to not be generic, and
// `FnMut` because we can't pass a `dyn FnOnce` around without boxing it.
// * It eliminates the generic return value, by writing it to the stack of this function.
// Otherwise the closure would have to return an unsized value, which isn't possible.
let dyn_callback: &mut dyn FnMut() = &mut || {
let taken_callback = opt_callback.take().unwrap();
*ret_ref = Some(taken_callback());
};
_grow(stack_size, dyn_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<usize> {
let current_ptr = current_stack_ptr();
get_stack_limit().map(|limit| current_ptr.saturating_sub(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::<u8>::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<Option<usize>> = Cell::new(unsafe {
backends::guess_os_stack_limit()
})
}
#[inline(always)]
fn get_stack_limit() -> Option<usize> {
STACK_LIMIT.with(|s| s.get())
}
#[inline(always)]
#[allow(unused)]
fn set_stack_limit(l: Option<usize>) {
STACK_LIMIT.with(|s| s.set(l))
}
psm_stack_manipulation! {
yes {
#[cfg(not(any(target_arch = "wasm32",target_os = "hermit")))]
#[path = "mmap_stack_restore_guard.rs"]
mod stack_restore_guard;
#[cfg(any(target_arch = "wasm32",target_os = "hermit"))]
#[path = "alloc_stack_restore_guard.rs"]
mod stack_restore_guard;
use stack_restore_guard::StackRestoreGuard;
fn _grow(requested_stack_size: usize, callback: &mut dyn FnMut()) {
// Other than that this code has no meaningful gotchas.
unsafe {
// 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).
// `StackRestoreGuard` allocates a memory area with suitable size and alignment.
// It also sets up stack guards if supported on target.
let guard = StackRestoreGuard::new(requested_stack_size);
let (stack_base, allocated_stack_size) = guard.stack_area();
debug_assert!(allocated_stack_size >= requested_stack_size);
set_stack_limit(Some(stack_base as usize));
let panic = psm::on_stack(stack_base, allocated_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(all(windows, not(miri))))]
fn _grow(stack_size: usize, callback: &mut dyn FnMut()) {
let _ = stack_size;
callback();
}
#[cfg(all(windows, not(miri)))]
use backends::windows::_grow;
}
}

View File

@@ -0,0 +1,129 @@
use crate::{get_stack_limit, set_stack_limit};
pub struct StackRestoreGuard {
mapping: *mut u8,
size_with_guard: usize,
page_size: usize,
old_stack_limit: Option<usize>,
}
impl StackRestoreGuard {
pub fn new(requested_size: usize) -> StackRestoreGuard {
// For maximum portability we want to produce a stack that is aligned to a page and has
// a size thats a multiple of page size. It is natural to use mmap to allocate
// these pages. 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.
let page_size = page_size();
let requested_pages = requested_size
.checked_add(page_size - 1)
.expect("unreasonably large stack requested")
/ page_size;
let page_count_with_guard = std::cmp::max(1, requested_pages) + 2;
let size_with_guard = page_count_with_guard
.checked_mul(page_size)
.expect("unreasonably large stack requested");
unsafe {
let new_stack = libc::mmap(
std::ptr::null_mut(),
size_with_guard,
libc::PROT_NONE,
libc::MAP_PRIVATE | libc::MAP_ANON,
-1, // Some implementations assert fd = -1 if MAP_ANON is specified
0,
);
assert_ne!(
new_stack,
libc::MAP_FAILED,
"mmap failed to allocate stack: {}",
std::io::Error::last_os_error()
);
let guard = StackRestoreGuard {
mapping: new_stack as *mut u8,
page_size,
size_with_guard,
old_stack_limit: get_stack_limit(),
};
// We leave two guard pages without read/write access in our allocation.
// There is one guard page below the stack and another above it.
let above_guard_page = new_stack.add(page_size);
#[cfg(not(target_os = "openbsd"))]
let result = libc::mprotect(
above_guard_page,
size_with_guard - 2 * page_size,
libc::PROT_READ | libc::PROT_WRITE,
);
#[cfg(target_os = "openbsd")]
let result = if libc::mmap(
above_guard_page,
size_with_guard - 2 * 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
};
assert_ne!(
result,
-1,
"mprotect/mmap failed: {}",
std::io::Error::last_os_error()
);
guard
}
}
// TODO this should return a *mut [u8], but pointer slices only got proper support with Rust 1.79.
pub fn stack_area(&self) -> (*mut u8, usize) {
unsafe {
(
self.mapping.add(self.page_size),
self.size_with_guard - 2 * self.page_size,
)
}
}
}
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.mapping as *mut std::ffi::c_void, self.size_with_guard);
}
set_stack_limit(self.old_stack_limit);
}
}
fn page_size() -> usize {
// FIXME: consider caching the page size.
unsafe { libc::sysconf(libc::_SC_PAGE_SIZE) as usize }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_stack_area() {
for stack_size_kb in 1..64 {
let size = stack_size_kb * 1024;
let stack = StackRestoreGuard::new(size);
let (mut ptr, actual_size) = stack.stack_area();
for _ in 0..actual_size {
unsafe {
core::ptr::write_volatile(ptr, 0b10101011);
ptr = ptr.add(1)
}
}
assert_eq!(
actual_size,
size.div_ceil(page_size()) * page_size()
)
}
}
}

Binary file not shown.

View File

View File

@@ -0,0 +1 @@
{"name":"stacker","vers":"0.1.23","deps":[{"name":"cfg-if","req":"^1.0.0","features":[],"optional":false,"default_features":true,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"libc","req":"^0.2.156","features":[],"optional":false,"default_features":true,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"psm","req":"^0.1.7","features":[],"optional":false,"default_features":true,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"cc","req":"^1.2.33","features":[],"optional":false,"default_features":true,"target":null,"kind":"build","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"windows-sys","req":">=0.59.0, <0.60.0","features":["Win32_System_Memory","Win32_System_Threading","Win32_Foundation"],"optional":false,"default_features":true,"target":"arm64ec-pc-windows-msvc","kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"windows-sys","req":">=0.52.0, <0.60.0","features":["Win32_System_Memory","Win32_System_Threading","Win32_Foundation"],"optional":false,"default_features":true,"target":"cfg(all(windows, not(target_arch = \"arm64ec\")))","kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false}],"features":{},"features2":null,"cksum":"3cfe21a4e5022d7fff79815766e155fe7cd30919868b92efdda64d18eb81f2c4","yanked":null,"links":null,"rust_version":null,"v":2}

Binary file not shown.

29
vendor/stacker/tests/simple.rs vendored Normal file
View File

@@ -0,0 +1,29 @@
extern crate stacker;
const RED_ZONE: usize = 100 * 1024; // 100k
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
pub fn ensure_sufficient_stack<R, F: FnOnce() -> 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));
}
#[allow(dropping_copy_types)]
drop(x);
}
#[test]
#[cfg_attr(miri, ignore)] // Too slow under Miri's interpreter
fn foo() {
let limit = if cfg!(target_arch = "wasm32") {
2000
} else {
10000
};
recurse(limit);
}

96
vendor/stacker/tests/smoke.rs vendored Normal file
View File

@@ -0,0 +1,96 @@
extern 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");
}
}
let limit = if cfg!(target_arch = "wasm32") || cfg!(miri) {
2000
} else {
256 * 1024
};
foo(limit, &mut []);
}
#[test]
#[cfg_attr(target_arch = "wasm32", ignore)]
#[cfg_attr(miri, ignore)] // Too slow under Miri's interpreter
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<F: FnOnce()>(n: usize, f: F) -> usize {
if n > 0 {
stacker::grow(64 * 1024, || recursive(n - 1, f) + 1)
} else {
f();
0
}
}
#[test]
#[cfg_attr(target_arch = "wasm32", ignore)]
fn catch_panic() {
let panic_result = std::panic::catch_unwind(|| {
recursive(100, || panic!());
});
assert!(panic_result.is_err());
}
#[test]
#[cfg_attr(target_arch = "wasm32", ignore)]
fn catch_panic_inside() {
stacker::grow(64 * 1024, || {
let panic_result = std::panic::catch_unwind(|| {
recursive(100, || panic!());
});
assert!(panic_result.is_err());
});
}
#[test]
#[cfg_attr(target_arch = "wasm32", ignore)]
fn catch_panic_leaf() {
stacker::grow(64 * 1024, || {
let panic_result = std::panic::catch_unwind(|| panic!());
assert!(panic_result.is_err());
});
}