abi: clean up unused stuff in ABI
This commit is contained in:
parent
009f545cb3
commit
07458f33e4
@ -17,11 +17,7 @@ extern {
|
||||
type ExitCode = yggdrasil_abi::process::ExitCode;
|
||||
type ProcessWait = yggdrasil_abi::process::ProcessWait;
|
||||
|
||||
type SentMessage = yggdrasil_abi::io::SentMessage;
|
||||
type ReceivedMessageMetadata = yggdrasil_abi::io::ReceivedMessageMetadata;
|
||||
type DeviceRequest = yggdrasil_abi::io::DeviceRequest;
|
||||
type FileMetadataUpdate = yggdrasil_abi::io::FileMetadataUpdate;
|
||||
type FilesystemControl = yggdrasil_abi::io::FilesystemControl;
|
||||
type Rename = yggdrasil_abi::io::Rename;
|
||||
|
||||
type MessageHeader = yggdrasil_abi::net::MessageHeader;
|
||||
@ -32,8 +28,6 @@ extern {
|
||||
|
||||
#[thin]
|
||||
type SeekFrom = yggdrasil_abi::io::SeekFrom;
|
||||
#[thin]
|
||||
type MessageDestination = yggdrasil_abi::io::MessageDestination;
|
||||
}
|
||||
|
||||
// abi::net
|
||||
|
@ -1,62 +0,0 @@
|
||||
//! Message channel handling
|
||||
use abi_lib::SyscallRegister;
|
||||
|
||||
pub use crate::generated::ChannelPublisherId;
|
||||
|
||||
use super::RawFd;
|
||||
|
||||
/// Describes a message sent using SendMessage
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum SentMessage<'m> {
|
||||
/// A file is sent
|
||||
File(RawFd),
|
||||
/// Binary data is sent
|
||||
Data(&'m [u8]),
|
||||
}
|
||||
|
||||
/// Describes a message received using ReceiveMessage
|
||||
#[derive(Debug)]
|
||||
pub enum ReceivedMessageMetadata {
|
||||
/// A file was received
|
||||
File(RawFd),
|
||||
/// Binary data was received (contains data length)
|
||||
Data(usize),
|
||||
}
|
||||
|
||||
/// Specifies where a message should be delivered on a channel
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum MessageDestination {
|
||||
/// Broadcast everywhere, including the sender.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// May cause a feedback loop if the sender is also a subscriber of the channel.
|
||||
All,
|
||||
/// Broadcast everywhere, except the sender
|
||||
AllExceptSelf,
|
||||
/// Send to a specific subscriber ID
|
||||
Specific(u32),
|
||||
}
|
||||
|
||||
impl SyscallRegister for MessageDestination {
|
||||
fn from_syscall_register(value: usize) -> Self {
|
||||
match value {
|
||||
0 => Self::All,
|
||||
1 => Self::AllExceptSelf,
|
||||
n => Self::Specific((n - 2) as _),
|
||||
}
|
||||
}
|
||||
|
||||
fn into_syscall_register(self) -> usize {
|
||||
match self {
|
||||
Self::All => 0,
|
||||
Self::AllExceptSelf => 1,
|
||||
Self::Specific(v) => (v + 2) as usize,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ChannelPublisherId {
|
||||
/// NULL publisher ID, usually represents the publisher which opened the channel
|
||||
pub const ZERO: Self = Self(0);
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
|
||||
pub mod options;
|
||||
|
||||
mod channel;
|
||||
pub mod device;
|
||||
mod file;
|
||||
pub mod filesystem;
|
||||
@ -13,7 +12,6 @@ pub use crate::generated::{
|
||||
AccessMode, DirectoryEntry, FileAttr, FileMode, FileSync, FileType, GroupId, MountOptions,
|
||||
OpenOptions, PollControl, RawFd, RemoveFlags, TimerOptions, UnmountOptions, UserId,
|
||||
};
|
||||
pub use channel::{ChannelPublisherId, MessageDestination, ReceivedMessageMetadata, SentMessage};
|
||||
pub use file::{FileMetadataUpdate, FileMetadataUpdateMode, FileTimesUpdate, SeekFrom};
|
||||
pub use input::{KeyboardKey, KeyboardKeyCode, KeyboardKeyEvent};
|
||||
pub use terminal::{
|
||||
|
@ -1,224 +0,0 @@
|
||||
//! IP-address related types, see [core::net::IpAddr]
|
||||
use core::{fmt, str::FromStr};
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
/// Describes an IPv4 address
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[repr(C)]
|
||||
pub struct Ipv4Addr([u8; 4]);
|
||||
|
||||
/// Describes an IPv6 address
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[repr(C)]
|
||||
pub struct Ipv6Addr([u8; 16]);
|
||||
|
||||
/// Describes an IPv4/IPv6 address
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[repr(C)]
|
||||
pub enum IpAddr {
|
||||
/// IPv4 address
|
||||
V4(Ipv4Addr),
|
||||
/// IPv6 address
|
||||
V6(Ipv6Addr),
|
||||
}
|
||||
|
||||
// IPv4
|
||||
|
||||
impl Ipv4Addr {
|
||||
/// An unspecified IPv4 address: 0.0.0.0
|
||||
pub const UNSPECIFIED: Self = Self([0, 0, 0, 0]);
|
||||
/// A broadcast IPv4 address: 255.255.255.255
|
||||
pub const BROADCAST: Self = Self([255, 255, 255, 255]);
|
||||
/// A loopback IPv4 address: 127.0.0.1
|
||||
pub const LOOPBACK: Self = Self([127, 0, 0, 1]);
|
||||
|
||||
/// Constructs a new IPv4 address from its octets
|
||||
pub fn new(x: u8, y: u8, z: u8, w: u8) -> Self {
|
||||
Self([x, y, z, w])
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Ipv4Addr {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let c = core::net::Ipv4Addr::from_str(s).map_err(|_| Error::InvalidArgument)?;
|
||||
Ok(Self(c.octets()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Ipv4Addr {
|
||||
fn from(value: u32) -> Self {
|
||||
Self(value.to_be_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ipv4Addr> for u32 {
|
||||
fn from(value: Ipv4Addr) -> Self {
|
||||
u32::from_be_bytes(value.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Ipv4Addr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(&core::net::Ipv4Addr::from(self.0), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<core::net::Ipv4Addr> for Ipv4Addr {
|
||||
fn from(value: core::net::Ipv4Addr) -> Self {
|
||||
Self(value.octets())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ipv4Addr> for core::net::Ipv4Addr {
|
||||
fn from(value: Ipv4Addr) -> Self {
|
||||
core::net::Ipv4Addr::from(value.0)
|
||||
}
|
||||
}
|
||||
|
||||
// IPv6
|
||||
|
||||
impl Ipv6Addr {
|
||||
/// An IPv6 unspecified address `::`.
|
||||
pub const UNSPECIFIED: Self = Self::new(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
/// Constructs a new IPv6 address from its words.
|
||||
///
|
||||
/// The result represents the IP address `a:b:c:d:e:f:g:h`.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Self {
|
||||
let addr16 = [
|
||||
a.to_be(),
|
||||
b.to_be(),
|
||||
c.to_be(),
|
||||
d.to_be(),
|
||||
e.to_be(),
|
||||
f.to_be(),
|
||||
g.to_be(),
|
||||
h.to_be(),
|
||||
];
|
||||
// SAFETY: `[u16; 8]` is safe to transmute to `[u8; 16]`
|
||||
Self(unsafe { core::mem::transmute::<_, [u8; 16]>(addr16) })
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Ipv6Addr {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let c = core::net::Ipv6Addr::from_str(s).map_err(|_| Error::InvalidArgument)?;
|
||||
Ok(Self(c.octets()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 16]> for Ipv6Addr {
|
||||
#[inline]
|
||||
fn from(value: [u8; 16]) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ipv6Addr> for [u8; 16] {
|
||||
#[inline]
|
||||
fn from(value: Ipv6Addr) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Ipv6Addr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(&core::net::Ipv6Addr::from(self.0), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<core::net::Ipv6Addr> for Ipv6Addr {
|
||||
#[inline]
|
||||
fn from(value: core::net::Ipv6Addr) -> Self {
|
||||
Self(value.octets())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ipv6Addr> for core::net::Ipv6Addr {
|
||||
#[inline]
|
||||
fn from(value: Ipv6Addr) -> Self {
|
||||
core::net::Ipv6Addr::from(value.0)
|
||||
}
|
||||
}
|
||||
|
||||
// IP
|
||||
|
||||
impl IpAddr {
|
||||
/// Returns `true` if the address is IPv4
|
||||
pub fn is_ipv4(&self) -> bool {
|
||||
matches!(self, Self::V4(_))
|
||||
}
|
||||
/// Returns `true` if the address is IPv6
|
||||
pub fn is_ipv6(&self) -> bool {
|
||||
matches!(self, Self::V6(_))
|
||||
}
|
||||
|
||||
/// Returns [Some] if this is an IPv4 address, [None] otherwise
|
||||
pub fn into_ipv4(self) -> Option<Ipv4Addr> {
|
||||
match self {
|
||||
Self::V4(address) => Some(address),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for IpAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::V4(addr) => fmt::Display::fmt(addr, f),
|
||||
Self::V6(addr) => fmt::Display::fmt(addr, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for IpAddr {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let c = core::net::IpAddr::from_str(s).map_err(|_| Error::InvalidArgument)?;
|
||||
Ok(Self::from(c))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IpAddr> for core::net::IpAddr {
|
||||
#[inline]
|
||||
fn from(value: IpAddr) -> Self {
|
||||
match value {
|
||||
IpAddr::V4(address) => core::net::IpAddr::V4(address.into()),
|
||||
IpAddr::V6(address) => core::net::IpAddr::V6(address.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<core::net::IpAddr> for IpAddr {
|
||||
#[inline]
|
||||
fn from(value: core::net::IpAddr) -> Self {
|
||||
match value {
|
||||
core::net::IpAddr::V4(address) => Self::V4(address.into()),
|
||||
core::net::IpAddr::V6(address) => Self::V6(address.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ipv4Addr> for IpAddr {
|
||||
fn from(value: Ipv4Addr) -> Self {
|
||||
Self::V4(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ipv6Addr> for IpAddr {
|
||||
fn from(value: Ipv6Addr) -> Self {
|
||||
Self::V6(value)
|
||||
}
|
||||
}
|
@ -1,189 +0,0 @@
|
||||
//! Socket address types
|
||||
use core::fmt;
|
||||
|
||||
use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
|
||||
/// Describes an IPv4 socket address: 1.2.3.4:443
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[repr(C)]
|
||||
pub struct SocketAddrV4(Ipv4Addr, u16);
|
||||
|
||||
/// Describes an IPv6 socket address: [::]:443
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[repr(C)]
|
||||
pub struct SocketAddrV6(Ipv6Addr, u16);
|
||||
|
||||
/// Describes a socket address
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum SocketAddr {
|
||||
/// IPv4 socket address
|
||||
V4(SocketAddrV4),
|
||||
/// IPv6 socket address
|
||||
V6(SocketAddrV6),
|
||||
}
|
||||
|
||||
// V4
|
||||
|
||||
impl SocketAddrV4 {
|
||||
/// "Null" IPv4 address used when sender/recepient is not known or cannot be represented
|
||||
pub const NULL: Self = Self::new(Ipv4Addr::UNSPECIFIED, 0);
|
||||
|
||||
/// Constructs an IPv4 socket address from its IP and port components
|
||||
pub const fn new(address: Ipv4Addr, port: u16) -> Self {
|
||||
Self(address, port)
|
||||
}
|
||||
|
||||
/// Returns the IP address part of the value
|
||||
pub const fn ip(&self) -> Ipv4Addr {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Returns the port part of the value
|
||||
pub const fn port(&self) -> u16 {
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SocketAddrV4 {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}:{}", self.0, self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<core::net::SocketAddrV4> for SocketAddrV4 {
|
||||
#[inline]
|
||||
fn from(value: core::net::SocketAddrV4) -> Self {
|
||||
SocketAddrV4::new((*value.ip()).into(), value.port())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SocketAddrV4> for core::net::SocketAddrV4 {
|
||||
#[inline]
|
||||
fn from(value: SocketAddrV4) -> Self {
|
||||
core::net::SocketAddrV4::new(value.ip().into(), value.port())
|
||||
}
|
||||
}
|
||||
|
||||
// V6
|
||||
|
||||
impl SocketAddrV6 {
|
||||
/// Constructs an IPv6 socket address from its IP and port components
|
||||
pub const fn new(address: Ipv6Addr, port: u16) -> Self {
|
||||
Self(address, port)
|
||||
}
|
||||
|
||||
/// Returns the IP address part of the value
|
||||
pub const fn ip(&self) -> Ipv6Addr {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Returns the port part of the value
|
||||
pub const fn port(&self) -> u16 {
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SocketAddrV6 {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}:{}", self.0, self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<core::net::SocketAddrV6> for SocketAddrV6 {
|
||||
#[inline]
|
||||
fn from(value: core::net::SocketAddrV6) -> Self {
|
||||
SocketAddrV6::new((*value.ip()).into(), value.port())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SocketAddrV6> for core::net::SocketAddrV6 {
|
||||
#[inline]
|
||||
fn from(value: SocketAddrV6) -> Self {
|
||||
core::net::SocketAddrV6::new(value.ip().into(), value.port(), 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// SocketAddr
|
||||
|
||||
impl SocketAddr {
|
||||
/// "Null" IPv4 address used when sender/recepient is not known or cannot be represented
|
||||
pub const NULL_V4: Self = Self::V4(SocketAddrV4::NULL);
|
||||
|
||||
/// Constructs a socket address from its IP and port components
|
||||
pub const fn new(address: IpAddr, port: u16) -> Self {
|
||||
match address {
|
||||
IpAddr::V4(address) => Self::V4(SocketAddrV4::new(address, port)),
|
||||
IpAddr::V6(address) => Self::V6(SocketAddrV6::new(address, port)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the IP address part of the value
|
||||
pub const fn ip(&self) -> IpAddr {
|
||||
match self {
|
||||
Self::V4(address) => IpAddr::V4(address.ip()),
|
||||
Self::V6(address) => IpAddr::V6(address.ip()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns [Some] if this is an IPv4 address, [None] otherwise
|
||||
pub fn into_ipv4(self) -> Option<SocketAddrV4> {
|
||||
match self {
|
||||
Self::V4(address) => Some(address),
|
||||
Self::V6(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the port part of the value
|
||||
pub const fn port(&self) -> u16 {
|
||||
match self {
|
||||
Self::V4(address) => address.port(),
|
||||
Self::V6(address) => address.port(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SocketAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::V4(address) => fmt::Display::fmt(address, f),
|
||||
Self::V6(address) => fmt::Display::fmt(address, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SocketAddr> for core::net::SocketAddr {
|
||||
#[inline]
|
||||
fn from(value: SocketAddr) -> Self {
|
||||
match value {
|
||||
SocketAddr::V4(address) => core::net::SocketAddr::V4(address.into()),
|
||||
SocketAddr::V6(address) => core::net::SocketAddr::V6(address.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<core::net::SocketAddr> for SocketAddr {
|
||||
#[inline]
|
||||
fn from(value: core::net::SocketAddr) -> Self {
|
||||
match value {
|
||||
core::net::SocketAddr::V4(address) => SocketAddr::V4(address.into()),
|
||||
core::net::SocketAddr::V6(address) => SocketAddr::V6(address.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SocketAddrV4> for SocketAddr {
|
||||
fn from(value: SocketAddrV4) -> Self {
|
||||
Self::V4(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SocketAddrV6> for SocketAddr {
|
||||
fn from(value: SocketAddrV6) -> Self {
|
||||
Self::V6(value)
|
||||
}
|
||||
}
|
@ -1,11 +1,5 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
pub mod message_channel {
|
||||
pub use abi::io::{
|
||||
ChannelPublisherId, MessageDestination, ReceivedMessageMetadata, SentMessage,
|
||||
};
|
||||
}
|
||||
|
||||
pub mod poll {
|
||||
pub use abi::io::PollControl;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user