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