alnyan/yggdrasil: more yggdrasil_rt functionality in std
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use crate::fmt;
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
// This is a safer version of debug_trace! from yggdrasil_rt that uses heap-allocated buffer
|
||||
// instead of a fixed-size chunk.
|
||||
#[macro_export]
|
||||
macro_rules! debug_trace {
|
||||
($($arg:tt)+) => {
|
||||
$crate::os::yggdrasil::debug::_debug_trace(format_args!($($arg)+))
|
||||
};
|
||||
}
|
||||
|
||||
pub fn _debug_trace(args: fmt::Arguments<'_>) {
|
||||
let string = format!("{}", args);
|
||||
unsafe {
|
||||
syscall::debug_trace(string.as_str());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use crate::fs::Metadata;
|
||||
use crate::sys_common::AsInner;
|
||||
use yggdrasil_rt::io::FileMode;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub trait MetadataExt {
|
||||
fn mode_ext(&self) -> FileMode;
|
||||
}
|
||||
|
||||
impl MetadataExt for Metadata {
|
||||
fn mode_ext(&self) -> FileMode {
|
||||
self.as_inner().mode_ext()
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,18 @@ pub(crate) mod raw;
|
||||
use crate::io::StdinLock;
|
||||
|
||||
use crate::mem::MaybeUninit;
|
||||
use crate::path::Path;
|
||||
use crate::sys::cvt_io;
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
use yggdrasil_rt::{
|
||||
io::{FileMode, OpenOptions},
|
||||
sys as syscall,
|
||||
};
|
||||
|
||||
// Public exports
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use yggdrasil_rt::io::{
|
||||
DeviceRequest, TerminalInputOptions, TerminalLineOptions, TerminalOptions,
|
||||
DeviceRequest, MountOptions, TerminalInputOptions, TerminalLineOptions, TerminalOptions,
|
||||
TerminalOutputOptions,
|
||||
};
|
||||
|
||||
@@ -64,6 +68,26 @@ pub unsafe fn get_terminal_options<F: raw::AsRawFd>(fd: F) -> crate::io::Result<
|
||||
Ok(opt.assume_init())
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub unsafe fn start_terminal_session<P: AsRef<Path>>(terminal: P) -> crate::io::Result<()> {
|
||||
let terminal = terminal.as_ref().to_str().unwrap();
|
||||
|
||||
cvt_io(syscall::start_session())?;
|
||||
|
||||
// TODO implement open flags to explicitly set stdin/stdout/stderr
|
||||
|
||||
cvt_io(syscall::open(None, terminal, OpenOptions::READ, FileMode::empty()))?;
|
||||
cvt_io(syscall::open(None, terminal, OpenOptions::WRITE, FileMode::empty()))?;
|
||||
cvt_io(syscall::open(None, terminal, OpenOptions::WRITE, FileMode::empty()))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub unsafe fn mount_raw(options: &MountOptions<'_>) -> crate::io::Result<()> {
|
||||
cvt_io(syscall::mount(options))
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub unsafe fn update_terminal_options<
|
||||
F: raw::AsRawFd,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#![stable(feature = "os", since = "1.0.0")]
|
||||
|
||||
pub mod debug;
|
||||
pub mod fs;
|
||||
pub mod io;
|
||||
pub mod process;
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ impl FileAttr {
|
||||
FileType(self.0.ty)
|
||||
}
|
||||
|
||||
pub fn mode_ext(&self) -> OsFileMode {
|
||||
self.0.mode
|
||||
}
|
||||
|
||||
pub fn modified(&self) -> io::Result<SystemTime> {
|
||||
Err(crate::io::const_io_error!(
|
||||
crate::io::ErrorKind::Unsupported,
|
||||
|
||||
Reference in New Issue
Block a user