alnyan/yggdrasil: add MessageChannel + get_random
This commit is contained in:
@@ -167,3 +167,32 @@ pub unsafe fn update_terminal_options<
|
||||
set_terminal_options(fd, new)?;
|
||||
Ok(old)
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub struct MessageChannel(OwnedFd);
|
||||
|
||||
impl MessageChannel {
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn open<S: AsRef<str>>(name: S, with_sub: bool) -> crate::io::Result<Self> {
|
||||
let raw_fd = cvt_io(unsafe { yggdrasil_rt::sys::open_channel(name.as_ref(), with_sub) })?;
|
||||
|
||||
Ok(Self(unsafe { OwnedFd::from_raw_fd(raw_fd) }))
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn send(&mut self, msg: &[u8]) -> crate::io::Result<()> {
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::send_message(self.0.as_raw_fd(), msg) })
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn receive(&mut self, msg: &mut [u8]) -> crate::io::Result<usize> {
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::receive_message(self.0.as_raw_fd(), msg) })
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
impl AsRawFd for MessageChannel {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
self.0.as_raw_fd()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use super::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
||||
use crate::marker::PhantomData;
|
||||
use crate::mem::forget;
|
||||
use crate::sys_common::IntoInner;
|
||||
|
||||
#[stable(feature = "io_safety", since = "1.63.0")]
|
||||
#[repr(transparent)]
|
||||
@@ -100,3 +101,10 @@ impl Drop for OwnedFd {
|
||||
}
|
||||
|
||||
// TODO: AsFd for File, From<File> for OwnedFd, From<OwnedFd> for File,
|
||||
#[stable(feature = "io_safety", since = "1.63.0")]
|
||||
impl From<crate::fs::File> for OwnedFd {
|
||||
fn from(value: crate::fs::File) -> OwnedFd {
|
||||
let inner = value.into_inner();
|
||||
Self { fd: inner.into_raw_fd() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#![stable(feature = "os_fd", since = "1.66.0")]
|
||||
|
||||
use crate::sys_common::AsInner;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub type RawFd = yggdrasil_rt::io::RawFd;
|
||||
|
||||
@@ -67,3 +69,10 @@ stdio_impl_as_raw_fd!(
|
||||
crate::io::Stdout => RawFd::STDOUT,
|
||||
crate::io::Stderr => RawFd::STDERR
|
||||
);
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl AsRawFd for crate::fs::File {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
self.as_inner().as_raw_fd()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,11 @@ pub mod fs;
|
||||
pub mod io;
|
||||
pub mod process;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn get_random(buffer: &mut [crate::mem::MaybeUninit<u8>]) {
|
||||
unsafe { yggdrasil_rt::sys::get_random(crate::mem::MaybeUninit::slice_assume_init_mut(buffer)) }
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_raw_fd", issue = "none")]
|
||||
pub mod fd {
|
||||
pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
|
||||
|
||||
@@ -208,7 +208,7 @@ impl AsRawFd for File {
|
||||
|
||||
impl IntoRawFd for File {
|
||||
fn into_raw_fd(self) -> RawFd {
|
||||
todo!()
|
||||
self.0.into_raw_fd()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user