Skip to content

Commit 59365fa

Browse files
feat(tty): Implement missing TTY termios ioctls (TCSETSF, TCSETA*) (#2141)
feat(tty): complete Linux-compatible termios and serial semantics Implement the legacy TCGETA/TCSETA ioctl family and the drain and flush behavior required by TCSETSW, TCSETSF, TCSETAW, and TCSETAF. Preserve termio flag merging, c_line ABI values, control characters, baud-rate encoding, job-control checks, and safe userspace copy-out semantics in line with Linux 6.6. Track retained N_TTY output and use interruptible, event-driven drain waits with correct handling for partial writes, signals, hangups, and peer teardown. Add bounded PTY staging queues and deferred peer delivery to preserve write ordering while avoiding cross-endpoint termios lock deadlocks. Align PTY polling, packet mode, flushing, unthrottling, and per-file hangup behavior with Linux semantics. Replace direct serial8250 PIO writes with an interrupt-driven TX queue, apply termios framing settings to hardware, implement bounded physical transmitter waits, and correctly route legacy COM ports over IRQ3 and IRQ4. Serialize console, emergency, and runtime output and notify blocking and epoll writers when TX capacity becomes available. Make TTY fasync and hangup state follow individual open file descriptions. Serialize F_SETFL updates with lifecycle cleanup and unregister stale TTY, pipe, and socket fasync entries on final release. Add focused termios, PTY hangup, tcflush, and fasync regression tests, and validate independent COM2 transmission without relying on IRQ4 traffic. Co-authored-by: longjin <longjin@dragonos.org> Co-authored-by: kado <2448956191@qq.com> Signed-off-by: kado <2448956191@qq.com> Signed-off-by: longjin <longjin@dragonos.org>
1 parent 1f4e6b6 commit 59365fa

24 files changed

Lines changed: 3006 additions & 232 deletions

File tree

kernel/src/driver/serial/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use crate::mm::VirtAddr;
88
use self::serial8250::serial8250_manager;
99

1010
use super::tty::{
11-
termios::{ControlMode, InputMode, LocalMode, OutputMode, Termios, INIT_CONTORL_CHARACTERS},
11+
termios::{
12+
ControlMode, InputMode, LocalMode, OutputMode, Termios, INIT_CONTORL_CHARACTERS,
13+
INIT_C_LINE_ABI,
14+
},
1215
tty_ldisc::LineDisciplineType,
1316
};
1417

@@ -67,6 +70,7 @@ lazy_static! {
6770
| LocalMode::IEXTEN,
6871
control_characters: INIT_CONTORL_CHARACTERS,
6972
line: LineDisciplineType::NTty,
73+
c_line_abi: INIT_C_LINE_ABI,
7074
input_speed: SERIAL_BAUDRATE.data(),
7175
output_speed: SERIAL_BAUDRATE.data(),
7276
}

0 commit comments

Comments
 (0)