Skip to content

Commit fe5e4ea

Browse files
authored
On PowerPC, when handling QEMU's TCGETS2, handle B0. (#845)
Linux uses an input speed of `B0` to mean that the input speed is the same as the output speed. Add that logic to rustix's code to work around QEMU's handling of `TCGETS2` on PowerPC.
1 parent d3158ed commit fe5e4ea

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/backend/libc/termios/syscalls.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> {
7070

7171
// QEMU's `TCGETS2` doesn't currently set `input_speed` or
7272
// `output_speed` on PowerPC, so set them manually if we can.
73-
#[cfg(all(linux_kernel, any(target_arch = "powerpc", target_arch = "powerpc64")))]
73+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
7474
{
7575
use crate::termios::speed;
7676

@@ -82,7 +82,11 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> {
8282
if result.input_speed == 0
8383
&& ((termios2.c_cflag & c::CIBAUD) >> c::IBSHIFT) != c::BOTHER
8484
{
85-
if let Some(input_speed) =
85+
// For input speeds, `B0` is special-cased to mean the input
86+
// speed is the same as the output speed.
87+
if ((termios2.c_cflag & c::CIBAUD) >> c::IBSHIFT) == c::B0 {
88+
result.input_speed = result.output_speed;
89+
} else if let Some(input_speed) =
8690
speed::decode((termios2.c_cflag & c::CIBAUD) >> c::IBSHIFT)
8791
{
8892
result.input_speed = input_speed;

src/backend/linux_raw/termios/syscalls.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> {
6363
if result.input_speed == 0
6464
&& ((result.control_modes.bits() & c::CIBAUD) >> c::IBSHIFT) != c::BOTHER
6565
{
66-
if let Some(input_speed) =
66+
// For input speeds, `B0` is special-cased to mean the input
67+
// speed is the same as the output speed.
68+
if ((result.control_modes.bits() & c::CIBAUD) >> c::IBSHIFT) == c::B0 {
69+
result.input_speed = result.output_speed;
70+
} else if let Some(input_speed) =
6771
speed::decode((result.control_modes.bits() & c::CIBAUD) >> c::IBSHIFT)
6872
{
6973
result.input_speed = input_speed;

0 commit comments

Comments
 (0)