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 print_parse_debug("app_info:\n");
42 print_parse_debug("type:");
43 ret = get_u32(mb, &app_type);
45 print_err("failed to read target application type\n");
49 print_parse_debug("id:");
50 ret = get_string(mb, &ta_id);
52 print_err("failed to read target application ID\n");
56 print_parse_debug("exec path:");
57 ret = get_string(mb, &exec_path);
59 print_err("failed to read executable path\n");
63 ai = kmalloc(sizeof(*ai), GFP_KERNEL);
65 print_err("out of memory\n");
70 case AT_TIZEN_NATIVE_APP:
76 ret = str_to_u32(ta_id, &pid);
78 print_err("converting string to PID, str='%s'\n", ta_id);
82 ai->at_data = (void *)pid;
86 print_err("wrong application type(%u)\n", app_type);
91 ai->app_type = (enum APP_TYPE)app_type;
92 ai->exec_path = exec_path;
100 put_strung(exec_path);
108 void destroy_app_info(struct app_info_data *ai)
110 switch (ai->app_type) {
111 case AT_TIZEN_NATIVE_APP:
113 put_strung(ai->at_data);
120 print_err("wrong application type(%u)\n", ai->app_type);
124 put_strung(ai->exec_path);
132 /* ============================================================================
134 * ============================================================================
136 struct conf_data *create_conf_data(struct msg_buf *mb)
138 struct conf_data *conf;
142 print_parse_debug("conf_data:\n");
144 print_parse_debug("features:");
145 if (get_u64(mb, &uf)) {
146 print_err("failed to read use_features\n");
150 print_parse_debug("sys trace period:");
151 if (get_u32(mb, &stp)) {
152 print_err("failed to read sys trace period\n");
156 print_parse_debug("data msg period:");
157 if (get_u32(mb, &dmp)) {
158 print_err("failed to read data message period\n");
162 conf = kmalloc(sizeof(*conf), GFP_KERNEL);
164 print_err("out of memory\n");
168 conf->use_features = uf;
169 conf->sys_trace_period = stp;
170 conf->data_msg_period = dmp;
175 void destroy_conf_data(struct conf_data *conf)
184 /* ============================================================================
186 * ============================================================================
188 struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
190 struct func_inst_data *fi;
194 print_parse_debug("func addr:");
195 if (get_u64(mb, &addr)) {
196 print_err("failed to read data function address\n");
200 print_parse_debug("funct args:");
201 if (get_string(mb, &args)) {
202 print_err("failed to read data function arguments\n");
206 fi = kmalloc(sizeof(*fi), GFP_KERNEL);
208 print_err("out of memory\n");
219 void destroy_func_inst_data(struct func_inst_data *fi)
221 put_strung(fi->args);
229 /* ============================================================================
231 * ============================================================================
233 struct lib_inst_data *create_lib_inst_data(struct msg_buf *mb)
235 struct lib_inst_data *li;
236 struct func_inst_data *fi;
240 print_parse_debug("bin path:");
241 if (get_string(mb, &path)) {
242 print_err("failed to read path of binary\n");
246 print_parse_debug("func count:");
247 if (get_u32(mb, &cnt)) {
248 print_err("failed to read count of functions\n");
252 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt) {
253 print_err("to match count of functions(%u)\n", cnt);
257 li = kmalloc(sizeof(*li), GFP_KERNEL);
260 print_err("out of memory\n");
264 li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
265 if (li->func == NULL)
266 if (li->func == NULL) {
267 print_err("out of memory\n");
271 for (i = 0; i < cnt; ++i) {
272 print_parse_debug("func #%d:\n", i + 1);
273 fi = create_func_inst_data(mb);
286 for (j = 0; j < i; ++j)
287 destroy_func_inst_data(li->func[j]);
299 void destroy_lib_inst_data(struct lib_inst_data *li)
303 put_strung(li->path);
305 for (i = 0; i < li->cnt_func; ++i)
306 destroy_func_inst_data(li->func[i]);
316 /* ============================================================================
318 * ============================================================================
320 struct app_inst_data *create_app_inst_data(struct msg_buf *mb)
322 struct app_inst_data *app_inst;
323 struct app_info_data *app_info;
324 struct func_inst_data *func;
325 struct lib_inst_data *lib;
326 u32 cnt_func, i_func = 0, cnt_lib, i_lib = 0, i;
328 app_info = create_app_info(mb);
329 if (app_info == NULL)
332 print_parse_debug("func count:");
333 if (get_u32(mb, &cnt_func)) {
334 print_err("failed to read count of functions\n");
338 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func) {
339 print_err("to match count of functions(%u)\n", cnt_func);
343 app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
344 if (app_inst == NULL) {
345 print_err("out of memory\n");
349 app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
351 if (app_inst->func == NULL) {
352 print_err("out of memory\n");
356 for (i_func = 0; i_func < cnt_func; ++i_func) {
357 print_parse_debug("func #%d:\n", i_func + 1);
358 func = create_func_inst_data(mb);
362 app_inst->func[i_func] = func;
365 print_parse_debug("lib count:");
366 if (get_u32(mb, &cnt_lib)) {
367 print_err("failed to read count of libraries\n");
371 if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib) {
372 print_err("to match count of libraries(%u)\n", cnt_lib);
376 app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
378 if (app_inst->lib == NULL) {
379 print_err("out of memory\n");
383 for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
384 print_parse_debug("lib #%d:\n", i_lib + 1);
385 lib = create_lib_inst_data(mb);
389 app_inst->lib[i_lib] = lib;
392 app_inst->app_info = app_info;
393 app_inst->cnt_func = cnt_func;
394 app_inst->cnt_lib = cnt_lib;
399 for (i = 0; i < i_lib; ++i)
400 destroy_lib_inst_data(app_inst->lib[i]);
401 kfree(app_inst->lib);
404 for (i = 0; i < i_func; ++i)
405 destroy_func_inst_data(app_inst->func[i]);
406 kfree(app_inst->func);
412 destroy_app_info(app_info);
417 void destroy_app_inst_data(struct app_inst_data *ai)
421 for (i = 0; i < ai->cnt_lib; ++i)
422 destroy_lib_inst_data(ai->lib[i]);
425 for (i = 0; i < ai->cnt_func; ++i)
426 destroy_func_inst_data(ai->func[i]);
429 destroy_app_info(ai->app_info);
437 /* ============================================================================
439 * ============================================================================
441 struct us_inst_data *create_us_inst_data(struct msg_buf *mb)
443 struct us_inst_data *ui;
444 struct app_inst_data *ai;
447 print_parse_debug("us_inst_data:\n");
449 print_parse_debug("app count:");
450 if (get_u32(mb, &cnt)) {
451 print_err("failed to read count of applications\n");
455 if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt) {
456 print_err("to match count of applications(%u)\n", cnt);
460 ui = kmalloc(sizeof(struct us_inst_data), GFP_KERNEL);
462 print_err("out of memory\n");
466 ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
468 if (ui->app_inst == NULL) {
469 print_err("out of memory\n");
473 for (i = 0; i < cnt; ++i) {
474 print_parse_debug("app #%d:\n",i+1);
475 ai = create_app_inst_data(mb);
479 ui->app_inst[i] = ai;
487 for (j = 0; j < i; ++j)
488 destroy_app_inst_data(ui->app_inst[j]);
497 void destroy_us_inst_data(struct us_inst_data *ui)
501 for (i = 0; i < ui->cnt; ++i)
502 destroy_app_inst_data(ui->app_inst[i]);