Skip to content

Commit 285f28a

Browse files
authored
Merge pull request #1237 from CarlWachter/no_lwip
feat(newlib): using kernel networking, instead of lwip
2 parents bcde371 + a3cea37 commit 285f28a

File tree

17 files changed

+41
-156
lines changed

17 files changed

+41
-156
lines changed

src/arch/aarch64/mm/paging.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option<PhysAddr> {
578578
get_physical_address::<BasePageSize>(virtual_address)
579579
}
580580

581-
#[no_mangle]
582-
pub extern "C" fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr {
581+
#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))]
582+
pub fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr {
583583
virtual_to_physical(virtual_address).unwrap()
584584
}
585585

src/arch/riscv64/mm/paging.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option<PhysAddr> {
584584
panic!("virtual_to_physical should never reach this point");
585585
}
586586

587-
#[no_mangle]
588-
pub extern "C" fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr {
587+
#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))]
588+
pub fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr {
589589
virtual_to_physical(virtual_address).unwrap()
590590
}
591591

src/arch/x86_64/kernel/apic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ fn default_apic() -> PhysAddr {
455455
default_address
456456
}
457457

458-
#[no_mangle]
459-
pub extern "C" fn eoi() {
458+
pub fn eoi() {
460459
local_apic_write(IA32_X2APIC_EOI, APIC_EOI_ACK);
461460
}
462461

src/arch/x86_64/kernel/interrupts.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ use hashbrown::HashMap;
77
use hermit_sync::{InterruptSpinMutex, InterruptTicketMutex};
88
pub use x86_64::instructions::interrupts::{disable, enable, enable_and_hlt as enable_and_wait};
99
use x86_64::set_general_handler;
10+
#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))]
11+
use x86_64::structures::idt;
12+
use x86_64::structures::idt::InterruptDescriptorTable;
1013
pub use x86_64::structures::idt::InterruptStackFrame as ExceptionStackFrame;
11-
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
1214

1315
use crate::arch::x86_64::kernel::core_local::{core_scheduler, increment_irq_counter};
1416
use crate::arch::x86_64::kernel::{apic, processor};
@@ -108,11 +110,8 @@ pub(crate) fn install() {
108110
IRQ_NAMES.lock().insert(7, "FPU");
109111
}
110112

111-
#[no_mangle]
112-
pub extern "C" fn irq_install_handler(
113-
irq_number: u8,
114-
handler: extern "x86-interrupt" fn(InterruptStackFrame),
115-
) {
113+
#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))]
114+
pub fn irq_install_handler(irq_number: u8, handler: idt::HandlerFunc) {
116115
debug!("Install handler for interrupt {}", irq_number);
117116

118117
let mut idt = IDT.lock();

src/arch/x86_64/mm/paging.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option<PhysAddr> {
118118
}
119119
}
120120

121-
#[no_mangle]
122-
pub extern "C" fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr {
121+
#[cfg(any(feature = "fuse", feature = "tcp", feature = "udp"))]
122+
pub fn virt_to_phys(virtual_address: VirtAddr) -> PhysAddr {
123123
virtual_to_physical(virtual_address).unwrap()
124124
}
125125

src/console.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ impl fmt::Write for Console {
2121
}
2222
}
2323

24-
#[cfg(feature = "newlib")]
25-
pub static CONSOLE: InterruptTicketMutex<Console> = InterruptTicketMutex::new(Console(()));
26-
#[cfg(not(feature = "newlib"))]
2724
static CONSOLE: InterruptTicketMutex<Console> = InterruptTicketMutex::new(Console(()));
2825

2926
#[doc(hidden)]

src/executor/mod.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,17 @@ use hermit_sync::without_interrupts;
2020
use smoltcp::time::Instant;
2121

2222
use crate::arch::core_local::*;
23-
#[cfg(all(
24-
any(feature = "tcp", feature = "udp"),
25-
not(feature = "pci"),
26-
not(feature = "newlib")
27-
))]
23+
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "pci")))]
2824
use crate::drivers::mmio::get_network_driver;
29-
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
25+
#[cfg(any(feature = "tcp", feature = "udp"))]
3026
use crate::drivers::net::NetworkDriver;
31-
#[cfg(all(
32-
any(feature = "tcp", feature = "udp"),
33-
feature = "pci",
34-
not(feature = "newlib")
35-
))]
27+
#[cfg(all(any(feature = "tcp", feature = "udp"), feature = "pci"))]
3628
use crate::drivers::pci::get_network_driver;
37-
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
29+
#[cfg(any(feature = "tcp", feature = "udp"))]
3830
use crate::executor::network::network_delay;
3931
use crate::executor::task::AsyncTask;
4032
use crate::fd::IoError;
41-
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
33+
#[cfg(any(feature = "tcp", feature = "udp"))]
4234
use crate::scheduler::PerCoreSchedulerExt;
4335
use crate::synch::futex::*;
4436

@@ -97,7 +89,7 @@ where
9789
}
9890

9991
pub fn init() {
100-
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
92+
#[cfg(any(feature = "tcp", feature = "udp"))]
10193
crate::executor::network::init();
10294
}
10395

src/fd/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use core::time::Duration;
77

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

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

1717
mod eventfd;
18-
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
18+
#[cfg(any(feature = "tcp", feature = "udp"))]
1919
pub(crate) mod socket;
2020
pub(crate) mod stdio;
2121

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

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

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

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

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

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

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

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

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

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

276276
/// shut down part of a full-duplex connection
277-
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
277+
#[cfg(any(feature = "tcp", feature = "udp"))]
278278
fn shutdown(&self, _how: i32) -> Result<(), IoError> {
279279
Err(IoError::ENOSYS)
280280
}

src/lib.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,9 @@ extern "C" fn initd(_arg: usize) {
130130
fn runtime_entry(argc: i32, argv: *const *const u8, env: *const *const u8) -> !;
131131
#[cfg(all(not(test), any(feature = "nostd", feature = "common-os")))]
132132
fn main(argc: i32, argv: *const *const u8, env: *const *const u8);
133-
#[cfg(feature = "newlib")]
134-
fn init_lwip();
135-
#[cfg(feature = "newlib")]
136-
fn init_rtl8139_netif(freq: u32) -> i32;
137133
}
138134

139135
if !env::is_uhyve() {
140-
// initialize LwIP library for newlib-based applications
141-
#[cfg(feature = "newlib")]
142-
unsafe {
143-
init_lwip();
144-
init_rtl8139_netif(processor::get_frequency() as u32);
145-
}
146-
147136
info!("Hermit is running on common system!");
148137
} else {
149138
info!("Hermit is running on uhyve!");

src/scheduler/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,18 +442,6 @@ impl PerCoreScheduler {
442442
})
443443
}
444444

445-
#[cfg(feature = "newlib")]
446-
#[inline]
447-
pub fn set_lwip_errno(&self, errno: i32) {
448-
without_interrupts(|| self.current_task.borrow_mut().lwip_errno = errno);
449-
}
450-
451-
#[cfg(feature = "newlib")]
452-
#[inline]
453-
pub fn get_lwip_errno(&self) -> i32 {
454-
without_interrupts(|| self.current_task.borrow().lwip_errno)
455-
}
456-
457445
#[inline]
458446
pub fn get_current_task_id(&self) -> TaskId {
459447
without_interrupts(|| self.current_task.borrow().id)

src/scheduler/task.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,6 @@ pub(crate) struct Task {
399399
// Physical address of the 1st level page table
400400
#[cfg(all(target_arch = "x86_64", feature = "common-os"))]
401401
pub root_page_table: usize,
402-
/// lwIP error code for this task
403-
#[cfg(feature = "newlib")]
404-
pub lwip_errno: i32,
405402
}
406403

407404
pub(crate) trait TaskFrame {
@@ -437,8 +434,6 @@ impl Task {
437434
tls: None,
438435
#[cfg(all(target_arch = "x86_64", feature = "common-os"))]
439436
root_page_table: arch::create_new_root_page_table(),
440-
#[cfg(feature = "newlib")]
441-
lwip_errno: 0,
442437
}
443438
}
444439

@@ -507,8 +502,6 @@ impl Task {
507502
tls: None,
508503
#[cfg(all(target_arch = "x86_64", feature = "common-os"))]
509504
root_page_table: *crate::scheduler::BOOT_ROOT_PAGE_TABLE.get().unwrap(),
510-
#[cfg(feature = "newlib")]
511-
lwip_errno: 0,
512505
}
513506
}
514507
}

src/syscalls/interfaces/uhyve.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,11 @@ use x86::io::*;
99
use crate::arch;
1010
use crate::arch::mm::{paging, PhysAddr, VirtAddr};
1111
use crate::syscalls::interfaces::SyscallInterface;
12-
#[cfg(feature = "newlib")]
13-
use crate::syscalls::lwip::sys_lwip_get_errno;
14-
#[cfg(feature = "newlib")]
15-
use crate::syscalls::{LWIP_FD_BIT, LWIP_LOCK};
1612

1713
const UHYVE_PORT_EXIT: u16 = 0x540;
1814
const UHYVE_PORT_CMDSIZE: u16 = 0x740;
1915
const UHYVE_PORT_CMDVAL: u16 = 0x780;
2016

21-
#[cfg(feature = "newlib")]
22-
extern "C" {
23-
fn lwip_write(fd: i32, buf: *const u8, len: usize) -> i32;
24-
fn lwip_read(fd: i32, buf: *mut u8, len: usize) -> i32;
25-
}
26-
2717
/// forward a request to the hypervisor uhyve
2818
#[inline]
2919
#[cfg(target_arch = "x86_64")]

src/syscalls/lwip.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/syscalls/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ mod condvar;
3434
mod entropy;
3535
mod futex;
3636
mod interfaces;
37-
#[cfg(feature = "newlib")]
38-
mod lwip;
3937
mod processor;
4038
#[cfg(feature = "newlib")]
4139
mod recmutex;
4240
mod semaphore;
43-
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
41+
#[cfg(any(feature = "tcp", feature = "udp"))]
4442
pub mod socket;
4543
mod spinlock;
4644
mod system;
@@ -49,12 +47,6 @@ pub(crate) mod table;
4947
mod tasks;
5048
mod timer;
5149

52-
#[cfg(feature = "newlib")]
53-
const LWIP_FD_BIT: i32 = 1 << 30;
54-
55-
#[cfg(feature = "newlib")]
56-
pub(crate) static LWIP_LOCK: InterruptTicketMutex<()> = InterruptTicketMutex::new(());
57-
5850
pub(crate) static SYS: Lazy<&'static dyn SyscallInterface> = Lazy::new(|| {
5951
if env::is_uhyve() {
6052
&self::interfaces::Uhyve

src/syscalls/semaphore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub unsafe extern "C" fn sys_sem_destroy(sem: *mut sem_t) -> i32 {
4444
// Consume the pointer to the raw memory into a Box again
4545
// and drop the Box to free the associated memory.
4646
unsafe {
47-
drop(Box::from_raw(sem));
47+
drop(Box::from_raw((*sem).cast_mut()));
4848
}
4949
0
5050
}

0 commit comments

Comments
 (0)