Repository navigation
Replace macOS ps exec with in-process sysctl-based Unity process discovery #1882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hatayama
merged 2 commits into
feature/pause-point-feedback-round3-integration
from
feat/macos-in-process-unity-process-enum
Jul 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //go:build darwin | ||
|
|
||
| package unityprocess | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| // listUnityProcessesMac enumerates Unity Editor processes via the kern.proc.all and | ||
| // kern.procargs2 sysctl nodes instead of exec'ing /bin/ps, so Unity process discovery | ||
| // keeps working inside sandboxes that deny exec of external binaries (ps included) but | ||
| // still permit process-info syscalls. | ||
| func listUnityProcessesMac(ctx context.Context) ([]UnityProcess, error) { | ||
| if err := ctx.Err(); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| kinfoProcs, err := unix.SysctlKinfoProcSlice("kern.proc.all") | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to retrieve Unity process list: %w", err) | ||
| } | ||
|
|
||
| processes := []UnityProcess{} | ||
| for _, kinfoProc := range kinfoProcs { | ||
| pid := int(kinfoProc.Proc.P_pid) | ||
| if pid <= 0 { | ||
| continue | ||
| } | ||
|
|
||
| args, err := macProcessArgs(pid) | ||
| if err != nil || len(args) == 0 { | ||
| // Reading another user's process args fails (EPERM). Non-root ps could | ||
| // not read those processes' arguments either, so they never matched | ||
| // before; skipping them preserves prior behavior. | ||
| continue | ||
| } | ||
|
|
||
| process, matched := matchMacUnityProcess(pid, strings.Join(args, " ")) | ||
| if matched { | ||
| processes = append(processes, process) | ||
| } | ||
| } | ||
| return processes, nil | ||
| } | ||
|
|
||
| // macProcessArgs reads a process's argv via the kern.procargs2 sysctl node. | ||
| func macProcessArgs(pid int) ([]string, error) { | ||
| buf, err := unix.SysctlRaw("kern.procargs2", pid) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return parseMacProcArgs2(buf) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| //go:build !darwin | ||
|
|
||
| package unityprocess | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| ) | ||
|
|
||
| // listUnityProcessesMac exists so the shared dispatcher in process.go compiles on | ||
| // every target OS; the real sysctl-based implementation lives in process_darwin.go | ||
| // and this stub is never reached at runtime because listUnityProcesses only calls it | ||
| // when runtime.GOOS == "darwin". | ||
| func listUnityProcessesMac(_ context.Context) ([]UnityProcess, error) { | ||
| return nil, errors.New("listUnityProcessesMac is unsupported on this platform") | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "sharedInputsHash": "9eed1894ac125f75cdbb2f5145977ecfa92095bf" | ||
| "sharedInputsHash": "ffe6879910a39cf2bfd41750d1004a74009bc166" | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "sharedInputsHash": "5e974fe74190b43814743342f870ff27ded3b83c" | ||
| "sharedInputsHash": "365d004e1dd5b0ffd4da57aafb814466595cbf26" | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Bound
argcbefore using it as slice capacity.argcis read directly from the raw sysctl buffer and used unbounded asmake([]string, 0, argc). A corrupted/unexpected buffer with a very large leading value (e.g. near0xFFFFFFFF) would attempt a huge allocation and could panic, defeating the malformed-buffer hardening this function is otherwise designed and tested for (short-buffer and missing-terminator cases are already rejected).🛡️ Proposed fix to cap the pre-allocation
📝 Committable suggestion
🤖 Prompt for AI Agents