Repository navigation
fix(build): preserve Android tagged pointers in OpenTUI FFI (fixes #43, #46) - #48
Open
MohamadOday wants to merge 1 commit into
Open
MohamadOday wants to merge 1 commit into
MohamadOday wants to merge 1 commit into
Conversation
…pe2333#43, Hope2333#46) On Android 11+ ARM64, Bionic Scudo applies a 0xb4 top-byte tag (ARM TBI) to heap allocations. In OpenTUI 0.6.x (shipped with OpenCode >= 2.1.4), toSafeNumberPointer() throws 'Pointer exceeds safe integer range' on any pointer above Number.MAX_SAFE_INTEGER, while toBunPointer2() casts BigInt pointers to Number, truncating bits beyond 53. Stripping the tag causes Bionic to abort on free(). Bun 1.4.0 FFI natively accepts BigInt values for pointer parameters and preserves the 64-bit tagged pointer. Update apply-platform-patch.sh to pass through BigInt pointers when exceeding Number.MAX_SAFE_INTEGER in toSafeNumberPointer, and return pointers directly in toBunPointer2. Add apply-platform-patch.bats unit tests to verify patch application, idempotency, and 64-bit preservation.
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.
Problem
On Android 11+ ARM64, Bionic Scudo applies a
0xb4top-byte tag (ARM TBI) to heap allocations.In OpenTUI 0.6.x (used by OpenCode >= 2.1.4),
toSafeNumberPointer()checkspointer > BigInt(Number.MAX_SAFE_INTEGER)and throwsError: Pointer exceeds safe integer range. This prevents the TUI from starting (reported in #43 and #46).Additionally,
toBunPointer2()casts BigInt pointers toNumber(pointer), which truncates bits beyond 53 before passing the address to nativetoArrayBuffer.Stripping the
0xb4tag is unsafe because Bionic Scudo validates the tag duringfree()and aborts withPointer tag for 0x... was truncated.Fix
Bun 1.4.0 FFI natively accepts BigInt values for
ptrarguments and preserves the 64-bit tagged pointer.tools/build-bionic/apply-platform-patch.sh, patchtoSafeNumberPointer()to return the pointer directly whenpointer > BigInt(Number.MAX_SAFE_INTEGER)instead of throwingPOINTER_UNSAFE.toBunPointer2()to return the pointer directly instead of casting toNumber(pointer).tests/unit/apply-platform-patch.batsto verify patch application, idempotency, OpenTUI 0.5.x compatibility, and runtime 64-bit pointer preservation under Node.js.Verification
tests/unit/apply-platform-patch.batsinside Termux: 5/5 tests passed.common.bats,make-opencode.bats,plugin-manager.bats,upgrade-matrix.bats): 53/53 tests passed.opencodelaunches the TUI without crashing, handles sessions, and exits cleanly without Bionic free aborts.