Skip to content

Commit

Permalink
Allow concurrent live Sessions
Browse files Browse the repository at this point in the history
The existing bindings require a `&mut` reference to the context,
indicating that only one session may be alive at a time per context.
However, GlobalPlatform v1.0 says:

However, it is valid for the Client Application to concurrently use
these functions to initialize or finalize different objects; in the
above example two threads could initialize different TEEC_Session
structures.

This indicates both:
1. It should be possible to have two simultaneous live sessions.
2. If synchronization is necessary on the `TEE_Context` object, it is
   the responsibility of the C library to provide that synchronization.

This means that we do not require exclusive access to the `TEE_Context`,
either at creation time or during use of the session, so we can take a
`&` instead.
  • Loading branch information
maurer committed Feb 3, 2024
1 parent b2fbfb0 commit 71c2ff2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions optee-teec/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl Context {
/// let mut ctx = Context::new().unwrap();
/// let mut raw_ptr: *mut optee_teec_sys::TEEC_Context = ctx.as_mut_raw_ptr();
/// ```
pub fn as_mut_raw_ptr(&mut self) -> *mut raw::TEEC_Context {
&mut self.raw
pub(crate) fn as_mut_raw_ptr(&self) -> *mut raw::TEEC_Context {
& self.raw as *const _ as *mut _
}

/// Opens a new session with the specified trusted application.
Expand All @@ -83,7 +83,7 @@ impl Context {
/// let uuid = Uuid::parse_str("8abcf200-2450-11e4-abe2-0002a5d5c51b").unwrap();
/// let session = ctx.open_session(uuid).unwrap();
/// ```
pub fn open_session(&mut self, uuid: Uuid) -> Result<Session> {
pub fn open_session(&self, uuid: Uuid) -> Result<Session> {
Session::new(
self,
uuid,
Expand All @@ -106,7 +106,7 @@ impl Context {
/// let session = ctx.open_session_with_operation(uuid, operation).unwrap();
/// ```
pub fn open_session_with_operation<A: Param, B: Param, C: Param, D: Param>(
&mut self,
&self,
uuid: Uuid,
operation: &mut Operation<A, B, C, D>,
) -> Result<Session> {
Expand Down
4 changes: 2 additions & 2 deletions optee-teec/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ pub enum ConnectionMethods {
/// Represents a connection between a client application and a trusted application.
pub struct Session<'ctx> {
raw: raw::TEEC_Session,
_marker: marker::PhantomData<&'ctx mut Context>,
_marker: marker::PhantomData<&'ctx Context>,
}

impl<'ctx> Session<'ctx> {
/// Initializes a TEE session object with specified context and uuid.
pub fn new<A: Param, B: Param, C: Param, D: Param>(
context: &'ctx mut Context,
context: &'ctx Context,
uuid: Uuid,
operation: Option<&mut Operation<A, B, C, D>>,
) -> Result<Self> {
Expand Down

0 comments on commit 71c2ff2

Please sign in to comment.