diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index cf307c07bc..3f8ebdd683 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -10,7 +10,6 @@ pub use self::futex::*; pub use self::processor::*; pub use self::recmutex::*; pub use self::semaphore::*; -pub use self::spinlock::*; pub use self::system::*; pub use self::tasks::*; pub use self::timer::*; @@ -32,7 +31,6 @@ pub mod net; mod processor; mod recmutex; mod semaphore; -mod spinlock; mod system; mod tasks; mod timer; diff --git a/src/syscalls/spinlock.rs b/src/syscalls/spinlock.rs deleted file mode 100644 index 9551c8de1a..0000000000 --- a/src/syscalls/spinlock.rs +++ /dev/null @@ -1,165 +0,0 @@ -use alloc::boxed::Box; - -use hermit_sync::{InterruptTicketMutex, InterruptTicketMutexGuard, TicketMutex, TicketMutexGuard}; - -use crate::errno::*; - -pub struct SpinlockContainer<'a> { - lock: TicketMutex<()>, - guard: Option>, -} - -pub struct SpinlockIrqSaveContainer<'a> { - lock: InterruptTicketMutex<()>, - guard: Option>, -} - -extern "C" fn __sys_spinlock_init(lock: *mut *mut SpinlockContainer<'_>) -> i32 { - if lock.is_null() { - return -EINVAL; - } - - let boxed_container = Box::new(SpinlockContainer { - lock: TicketMutex::new(()), - guard: None, - }); - unsafe { - *lock = Box::into_raw(boxed_container); - } - 0 -} - -#[no_mangle] -pub extern "C" fn sys_spinlock_init(lock: *mut *mut SpinlockContainer<'_>) -> i32 { - kernel_function!(__sys_spinlock_init(lock)) -} - -extern "C" fn __sys_spinlock_destroy(lock: *mut SpinlockContainer<'_>) -> i32 { - if lock.is_null() { - return -EINVAL; - } - - // Consume the lock into a box, which is then dropped. - unsafe { - drop(Box::from_raw(lock)); - } - 0 -} - -#[no_mangle] -pub extern "C" fn sys_spinlock_destroy(lock: *mut SpinlockContainer<'_>) -> i32 { - kernel_function!(__sys_spinlock_destroy(lock)) -} - -extern "C" fn __sys_spinlock_lock(lock: *mut SpinlockContainer<'_>) -> i32 { - if lock.is_null() { - return -EINVAL; - } - - let container = unsafe { &mut *lock }; - assert!( - container.guard.is_none(), - "Called sys_spinlock_lock when a lock is already held!" - ); - container.guard = Some(container.lock.lock()); - 0 -} - -#[no_mangle] -pub extern "C" fn sys_spinlock_lock(lock: *mut SpinlockContainer<'_>) -> i32 { - kernel_function!(__sys_spinlock_lock(lock)) -} - -extern "C" fn __sys_spinlock_unlock(lock: *mut SpinlockContainer<'_>) -> i32 { - if lock.is_null() { - return -EINVAL; - } - - let container = unsafe { &mut *lock }; - assert!( - container.guard.is_some(), - "Called sys_spinlock_unlock when no lock is currently held!" - ); - container.guard = None; - 0 -} - -#[no_mangle] -pub extern "C" fn sys_spinlock_unlock(lock: *mut SpinlockContainer<'_>) -> i32 { - kernel_function!(__sys_spinlock_unlock(lock)) -} - -extern "C" fn __sys_spinlock_irqsave_init(lock: *mut *mut SpinlockIrqSaveContainer<'_>) -> i32 { - if lock.is_null() { - return -EINVAL; - } - - let boxed_container = Box::new(SpinlockIrqSaveContainer { - lock: InterruptTicketMutex::new(()), - guard: None, - }); - unsafe { - *lock = Box::into_raw(boxed_container); - } - 0 -} - -#[no_mangle] -pub extern "C" fn sys_spinlock_irqsave_init(lock: *mut *mut SpinlockIrqSaveContainer<'_>) -> i32 { - kernel_function!(__sys_spinlock_irqsave_init(lock)) -} - -extern "C" fn __sys_spinlock_irqsave_destroy(lock: *mut SpinlockIrqSaveContainer<'_>) -> i32 { - if lock.is_null() { - return -EINVAL; - } - - // Consume the lock into a box, which is then dropped. - unsafe { - drop(Box::from_raw(lock)); - } - 0 -} - -#[no_mangle] -pub extern "C" fn sys_spinlock_irqsave_destroy(lock: *mut SpinlockIrqSaveContainer<'_>) -> i32 { - kernel_function!(__sys_spinlock_irqsave_destroy(lock)) -} - -extern "C" fn __sys_spinlock_irqsave_lock(lock: *mut SpinlockIrqSaveContainer<'_>) -> i32 { - if lock.is_null() { - return -EINVAL; - } - - let container = unsafe { &mut *lock }; - assert!( - container.guard.is_none(), - "Called sys_spinlock_irqsave_lock when a lock is already held!" - ); - container.guard = Some(container.lock.lock()); - 0 -} - -#[no_mangle] -pub extern "C" fn sys_spinlock_irqsave_lock(lock: *mut SpinlockIrqSaveContainer<'_>) -> i32 { - kernel_function!(__sys_spinlock_irqsave_lock(lock)) -} - -extern "C" fn __sys_spinlock_irqsave_unlock(lock: *mut SpinlockIrqSaveContainer<'_>) -> i32 { - if lock.is_null() { - return -EINVAL; - } - - let container = unsafe { &mut *lock }; - assert!( - container.guard.is_some(), - "Called sys_spinlock_irqsave_unlock when no lock is currently held!" - ); - container.guard = None; - 0 -} - -#[no_mangle] -pub extern "C" fn sys_spinlock_irqsave_unlock(lock: *mut SpinlockIrqSaveContainer<'_>) -> i32 { - kernel_function!(__sys_spinlock_irqsave_unlock(lock)) -}