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, &tgid);
78 print_err("converting string to PID, str='%s'\n", ta_id);
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;
102 put_strung(exec_path);
110 void destroy_app_info(struct app_info_data *ai)
112 put_strung(ai->exec_path);
120 /* ============================================================================
122 * ============================================================================
124 struct conf_data *create_conf_data(struct msg_buf *mb)
126 struct conf_data *conf;
130 print_parse_debug("conf_data:\n");
132 print_parse_debug("features:");
133 if (get_u64(mb, &uf)) {
134 print_err("failed to read use_features\n");
138 print_parse_debug("sys trace period:");
139 if (get_u32(mb, &stp)) {
140 print_err("failed to read sys trace period\n");
144 print_parse_debug("data msg period:");
145 if (get_u32(mb, &dmp)) {
146 print_err("failed to read data message period\n");
150 conf = kmalloc(sizeof(*conf), GFP_KERNEL);
152 print_err("out of memory\n");
156 conf->use_features = uf;
157 conf->sys_trace_period = stp;
158 conf->data_msg_period = dmp;
163 void destroy_conf_data(struct conf_data *conf)
172 /* ============================================================================
174 * ============================================================================
176 struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
178 struct func_inst_data *fi;
182 print_parse_debug("func addr:");
183 if (get_u64(mb, &addr)) {
184 print_err("failed to read data function address\n");
188 print_parse_debug("funct args:");
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 print_parse_debug("bin path:");
229 if (get_string(mb, &path)) {
230 print_err("failed to read path of binary\n");
234 print_parse_debug("func count:");
235 if (get_u32(mb, &cnt)) {
236 print_err("failed to read count of functions\n");
240 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt) {
241 print_err("to match count of functions(%u)\n", cnt);
245 li = kmalloc(sizeof(*li), GFP_KERNEL);
248 print_err("out of memory\n");
252 li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
253 if (li->func == NULL)
254 if (li->func == NULL) {
255 print_err("out of memory\n");
259 for (i = 0; i < cnt; ++i) {
260 print_parse_debug("func #%d:\n", i + 1);
261 fi = create_func_inst_data(mb);
274 for (j = 0; j < i; ++j)
275 destroy_func_inst_data(li->func[j]);
287 void destroy_lib_inst_data(struct lib_inst_data *li)
291 put_strung(li->path);
293 for (i = 0; i < li->cnt_func; ++i)
294 destroy_func_inst_data(li->func[i]);
304 /* ============================================================================
306 * ============================================================================
308 struct app_inst_data *create_app_inst_data(struct msg_buf *mb)
310 struct app_inst_data *app_inst;
311 struct app_info_data *app_info;
312 struct func_inst_data *func;
313 struct lib_inst_data *lib;
314 u32 cnt_func, i_func = 0, cnt_lib, i_lib = 0, i;
316 app_info = create_app_info(mb);
317 if (app_info == NULL)
320 print_parse_debug("func count:");
321 if (get_u32(mb, &cnt_func)) {
322 print_err("failed to read count of functions\n");
326 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func) {
327 print_err("to match count of functions(%u)\n", cnt_func);
331 app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
332 if (app_inst == NULL) {
333 print_err("out of memory\n");
337 app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
339 if (app_inst->func == NULL) {
340 print_err("out of memory\n");
344 for (i_func = 0; i_func < cnt_func; ++i_func) {
345 print_parse_debug("func #%d:\n", i_func + 1);
346 func = create_func_inst_data(mb);
350 app_inst->func[i_func] = func;
353 print_parse_debug("lib count:");
354 if (get_u32(mb, &cnt_lib)) {
355 print_err("failed to read count of libraries\n");
359 if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib) {
360 print_err("to match count of libraries(%u)\n", cnt_lib);
364 app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
366 if (app_inst->lib == NULL) {
367 print_err("out of memory\n");
371 for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
372 print_parse_debug("lib #%d:\n", i_lib + 1);
373 lib = create_lib_inst_data(mb);
377 app_inst->lib[i_lib] = lib;
380 app_inst->app_info = app_info;
381 app_inst->cnt_func = cnt_func;
382 app_inst->cnt_lib = cnt_lib;
387 for (i = 0; i < i_lib; ++i)
388 destroy_lib_inst_data(app_inst->lib[i]);
389 kfree(app_inst->lib);
392 for (i = 0; i < i_func; ++i)
393 destroy_func_inst_data(app_inst->func[i]);
394 kfree(app_inst->func);
400 destroy_app_info(app_info);
405 void destroy_app_inst_data(struct app_inst_data *ai)
409 for (i = 0; i < ai->cnt_lib; ++i)
410 destroy_lib_inst_data(ai->lib[i]);
413 for (i = 0; i < ai->cnt_func; ++i)
414 destroy_func_inst_data(ai->func[i]);
417 destroy_app_info(ai->app_info);
425 /* ============================================================================
427 * ============================================================================
429 struct us_inst_data *create_us_inst_data(struct msg_buf *mb)
431 struct us_inst_data *ui;
432 struct app_inst_data *ai;
435 print_parse_debug("us_inst_data:\n");
437 print_parse_debug("app count:");
438 if (get_u32(mb, &cnt)) {
439 print_err("failed to read count of applications\n");
443 if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt) {
444 print_err("to match count of applications(%u)\n", cnt);
448 ui = kmalloc(sizeof(struct us_inst_data), GFP_KERNEL);
450 print_err("out of memory\n");
454 ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
456 if (ui->app_inst == NULL) {
457 print_err("out of memory\n");
461 for (i = 0; i < cnt; ++i) {
462 print_parse_debug("app #%d:\n",i+1);
463 ai = create_app_inst_data(mb);
467 ui->app_inst[i] = ai;
475 for (j = 0; j < i; ++j)
476 destroy_app_inst_data(ui->app_inst[j]);
485 void destroy_us_inst_data(struct us_inst_data *ui)
489 for (i = 0; i < ui->cnt; ++i)
490 destroy_app_inst_data(ui->app_inst[i]);