Repository navigation
Conversation
On MIPS, glibc defines `TCSANOW`/`TCSADRAIN`/`TCSAFLUSH` as `TCSETS`, `TCSETSW` and `TCSETSF`, so the libc backend subtracted `TCSETS` from `optional_actions` to get the offset. musl defines `TCSANOW` as 0 on every architecture, so on `mips*-unknown-linux-musl` the computed request was `TCSETS2 - TCSETS`, an invalid ioctl that fails with `ENOTTY`. The `TCSETS` fallback then issued `ioctl(fd, 0)`, which also fails, so every `tcsetattr` call returned `ENOTTY`. Only apply the MIPS adjustment when not targeting musl, and add a test that exercises every `OptionalActions` value on a pseudoterminal.
With a 64-bit `time_t` (musl >= 1.2 ABI, `libc_unstable_musl_v1_2` in the
`libc` crate), musl's `struct timespec` on 32-bit targets pads `tv_nsec` to
64 bits: `{ i64 tv_sec; u32 pad; i32 tv_nsec }` on big-endian and
`{ i64 tv_sec; i32 tv_nsec; u32 pad }` on little-endian. rustix used
`Nsecs = c_long`, giving `{ i64 tv_sec; i32 tv_nsec; u32 pad }` on every
endianness. Both are 16 bytes, so the pointer cast in
`as_libc_timespec_ptr` compiles, but on big-endian (e.g.
`mips-unknown-linux-musl`) libc reads `tv_nsec` from rustix's uninitialized
padding: `poll`/`ppoll` timeouts lose their sub-second part, and a garbage
value would make the call fail with `EINVAL`.
Use a 64-bit `Nsecs` for the libc backend on 32-bit musl, which matches
both layouts, and replace the field-offset layout test for this case with
a test that reads the values back through `c::timespec`.
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.
Fixes #1765.
Two independent fixes for
mips*-unknown-linux-musl, which uses the libc backend:tcsetattrrequest codes on MIPS with musl. The MIPS adjustment (optional_actions - TCSETS) assumes glibc, whereTCSANOW == TCSETSon MIPS. musl definesTCSANOWas 0, so everytcsetattrcall failed withENOTTY. The adjustment now applies only whentarget_env != "musl". New test:test_termios_optional_actions, which checksNow,DrainandFlushon a pty.Timespeclayout on 32-bit musl. With musl's 64-bittime_tABI (libc_unstable_musl_v1_2in thelibccrate),tv_nsecis padded to 64 bits, with the padding before it on big-endian. WithNsecs = c_long, libc readtv_nsecfrom rustix's uninitialized padding on big-endian, sopoll/ppolltimeouts lost their sub-second part.Nsecsis nowi64for the libc backend on 32-bit musl, which matches both endiannesses. For this case, the field-offset test is replaced bytimespec_musl32_matches_libc, which reads the values back throughc::timespec.Testing:
mips-unknown-linux-musl, run on hardware (MIPS32r2 big-endian, musl 1.2.5, built with nightly-Zbuild-stdand--cfg libc_unstable_musl_v1_2):tests/termiospasses exceptttyname::test_ttyname_not_tty, which also fails without this change (environment). The libtimespectests pass. Before the change, 6 termios tests fail.x86_64-unknown-linux-gnu, with and withoutuse-libc: the libtimespectests andtests/termiospass.Not addressed: 32-bit musl with the
libccrate default (32-bittime_t). See the issue.