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"
29 #include "da_protocol_inst.h"
31 #include "da_protocol_check.h"
33 //----------------- hash
34 static uint32_t calc_lib_hash(struct us_lib_inst_t *lib)
37 char *p = lib->bin_path;
46 static uint32_t calc_app_hash(struct app_info_t *app)
49 char *p = app->exe_path;
59 //----------------------------------- parse -----------------------------------
60 static int parse_us_inst_func(struct msg_buf_t *msg, struct probe_list_t **dest)
63 //name | type | len | info
64 //------------------------------------------
65 //func_addr | uint64 | 8 |
66 //args | string | len(args) |end with '\0'
67 //ret_type | char | 1 |
70 struct us_func_inst_plane_t *func;
72 char *ret_type = NULL;
74 par_count = strlen(msg->cur_pos + sizeof(func->func_addr));
75 size = sizeof(*func) + par_count + 1 +
76 sizeof(char) /* sizeof(char) for ret_type */;
78 if (!parse_int64(msg, &(func->func_addr))) {
79 LOGE("func addr parsing error\n");
83 if (!parse_string_no_alloc(msg, func->args) ||
84 !check_us_inst_func_args(func->args))
86 LOGE("args format parsing error\n");
90 //func->args type is char[0]
91 //and we need put ret_type after func->args
92 ret_type = func->args + par_count + 1;
93 if (!parse_int8(msg, (uint8_t *)ret_type) ||
94 !check_us_inst_func_ret_type(*ret_type))
96 LOGE("return type parsing error\n");
102 LOGE("alloc new_probe error\n");
105 (*dest)->size = size;
106 (*dest)->func = func;
113 static int parse_func_inst_list(struct msg_buf_t *msg,
114 struct data_list_t *dest)
116 uint32_t i = 0, num = 0;
117 struct probe_list_t *probe_el;
119 if (!parse_int32(msg, &num) ||
120 !check_us_app_inst_func_count(num))
122 LOGE("func num parsing error\n");
125 //parse user space function list
127 parse_deb("app_int_num = %d\n", num);
128 for (i = 0; i < num; i++) {
129 parse_deb("app_int #%d\n", i);
130 if (!parse_us_inst_func(msg, &probe_el)) {
131 // TODO maybe need to free allocated memory up there
132 LOGE("parse us inst func #%d failed\n", i + 1);
135 probe_list_append(dest, probe_el);
137 dest->func_num = num;
141 static int parse_inst_lib(struct msg_buf_t *msg, struct lib_list_t **dest)
145 LOGE("lib alloc error\n");
149 if (!parse_string(msg, &((*dest)->lib->bin_path)) ||
150 !check_exec_path((*dest)->lib->bin_path))
152 LOGE("bin path parsing error\n");
156 if (!parse_func_inst_list(msg, (struct data_list_t *) *dest)) {
157 LOGE("funcs parsing error\n");
161 (*dest)->size += strlen((*dest)->lib->bin_path) + 1 + sizeof((*dest)->func_num);
162 (*dest)->hash = calc_lib_hash((*dest)->lib);
167 int parse_lib_inst_list(struct msg_buf_t *msg,
169 struct lib_list_t **lib_list)
172 struct lib_list_t *lib = NULL;
173 if (!parse_int32(msg, num) ||
174 !check_lib_inst_count(*num))
176 LOGE("lib num parsing error\n");
180 for (i = 0; i < *num; i++) {
181 if (!parse_inst_lib(msg, &lib)) {
182 // TODO maybe need free allocated memory up there
183 LOGE("parse is inst lib #%d failed\n", i + 1);
186 data_list_append((struct data_list_t **)lib_list,
187 (struct data_list_t *)lib);
193 int parse_inst_app(struct msg_buf_t *msg, struct app_list_t **dest)
196 struct app_info_t *app_info = NULL;
200 LOGE("lib alloc error\n");
204 app_info = (*dest)->app;
205 start = msg->cur_pos;
206 if (!parse_int32(msg, &app_info->app_type) ||
207 !check_app_type(app_info->app_type))
209 LOGE("app type parsing error <0x%X>\n", app_info->app_type);
213 if (!parse_string(msg, &app_info->app_id) ||
214 !check_app_id(app_info->app_type, app_info->app_id))
216 LOGE("app id parsing error\n");
219 if (!parse_string(msg, &app_info->exe_path) ||
220 !check_exec_path(app_info->exe_path))
222 LOGE("exec path parsing error\n");
227 if (!parse_func_inst_list(msg, (struct data_list_t *)*dest)) {
228 LOGE("funcs parsing error\n");
232 (*dest)->size += (end - start) + sizeof((*dest)->func_num);
233 (*dest)->hash = calc_app_hash(app_info);
237 int parse_app_inst_list(struct msg_buf_t *msg,
239 struct app_list_t **app_list)
242 struct app_list_t *app = NULL;
243 if (!parse_int32(msg, num) ||
244 !check_lib_inst_count(*num))
246 LOGE("app num parsing error\n");
250 parse_deb("app_int_num = %d\n", *num);
251 for (i = 0; i < *num; i++) {
252 parse_deb("app_int #%d\n", i);
253 if (!parse_inst_app(msg, &app)) {
254 // TODO maybe need free allocated memory up there
255 LOGE("parse is inst app #%d failed\n", i + 1);
258 data_list_append((struct data_list_t **)app_list,
259 (struct data_list_t *)app);
262 if (!parse_replay_event_seq(msg, &prof_session.replay_event_seq)) {
263 LOGE("replay parsing error\n");