TEEC_Context和TEEC_InitializeContext介绍
思考:
TEEC_InitializeContext做了哪些事情?
TEEC_Context是干什么用的?
Userspace的TEEC_Context、Kernel Space的tee_context的區別?
本質(最佳理解): Represents a connection between a client application and a TEE
1、從UserSpace角度來看Context
本質 :在調用TEEC_InitializeContext時,上層返回一個ctx結構體,該結構體中有三個元素,其中fd是open返回的文件描述符,另外兩個元素有上層hardcoding. filename/fd和kernel層的inode—device綁定. 在Kernel層,也有一個Kernel層的ctx結構體(與Userspace的不一樣),該結構體會在Kernel層填充。TEEC_InitializeContext函數調用,在Kernel層就結束,不會進入TEE.
TEEC_InitializeContext返回一個TEEC_Context結構體,該結構體有三個元素:
- fd : Userpace通過open調用Kernel返回的文件描述符(如下圖所示,fd和Kernel層的tee_device綁定起來)
- reg_mem
- memref_null
Userspace調用KernelSpace的open device流程:
2、Kernel Space中的tee_context
在teedev_open講tee_device填充到teedev. 其它元素在后續使用時填充
struct tee_context {struct tee_device *teedev;void *data;struct kref refcount;bool releasing;bool supp_nowait;bool cap_memref_null; }; static struct tee_context *teedev_open(struct tee_device *teedev) {int rc;struct tee_context *ctx;if (!tee_device_get(teedev))return ERR_PTR(-EINVAL);ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);if (!ctx) {rc = -ENOMEM;goto err;}kref_init(&ctx->refcount);ctx->teedev = teedev;rc = teedev->desc->ops->open(ctx);if (rc)goto err;return ctx; err:kfree(ctx);tee_device_put(teedev);return ERR_PTR(rc);}3、代碼使用示例
TEEC_Context teec_ctx;
TEEC_Session session = { .ctx = 0 };
1、TEEC_InitializeContext(_device, &teec_ctx); // 初始化一個Context,表示此Application和TEE的連接
2、TEEC_OpenSession(&teec_ctx, session, uuid, TEEC_LOGIN_PUBLIC, NULL, op, ret_orig); // open session,表示此Application和TA的連接
3、TEEC_InvokeCommand(session, TA_ZHOUHEHE_CMD_1, &op, &ret_orig);
4、TEEC_CloseSession(session);
5、TEEC_FinalizeContext(&teec_ctx); // 終止Context
總結
以上是生活随笔為你收集整理的TEEC_Context和TEEC_InitializeContext介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [armv9]-Introducing-
- 下一篇: CA/TA参数传输中tmpref,mem