#[unsafe(no_mangle)]pub extern "C" fn TEEC_FinalizeContext(ctx: *mut TEEC_Context)Expand description
TEEC_FinalizeContext() - 销毁保存连接信息的上下文。
该函数用于销毁已初始化的 TEE 上下文,关闭客户端应用与 TEE 之间的连接。 仅当与该上下文关联的所有会话已关闭且所有共享内存块已释放时才可调用。
@param ctx 要销毁的上下文。
Examples found in repository?
examples/cc-teec.rs (line 93)
70 fn new(uuid: &raw::TEEC_UUID) -> Result<Self> {
71 // SAFETY: `TEEC_Context` 和 `TEEC_Session` 是 POD 类型,没有无效的位模式。
72 // `mem::zeroed()` 在这里是安全的,因为这些结构体只包含整数和指针。
73 let mut ctx: Box<raw::TEEC_Context> = Box::new(unsafe { mem::zeroed() });
74 let mut session: raw::TEEC_Session = unsafe { mem::zeroed() };
75 let mut origin = 0_u32;
76
77 let res = TEEC_InitializeContext(ptr::null(), ctx.as_mut());
78 if res != raw::TEEC_SUCCESS {
79 return Err(Error::from_raw_os_error(res as i32));
80 }
81
82 let res = TEEC_OpenSession(
83 ctx.as_mut(),
84 &mut session,
85 uuid,
86 raw::TEEC_LOGIN_PUBLIC,
87 ptr::null(),
88 ptr::null_mut(),
89 &mut origin,
90 );
91
92 if res != raw::TEEC_SUCCESS {
93 TEEC_FinalizeContext(ctx.as_mut());
94 return Err(Error::from_raw_os_error(res as i32));
95 }
96
97 Ok(Self { ctx, session })
98 }
99
100 fn invoke_command(&self, cmd_id: u32, op: &mut raw::TEEC_Operation) -> Result<()> {
101 let mut origin = 0_u32;
102 let res = TEEC_InvokeCommand(&self.session as *const _ as *mut _, cmd_id, op, &mut origin);
103
104 if res != raw::TEEC_SUCCESS {
105 return Err(Error::from_raw_os_error(res as i32));
106 }
107
108 Ok(())
109 }
110
111 /// 获取 TEE Context 的可变引用
112 fn context_mut(&mut self) -> &mut raw::TEEC_Context {
113 self.ctx.as_mut()
114 }
115}
116
117impl Drop for Client_Session {
118 fn drop(&mut self) {
119 TEEC_CloseSession(&mut self.session);
120 TEEC_FinalizeContext(self.ctx.as_mut());
121 }