diff --git a/src/arch/aarch64/mm/paging.rs b/src/arch/aarch64/mm/paging.rs index eb3c4268f1..5e03396a35 100644 --- a/src/arch/aarch64/mm/paging.rs +++ b/src/arch/aarch64/mm/paging.rs @@ -578,8 +578,8 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option { get_physical_address::(virtual_address) } -#[no_mangle] -pub extern "C" fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr { +#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))] +pub fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr { virtual_to_physical(virtual_address).unwrap() } diff --git a/src/arch/riscv64/mm/paging.rs b/src/arch/riscv64/mm/paging.rs index 97e73b1514..7bd8940311 100644 --- a/src/arch/riscv64/mm/paging.rs +++ b/src/arch/riscv64/mm/paging.rs @@ -584,8 +584,8 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option { panic!("virtual_to_physical should never reach this point"); } -#[no_mangle] -pub extern "C" fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr { +#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))] +pub fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr { virtual_to_physical(virtual_address).unwrap() } diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index d38ec8ea39..cdb6c95255 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -455,8 +455,7 @@ fn default_apic() -> PhysAddr { default_address } -#[no_mangle] -pub extern "C" fn eoi() { +pub fn eoi() { local_apic_write(IA32_X2APIC_EOI, APIC_EOI_ACK); } diff --git a/src/arch/x86_64/kernel/interrupts.rs b/src/arch/x86_64/kernel/interrupts.rs index fd170b0f58..c0495869bb 100644 --- a/src/arch/x86_64/kernel/interrupts.rs +++ b/src/arch/x86_64/kernel/interrupts.rs @@ -7,8 +7,10 @@ use hashbrown::HashMap; use hermit_sync::{InterruptSpinMutex, InterruptTicketMutex}; pub use x86_64::instructions::interrupts::{disable, enable, enable_and_hlt as enable_and_wait}; use x86_64::set_general_handler; +#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))] +use x86_64::structures::idt; +use x86_64::structures::idt::InterruptDescriptorTable; pub use x86_64::structures::idt::InterruptStackFrame as ExceptionStackFrame; -use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; use crate::arch::x86_64::kernel::core_local::{core_scheduler, increment_irq_counter}; use crate::arch::x86_64::kernel::{apic, processor}; @@ -108,11 +110,8 @@ pub(crate) fn install() { IRQ_NAMES.lock().insert(7, "FPU"); } -#[no_mangle] -pub extern "C" fn irq_install_handler( - irq_number: u8, - handler: extern "x86-interrupt" fn(InterruptStackFrame), -) { +#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))] +pub fn irq_install_handler(irq_number: u8, handler: idt::HandlerFunc) { debug!("Install handler for interrupt {}", irq_number); let mut idt = IDT.lock(); diff --git a/src/arch/x86_64/mm/paging.rs b/src/arch/x86_64/mm/paging.rs index 8e80da762b..6607671d64 100644 --- a/src/arch/x86_64/mm/paging.rs +++ b/src/arch/x86_64/mm/paging.rs @@ -118,8 +118,8 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option { } } -#[no_mangle] -pub extern "C" fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr { +#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))] +pub fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr { virtual_to_physical(virtual_address).unwrap() } diff --git a/src/console.rs b/src/console.rs index f22fe354bf..3c4a205955 100644 --- a/src/console.rs +++ b/src/console.rs @@ -21,9 +21,6 @@ impl fmt::Write for Console { } } -#[cfg(feature = "newlib")] -pub static CONSOLE: InterruptTicketMutex = InterruptTicketMutex::new(Console(())); -#[cfg(not(feature = "newlib"))] static CONSOLE: InterruptTicketMutex = InterruptTicketMutex::new(Console(())); #[doc(hidden)] diff --git a/src/executor/mod.rs b/src/executor/mod.rs index 40a911f3ef..ddfb6b4126 100644 --- a/src/executor/mod.rs +++ b/src/executor/mod.rs @@ -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::*; @@ -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(); } diff --git a/src/fd/mod.rs b/src/fd/mod.rs index a910bb6deb..660e303e29 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -7,7 +7,7 @@ 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; @@ -15,7 +15,7 @@ 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; @@ -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 { 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 { 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 { 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 { 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) } @@ -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 { 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) } diff --git a/src/lib.rs b/src/lib.rs index b939c26384..d5fefb8d3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,20 +130,9 @@ extern "C" fn initd(_arg: usize) { fn runtime_entry(argc: i32, argv: *const *const u8, env: *const *const u8) -> !; #[cfg(all(not(test), any(feature = "nostd", feature = "common-os")))] fn main(argc: i32, argv: *const *const u8, env: *const *const u8); - #[cfg(feature = "newlib")] - fn init_lwip(); - #[cfg(feature = "newlib")] - fn init_rtl8139_netif(freq: u32) -> i32; } if !env::is_uhyve() { - // initialize LwIP library for newlib-based applications - #[cfg(feature = "newlib")] - unsafe { - init_lwip(); - init_rtl8139_netif(processor::get_frequency() as u32); - } - info!("Hermit is running on common system!"); } else { info!("Hermit is running on uhyve!"); diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index 9c7ca0f29e..6a69d7170f 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -442,18 +442,6 @@ impl PerCoreScheduler { }) } - #[cfg(feature = "newlib")] - #[inline] - pub fn set_lwip_errno(&self, errno: i32) { - without_interrupts(|| self.current_task.borrow_mut().lwip_errno = errno); - } - - #[cfg(feature = "newlib")] - #[inline] - pub fn get_lwip_errno(&self) -> i32 { - without_interrupts(|| self.current_task.borrow().lwip_errno) - } - #[inline] pub fn get_current_task_id(&self) -> TaskId { without_interrupts(|| self.current_task.borrow().id) diff --git a/src/scheduler/task.rs b/src/scheduler/task.rs index 0a988b65dd..cd77533399 100644 --- a/src/scheduler/task.rs +++ b/src/scheduler/task.rs @@ -399,9 +399,6 @@ pub(crate) struct Task { // Physical address of the 1st level page table #[cfg(all(target_arch = "x86_64", feature = "common-os"))] pub root_page_table: usize, - /// lwIP error code for this task - #[cfg(feature = "newlib")] - pub lwip_errno: i32, } pub(crate) trait TaskFrame { @@ -437,8 +434,6 @@ impl Task { tls: None, #[cfg(all(target_arch = "x86_64", feature = "common-os"))] root_page_table: arch::create_new_root_page_table(), - #[cfg(feature = "newlib")] - lwip_errno: 0, } } @@ -507,8 +502,6 @@ impl Task { tls: None, #[cfg(all(target_arch = "x86_64", feature = "common-os"))] root_page_table: *crate::scheduler::BOOT_ROOT_PAGE_TABLE.get().unwrap(), - #[cfg(feature = "newlib")] - lwip_errno: 0, } } } diff --git a/src/syscalls/interfaces/uhyve.rs b/src/syscalls/interfaces/uhyve.rs index 9c375421ae..6a283ab08b 100644 --- a/src/syscalls/interfaces/uhyve.rs +++ b/src/syscalls/interfaces/uhyve.rs @@ -9,21 +9,11 @@ use x86::io::*; use crate::arch; use crate::arch::mm::{paging, PhysAddr, VirtAddr}; use crate::syscalls::interfaces::SyscallInterface; -#[cfg(feature = "newlib")] -use crate::syscalls::lwip::sys_lwip_get_errno; -#[cfg(feature = "newlib")] -use crate::syscalls::{LWIP_FD_BIT, LWIP_LOCK}; const UHYVE_PORT_EXIT: u16 = 0x540; const UHYVE_PORT_CMDSIZE: u16 = 0x740; const UHYVE_PORT_CMDVAL: u16 = 0x780; -#[cfg(feature = "newlib")] -extern "C" { - fn lwip_write(fd: i32, buf: *const u8, len: usize) -> i32; - fn lwip_read(fd: i32, buf: *mut u8, len: usize) -> i32; -} - /// forward a request to the hypervisor uhyve #[inline] #[cfg(target_arch = "x86_64")] diff --git a/src/syscalls/lwip.rs b/src/syscalls/lwip.rs deleted file mode 100644 index 74677e42b3..0000000000 --- a/src/syscalls/lwip.rs +++ /dev/null @@ -1,39 +0,0 @@ -use hermit_sync::{InterruptTicketMutexGuard, SpinMutex}; -use lock_api::MutexGuard; - -use crate::arch::core_local::core_scheduler; -use crate::{arch, console}; - -#[hermit_macro::system] -#[no_mangle] -pub extern "C" fn sys_lwip_get_errno() -> i32 { - core_scheduler().get_lwip_errno() -} - -#[hermit_macro::system] -#[no_mangle] -pub extern "C" fn sys_lwip_set_errno(errno: i32) { - core_scheduler().set_lwip_errno(errno); -} - -#[hermit_macro::system] -#[no_mangle] -pub extern "C" fn sys_acquire_putchar_lock() { - // FIXME: use core-local storage instead - // better yet: remove and replace all of this - MutexGuard::leak(console::CONSOLE.lock()); -} - -#[hermit_macro::system] -#[no_mangle] -pub extern "C" fn sys_putchar(character: u8) { - arch::output_message_buf(&[character]); -} - -#[hermit_macro::system] -#[no_mangle] -pub unsafe extern "C" fn sys_release_putchar_lock() { - unsafe { - console::CONSOLE.force_unlock(); - } -} diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 0ffc0e7494..93dcd0e395 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -34,13 +34,11 @@ mod condvar; mod entropy; mod futex; mod interfaces; -#[cfg(feature = "newlib")] -mod lwip; 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; @@ -49,12 +47,6 @@ pub(crate) mod table; mod tasks; mod timer; -#[cfg(feature = "newlib")] -const LWIP_FD_BIT: i32 = 1 << 30; - -#[cfg(feature = "newlib")] -pub(crate) static LWIP_LOCK: InterruptTicketMutex<()> = InterruptTicketMutex::new(()); - pub(crate) static SYS: Lazy<&'static dyn SyscallInterface> = Lazy::new(|| { if env::is_uhyve() { &self::interfaces::Uhyve diff --git a/src/syscalls/semaphore.rs b/src/syscalls/semaphore.rs index c11db47667..78f7784475 100644 --- a/src/syscalls/semaphore.rs +++ b/src/syscalls/semaphore.rs @@ -44,7 +44,7 @@ pub unsafe extern "C" fn sys_sem_destroy(sem: *mut sem_t) -> i32 { // Consume the pointer to the raw memory into a Box again // and drop the Box to free the associated memory. unsafe { - drop(Box::from_raw(sem)); + drop(Box::from_raw((*sem).cast_mut())); } 0 } diff --git a/src/syscalls/socket.rs b/src/syscalls/socket.rs index 5d937d601b..3a2a118724 100644 --- a/src/syscalls/socket.rs +++ b/src/syscalls/socket.rs @@ -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::*; @@ -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 for IpListenEndpoint { fn from(addr: sockaddr_in) -> IpListenEndpoint { let port = u16::from_be(addr.sin_port); @@ -118,7 +118,7 @@ impl From for IpListenEndpoint { } } -#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))] +#[cfg(any(feature = "tcp", feature = "udp"))] impl From for IpEndpoint { fn from(addr: sockaddr_in) -> IpEndpoint { let port = u16::from_be(addr.sin_port); @@ -129,7 +129,7 @@ impl From for IpEndpoint { } } -#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))] +#[cfg(any(feature = "tcp", feature = "udp"))] impl From for sockaddr_in { fn from(endpoint: IpEndpoint) -> Self { match endpoint.addr { @@ -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 for IpListenEndpoint { fn from(addr: sockaddr_in6) -> IpListenEndpoint { let port = u16::from_be(addr.sin6_port); @@ -184,7 +184,7 @@ impl From for IpListenEndpoint { } } -#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))] +#[cfg(any(feature = "tcp", feature = "udp"))] impl From for IpEndpoint { fn from(addr: sockaddr_in6) -> IpEndpoint { let port = u16::from_be(addr.sin6_port); @@ -202,7 +202,7 @@ impl From for IpEndpoint { } } -#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))] +#[cfg(any(feature = "tcp", feature = "udp"))] impl From for sockaddr_in6 { fn from(endpoint: IpEndpoint) -> Self { match endpoint.addr { diff --git a/xtask/src/build.rs b/xtask/src/build.rs index 827066eed2..dc4892eb92 100644 --- a/xtask/src/build.rs +++ b/xtask/src/build.rs @@ -109,22 +109,7 @@ impl Build { let archive = self.cargo_build.artifact.dist_archive(); let syscall_symbols = archive.syscall_symbols()?; - let explicit_exports = [ - "_start", - "__bss_start", - "mcount", - "runtime_entry", - // lwIP functions (C runtime) - "init_lwip", - "lwip_read", - "lwip_write", - // lwIP rtl8139 driver - "init_rtl8139_netif", - "irq_install_handler", - "virt_to_phys", - "eoi", - ] - .into_iter(); + let explicit_exports = ["_start", "__bss_start", "mcount", "runtime_entry"].into_iter(); let symbols = explicit_exports.chain(syscall_symbols.iter().map(String::as_str));