Prevent drop on WaitCondition

This commit is contained in:
Wildan M
2026-02-27 12:34:13 +07:00
parent 159e67f26d
commit 437f762339
6 changed files with 65 additions and 12 deletions
+4
View File
@@ -85,6 +85,10 @@ impl EventQueue {
Ok(events.len())
}
pub fn into_drop(self, token: &mut CleanLockToken) {
self.queue.condition.into_drop(token);
}
}
pub type EventQueueList = HashMap<EventQueueId, Arc<EventQueue>>;
+6 -3
View File
@@ -43,10 +43,13 @@ impl KernelScheme for EventScheme {
fn close(&self, id: usize, token: &mut CleanLockToken) -> Result<()> {
let id = EventQueueId::from(id);
queues_mut(token.token())
let queue = queues_mut(token.token())
.remove(&id)
.ok_or(Error::new(EBADF))
.and(Ok(()))
.ok_or(Error::new(EBADF))?;
if let Some(queue) = Arc::into_inner(queue) {
queue.into_drop(token);
}
Ok(())
}
fn kread(
+11 -4
View File
@@ -225,10 +225,17 @@ impl SchemeList {
/// Remove a scheme
fn remove(&self, id: usize, token: &mut CleanLockToken) {
assert!(handles()
.write(token.token())
.remove(&SchemeId(id))
.is_some());
let scheme = handles().write(token.token()).remove(&SchemeId(id));
assert!(scheme.is_some());
match scheme {
Some(Handle::Scheme(KernelSchemes::User(user))) => {
if let Some(user) = Arc::into_inner(user.inner) {
user.into_drop(token);
}
}
_ => {}
}
}
}
+22 -1
View File
@@ -136,7 +136,28 @@ impl KernelScheme for PipeScheme {
};
if can_remove {
let _ = PIPES.write(token.token()).remove(&key);
match { PIPES.write(token.token()).remove(&key) } {
Some(Handle::Pipe(pipe)) => {
if let Some(pipe) = Arc::into_inner(pipe) {
{
pipe.read_condition.into_drop(token);
}
{
pipe.write_condition.into_drop(token);
}
}
}
_ => {}
}
}
if let Some(pipe) = Arc::into_inner(pipe) {
{
pipe.read_condition.into_drop(token);
}
{
pipe.write_condition.into_drop(token);
}
}
Ok(())
+4
View File
@@ -1260,6 +1260,10 @@ impl UserInner {
Ok(num_fds)
}
pub fn into_drop(self, token: &mut CleanLockToken) {
self.todo.condition.into_drop(token);
}
}
pub struct CaptureGuard<const READ: bool, const WRITE: bool> {
destroyed: bool,
+18 -4
View File
@@ -1,3 +1,5 @@
use core::mem::ManuallyDrop;
use alloc::{
sync::{Arc, Weak},
vec::Vec,
@@ -124,14 +126,26 @@ impl WaitCondition {
waited
}
pub fn into_drop(mut self, token: &mut CleanLockToken) {
ManuallyDrop::new(self).inner_drop(token);
}
fn inner_drop(&mut self, token: &mut CleanLockToken) {
unsafe {
self.notify_signal(token);
}
}
}
impl Drop for WaitCondition {
fn drop(&mut self) {
//TODO: drop violates lock tokens
unsafe {
let mut token = CleanLockToken::new();
self.notify_signal(&mut token);
};
let mut token = unsafe { CleanLockToken::new() };
self.inner_drop(&mut token);
#[cfg(feature = "drop_panic")]
{
panic!("WaitCondition dropped");
}
}
}