Skip to content

Add experimental macOS attach support#161

Open
Fewmanism wants to merge 4 commits into
nelhage:masterfrom
Fewmanism:feat/darwin-experimental-attach
Open

Add experimental macOS attach support#161
Fewmanism wants to merge 4 commits into
nelhage:masterfrom
Fewmanism:feat/darwin-experimental-attach

Conversation

@Fewmanism

@Fewmanism Fewmanism commented May 18, 2026

Copy link
Copy Markdown

Summary

This adds an experimental Darwin/macOS backend with enough support to build and exercise reptyr on macOS:

  • add Darwin platform objects and platform stubs so the project builds on macOS
  • support reptyr -l / reptyr -L on macOS
  • add an arm64 Mach-based attach path for debug-attachable same-user targets
  • support both reptyr -s PID and plain reptyr PID
    • -s redirects target fds 0/1/2
    • plain attach discovers open fds that alias the target's controlling tty using sysctl(KERN_PROC_PID) + proc_pidinfo(PROC_PIDLISTFDS) / PROC_PIDFDVNODEPATHINFO
  • add Darwin smoke tests with ad-hoc signing for task_for_pid()
  • update Cirrus from the EOL FreeBSD 12 image to FreeBSD 13.2 so the existing FreeBSD CI can start and install packages

The attach backend is deliberately scoped as experimental. It redirects matching fds to a new pty; it does not yet implement full Linux parity for controlling-terminal/session handoff (setsid, TIOCNOTTY, TIOCSCTTY, foreground pgrp, etc.). The README calls that out explicitly.

Implementation notes

The Darwin attach path uses task_for_pid(), allocates a small remote payload, suspends the target's threads, runs one arm64 thread through an open/dup2/close syscall payload, restores the saved thread state, then resumes the target. The payload records syscall success/failure back to reptyr so attach failures do not silently corrupt target fds.

The Cirrus change is included because the previous freebsd-12-4-release-amd64 task could no longer install packages (pkgmir.geo.freebsd.org/FreeBSD:12:amd64/quarterly returned 404). The updated FreeBSD 13 task passes on this PR.

Test plan

Run locally on Apple Silicon macOS:

  • make test PYTHON_CMD=/usr/bin/python3
  • make darwin-attach-test PYTHON_CMD=/usr/bin/python3
  • make PYTHON_CMD=/usr/bin/python3 CFLAGS='-arch x86_64' LDFLAGS='-arch x86_64'
  • git diff --check HEAD~1..HEAD
  • /usr/bin/python3 -m py_compile test/list-pty.py test/darwin-basic.py

Remote CI:

  • Cirrus freebsd_13: passing

The Darwin attach test ad-hoc signs ./reptyr and test/darwin-victim with com.apple.security.get-task-allow before exercising both reptyr -s PID and plain reptyr PID.

@Fewmanism Fewmanism force-pushed the feat/darwin-experimental-attach branch 2 times, most recently from 43cda9b to 9a8c97a Compare May 18, 2026 14:33
@Fewmanism Fewmanism force-pushed the feat/darwin-experimental-attach branch from 9a8c97a to 999cfe2 Compare May 18, 2026 14:37
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