Skip to content

Commit

Permalink
syscall/obj: Close an ObjHandle when dropped
Browse files Browse the repository at this point in the history
Implement Drop for the ObjHandle to close the underlying kernel object
when the ObjHandle is dropped in the user mode.

Co-developed-by: Vijay Dhanraj <[email protected]>
Signed-off-by: Chuanxiao Dong <[email protected]>
  • Loading branch information
cxdong authored and vijaydhanraj committed Nov 6, 2024
1 parent 1fc0b60 commit 8c00c05
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions syscall/src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//
// Author: Chuanxiao Dong <[email protected]>

use super::call::syscall1;
use super::SYS_CLOSE;

/// The object is exposed to the user mode via the object-opening related
/// syscalls, which returns the id of the object created by the COCONUT-SVSM
/// kernel. The user mode can make use this id to access the corresponding
Expand Down Expand Up @@ -31,3 +34,11 @@ impl From<&ObjHandle> for u32 {
pub trait Obj {
fn id(&self) -> u32;
}

impl Drop for ObjHandle {
fn drop(&mut self) {
unsafe {
let _ = syscall1(SYS_CLOSE, self.0.into());
}
}
}

0 comments on commit 8c00c05

Please sign in to comment.