diff --git a/library/std/src/os/yggdrasil/io/device.rs b/library/std/src/os/yggdrasil/io/device.rs index 93fba9e4dda..e14a43f139c 100644 --- a/library/std/src/os/yggdrasil/io/device.rs +++ b/library/std/src/os/yggdrasil/io/device.rs @@ -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 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)) +} diff --git a/library/std/src/os/yggdrasil/io/mapping.rs b/library/std/src/os/yggdrasil/io/mapping.rs index ac42e545f87..0bfaf6113c8 100644 --- a/library/std/src/os/yggdrasil/io/mapping.rs +++ b/library/std/src/os/yggdrasil/io/mapping.rs @@ -1,3 +1,5 @@ +#![unstable(feature = "yggdrasil_os", issue = "none")] + use crate::os::fd::{AsRawFd, OwnedFd}; use crate::sys::cvt_io; diff --git a/library/std/src/os/yggdrasil/io/message_channel.rs b/library/std/src/os/yggdrasil/io/message_channel.rs index f473ea478b9..a0682fb5b18 100644 --- a/library/std/src/os/yggdrasil/io/message_channel.rs +++ b/library/std/src/os/yggdrasil/io/message_channel.rs @@ -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>(name: S, with_sub: bool) -> io::Result { - 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())) } diff --git a/library/std/src/os/yggdrasil/io/mod.rs b/library/std/src/os/yggdrasil/io/mod.rs index 4caa6b30935..0067d207498 100644 --- a/library/std/src/os/yggdrasil/io/mod.rs +++ b/library/std/src/os/yggdrasil/io/mod.rs @@ -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)) -} diff --git a/library/std/src/os/yggdrasil/io/pipe.rs b/library/std/src/os/yggdrasil/io/pipe.rs new file mode 100644 index 00000000000..26a12cee2c8 --- /dev/null +++ b/library/std/src/os/yggdrasil/io/pipe.rs @@ -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)) +} diff --git a/library/std/src/os/yggdrasil/io/poll.rs b/library/std/src/os/yggdrasil/io/poll.rs index b312639a541..02b202bf5f0 100644 --- a/library/std/src/os/yggdrasil/io/poll.rs +++ b/library/std/src/os/yggdrasil/io/poll.rs @@ -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); diff --git a/library/std/src/os/yggdrasil/io/shared_memory.rs b/library/std/src/os/yggdrasil/io/shared_memory.rs index d0b65a39cc3..571a5b3dc50 100644 --- a/library/std/src/os/yggdrasil/io/shared_memory.rs +++ b/library/std/src/os/yggdrasil/io/shared_memory.rs @@ -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; diff --git a/library/std/src/os/yggdrasil/io/terminal.rs b/library/std/src/os/yggdrasil/io/terminal.rs index 4d4b8a7d386..d50f8534019 100644 --- a/library/std/src/os/yggdrasil/io/terminal.rs +++ b/library/std/src/os/yggdrasil/io/terminal.rs @@ -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(fd: F, opt: TerminalOptions) -> io::Result<()> { let mut req = DeviceRequest::SetTerminalOptions(opt); @@ -24,6 +32,7 @@ pub unsafe fn get_terminal_options(fd: F) -> io::Result(fd: F) -> io::Result { let mut req = DeviceRequest::GetTerminalSize(MaybeUninit::uninit()); cvt_io(unsafe { syscall::device_request(fd.as_raw_fd(), &mut req) })?; diff --git a/library/std/src/sys/yggdrasil/process.rs b/library/std/src/sys/yggdrasil/process.rs index 951c93a601d..8294bb6ebbd 100644 --- a/library/std/src/sys/yggdrasil/process.rs +++ b/library/std/src/sys/yggdrasil/process.rs @@ -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 { 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 }) }