apache / incubator-teaclave-trustzone-sdk

Teaclave TrustZone SDK enables safe, functional, and ergonomic development of trustlets.
https://teaclave.apache.org
Apache License 2.0
206 stars 59 forks source link

Where is the ta_heap array being used? #14

Closed dreemkiller closed 4 years ago

dreemkiller commented 4 years ago

I'm having an issue where a TA is running out of heap memory. I've increased TA_DATA_SIZE, but this appears to have no effect. Looking through the code, the ta_heap array is allocated in ta_static.rs and placed in bss. However, I cannot find where ta_heap is being added to the memory pools (or even if the OPTEE memory pool implementation is being used by the rust allocator). Where in the code is the ta_heap array being used?

mssun commented 4 years ago

ta_heap and ta_heap_size will be extern in OPTEE:

https://github.com/OP-TEE/optee_os/blob/dd655cb9906c75165774da5dae95c257ee4e2d21/lib/libutee/arch/arm/user_ta_entry.c#L29

If you implement TA in C, you have to set them here:

https://github.com/OP-TEE/optee_os/blob/dd655cb9906c75165774da5dae95c257ee4e2d21/ta/arch/arm/user_ta_header.c#L92

For your issue, you can change them over here:

https://github.com/mesalock-linux/rust-optee-trustzone-sdk/blob/820f9af00f9677c0334b162b971804ed570bff63/examples/message_passing_interface/ta/src/main.rs#L67-L75

I believe it works in our examples since library like serde need more memory, we increase the heap size so that to use it.

dreemkiller commented 4 years ago

I found the functions in user_ta_entry.c, but I do not see them getting called. The main entry point for user_ta_entry.c , __utee_entry, is not getting called. Do I need to somehow call __utee_entry in the create or open_session functions of my TA in order to get my ta_heap allocation added to the memory pools?

mssun commented 4 years ago

The entrypoint of a TA is __ta_entry:

https://github.com/OP-TEE/optee_os/blob/b4814b22dcf813691f1a6697e2013b0cbeb8dca3/ta/arch/arm/user_ta_header.c#L43

This entrypoint is specified by linker: https://github.com/OP-TEE/optee_os/blob/b4814b22dcf813691f1a6697e2013b0cbeb8dca3/ta/arch/arm/link.mk#L29

So, I think it is already added to the memory pools when TA started.

mssun commented 4 years ago

Issue staled. I'm closing it. Feel free to reopen if you think it's still valid.