alnyan/yggdrasil: split os::io into submodules
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use yggdrasil_rt::io::device as rt;
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
use super::DeviceRequest;
|
||||
use crate::io;
|
||||
use crate::os::fd::AsRawFd;
|
||||
use crate::sys::cvt_io;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type DeviceRequest = rt::DeviceRequest;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type MountOptions<'a> = rt::MountOptions<'a>;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type UnmountOptions = rt::UnmountOptions;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub trait FdDeviceRequest {
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
@@ -18,3 +29,8 @@ impl<T: AsRawFd> FdDeviceRequest for T {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub unsafe fn mount_raw(options: &MountOptions<'_>) -> crate::io::Result<()> {
|
||||
cvt_io(syscall::mount(options))
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use crate::os::fd::{AsRawFd, OwnedFd};
|
||||
use crate::sys::cvt_io;
|
||||
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
#![allow(unused)]
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use yggdrasil_rt::io::message_channel as rt;
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
use crate::io;
|
||||
use crate::mem::MaybeUninit;
|
||||
use crate::os::yggdrasil::io::{AsRawFd, FileMapping, FromRawFd, OwnedFd, RawFd};
|
||||
use crate::os::yggdrasil::io::{AsRawFd, FromRawFd, OwnedFd, RawFd};
|
||||
use crate::sync::Arc;
|
||||
use crate::sys::cvt_io;
|
||||
|
||||
use yggdrasil_rt::io::{MessageDestination, ReceivedMessageMetadata, SentMessage};
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type MessageDestination = rt::MessageDestination;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type ReceivedMessageMetadata = rt::ReceivedMessageMetadata;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type SentMessage<'a> = rt::SentMessage<'a>;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub struct MessageChannel(OwnedFd);
|
||||
@@ -57,7 +67,7 @@ pub trait MessageReceiver {
|
||||
impl MessageChannel {
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn open<S: AsRef<str>>(name: S, with_sub: bool) -> io::Result<Self> {
|
||||
let raw_fd = cvt_io(unsafe { yggdrasil_rt::sys::open_channel(name.as_ref(), with_sub) })?;
|
||||
let raw_fd = cvt_io(unsafe { syscall::open_channel(name.as_ref(), with_sub) })?;
|
||||
|
||||
Ok(Self(unsafe { OwnedFd::from_raw_fd(raw_fd) }))
|
||||
}
|
||||
@@ -75,7 +85,7 @@ impl MessageChannel {
|
||||
impl MessageSender for MessageChannel {
|
||||
#[inline]
|
||||
fn send_raw(&self, msg: &SentMessage<'_>, dst: MessageDestination) -> io::Result<()> {
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::send_message(self.0.as_raw_fd(), msg, dst) })
|
||||
cvt_io(unsafe { syscall::send_message(self.0.as_raw_fd(), msg, dst) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +97,7 @@ impl MessageReceiver for MessageChannel {
|
||||
let mut from = MaybeUninit::uninit();
|
||||
|
||||
cvt_io(unsafe {
|
||||
yggdrasil_rt::sys::receive_message(self.0.as_raw_fd(), &mut metadata, buf, &mut from)
|
||||
syscall::receive_message(self.0.as_raw_fd(), &mut metadata, buf, &mut from)
|
||||
})?;
|
||||
|
||||
unsafe { Ok((from.assume_init(), metadata.assume_init())) }
|
||||
|
||||
@@ -1,64 +1,21 @@
|
||||
#![stable(feature = "os_fd", since = "1.66.0")]
|
||||
#![allow(dead_code)]
|
||||
|
||||
mod device;
|
||||
mod mapping;
|
||||
mod message_channel;
|
||||
mod net;
|
||||
pub mod owned;
|
||||
mod poll;
|
||||
pub(crate) mod net;
|
||||
pub(crate) mod owned;
|
||||
pub(crate) mod raw;
|
||||
mod shared_memory;
|
||||
mod terminal;
|
||||
|
||||
use crate::mem::MaybeUninit;
|
||||
use crate::sys::cvt_io;
|
||||
use yggdrasil_rt::{
|
||||
// io::{FileMode, OpenOptions},
|
||||
sys as syscall,
|
||||
};
|
||||
pub mod device;
|
||||
pub mod mapping;
|
||||
pub mod message_channel;
|
||||
pub mod pipe;
|
||||
pub mod poll;
|
||||
pub mod shared_memory;
|
||||
pub mod terminal;
|
||||
|
||||
// Public exports
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use yggdrasil_rt::io::{
|
||||
DeviceRequest, MessageDestination, MountOptions, ReceivedMessageMetadata, TerminalInputOptions,
|
||||
TerminalLineOptions, TerminalOptions, TerminalOutputOptions, TerminalSize,
|
||||
};
|
||||
|
||||
#[stable(feature = "io_safety", since = "1.63.0")]
|
||||
pub use owned::*;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use raw::*;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use device::FdDeviceRequest;
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use mapping::FileMapping;
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use message_channel::{
|
||||
MessageChannel, MessageChannelReceiver, MessageChannelSender, MessageReceiver, MessageSender,
|
||||
};
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use poll::PollChannel;
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use shared_memory::SharedMemory;
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use terminal::{
|
||||
create_pty, get_terminal_options, set_terminal_options, start_terminal_session,
|
||||
update_terminal_options,
|
||||
};
|
||||
|
||||
#[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 fn create_pipe_pair() -> crate::io::Result<(OwnedFd, OwnedFd)> {
|
||||
let mut buffer = MaybeUninit::uninit_array();
|
||||
cvt_io(unsafe { syscall::create_pipe(&mut buffer) })?;
|
||||
let read = unsafe { OwnedFd::from_raw_fd(buffer[0].assume_init()) };
|
||||
let write = unsafe { OwnedFd::from_raw_fd(buffer[1].assume_init()) };
|
||||
Ok((read, write))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
use crate::mem::MaybeUninit;
|
||||
use crate::os::fd::{FromRawFd, OwnedFd};
|
||||
use crate::sys::cvt_io;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn create_pipe_pair() -> crate::io::Result<(OwnedFd, OwnedFd)> {
|
||||
let mut buffer = MaybeUninit::uninit_array();
|
||||
cvt_io(unsafe { syscall::create_pipe(&mut buffer) })?;
|
||||
let read = unsafe { OwnedFd::from_raw_fd(buffer[0].assume_init()) };
|
||||
let write = unsafe { OwnedFd::from_raw_fd(buffer[1].assume_init()) };
|
||||
Ok((read, write))
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use crate::io;
|
||||
use crate::os::yggdrasil::io::{AsRawFd, FromRawFd, OwnedFd, RawFd};
|
||||
use crate::sys::cvt_io;
|
||||
use crate::time::Duration;
|
||||
|
||||
use yggdrasil_rt::io::PollControl;
|
||||
use yggdrasil_rt::io::poll as rt;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type PollControl = rt::PollControl;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub struct PollChannel(OwnedFd);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use crate::io;
|
||||
use crate::os::yggdrasil::io::{AsRawFd, FileMapping, FromRawFd, OwnedFd, RawFd};
|
||||
use crate::os::yggdrasil::io::mapping::FileMapping;
|
||||
use crate::os::yggdrasil::io::{AsRawFd, FromRawFd, OwnedFd, RawFd};
|
||||
use crate::sys::cvt_io;
|
||||
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#![unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
use yggdrasil_rt::io::{device::DeviceRequest, terminal as rt_terminal};
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
use super::{DeviceRequest, TerminalOptions, TerminalSize};
|
||||
use crate::fs::File;
|
||||
use crate::io;
|
||||
use crate::mem::MaybeUninit;
|
||||
@@ -8,6 +10,12 @@ use crate::os::fd::{AsRawFd, FromRawFd};
|
||||
use crate::path::Path;
|
||||
use crate::sys::cvt_io;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type TerminalOptions = rt_terminal::TerminalOptions;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub type TerminalSize = rt_terminal::TerminalSize;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub unsafe fn set_terminal_options<F: AsRawFd>(fd: F, opt: TerminalOptions) -> io::Result<()> {
|
||||
let mut req = DeviceRequest::SetTerminalOptions(opt);
|
||||
@@ -24,6 +32,7 @@ pub unsafe fn get_terminal_options<F: AsRawFd>(fd: F) -> io::Result<TerminalOpti
|
||||
Ok(opt.assume_init())
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn get_terminal_size<F: AsRawFd>(fd: F) -> io::Result<TerminalSize> {
|
||||
let mut req = DeviceRequest::GetTerminalSize(MaybeUninit::uninit());
|
||||
cvt_io(unsafe { syscall::device_request(fd.as_raw_fd(), &mut req) })?;
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::ffi::OsStr;
|
||||
use crate::fmt;
|
||||
use crate::io;
|
||||
use crate::num::NonZeroI32;
|
||||
use crate::os::yggdrasil::io::pipe as os_pipe;
|
||||
use crate::os::yggdrasil::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd};
|
||||
use crate::path::Path;
|
||||
use crate::sys::cvt_io;
|
||||
@@ -17,6 +18,7 @@ use yggdrasil_rt::io::RawFd;
|
||||
use yggdrasil_rt::process::{
|
||||
ExitCode as OsExitCode, Signal as OsSignal, SpawnOption, SpawnOptions,
|
||||
};
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
// Process
|
||||
|
||||
@@ -62,12 +64,12 @@ impl Process {
|
||||
}
|
||||
|
||||
pub fn kill(&mut self) -> io::Result<()> {
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::send_signal(self.pid, OsSignal::Killed) })
|
||||
cvt_io(unsafe { syscall::send_signal(self.pid, OsSignal::Killed) })
|
||||
}
|
||||
|
||||
pub fn wait(&mut self) -> io::Result<ExitStatus> {
|
||||
let mut status = OsExitCode::Exited(0);
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::wait_process(self.pid, &mut status) })?;
|
||||
cvt_io(unsafe { syscall::wait_process(self.pid, &mut status) })?;
|
||||
Ok(ExitStatus(status))
|
||||
}
|
||||
|
||||
@@ -92,7 +94,7 @@ impl Stdio {
|
||||
Stdio::Inherit => Ok((ChildStdio::Inherit, None)),
|
||||
Stdio::Null => Ok((ChildStdio::Null, None)),
|
||||
Stdio::MakePipe => {
|
||||
let (read, write) = crate::os::yggdrasil::io::create_pipe_pair()?;
|
||||
let (read, write) = os_pipe::create_pipe_pair()?;
|
||||
|
||||
if readable {
|
||||
let write = unsafe { AnonPipe::from(write) };
|
||||
@@ -340,7 +342,7 @@ impl Command {
|
||||
|
||||
let options = SpawnOptions { program, arguments, environment, optional: &optional };
|
||||
|
||||
let pid = cvt_io(unsafe { yggdrasil_rt::sys::spawn_process(&options) })?;
|
||||
let pid = cvt_io(unsafe { syscall::spawn_process(&options) })?;
|
||||
|
||||
Ok(Process { pid })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user