Skip to content

Commit f93cb27

Browse files
author
Pengguang Zhu
committed
libutee: Fix the init_done status while closing session
Mark init_done as false if uninit_instance is called. This is necessary to avoid running a TA uninitialized. Also, need to call __utee_gprof_fini() and __utee_call_elf_fini_fn() next time opening TA session. Signed-off-by: Pengguang Zhu <[email protected]>
1 parent 3edbed4 commit f93cb27

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/libutee/user_ta_entry.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct ta_session {
2828
static TAILQ_HEAD(ta_sessions, ta_session) ta_sessions =
2929
TAILQ_HEAD_INITIALIZER(ta_sessions);
3030

31+
static bool internal_init_done;
32+
static bool init_done;
33+
3134
/* From user_ta_header.c, built within TA */
3235
extern uint8_t ta_heap[];
3336
extern const size_t ta_heap_size;
@@ -165,8 +168,6 @@ static unsigned int get_memtag_implementation(void)
165168

166169
static TEE_Result init_instance(void)
167170
{
168-
static bool internal_init_done;
169-
static bool init_done;
170171
TEE_Result res;
171172

172173
if (init_done)
@@ -176,7 +177,6 @@ static TEE_Result init_instance(void)
176177
goto create_entrypoint;
177178

178179
trace_set_level(tahead_get_trace_level());
179-
__utee_gprof_init();
180180
malloc_add_pool(ta_heap, ta_heap_size);
181181
if (__ta_no_share_heap_size) {
182182
__ta_no_share_malloc_ctx = malloc(raw_malloc_get_ctx_size());
@@ -190,13 +190,19 @@ static TEE_Result init_instance(void)
190190
memtag_init_ops(get_memtag_implementation());
191191
_TEE_MathAPI_Init();
192192
__utee_tcb_init();
193-
__utee_call_elf_init_fn();
194193
internal_init_done = true;
195194

196195
create_entrypoint:
196+
__utee_gprof_init();
197+
__utee_call_elf_init_fn();
198+
197199
res = TA_CreateEntryPoint();
198-
if (!res)
200+
if (!res) {
199201
init_done = true;
202+
} else {
203+
__utee_gprof_fini();
204+
__utee_call_elf_fini_fn();
205+
}
200206

201207
return res;
202208
}
@@ -206,6 +212,7 @@ static void uninit_instance(void)
206212
__utee_gprof_fini();
207213
TA_DestroyEntryPoint();
208214
__utee_call_elf_fini_fn();
215+
init_done = false;
209216
}
210217

211218
static void ta_header_save_params(uint32_t param_types,

0 commit comments

Comments
 (0)