4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
23 * - Samsung RnD Institute Russia
28 #include "da_protocol.h"
30 #include "da_protocol_check.h"
32 //----------------- hash
33 static uint32_t calc_lib_hash(struct us_lib_inst_t *lib)
36 char *p = lib->bin_path;
45 static uint32_t calc_app_hash(struct app_info_t *app)
48 char *p = app->exe_path;
58 //----------------------------------- parse -----------------------------------
59 int parse_us_inst_func(struct msg_buf_t *msg, struct probe_list_t **dest)
62 struct us_func_inst_plane_t *func;
64 size = sizeof(*func) + strlen(msg->cur_pos + sizeof(func->func_addr) ) + 1;
66 if (!parse_int64(msg, &(func->func_addr))) {
67 LOGE("func addr parsing error\n");
72 if (!parse_string_no_alloc(msg, func->args) ||
73 !check_us_inst_func_args(func->args))
75 LOGE("args format parsing error\n");
82 LOGE("alloc new_probe error\n");
91 int parse_func_inst_list(struct msg_buf_t *msg,
92 struct data_list_t *dest)
94 uint32_t i = 0, num = 0;
95 struct probe_list_t *probe_el;
97 if (!parse_int32(msg, &num) ||
98 !check_us_app_inst_func_count(num))
100 LOGE("func num parsing error\n");
103 //parse user space function list
105 parse_deb("app_int_num = %d\n", num);
106 for (i = 0; i < num; i++) {
107 parse_deb("app_int #%d\n", i);
108 if (!parse_us_inst_func(msg, &probe_el)) {
109 // TODO maybe need to free allocated memory up there
110 LOGE("parse us inst func #%d failed\n", i + 1);
113 probe_list_append(dest, probe_el);
115 dest->func_num = num;
119 int parse_inst_lib(struct msg_buf_t *msg, struct lib_list_t **dest)
123 LOGE("lib alloc error\n");
127 if (!parse_string(msg, &((*dest)->lib->bin_path)) ||
128 !check_exec_path((*dest)->lib->bin_path))
130 LOGE("bin path parsing error\n");
134 if (!parse_func_inst_list(msg, (struct data_list_t *) *dest)) {
135 LOGE("funcs parsing error\n");
139 (*dest)->size += strlen((*dest)->lib->bin_path) + 1 + sizeof((*dest)->func_num);
140 (*dest)->hash = calc_lib_hash((*dest)->lib);
145 int parse_lib_inst_list(struct msg_buf_t *msg,
147 struct lib_list_t **lib_list)
150 struct lib_list_t *lib = NULL;
151 if (!parse_int32(msg, num) ||
152 !check_lib_inst_count(*num))
154 LOGE("lib num parsing error\n");
158 for (i = 0; i < *num; i++) {
159 if (!parse_inst_lib(msg, &lib)) {
160 // TODO maybe need free allocated memory up there
161 LOGE("parse is inst lib #%d failed\n", i + 1);
164 data_list_append((struct data_list_t **)lib_list,
165 (struct data_list_t *)lib);
171 int parse_inst_app(struct msg_buf_t *msg, struct app_list_t **dest)
174 struct app_info_t *app_info = NULL;
178 LOGE("lib alloc error\n");
182 app_info = (*dest)->app;
183 start = msg->cur_pos;
184 if (!parse_int32(msg, &app_info->app_type) ||
185 !check_app_type(app_info->app_type))
187 LOGE("app type parsing error <0x%X>\n", app_info->app_type);
191 if (!parse_string(msg, &app_info->app_id) ||
192 !check_app_id(app_info->app_type, app_info->app_id))
194 LOGE("app id parsing error\n");
197 if (!parse_string(msg, &app_info->exe_path) ||
198 !check_exec_path(app_info->exe_path))
200 LOGE("exec path parsing error\n");
205 if (!parse_func_inst_list(msg, (struct data_list_t *)*dest)) {
206 LOGE("funcs parsing error\n");
210 (*dest)->size += (end - start) + sizeof((*dest)->func_num);
211 (*dest)->hash = calc_app_hash(app_info);
215 int parse_app_inst_list(struct msg_buf_t *msg,
217 struct app_list_t **app_list)
220 struct app_list_t *app = NULL;
221 if (!parse_int32(msg, num) ||
222 !check_lib_inst_count(*num))
224 LOGE("app num parsing error\n");
228 parse_deb("app_int_num = %d\n", *num);
229 for (i = 0; i < *num; i++) {
230 parse_deb("app_int #%d\n", i);
231 if (!parse_inst_app(msg, &app)) {
232 // TODO maybe need free allocated memory up there
233 LOGE("parse is inst app #%d failed\n", i + 1);
236 data_list_append((struct data_list_t **)app_list,
237 (struct data_list_t *)app);
240 if (!parse_replay_event_seq(msg, &prof_session.replay_event_seq)) {
241 LOGE("replay parsing error\n");