Skip to content

Commit

Permalink
Enable kernel network stack for newlib
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlWachter authored and mkroening committed Jun 4, 2024
1 parent 60a1bb9 commit a3cea37
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
20 changes: 6 additions & 14 deletions src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,17 @@ use hermit_sync::without_interrupts;
use smoltcp::time::Instant;

use crate::arch::core_local::*;
#[cfg(all(
any(feature = "tcp", feature = "udp"),
not(feature = "pci"),
not(feature = "newlib")
))]
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "pci")))]
use crate::drivers::mmio::get_network_driver;
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
use crate::drivers::net::NetworkDriver;
#[cfg(all(
any(feature = "tcp", feature = "udp"),
feature = "pci",
not(feature = "newlib")
))]
#[cfg(all(any(feature = "tcp", feature = "udp"), feature = "pci"))]
use crate::drivers::pci::get_network_driver;
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
use crate::executor::network::network_delay;
use crate::executor::task::AsyncTask;
use crate::fd::IoError;
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
use crate::scheduler::PerCoreSchedulerExt;
use crate::synch::futex::*;

Expand Down Expand Up @@ -97,7 +89,7 @@ where
}

pub fn init() {
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
crate::executor::network::init();
}

Expand Down
26 changes: 13 additions & 13 deletions src/fd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use core::time::Duration;

use async_trait::async_trait;
use dyn_clone::DynClone;
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
use smoltcp::wire::{IpEndpoint, IpListenEndpoint};

use crate::arch::kernel::core_local::core_scheduler;
use crate::executor::{block_on, poll_on};
use crate::fs::{DirectoryEntry, FileAttr, SeekWhence};

mod eventfd;
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
pub(crate) mod socket;
pub(crate) mod stdio;

Expand Down Expand Up @@ -207,56 +207,56 @@ pub(crate) trait ObjectInterface: Sync + Send + core::fmt::Debug + DynClone {
}

/// `accept` a connection on a socket
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn accept(&self) -> Result<IpEndpoint, IoError> {
Err(IoError::EINVAL)
}

/// initiate a connection on a socket
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn connect(&self, _endpoint: IpEndpoint) -> Result<(), IoError> {
Err(IoError::EINVAL)
}

/// `bind` a name to a socket
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn bind(&self, _name: IpListenEndpoint) -> Result<(), IoError> {
Err(IoError::EINVAL)
}

/// `listen` for connections on a socket
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn listen(&self, _backlog: i32) -> Result<(), IoError> {
Err(IoError::EINVAL)
}

/// `setsockopt` sets options on sockets
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn setsockopt(&self, _opt: SocketOption, _optval: bool) -> Result<(), IoError> {
Err(IoError::EINVAL)
}

/// `getsockopt` gets options on sockets
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn getsockopt(&self, _opt: SocketOption) -> Result<bool, IoError> {
Err(IoError::EINVAL)
}

/// `getsockname` gets socket name
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn getsockname(&self) -> Option<IpEndpoint> {
None
}

/// `getpeername` get address of connected peer
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
#[allow(dead_code)]
fn getpeername(&self) -> Option<IpEndpoint> {
None
}

/// receive a message from a socket
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn recvfrom(&self, _buffer: &mut [u8]) -> Result<(usize, IpEndpoint), IoError> {
Err(IoError::ENOSYS)
}
Expand All @@ -268,13 +268,13 @@ pub(crate) trait ObjectInterface: Sync + Send + core::fmt::Debug + DynClone {
/// If a peer address has been prespecified, either the message shall
/// be sent to the address specified by dest_addr (overriding the pre-specified peer
/// address).
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn sendto(&self, _buffer: &[u8], _endpoint: IpEndpoint) -> Result<usize, IoError> {
Err(IoError::ENOSYS)
}

/// shut down part of a full-duplex connection
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
fn shutdown(&self, _how: i32) -> Result<(), IoError> {
Err(IoError::ENOSYS)
}
Expand Down
2 changes: 1 addition & 1 deletion src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod processor;
#[cfg(feature = "newlib")]
mod recmutex;
mod semaphore;
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
pub mod socket;
mod spinlock;
mod system;
Expand Down
14 changes: 7 additions & 7 deletions src/syscalls/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::ffi::{c_char, c_void};
use core::mem::size_of;
use core::ops::DerefMut;

#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
use smoltcp::wire::{IpAddress, IpEndpoint, IpListenEndpoint};

use crate::errno::*;
Expand Down Expand Up @@ -102,7 +102,7 @@ pub struct sockaddr_in {
pub sin_zero: [c_char; 8],
}

#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
impl From<sockaddr_in> for IpListenEndpoint {
fn from(addr: sockaddr_in) -> IpListenEndpoint {
let port = u16::from_be(addr.sin_port);
Expand All @@ -118,7 +118,7 @@ impl From<sockaddr_in> for IpListenEndpoint {
}
}

#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
impl From<sockaddr_in> for IpEndpoint {
fn from(addr: sockaddr_in) -> IpEndpoint {
let port = u16::from_be(addr.sin_port);
Expand All @@ -129,7 +129,7 @@ impl From<sockaddr_in> for IpEndpoint {
}
}

#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
impl From<IpEndpoint> for sockaddr_in {
fn from(endpoint: IpEndpoint) -> Self {
match endpoint.addr {
Expand Down Expand Up @@ -162,7 +162,7 @@ pub struct sockaddr_in6 {
pub sin6_scope_id: u32,
}

#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
impl From<sockaddr_in6> for IpListenEndpoint {
fn from(addr: sockaddr_in6) -> IpListenEndpoint {
let port = u16::from_be(addr.sin6_port);
Expand All @@ -184,7 +184,7 @@ impl From<sockaddr_in6> for IpListenEndpoint {
}
}

#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
impl From<sockaddr_in6> for IpEndpoint {
fn from(addr: sockaddr_in6) -> IpEndpoint {
let port = u16::from_be(addr.sin6_port);
Expand All @@ -202,7 +202,7 @@ impl From<sockaddr_in6> for IpEndpoint {
}
}

#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
#[cfg(any(feature = "tcp", feature = "udp"))]
impl From<IpEndpoint> for sockaddr_in6 {
fn from(endpoint: IpEndpoint) -> Self {
match endpoint.addr {
Expand Down

0 comments on commit a3cea37

Please sign in to comment.