forked from google-antigravity/antigravity-cli
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add distro-agnostic PRoot/Chroot support for 39-bit Android #5
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
wallentx
merged 12 commits into
wallentx:dev
from
estiaksoyeb:feat/ubuntu-chroot-compat
May 28, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a833874
feat: add Ubuntu chroot and 39-bit VA compatibility layer
estiaksoyeb 00b02dd
docs: add Ubuntu chroot compatibility layer technical reference
wallentx 30c8478
feat(build): implement dynamic hex header code-generation pipeline
wallentx bd757b5
chore(git): ignore transient mmap interposer build files
wallentx 929c5bd
ci(workflow): bootstrap transient headers and implement hybrid compil…
wallentx 6524e57
fix(ci): disable thread-comments and exclude generated header from fo…
wallentx 35c5756
feat(compat): refine PRoot terminology in docs and fix installer logic
wallentx 714aead
fix(compat): handle interposer extraction failure and warn on bionic …
wallentx 8f60967
style: run clang-format to fix CI
wallentx 9a9c74e
fix(ci): handle execv return value and fix clang-tidy err33-c
wallentx c0d6460
fix(compat): Expand library search paths for guest environments
wallentx 4e36eb6
style(lib): Reformat long library path string for readability
wallentx 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
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,30 @@ | ||
| # PRoot Distro and 39-Bit Virtual Address Space Compatibility | ||
|
|
||
| ## Purpose | ||
| This document explains the runtime interposer and environment-aware bootstrapper architecture implemented to support executing the Antigravity CLI within non-native Termux environments (e.g., guest PRoot/Chroot distributions on Android). | ||
|
|
||
| ## Problem: 39-Bit Virtual Address Space Limits | ||
| The upstream dynamic binary utilizes Google's `TCMalloc` allocator, which assumes a standard 48-bit Virtual Address (VA) space. | ||
|
|
||
| However, many ARM64 Android kernels limit user space to a 39-bit VA space. When TCMalloc makes `mmap` calls specifying a high hint address (e.g., above `2^39`), the call fails on these kernels, triggering an immediate abort: | ||
| ```text | ||
| FATAL ERROR: Out of memory trying to allocate internal tcmalloc data | ||
| MmapAligned() failed - unable to allocate with tag (hint=0x2f4c00000000, size=1073741824) | ||
| ``` | ||
|
|
||
| ## Solution: Runtime Mmap Interposition | ||
| Because the upstream Go binary is precompiled, system calls made during its execution cannot be modified at source level. The compatibility layer intercepts these calls at the dynamic loading boundary. | ||
|
|
||
| ### 1. The Interposer (`lib/mmap_va39_fix.c`) | ||
| A minimal shared library intercepts dynamic `mmap` calls at runtime. If a requested hint address exceeds the 39-bit boundary (`1ULL << 39`), the interposer clears the hint (setting it to `NULL`). This redirects the kernel to allocate memory at a valid, lower virtual address, preventing the TCMalloc crash. | ||
|
|
||
| ### 2. Transient Build-Time Embedding | ||
| To keep the release archive restricted strictly to the `bin/` directory, the interposer is embedded directly inside the bootstrapper rather than being packaged as a separate file in the release archive: | ||
| * **Build-Time**: `build.sh` compiles `lib/mmap_va39_fix.c` to `libmmap_va39_fix.so`, converts the raw binary data into a C byte array header (`lib/mmap_va39_fix_bytes.h`), and compiles it into the `bin/agy` executable. | ||
| * **Git Hygiene**: The generated header and intermediate `.so` are git-ignored to keep the repository history clean. | ||
|
|
||
| ### 3. Just-In-Time Extraction & Preloading (`lib/agy_helper.c`) | ||
| At runtime, the bootstrapper `bin/agy` executes the following sequence: | ||
| 1. **Environment Detection**: Detects if execution is running natively inside Termux or within a guest PRoot/Chroot distribution. | ||
| 2. **Dynamic Unpacking**: If running in a guest PRoot/Chroot distribution, the bootstrapper extracts the embedded `.so` bytes from memory to a writable temporary directory (prioritizing `$TMPDIR` before falling back to `/tmp`). Writing is skipped if the file already exists with matching size. | ||
| 3. **Preload Injection**: Appends the extracted `.so` path to the glibc loader `--preload` argument and configures relocatable library search paths (e.g., dynamically adding `/lib` and `/usr/lib`) before executing `execv`. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.