Skip to content

Commit

Permalink
syscall/obj: Define ObjHandle for the user mode
Browse files Browse the repository at this point in the history
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
object via other syscalls.

From the user mode's point of view, an ObjHanle is defined to wrap a u32
which is the value returned by an object-opening syscall. This u32 value
can be used as the input for the syscalls to access the corresponding
kernel object. The ObjHandle doesn't implement Copy/Clone trait, and the
From trait is implemented for a reference to ObjHandle to create a u32.

Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
  • Loading branch information
cxdong committed Sep 18, 2024
1 parent fffd2bd commit 2b9e675
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions syscall/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
#![no_std]

mod numbers;
mod obj;

pub use numbers::*;
pub use obj::*;
29 changes: 29 additions & 0 deletions syscall/src/obj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2024 Intel Corporation.
//
// Author: Chuanxiao Dong <chuanxiao.dong@intel.com>

/// 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
/// object via other syscalls. From the user mode's point of view, an
/// ObjHanle is defined to wrap a u32 which is the value returned by an
/// object-opening syscall. This u32 value can be used as the input for the
/// syscalls to access the corresponding kernel object.
#[derive(Debug)]
pub struct ObjHandle(u32);

impl ObjHandle {
#[allow(dead_code)]
pub(crate) fn new(id: u32) -> Self {
Self(id)
}
}

impl From<&ObjHandle> for u32 {
#[inline]
fn from(obj_handle: &ObjHandle) -> Self {
obj_handle.0
}
}

0 comments on commit 2b9e675

Please sign in to comment.