Data processing method, terminal device, and readable storage medium
Abstract
An REE and a TEE are deployed in the terminal device. The data processing method includes: storing, in the REE, an ecall task initiated by a CA through a first thread into a shared memory; obtaining, in the TEE, the ecall task from the shared memory; and executing, by a TA in the TEE, the ecall task through a second thread, and storing a task result into the shared memory. The shared memory is pre-applied in the REE for the CA and can be accessed by the REE and the TEE. The second thread is created in the TEE. The second thread and the first thread are bound to different processing units. The shared memory is pre-applied, to avoid data copy. Processing units bound to threads that execute the ecall task in the REE and the TEE are different, and the second thread is created in the TEE.
Claims
exact text as granted — not AI-modified1 . A data processing method, applied to a terminal device, wherein a trusted execution environment and an untrusted execution environment are deployed in the terminal device, and the method comprises:
storing, in a first execution environment, a task initiated by a first application through a first thread into a shared memory, wherein the task is used to call a software function provided by a second application in a second execution environment, the shared memory is a physical memory region that is applied for the first application in advance in the untrusted execution environment and that is used to be accessed by the untrusted execution environment and the trusted execution environment, and the first execution environment is the untrusted execution environment, and the second execution environment is the trusted execution environment, or the first execution environment is the trusted execution environment, and the second execution environment is the untrusted execution environment; obtaining, in the second execution environment, the task from the shared memory; allocating a second thread to the task in the second execution environment, wherein the second thread is created in the second execution environment, and the second thread and the first thread are bound to different processing units; and executing, by the second application in the second execution environment, the task through the second thread, to obtain a task result, and storing the task result into the shared memory.
2 . The method according to claim 1 , wherein the storing, in the first execution environment, the task into the shared memory comprises:
serializing the task in the first execution environment to obtain a serialized message of the task; storing, in the first execution environment, the serialized message of the task in a message queue, wherein the message queue is stored into the shared memory and is used to store serialized messages respectively corresponding to a plurality of tasks initiated by the first application; and setting, in the first execution environment, an execution flag bit of the serialized message of the task to a first value, wherein the first value indicates that a state of the serialized message is a to-be-executed state.
3 . The method according to claim 2 , wherein the obtaining, in the second execution environment, the task from the shared memory comprises:
accessing, in the second execution environment, the message queue, and obtaining the serialized message of the task whose execution flag bit is the first value; and parsing, in the second execution environment, the serialized message of the task to obtain the task.
4 . The method according to claim 2 , wherein after the executing, by the second application in the second execution environment, the task through the second thread, to obtain a task result, and storing the task result into the shared memory, the method further comprises:
setting, in the second execution environment, the execution flag bit of the serialized message of the task to a second value, wherein the second value indicates that the state of the serialized message is an executed state.
5 . The method according to claim 1 , wherein before the storing, in a first execution environment, a task initiated by a first application through a first thread into a shared memory, the method further comprises:
initiating, by the first application program in the first execution environment, the task through the first thread, and registering a callback function.
6 . The method according to claim 5 , wherein the method further comprises:
calling, in the first execution environment, the callback function through a third thread, wherein the third thread is different from the first thread.
7 . The method according to claim 6 , wherein a quantity of the third threads is less than or equal to a quantity of tasks initiated by the first application.
8 . The method according to claim 1 , wherein the task comprises an incoming parameter and an outgoing parameter, and the incoming parameter and the outgoing parameter are stored into the shared memory; and
before the storing, in a first execution environment, a task initiated by a first application through a first thread into a shared memory, the method further comprises: obtaining, in the first execution environment, a first reference address of the shared memory in the first execution environment, a first input address of the incoming parameter in the first execution environment, and a first output address of the outgoing parameter in the first execution environment; and converting, in the first execution environment, the first input address into a first input offset relative to the first reference address, and converting the first output address into a first output offset relative to the first reference address.
9 . The method according to claim 8 , wherein before the executing, by the second application in the second execution environment, the task through the second thread, the method further comprises:
obtaining, in the second execution environment, a second reference address of the shared memory in the second execution environment; and obtaining, in the second execution environment, a second input address of the incoming parameter in the second execution environment based on the second reference address and the first input offset, and obtaining a second output address of the outgoing parameter in the second execution environment based on the second reference address and the first output offset.
10 . The method according to claim 1 , wherein the first execution environment is the trusted execution environment, the second execution environment is the untrusted execution environment, and the task is an ocall task.
11 . The method according to claim 1 , wherein the first execution environment is the untrusted execution environment, the second execution environment is the trusted execution environment, and the task is an ecall task.
12 . The method according to claim 11 , wherein a thread pool is established in the second execution environment for the first application, the thread pool comprises a plurality of threads, and the threads in the thread pool are created in the second execution environment; and
the second thread is an idle thread in the thread pool.
13 . The method according to claim 12 , wherein the method further comprises:
obtaining, in the second execution environment, a first quantity of idle threads in the thread pool; obtaining, in the second execution environment, a second quantity of tasks that are not executed in at least one task initiated by the first application; and adjusting, in the second execution environment, a quantity of threads in the thread pool based on the first quantity and the second quantity.
14 . The method according to claim 13 , wherein the adjusting, in the second execution environment, a quantity of threads in the thread pool based on the first quantity and the second quantity comprises:
destroying, in the second execution environment, one thread in the thread pool if the first quantity is greater than the second quantity and the total quantity of threads in the thread pool is greater than a minimum threshold; or creating, in the second execution environment, at least one thread in the thread pool if the first quantity is less than the second quantity and the total quantity of threads in the thread pool is less than a maximum threshold, wherein a quantity of the at least one thread is less than or equal to a difference between the maximum threshold and the total quantity of threads in the thread pool.
15 . The method according to claim 12 , wherein before the storing, in a first execution environment, a task initiated by a first application through a first thread into a shared memory, the method further comprises:
sending, in the first execution environment, a minimum threshold, a maximum threshold, and an intermediate threshold to the second execution environment, wherein the intermediate threshold is greater than the minimum threshold and less than the maximum threshold; and establishing, in the second execution environment, the thread pool for the first application, wherein a quantity of threads in the thread pool is the intermediate threshold.
16 . The method according to claim 11 , wherein before the storing, in a first execution environment, a task initiated by a first application through a first thread into a shared memory, the method further comprises:
obtaining, in the first execution environment, a memory size of the shared memory; allocating, in the first execution environment, the shared memory based on the memory size; and sending, in the first execution environment, related information of the shared memory to the second execution environment.
17 . The method according to claim 16 , wherein the memory size comprises a first memory size occupied by the message queue and a second memory size occupied by application data, and the message queue is stored into the shared memory and is used to store the serialized messages respectively corresponding to the plurality of tasks initiated by the first application; and
the shared memory comprises first memory space of the first memory size and second memory space of the second memory size.
18 . The method according to claim 17 , wherein addresses of the first memory space and the second memory space are contiguous.
19 . A terminal device, comprising a processor, wherein the processor is coupled to a storage, and reads instructions in the storage, to enable, based on the instructions, the terminal device to perform a data processing method, applied to a terminal device, wherein a trusted execution environment and an untrusted execution environment are deployed in the terminal device, and the method comprises:
storing, in a first execution environment, a task initiated by a first application through a first thread into a shared memory, wherein the task is used to call a software function provided by a second application in a second execution environment, the shared memory is a physical memory region that is applied for the first application in advance in the untrusted execution environment and that is used to be accessed by the untrusted execution environment and the trusted execution environment, and the first execution environment is the untrusted execution environment, and the second execution environment is the trusted execution environment, or the first execution environment is the trusted execution environment, and the second execution environment is the untrusted execution environment; obtaining, in the second execution environment, the task from the shared memory; allocating a second thread to the task in the second execution environment, wherein the second thread is created in the second execution environment, and the second thread and the first thread are bound to different processing units; and executing, by the second application in the second execution environment, the task through the second thread, to obtain a task result, and storing the task result into the shared memory.
20 . A computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer instructions are run on a terminal device, the terminal device is enabled to perform a data processing method, applied to a terminal device, wherein a trusted execution environment and an untrusted execution environment are deployed in the terminal device, and the method comprises:
storing, in a first execution environment, a task initiated by a first application through a first thread into a shared memory, wherein the task is used to call a software function provided by a second application in a second execution environment, the shared memory is a physical memory region that is applied for the first application in advance in the untrusted execution environment and that is used to be accessed by the untrusted execution environment and the trusted execution environment, and the first execution environment is the untrusted execution environment, and the second execution environment is the trusted execution environment, or the first execution environment is the trusted execution environment, and the second execution environment is the untrusted execution environment; obtaining, in the second execution environment, the task from the shared memory; allocating a second thread to the task in the second execution environment, wherein the second thread is created in the second execution environment, and the second thread and the first thread are bound to different processing units; and executing, by the second application in the second execution environment, the task through the second thread, to obtain a task result, and storing the task result into the shared memory.Join the waitlist — get patent alerts
Track US2025238269A1 — get alerts on status changes and closely related new filings.
We store only your email — no account needed. See our privacy policy.