-
Notifications
You must be signed in to change notification settings - Fork 4.7k
sys: add bun.sys.termios wrapper for Android bionic #30391
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
Open
robobun
wants to merge
6
commits into
main
Choose a base branch
from
farm/43e239ac/android-termios
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2cfb968
sys: add bun.sys.termios wrapper for Android bionic
robobun b299ed5
test: use static import for bun:internal-for-testing
robobun 652c7b6
[autofix.ci] apply automated fixes
autofix-ci[bot] 54fd2c2
sys_jsc: close posix_openpt fd via bun.FD
robobun 1c6f79a
sys_jsc: probe termios on the PTY slave, not the master
robobun 5f2af29
test: resolve termiosLayout lazily so JUnit records the fail-before
robobun 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
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,36 @@ | ||
| // bun.sys.termios must match the host libc's `struct termios`. Zig's | ||
| // std.posix.termios assumes the glibc/musl layout on Linux (cc[32] plus | ||
| // trailing c_ispeed/c_ospeed, ~60B), which is wrong for bionic (Android | ||
| // uses the raw kernel struct: cc[19], no speed fields, 36B). The first | ||
| // 36B are layout-compatible so tcgetattr/tcsetattr "mostly work", but | ||
| // writes to .ispeed/.ospeed land past bionic's struct and reinitialising | ||
| // c_cflag zeroes CBAUD → baud becomes B0. | ||
| // | ||
| // This test opens a PTY slave via posix_openpt/grantpt/unlockpt/ptsname | ||
| // (the master fd isn't a terminal on BSD/macOS), writes a sentinel into | ||
| // c_cc[VLNEXT] and toggles ECHO via bun.sys.tcsetattr, then reads both | ||
| // back via bun.sys.tcgetattr. That round-trip holds iff the Zig struct | ||
| // agrees with libc's on this platform. | ||
| import { expect, test } from "bun:test"; | ||
| import { isPosix } from "harness"; | ||
|
|
||
| test.skipIf(!isPosix)("bun.sys.termios matches the host libc's struct termios", () => { | ||
| // Resolve lazily: a static `import { termiosLayout }` throws | ||
| // `SyntaxError: Export named 'termiosLayout' not found` at module | ||
| // load on a binary without the binding. bun:test's console output | ||
| // counts that as "1 fail", but the JUnit reporter emits zero | ||
| // testcases — so a fail-before gate that parses JUnit sees 0 | ||
| // failures and concludes the test doesn't exercise the fix. | ||
| // Requiring inside the test body turns the missing export into an | ||
| // ordinary assertion failure that JUnit records. This mirrors | ||
| // sigaction-layout.test.ts. | ||
| const { termiosLayout } = require("bun:internal-for-testing") as typeof import("bun:internal-for-testing"); | ||
| expect(termiosLayout).toBeFunction(); | ||
|
|
||
| const result = termiosLayout(); | ||
| expect(result).toBeDefined(); | ||
| // c_cc[VLNEXT] and lflag.ECHO must survive the trip through libc. | ||
| expect(result!.readback).toEqual(result!.installed); | ||
| expect(result!.installed.cc_lnext).toBe(0x5a); | ||
| expect(result!.sizeof).toBeGreaterThan(0); | ||
| }); | ||
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.