Skip to content
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

feat(tty): enhance TTY support with Termios implementation #181

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ members = [
"crates/spinlock",
"crates/timer_list",
"crates/tuple_for_each",
"crates/tty",
"crates/ringbuffer",

"modules/axalloc",
"modules/axlog",
Expand All @@ -53,6 +53,7 @@ members = [
"modules/ruxtask",
"modules/ruxfutex",
"modules/ruxrand",
"modules/ruxtty",

"api/ruxfeat",
"api/arceos_api",
Expand Down
20 changes: 17 additions & 3 deletions api/ruxfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ alloc = ["axalloc", "ruxruntime/alloc", "ruxfs/alloc", "ruxhal/alloc"]
alloc-tlsf = ["axalloc/tlsf"]
alloc-slab = ["axalloc/slab"]
alloc-buddy = ["axalloc/buddy"]
paging = ["alloc", "ruxhal/paging", "ruxtask/paging", "ruxruntime/paging", "ruxmm/paging"]
paging = [
"alloc",
"ruxhal/paging",
"ruxtask/paging",
"ruxruntime/paging",
"ruxmm/paging",
]
tls = ["alloc", "ruxhal/tls", "ruxruntime/tls", "ruxtask?/tls"]

# Multi-threading and scheduler
Expand Down Expand Up @@ -78,7 +84,13 @@ virtio-9p = [
net-9p = ["9pfs", "net", "rux9p/net-9p", "ruxruntime/net-9p"]

# virtio console
virtio_console = ["ruxhal/virtio_console", "ruxruntime/virtio_console", "alloc", "ruxdriver/virtio_console", "ruxdriver/virtio"]
virtio_console = [
"ruxhal/virtio_console",
"ruxruntime/virtio_console",
"alloc",
"ruxdriver/virtio_console",
"ruxdriver/virtio",
]

# Device drivers
bus-mmio = ["ruxdriver?/bus-mmio"]
Expand All @@ -95,11 +107,13 @@ log-level-info = ["axlog/log-level-info"]
log-level-debug = ["axlog/log-level-debug"]
log-level-trace = ["axlog/log-level-trace"]

tty = ["ruxhal/tty", "ruxruntime/tty", "alloc", "irq"]
# this feature has already been deprecated
tty = []

[dependencies]
ruxruntime = { path = "../../modules/ruxruntime" }
ruxhal = { path = "../../modules/ruxhal" }
ruxtty = { path = "../../modules/ruxtty" }
ruxmm = { path = "../../modules/ruxmm" }
axlog = { path = "../../modules/axlog" }
axalloc = { path = "../../modules/axalloc", optional = true }
Expand Down
6 changes: 5 additions & 1 deletion api/ruxos_posix_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ ruxfdtable = { path = "../../modules/ruxfdtable" }
ruxmm = { path = "../../modules/ruxmm", optional = true }
ruxfutex = { path = "../../modules/ruxfutex", optional = true }
axalloc = { path = "../../modules/axalloc", optional = true }
ruxtask = { path = "../../modules/ruxtask", features = ["notest"], optional = true }
ruxtask = { path = "../../modules/ruxtask", features = [
"notest",
], optional = true }
ruxfs = { path = "../../modules/ruxfs", optional = true }
ruxnet = { path = "../../modules/ruxnet", optional = true }
ruxtty = { path = "../../modules/ruxtty" }

# Other crates
axio = { path = "../../crates/axio" }
axerrno = { path = "../../crates/axerrno" }
ringbuffer = { path = "../../crates/ringbuffer" }
memory_addr = "0.1.0"
static_assertions = "1.1.0"
spin = { version = "0.9" }
Expand Down
8 changes: 4 additions & 4 deletions api/ruxos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ruxfs::{
use crate::ctypes;
use ruxtask::fs::{get_file_like, Directory, File};

use super::stdio::{stdin, stdout};
use super::stdio::{Stdin, Stdout};

struct InitFsImpl;

Expand All @@ -33,9 +33,9 @@ impl ruxtask::fs::InitFs for InitFsImpl {
fn add_stdios_to_fd_table(fs: &mut ruxtask::fs::FileSystem) {
debug!("init initial process's fd_table");
let fd_table = &mut fs.fd_table;
fd_table.add_at(0, Arc::new(stdin()) as _).unwrap(); // stdin
fd_table.add_at(1, Arc::new(stdout()) as _).unwrap(); // stdout
fd_table.add_at(2, Arc::new(stdout()) as _).unwrap(); // stderr
fd_table.add_at(0, Arc::new(Stdin::default()) as _).unwrap(); // stdin
fd_table.add_at(1, Arc::new(Stdout {}) as _).unwrap(); // stdout
fd_table.add_at(2, Arc::new(Stdout {}) as _).unwrap(); // stderr
}
}

Expand Down
11 changes: 7 additions & 4 deletions api/ruxos_posix_api/src/imp/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ use crate::ctypes;
use axerrno::LinuxError;
use core::ffi::{c_int, c_void};

#[cfg(not(feature = "fd"))]
use axio::prelude::*;
#[cfg(feature = "fd")]
use ruxtask::fs::get_file_like;
#[cfg(not(feature = "fd"))]
use {
axio::prelude::*,
imp::stdio::{Stdin, Stdout},
};

/// Read data from the file indicated by `fd`.
///
Expand All @@ -32,7 +35,7 @@ pub fn sys_read(fd: c_int, buf: *mut c_void, count: usize) -> ctypes::ssize_t {
}
#[cfg(not(feature = "fd"))]
match fd {
0 => Ok(super::stdio::stdin().read(dst)? as ctypes::ssize_t),
0 => Ok(Stdin::default()._read(dst)? as ctypes::ssize_t),
1 | 2 => Err(LinuxError::EPERM),
_ => Err(LinuxError::EBADF),
}
Expand All @@ -56,7 +59,7 @@ pub fn sys_write(fd: c_int, buf: *const c_void, count: usize) -> ctypes::ssize_t
#[cfg(not(feature = "fd"))]
match fd {
0 => Err(LinuxError::EPERM),
1 | 2 => Ok(super::stdio::stdout().write(src)? as ctypes::ssize_t),
1 | 2 => Ok(Stdout {}.write(src)? as ctypes::ssize_t),
_ => Err(LinuxError::EBADF),
}
})
Expand Down
45 changes: 3 additions & 42 deletions api/ruxos_posix_api/src/imp/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,12 @@
* See the Mulan PSL v2 for more details.
*/

use crate::sys_getpgid;
use axerrno::LinuxError;
use core::ffi::c_int;
use ruxtask::fs::get_file_like;

/// IOCTL oprations
pub const TCGETS: usize = 0x5401;
pub const TIOCGPGRP: usize = 0x540F;
pub const TIOCSPGRP: usize = 0x5410;
pub const TIOCGWINSZ: usize = 0x5413;
pub const FIONBIO: usize = 0x5421;
pub const FIOCLEX: usize = 0x5451;

#[derive(Clone, Copy, Default)]
pub struct ConsoleWinSize {
pub ws_row: u16,
pub ws_col: u16,
pub ws_xpixel: u16,
pub ws_ypixel: u16,
}

/// ioctl implementation,
/// currently only support fd = 1
pub fn sys_ioctl(fd: c_int, request: usize, data: usize) -> c_int {
Expand All @@ -40,35 +25,11 @@ pub fn sys_ioctl(fd: c_int, request: usize, data: usize) -> c_int {
}
Ok(0)
}
// TODO: a temporary solution for TIOCGWINSZ.
TIOCGWINSZ => {
let winsize = data as *mut ConsoleWinSize;
unsafe {
*winsize = ConsoleWinSize::default();
}
if fd == 0 || fd == 1 || fd == 2 {
Ok(0)
} else {
Ok(-1)
}
}
TCGETS => {
debug!("sys_ioctl: tty TCGETS");
Ok(0)
}
TIOCSPGRP => {
warn!("stdout pretend to be tty");
Ok(0)
}
TIOCGPGRP => {
warn!("stdout TIOCGPGRP, pretend to be have a tty process group.");
unsafe {
*(data as *mut u32) = sys_getpgid(0) as _;
}
FIOCLEX => Ok(0),
_ => {
get_file_like(fd)?.ioctl(request, data)?;
Ok(0)
}
FIOCLEX => Ok(0),
_ => Err(LinuxError::EINVAL),
}
})
}
Loading
Loading