Prevent drop on WaitCondition
This commit is contained in:
@@ -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
@@ -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
@@ -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
@@ -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(())
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user