Skip to content

Support hierarchical zygote startup via stub processes#100

Merged
JingMatrix merged 4 commits intomasterfrom
stub
Feb 21, 2026
Merged

Support hierarchical zygote startup via stub processes#100
JingMatrix merged 4 commits intomasterfrom
stub

Conversation

@JingMatrix
Copy link
Copy Markdown
Owner

The ptrace monitoring logic has been re-architected to support a new Android startup chain where zygote is not a direct child of the init process. On some devices, the boot sequence is init -> stub_zygote -> zygote, which the previous flat monitoring model could not handle.

This change transitions the system from monitoring only direct children of init to a hierarchical model capable of recursively tracing a designated chain of processes.

Key changes include:

  1. Generalized Parent Handling: The logic specific to the init process has been refactored into a generic handleParentEvent. This function now handles fork events from any designated parent, including init or an intermediate stub process.

  2. Stub Process Promotion: When a traced child process executes a known stub_zygote binary, it is not detached. Instead, it is "promoted" to a new parent role. Its ptrace options are upgraded to trace forks, and its PID is added to a new stub_processes_ set for tracking.

  3. Hierarchical Dispatch: The central handleChildEvent dispatcher now prioritizes routing events for PIDs in the stub_processes_ set to the parent handler, allowing the monitor to discover and attach to grandchildren (the real zygote).

This new architecture is more resilient to platform variations in the boot process without sacrificing the precision of the injection mechanism.

The ptrace monitoring logic has been re-architected to support a new Android startup chain where zygote is not a direct child of the init process. On some devices, the boot sequence is `init -> stub_zygote -> zygote`, which the previous flat monitoring model could not handle.

This change transitions the system from monitoring only direct children of init to a hierarchical model capable of recursively tracing a designated chain of processes.

Key changes include:

1.  Generalized Parent Handling: The logic specific to the `init` process has been refactored into a generic `handleParentEvent`. This function now handles fork events from any designated parent, including `init` or an intermediate stub process.

2.  Stub Process Promotion: When a traced child process executes a known `stub_zygote` binary, it is not detached. Instead, it is "promoted" to a new parent role. Its ptrace options are upgraded to trace forks, and its PID is added to a new `stub_processes_` set for tracking.

3.  Hierarchical Dispatch: The central `handleChildEvent` dispatcher now prioritizes routing events for PIDs in the `stub_processes_` set to the parent handler, allowing the monitor to discover and attach to grandchildren (the real zygote).

This new architecture is more resilient to platform variations in the boot process without sacrificing the precision of the injection mechanism.
@JingMatrix JingMatrix linked an issue Feb 20, 2026 that may be closed by this pull request
1 task
Comment on lines +414 to +415
ptrace(PTRACE_CONT, pid, 0, 0);
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The process might be not ready if it not discovered via waitpid but observed from PTRACE_EVENT_FORK.
@JingMatrix JingMatrix merged commit aae20a8 into master Feb 21, 2026
1 check passed
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.

[Bug] Support for VR headset

2 participants