Skip to content

attach: fix ptrace signal crash#2707

Open
meserve-amd wants to merge 12 commits intodevelopfrom
users/meserve-amd/attach/ptrace-thread-fix
Open

attach: fix ptrace signal crash#2707
meserve-amd wants to merge 12 commits intodevelopfrom
users/meserve-amd/attach/ptrace-thread-fix

Conversation

@meserve-amd
Copy link
Contributor

  • Reworks ptrace calls to originate from the same thread per target pid, as required

Motivation

Crashes were observed when extraneous signals were sent to an attached target. Bug introduced in #1653

Prior to #1653, all ptrace operations were handled from a singleton thread in rocattach.cpp. This was changed in favor of re-entrancy support to allow the library to attach to multiple processes simultaneously. This particular detail was lost in the transition.

Technical Details

ptrace session are tracked per thread ID, so all ptrace operations targetting a given PID must originate from the same thread.
This reworks ptrace operations into a new class called PTraceRunner which aims to be as similar to the original ptrace call as possible.

PTraceRunner is a simple single worker thread that handles ptrace operations serially with mutex and atomic mailbox. Each PTraceSession owns a single PTraceRunner that is shared between the main thread and the signal handler thread via shared_ptr.

Aside: ptrace is defined as long ptrace (int op, ...). For consistency's sake, we choose to define it as uint64_t ptrace(__ptrace_operation op, void* addr, void* data). Some changes are made in PTraceSession to enforce the stricter typing.

JIRA ID

Test Plan

Ran parallel-attach test and resized window during test to send extraneous signals (SIGWINCH).
@itrowbri has developed a test which provides a signal mid-attach to ensure this behavior in the future

Test Result

Logging indicated the extraneous signal was handled and sent to the target program.

Submission Checklist

@meserve-amd meserve-amd requested a review from itrowbri January 21, 2026 00:16
@meserve-amd meserve-amd requested a review from a team as a code owner January 21, 2026 00:16
@meserve-amd meserve-amd requested a review from a team as a code owner January 21, 2026 00:16
@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch from f95942e to 7793490 Compare January 21, 2026 01:09
@meserve-amd meserve-amd requested a review from bwelton January 22, 2026 18:40
@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch from d09c054 to 9acc94a Compare January 26, 2026 18:17
@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch from 9acc94a to cc1e939 Compare February 3, 2026 23:46
@meserve-amd meserve-amd requested a review from bwelton February 4, 2026 00:09
@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch 2 times, most recently from c309d6a to 3d22639 Compare February 24, 2026 21:20
@meserve-amd
Copy link
Contributor Author

changes requested in #3265
Some refactoring is needed to hide the PTraceRunner class as requested, will update when that is completed

@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch from c2c8dfb to 7141d1c Compare March 3, 2026 20:53
@meserve-amd meserve-amd requested a review from itrowbri March 3, 2026 20:55
@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch 2 times, most recently from 7369719 to c103e22 Compare March 17, 2026 19:55
@meserve-amd meserve-amd changed the base branch from develop to amd/dev/gandryey/AIRUNTIME-84-4 March 18, 2026 00:49
@meserve-amd meserve-amd changed the base branch from amd/dev/gandryey/AIRUNTIME-84-4 to develop March 18, 2026 00:49
@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch from c103e22 to a5ae6f7 Compare March 18, 2026 00:51
@meserve-amd meserve-amd requested a review from a team as a code owner March 18, 2026 00:51
@meserve-amd
Copy link
Contributor Author

@ROCm/clr-reviewers I've temporarily integrated a commit from #4169 to get PSDB build passing so I can inspect test results. Review is not required and this commit will be removed from this branch before merging.

@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch from a5ae6f7 to 1120621 Compare March 18, 2026 14:47
@meserve-amd meserve-amd removed the request for review from a team March 18, 2026 14:48
@meserve-amd meserve-amd force-pushed the users/meserve-amd/attach/ptrace-thread-fix branch from 1120621 to f2b4c22 Compare March 23, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants