1 #include <linux/slab.h>
2 #include "msg_parser.h"
4 #include "parser_defs.h"
7 static int str_to_u32(const char* str, u32 *val)
13 for (result = 0 ; *str; ++str) {
14 if (*str < '0' || *str> '9')
17 result = result * 10 + (*str - '0');
29 /* ============================================================================
31 * ============================================================================
33 struct app_info_data *create_app_info(struct msg_buf *mb)
36 struct app_info_data *ai;
38 char *ta_id, *exec_path;
40 ret = get_u32(mb, &app_type);
42 print_err("failed to read target application type\n");
46 ret = get_string(mb, &ta_id);
48 print_err("failed to read target application ID\n");
52 ret = get_string(mb, &exec_path);
54 print_err("failed to read executable path\n");
58 ai = kmalloc(sizeof(*ai), GFP_KERNEL);
60 print_err("out of memory\n");
65 case AT_TIZEN_NATIVE_APP:
71 ret = str_to_u32(ta_id, &pid);
73 print_err("converting string to PID, str='%s'\n", ta_id);
77 ai->at_data = (void *)pid;
81 print_err("wrong application type(%u)\n", app_type);
86 ai->app_type = (enum APP_TYPE)app_type;
87 ai->exec_path = exec_path;
95 put_strung(exec_path);
103 void destroy_app_info(struct app_info_data *ai)
105 switch (ai->app_type) {
106 case AT_TIZEN_NATIVE_APP:
108 put_strung(ai->at_data);
115 print_err("wrong application type(%u)\n", ai->app_type);
119 put_strung(ai->exec_path);
127 /* ============================================================================
129 * ============================================================================
131 struct conf_data *create_conf_data(struct msg_buf *mb)
133 struct conf_data *conf;
137 if (get_u64(mb, &uf)) {
138 print_err("failed to read use_features\n");
142 if (get_u32(mb, &stp)) {
143 print_err("failed to read sys trace period\n");
147 if (get_u32(mb, &dmp)) {
148 print_err("failed to read data message period\n");
152 conf = kmalloc(sizeof(*conf), GFP_KERNEL);
154 print_err("out of memory\n");
158 conf->use_features = uf;
159 conf->sys_trace_period = stp;
160 conf->data_msg_period = dmp;
165 void destroy_conf_data(struct conf_data *conf)
174 /* ============================================================================
176 * ============================================================================
178 struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
180 struct func_inst_data *fi;
184 if (get_u64(mb, &addr)) {
185 print_err("failed to read data function address\n");
189 if (get_string(mb, &args)) {
190 print_err("failed to read data function arguments\n");
194 fi = kmalloc(sizeof(*fi), GFP_KERNEL);
196 print_err("out of memory\n");
207 void destroy_func_inst_data(struct func_inst_data *fi)
209 put_strung(fi->args);
217 /* ============================================================================
219 * ============================================================================
221 struct lib_inst_data *create_lib_inst_data(struct msg_buf *mb)
223 struct lib_inst_data *li;
224 struct func_inst_data *fi;
228 if (get_string(mb, &path)) {
229 print_err("failed to read path of binary\n");
233 if (get_u32(mb, &cnt)) {
234 print_err("failed to read count of functions\n");
238 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt) {
239 print_err("to match count of functions(%u)\n", cnt);
243 li = kmalloc(sizeof(*li), GFP_KERNEL);
246 print_err("out of memory\n");
250 li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
251 if (li->func == NULL)
252 if (li->func == NULL) {
253 print_err("out of memory\n");
257 for (i = 0; i < cnt; ++i) {
258 fi = create_func_inst_data(mb);
271 for (j = 0; j < i; ++j)
272 destroy_func_inst_data(li->func[j]);
284 void destroy_lib_inst_data(struct lib_inst_data *li)
288 put_strung(li->path);
290 for (i = 0; i < li->cnt_func; ++i)
291 destroy_func_inst_data(li->func[i]);
301 /* ============================================================================
303 * ============================================================================
305 struct app_inst_data *create_app_inst_data(struct msg_buf *mb)
307 struct app_inst_data *app_inst;
308 struct app_info_data *app_info;
309 struct func_inst_data *func;
310 struct lib_inst_data *lib;
311 u32 cnt_func, i_func = 0, cnt_lib, i_lib = 0, i;
313 app_info = create_app_info(mb);
314 if (app_info == NULL)
317 if (get_u32(mb, &cnt_func)) {
318 print_err("failed to read count of functions\n");
322 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func) {
323 print_err("to match count of functions(%u)\n", cnt_func);
327 app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
328 if (app_inst == NULL) {
329 print_err("out of memory\n");
333 app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
335 if (app_inst->func == NULL) {
336 print_err("out of memory\n");
340 for (i_func = 0; i_func < cnt_func; ++i_func) {
341 func = create_func_inst_data(mb);
345 app_inst->func[i_func] = func;
348 if (get_u32(mb, &cnt_lib)) {
349 print_err("failed to read count of libraries\n");
353 if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib) {
354 print_err("to match count of libraries(%u)\n", cnt_lib);
358 app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
360 if (app_inst->lib == NULL) {
361 print_err("out of memory\n");
365 for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
366 lib = create_lib_inst_data(mb);
370 app_inst->lib[i_lib] = lib;
373 app_inst->app_info = app_info;
374 app_inst->cnt_func = cnt_func;
375 app_inst->cnt_lib = cnt_lib;
380 for (i = 0; i < i_lib; ++i)
381 destroy_lib_inst_data(app_inst->lib[i]);
382 kfree(app_inst->lib);
385 for (i = 0; i < i_func; ++i)
386 destroy_func_inst_data(app_inst->func[i]);
387 kfree(app_inst->func);
393 destroy_app_info(app_info);
398 void destroy_app_inst_data(struct app_inst_data *ai)
402 for (i = 0; i < ai->cnt_lib; ++i)
403 destroy_lib_inst_data(ai->lib[i]);
406 for (i = 0; i < ai->cnt_func; ++i)
407 destroy_func_inst_data(ai->func[i]);
410 destroy_app_info(ai->app_info);
418 /* ============================================================================
420 * ============================================================================
422 struct us_inst_data *create_us_inst_data(struct msg_buf *mb)
424 struct us_inst_data *ui;
425 struct app_inst_data *ai;
428 if (get_u32(mb, &cnt)) {
429 print_err("failed to read count of applications\n");
433 if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt) {
434 print_err("to match count of applications(%u)\n", cnt);
438 ui = kmalloc(sizeof(struct us_inst_data), GFP_KERNEL);
440 print_err("out of memory\n");
444 ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
446 if (ui->app_inst == NULL) {
447 print_err("out of memory\n");
451 for (i = 0; i < cnt; ++i) {
452 ai = create_app_inst_data(mb);
456 ui->app_inst[i] = ai;
464 for (j = 0; j < i; ++j)
465 destroy_app_inst_data(ui->app_inst[j]);
474 void destroy_us_inst_data(struct us_inst_data *ui)
478 for (i = 0; i < ui->cnt; ++i)
479 destroy_app_inst_data(ui->app_inst[i]);