• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #include <stddef.h>
14 #include <ta_framework.h>
15 #include <tee_internal_api.h>
16 #include <tee_log.h>
17 #include "gtask_config_hal.h"
18 #include "tee_config.h"
19 #include "gtask_inner.h"
20 #include "service_manager.h"
21 #include "gtask_core.h"
22 
load_internal_task(const TEE_UUID * puuid)23 void load_internal_task(const TEE_UUID *puuid)
24 {
25     uint32_t num;
26     uint32_t i;
27     uint32_t ret;
28     struct ta_property pty;
29     const TEE_UUID *task_uuid = puuid;
30     struct service_attr service_attr = { 0 };
31 
32     bool all_tasks = (puuid == LOAD_ALL_TASKS) ? true : false;
33 
34     num = get_builtin_task_nums();
35     for (i = 0; i < num; i++) {
36         const struct task_info_st *builtin_task_info = get_builtin_task_info_by_index(i);
37         if (builtin_task_info == NULL)
38             break;
39 
40         if (all_tasks == true)
41             task_uuid = &builtin_task_info->uuid;
42         else if (TEE_MemCompare(task_uuid, &builtin_task_info->uuid, sizeof(TEE_UUID)) != 0)
43             continue;
44 
45         service_attr.build_in     = true;
46         service_attr.ta_64bit     = builtin_task_info->ta_64bit;
47 
48         /* from loadELF_to_tee */
49         ret = register_service(builtin_task_info->name, task_uuid, false, &service_attr);
50         if (ret) {
51             tloge("internal task register failed %s\n", builtin_task_info->name);
52             continue;
53         }
54         ret = get_build_in_services_property(task_uuid, &pty);
55         if (ret) {
56             tloge("internal task get property failed %s\n", builtin_task_info->name);
57             continue;
58         }
59         init_service_property(&pty.uuid, pty.stack_size, pty.heap_size, pty.single_instance, pty.multi_session,
60                               pty.keep_alive, pty.ssa_enum_enable, false, (char *)pty.other_buff,
61                               pty.other_len);
62     }
63 }
64 
load_dynamic_service(const struct service_struct * dead_srv)65 void load_dynamic_service(const struct service_struct *dead_srv)
66 {
67     struct service_attr service_attr = { 0 };
68 
69     if (dead_srv == NULL)
70         return;
71 
72     service_attr.build_in     = false;
73     service_attr.ta_64bit     = dead_srv->ta_64bit;
74     service_attr.img_type     = dead_srv->img_type;
75 
76     /* from loadELF_to_tee */
77     TEE_Result ret = register_service(dead_srv->name, &(dead_srv->property.uuid),
78         dead_srv->is_dyn_conf_registed, &service_attr);
79     if (ret != TEE_SUCCESS) {
80         tloge("task register failed %s, ret:0x%x\n", dead_srv->name, ret);
81         return;
82     }
83 
84     init_service_property(&(dead_srv->property.uuid), dead_srv->property.stack_size,
85         dead_srv->property.heap_size, dead_srv->property.single_instance, dead_srv->property.multi_session,
86         dead_srv->property.keep_alive, dead_srv->property.ssa_enum_enable, false,
87         dead_srv->property.other_buff, dead_srv->property.other_len);
88 }
89