Skip to content

std: refactor UNIX stack overflow code - #162296

Open
joboet wants to merge 1 commit into
rust-lang:mainfrom
joboet:refactor_stack_overflow
Open

std: refactor UNIX stack overflow code#162296
joboet wants to merge 1 commit into
rust-lang:mainfrom
joboet:refactor_stack_overflow

Conversation

@joboet

@joboet joboet commented Sep 4, 2026

Copy link
Copy Markdown
Member

The idea here is to split the code up into two main areas:

  • The actual stack overflow handling involving signals/exceptions
  • Guard page installing, itself split into three functions:
    • install_main_guard installs the main thread's guard page
    • find_main_guard (new) finds the guard page the system has set up for the main thread (this was previously mashed in with install_main_guard)
    • current_guard finds the guard page of the current (non-main) thread

Splitting the guard page stuff out will allow us to enable the soundness-critical guard page install logic even if the system doesn't support signals; and also makes it easier to work on the individual areas in parallel.

Unfortunately this isn't as simple as moving the code around: the current code caches the system's page size in a PAGE_SIZE atomic, but that atomic is not always accessed. Thus there are some non-functional changes here in regards to how the page size is passed around. Also, since the guard page code now needs to compile on all systems, the cfg!()-based switching used to simplify cross-platform code checking would necessitate some stub implementations, so I've switched to proper cfg_select! based logic.

These kinds of code moves don't display nicely in the diff unfortunately, let me know if there's anything I can do to help with the review!

@rustbot

rustbot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Any special-casing of Miri in the standard library requires review.

cc @rust-lang/miri

@rustbot rustbot added O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 4, 2026
@rustbot

rustbot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

r? @ChrisDenton

rustbot has assigned @ChrisDenton.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from ChrisDenton, Darksonn, JohnTitor, Mark-Simulacrum, clarfonthey

Comment thread library/std/src/sys/pal/unix/stack_overflow/mod.rs
@joboet
joboet force-pushed the refactor_stack_overflow branch from 305f083 to f8cd163 Compare September 4, 2026 17:42
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/fail/tree_borrows/wildcard/subtree_internal_relatedness.rs ... ok
tests/fail/tree_borrows/wildcard/subtree_internal_relatedness_wildcard.rs ... ok

FAILED TEST: tests/fail/data_race/dangling_thread_race.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-e1VmZq" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail/data_race" "tests/fail/data_race/dangling_thread_race.rs" "-Zmiri-deterministic-concurrency" "-Zmiri-disable-stacked-borrows" "--edition" "2021"

error: test got exit status: 0, but expected 1
 = note: compilation succeeded, but was expected to fail

error: no output was emitted
Execute `./miri test --bless` to remove `tests/fail/data_race/dangling_thread_race.stderr`

error: `Data race detected between (1) non-atomic write on thread `unnamed-1` and (2) non-atomic write on thread `main`` not found in diagnostics on line 37
##[error]  --> tests/fail/data_race/dangling_thread_race.rs:37:31
   |
37 | ...ERROR: Data race detected between (1) non-atomic write on thread `unnamed-1` and (2) non-atomic write on thread `main`
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected because of this pattern
   |

full stderr:

full stdout:



FAILED TEST: tests/fail/data_race/dangling_thread_async_race.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-e1VmZq" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail/data_race" "tests/fail/data_race/dangling_thread_async_race.rs" "-Zmiri-deterministic-concurrency" "-Zmiri-disable-stacked-borrows" "--edition" "2021"

error: test got exit status: 0, but expected 1
 = note: compilation succeeded, but was expected to fail

error: no output was emitted
Execute `./miri test --bless` to remove `tests/fail/data_race/dangling_thread_async_race.stderr`

error: `Data race detected between (1) non-atomic write on thread `unnamed-1` and (2) non-atomic write on thread `unnamed-3`` not found in diagnostics on line 39
##[error]  --> tests/fail/data_race/dangling_thread_async_race.rs:39:35
   |
39 | ...ROR: Data race detected between (1) non-atomic write on thread `unnamed-1` and (2) non-atomic write on thread `unnamed-3`
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected because of this pattern
   |

full stderr:

---

Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.30.7/src/lib.rs:365

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/miri/54d3518e03e017c2/out/ui-54d3518e03e017c2` (exit status: 1)
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo test --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout -Zembed-metadata=no --locked --color=always --profile=release --manifest-path /checkout/src/tools/miri/Cargo.toml -- [workdir=/checkout]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:208:21
Executed at: src/bootstrap/src/core/build_steps/test.rs:790:19

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test --stage 2 miri cargo-miri`
Currently active steps:
test::Miri { target: x86_64-unknown-linux-gnu } at src/bootstrap/src/core/build_steps/test.rs:716
Build completed unsuccessfully in 0:41:33
  local time: Fri Sep  4 18:29:11 UTC 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants