From 6634fb72ffda30e62f9372f979fa45d865617edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 18 Sep 2023 18:27:13 +0200 Subject: [PATCH] fix(syscalls/lwip): don't allow sending InterruptMutexGuard between threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/syscalls/lwip.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/syscalls/lwip.rs b/src/syscalls/lwip.rs index de889ad9f1..14a8ccb9e8 100644 --- a/src/syscalls/lwip.rs +++ b/src/syscalls/lwip.rs @@ -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>> = - SpinMutex::new(None); extern "C" fn __sys_lwip_get_errno() -> i32 { core_scheduler().get_lwip_errno() @@ -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] @@ -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]