diff --git a/syscall/src/obj.rs b/syscall/src/obj.rs index ae52cc66f..ce3ea2f5e 100644 --- a/syscall/src/obj.rs +++ b/syscall/src/obj.rs @@ -4,6 +4,9 @@ // // Author: Chuanxiao Dong +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 @@ -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()); + } + } +}