Add experimental macOS attach support#161
Open
Fewmanism wants to merge 4 commits into
Open
Conversation
43cda9b to
9a8c97a
Compare
9a8c97a to
999cfe2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds an experimental Darwin/macOS backend with enough support to build and exercise reptyr on macOS:
reptyr -l/reptyr -Lon macOSreptyr -s PIDand plainreptyr PID-sredirects target fds 0/1/2sysctl(KERN_PROC_PID)+proc_pidinfo(PROC_PIDLISTFDS)/PROC_PIDFDVNODEPATHINFOtask_for_pid()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 anopen/dup2/closesyscall 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-amd64task could no longer install packages (pkgmir.geo.freebsd.org/FreeBSD:12:amd64/quarterlyreturned 404). The updated FreeBSD 13 task passes on this PR.Test plan
Run locally on Apple Silicon macOS:
make test PYTHON_CMD=/usr/bin/python3make darwin-attach-test PYTHON_CMD=/usr/bin/python3make 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.pyRemote CI:
freebsd_13: passingThe Darwin attach test ad-hoc signs
./reptyrandtest/darwin-victimwithcom.apple.security.get-task-allowbefore exercising bothreptyr -s PIDand plainreptyr PID.