Skip to content

fix(runtime): use typed pthread attributes for Linux stack bounds - #9752

Closed
proggeramlug wants to merge 2 commits into
PerryTS:mainfrom
proggeramlug:fix/linux-pthread-stack-attributes
Closed

fix(runtime): use typed pthread attributes for Linux stack bounds#9752
proggeramlug wants to merge 2 commits into
PerryTS:mainfrom
proggeramlug:fix/linux-pthread-stack-attributes

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Linux builds fail -D warnings because the GC and Error.stack paths redeclare three pthread functions with incompatible pointer types. The ARM64 GC frame walker repeats the byte-buffer variant. Replace all three implementations with one Linux-only helper using libc::pthread_attr_t and libc's declarations.

The shared helper has target-correct storage alignment and size, destroys attributes after a successful lookup, and returns zero if bounds cannot be read or overflow. GC and frame walkers retain their existing zero-bound fallback. Two runtime tests check current-thread bounds and workers with different requested stack sizes.

Validation:

  • On pristine 12efed1222, Linux RUSTFLAGS="-D warnings" cargo check -p perry-runtime --lib fails with the three conflicting-declaration errors; the same command passes with this change.
  • The actual helper source passes standalone main-thread and unit-test probes on x86_64 glibc and musl, plus an ARM64 Linux compile check, all with warnings denied.
  • All 3,125 Linux runtime unit tests pass (4 ignored), run single-threaded.
  • Formatting, file-size, test registration, address-classification, store-site and holder-inventory checks pass.

This removes the pre-existing Linux warnings failure reported on #9746, #9747, #9748 and #9750. The separate baseline raw-TLS policy failure is addressed by #9750. No version bump.

Summary by CodeRabbit

  • Bug Fixes
    • Improved stack boundary detection on Linux for garbage collection and error reporting.
    • Increased reliability of stack walking on Linux, including aarch64 systems.
    • Corrected handling for thread stacks with custom sizes and unusual boundary conditions.
    • Added safeguards to stop stack processing safely when valid stack boundaries cannot be determined.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 058cb6aa-29dc-4ddf-a15a-396358254253

📥 Commits

Reviewing files that changed from the base of the PR and between 12efed1 and 1cf5077.

📒 Files selected for processing (6)
  • changelog.d/9752-linux-pthread-stack-attributes.md
  • crates/perry-runtime/src/error_stack_frames.rs
  • crates/perry-runtime/src/gc/roots.rs
  • crates/perry-runtime/src/gc/roots/stack_maps.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-runtime/src/native_stack.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The runtime adds a validated Linux pthread stack-bound helper. GC roots, error-stack frames, and frame-pointer walking now use the shared helper. Tests cover current-thread and custom-thread stack bounds.

Changes

Linux stack-bound handling

Layer / File(s) Summary
Add validated native stack helper
crates/perry-runtime/src/lib.rs, crates/perry-runtime/src/native_stack.rs
The Linux-only native_stack module provides stack_top(). The helper validates pthread results, null addresses, zero sizes, and overflow. Tests cover current-thread and custom-thread stack bounds.
Route runtime consumers through helper
crates/perry-runtime/src/gc/roots.rs, crates/perry-runtime/src/error_stack_frames.rs, crates/perry-runtime/src/gc/roots/stack_maps.rs, changelog.d/9752-linux-pthread-stack-attributes.md
Linux GC roots, error-stack frame discovery, and frame-pointer walking now delegate stack-bound lookup to native_stack::stack_top(). The changelog records the pthread attribute fix.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 1cf50

Linux stack-bound discovery is consolidated behind a validated pthread helper for GC and error-stack walking, preserving safe fallback behavior. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: using typed pthread attributes for Linux stack-bound handling.
Description check ✅ Passed The description explains the problem, implementation, affected runtime paths, issue references, validation steps, test results, and versioning status. It does not follow every template heading or incl…
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. (1 skipped: 1 u…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main via merge train #9798 (rebase-merged, so your commits keep their authorship). Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant