Skip to content

Conversation

lateralusX
Copy link
Member

@lateralusX lateralusX commented Jul 28, 2025

As identified by #116545, macOS26 have broken semaphores in case debugger and debuggee have been signed with different team ids, currently only mentioned for iOS/iPadOS, https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-26-release-notes, but testing shows its broken for regular apps as well.

This PR adds support for a different startup handshake protocol for debugger/debuggee using FIFO file (aka named pipes) on Apple platforms due to limitation introduced in macOS26. All other POSIX platforms will continue to use the semaphore based handshake protocol.

The implementation is backward compatible on Apple platforms. First it will check for new FIFO files, if not found, it will fallback to semaphores, making sure old debugger implementation will continue to work as is even if runtime supports new handshake protocol. It will be the debugger that decides what protocol version to use, runtime will continue working with both versions of the protocol. This also makes this PR standalone from the corresponding change in debugger (dbgshim), so debugger should continue to work on Apple platforms (except macOS26) with old dbgshim.

In order for this change to work E2E, the debugger needs to use a new dbgshim implementing updated startup handshake protocol, dotnet/diagnostics#5530. Until both debugger and debuggee have been update, debug launch on macOS26 won't work.

Names of the two new FIFO files follow the same naming pattern as we have for existing debugger FIFO's, using suffix currently used for the startup and continue semaphores, "st" for startup and "co" for continue, example of full FIFO names:

/var/folders/d0/l_56x0lx6l7bbrv3pfr128xc0000gn/T/clr-debug-pipe-11462-1753451225-st
/var/folders/d0/l_56x0lx6l7bbrv3pfr128xc0000gn/T/clr-debug-pipe-11462-1753451225-co

@Copilot Copilot AI review requested due to automatic review settings July 28, 2025 11:12
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 28, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a workaround for broken semaphore functionality in macOS 26 where semaphores fail when debugger and debuggee are signed with different team ids. The solution introduces an alternative handshake protocol using FIFO files (named pipes) while maintaining backward compatibility with the existing semaphore-based approach.

Key changes:

  • Adds FIFO-based runtime startup handshake protocol for Apple platforms
  • Implements backward compatibility by attempting FIFO first, then falling back to semaphores
  • Refactors existing semaphore logic into a separate function for better code organization

@lateralusX
Copy link
Member Author

lateralusX commented Jul 28, 2025

Matching diagnostics PR, dotnet/diagnostics#5530.

@tommcdon tommcdon added area-Diagnostics-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 28, 2025
@tommcdon tommcdon added this to the 10.0.0 milestone Jul 28, 2025
Copy link
Member

@tommcdon tommcdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a comment for your review.

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

lateralusX added a commit to dotnet/diagnostics that referenced this pull request Jul 30, 2025
…5530)

As identified by dotnet/runtime#116545,
macOS26 have broken semaphores in case debugger and debuggee have been
signed with different team ids, currently only mentioned for iOS/iPadOS,
https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-26-release-notes,
but testing shows its broken for regular apps as well.

This PR adds support for a different startup handshake protocol for
debugger/debuggee using FIFO file (aka named pipes) on Apple platforms
due to limitation introduced in macOS26. All other POSIX platforms will
continue to use the semaphore based handshake protocol.

The implementation is backward compatible on Apple platforms.
Implementation will always setup semaphores to support runtimes using
semaphore protocol, but on Apple platforms it will also create the new
FIFO files, it will then spawn a separate background thread checking the
FIFO files for connections and handling the protocol. In case runtime
supports new FIFIO based protocol, background thread will handle
complete protocol and signal/wait semaphores, making the underlying
protocol transparent for the startup thread, it will always use the
semaphores. In case runtime doesn't support FIFO files, runtime will
signal/wait on the semaphores as normal coordinating with the debugger
startup thread. In the case runtime doesn't support FIFO files, the
background thread will just sit and wait on connections until canceled.
Unregister cancel out background thread in case runtime didn't support
FIFO files.

Since this fix supports both semaphores and FIFO files on Apple platform
it is compatible with old runtimes using semaphores as well as new
runtimes that supports the FIFO based handshake protocol.

In order for this change to work E2E, the debugger needs to use changes
introduced in this PR with a runtime including
dotnet/runtime#118120. Until both debugger and
debuggee have been update, debug launch on macOS26 won't work.

Names of the two new FIFO files follow the same naming pattern as we
have for existing debugger FIFO's, using suffix currently used for the
startup and continue semaphores, "st" for startup and "co" for continue,
example of full FIFO names:


/var/folders/d0/l_56x0lx6l7bbrv3pfr128xc0000gn/T/clr-debug-pipe-11462-1753451225-st

/var/folders/d0/l_56x0lx6l7bbrv3pfr128xc0000gn/T/clr-debug-pipe-11462-1753451225-co
@lateralusX lateralusX merged commit 913c282 into dotnet:main Jul 30, 2025
99 checks passed
@steveisok
Copy link
Member

/backport to release/9.0-staging

@steveisok
Copy link
Member

/backport to release/8.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/16627176985

Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/16627180419

steveisok pushed a commit that referenced this pull request Aug 5, 2025
…protocol on macOS26. (#118213)

Backport of #118120

* Add support for new startup handshake protocol over pipes instead of sempahores.

* Remove NonBlocking runtime support.

* Renames, logging and simplification.

* Improve tracing.

* Make open check non blocking.

* Fold access into open calls and track ENOENT | ENOACCES

* Review feedback.

---------

Co-authored-by: lateralusX <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants