Skip to content

Commit

Permalink
fix(syscalls/lwip): don't allow sending InterruptMutexGuard between t…
Browse files Browse the repository at this point in the history
…hreads

Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Sep 18, 2023
1 parent 168e27f commit 6634fb7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/syscalls/lwip.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use hermit_sync::{InterruptTicketMutexGuard, SpinMutex};
use lock_api::MutexGuard;

use crate::arch::core_local::core_scheduler;
use crate::{arch, console};

/// Enables lwIP's printf to print a whole string without being interrupted by
/// a message from the kernel.
static CONSOLE_GUARD: SpinMutex<Option<InterruptTicketMutexGuard<'_, console::Console>>> =
SpinMutex::new(None);

extern "C" fn __sys_lwip_get_errno() -> i32 {
core_scheduler().get_lwip_errno()
Expand All @@ -27,9 +26,9 @@ pub extern "C" fn sys_lwip_set_errno(errno: i32) {
}

extern "C" fn __sys_acquire_putchar_lock() {
let mut console_guard = CONSOLE_GUARD.lock();
assert!(console_guard.is_none());
*console_guard = Some(console::CONSOLE.lock());
// FIXME: use core-local storage instead
// better yet: remove and replace all of this
MutexGuard::leak(console::CONSOLE.lock());
}

#[no_mangle]
Expand All @@ -46,10 +45,10 @@ pub extern "C" fn sys_putchar(character: u8) {
kernel_function!(__sys_putchar(character))
}

extern "C" fn __sys_release_putchar_lock() {
let mut console_guard = CONSOLE_GUARD.lock();
assert!(console_guard.is_some());
drop(console_guard.take());
unsafe extern "C" fn __sys_release_putchar_lock() {
unsafe {
console::CONSOLE.force_unlock();
}
}

#[no_mangle]
Expand Down

0 comments on commit 6634fb7

Please sign in to comment.