3 * modules/parser/msg_parser.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin, Vitaliy Cherepanov: SWAP Parser implement
26 #include <linux/slab.h>
27 #include "msg_parser.h"
29 #include "parser_defs.h"
32 static int str_to_u32(const char* str, u32 *val)
38 for (result = 0 ; *str; ++str) {
39 if (*str < '0' || *str> '9')
42 result = result * 10 + (*str - '0');
54 /* ============================================================================
56 * ============================================================================
58 struct app_info_data *create_app_info(struct msg_buf *mb)
61 struct app_info_data *ai;
63 char *ta_id, *exec_path;
65 print_parse_debug("app_info:\n");
67 print_parse_debug("type:");
68 ret = get_u32(mb, &app_type);
70 print_err("failed to read target application type\n");
74 print_parse_debug("id:");
75 ret = get_string(mb, &ta_id);
77 print_err("failed to read target application ID\n");
81 print_parse_debug("exec path:");
82 ret = get_string(mb, &exec_path);
84 print_err("failed to read executable path\n");
88 ai = kmalloc(sizeof(*ai), GFP_KERNEL);
90 print_err("out of memory\n");
95 case AT_TIZEN_NATIVE_APP:
96 case AT_TIZEN_WEB_APP:
103 if (*ta_id != '\0') {
104 ret = str_to_u32(ta_id, &tgid);
106 print_err("converting string to PID, "
107 "str='%s'\n", ta_id);
116 print_err("wrong application type(%u)\n", app_type);
121 ai->app_type = (enum APP_TYPE)app_type;
122 ai->exec_path = exec_path;
132 put_string(exec_path);
140 void destroy_app_info(struct app_info_data *ai)
142 put_string(ai->exec_path);
150 /* ============================================================================
152 * ============================================================================
154 struct conf_data *create_conf_data(struct msg_buf *mb)
156 struct conf_data *conf;
157 u64 use_features0, use_features1;
160 print_parse_debug("conf_data:\n");
162 print_parse_debug("features:");
163 if (get_u64(mb, &use_features0)) {
164 print_err("failed to read use_features\n");
168 if (get_u64(mb, &use_features1)) {
169 print_err("failed to read use_features\n");
173 print_parse_debug("sys trace period:");
174 if (get_u32(mb, &stp)) {
175 print_err("failed to read sys trace period\n");
179 print_parse_debug("data msg period:");
180 if (get_u32(mb, &dmp)) {
181 print_err("failed to read data message period\n");
185 conf = kmalloc(sizeof(*conf), GFP_KERNEL);
187 print_err("out of memory\n");
191 conf->use_features0 = use_features0;
192 conf->use_features1 = use_features1;
193 conf->sys_trace_period = stp;
194 conf->data_msg_period = dmp;
199 void destroy_conf_data(struct conf_data *conf)
204 static struct conf_data config;
205 void save_config(const struct conf_data *conf)
207 memcpy(&config, conf, sizeof(config));
210 void restore_config(struct conf_data *conf)
212 memcpy(conf, &config, sizeof(*conf));
217 /* ============================================================================
219 * ============================================================================
221 struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
223 struct func_inst_data *fi;
228 print_parse_debug("func addr:");
229 if (get_u64(mb, &addr)) {
230 print_err("failed to read data function address\n");
234 print_parse_debug("funct args:");
235 if (get_string(mb, &args)) {
236 print_err("failed to read data function arguments\n");
240 print_parse_debug("funct ret type:");
241 if (get_u8(mb, (u8 *)&ret_type)) {
242 print_err("failed to read data function arguments\n");
246 fi = kmalloc(sizeof(*fi), GFP_KERNEL);
248 print_err("out of memory\n");
254 fi->ret_type = ret_type;
263 void destroy_func_inst_data(struct func_inst_data *fi)
265 put_string(fi->args);
273 /* ============================================================================
275 * ============================================================================
277 struct lib_inst_data *create_lib_inst_data(struct msg_buf *mb)
279 struct lib_inst_data *li;
280 struct func_inst_data *fi;
284 print_parse_debug("bin path:");
285 if (get_string(mb, &path)) {
286 print_err("failed to read path of binary\n");
290 print_parse_debug("func count:");
291 if (get_u32(mb, &cnt)) {
292 print_err("failed to read count of functions\n");
296 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt) {
297 print_err("to match count of functions(%u)\n", cnt);
301 li = kmalloc(sizeof(*li), GFP_KERNEL);
304 print_err("out of memory\n");
308 li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
309 if (li->func == NULL)
310 if (li->func == NULL) {
311 print_err("out of memory\n");
315 for (i = 0; i < cnt; ++i) {
316 print_parse_debug("func #%d:\n", i + 1);
317 fi = create_func_inst_data(mb);
330 for (j = 0; j < i; ++j)
331 destroy_func_inst_data(li->func[j]);
343 void destroy_lib_inst_data(struct lib_inst_data *li)
347 put_string(li->path);
349 for (i = 0; i < li->cnt_func; ++i)
350 destroy_func_inst_data(li->func[i]);
360 /* ============================================================================
362 * ============================================================================
364 struct app_inst_data *create_app_inst_data(struct msg_buf *mb)
366 struct app_inst_data *app_inst;
367 struct app_info_data *app_info;
368 struct func_inst_data *func;
369 struct lib_inst_data *lib;
370 u32 cnt_func, i_func = 0, cnt_lib, i_lib = 0, i;
372 app_info = create_app_info(mb);
373 if (app_info == NULL)
376 print_parse_debug("func count:");
377 if (get_u32(mb, &cnt_func)) {
378 print_err("failed to read count of functions\n");
382 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func) {
383 print_err("to match count of functions(%u)\n", cnt_func);
387 app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
388 if (app_inst == NULL) {
389 print_err("out of memory\n");
393 app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
395 if (app_inst->func == NULL) {
396 print_err("out of memory\n");
400 for (i_func = 0; i_func < cnt_func; ++i_func) {
401 print_parse_debug("func #%d:\n", i_func + 1);
402 func = create_func_inst_data(mb);
406 app_inst->func[i_func] = func;
409 print_parse_debug("lib count:");
410 if (get_u32(mb, &cnt_lib)) {
411 print_err("failed to read count of libraries\n");
415 if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib) {
416 print_err("to match count of libraries(%u)\n", cnt_lib);
420 app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
422 if (app_inst->lib == NULL) {
423 print_err("out of memory\n");
427 for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
428 print_parse_debug("lib #%d:\n", i_lib + 1);
429 lib = create_lib_inst_data(mb);
433 app_inst->lib[i_lib] = lib;
436 app_inst->app_info = app_info;
437 app_inst->cnt_func = cnt_func;
438 app_inst->cnt_lib = cnt_lib;
443 for (i = 0; i < i_lib; ++i)
444 destroy_lib_inst_data(app_inst->lib[i]);
445 kfree(app_inst->lib);
448 for (i = 0; i < i_func; ++i)
449 destroy_func_inst_data(app_inst->func[i]);
450 kfree(app_inst->func);
456 destroy_app_info(app_info);
461 void destroy_app_inst_data(struct app_inst_data *ai)
465 for (i = 0; i < ai->cnt_lib; ++i)
466 destroy_lib_inst_data(ai->lib[i]);
469 for (i = 0; i < ai->cnt_func; ++i)
470 destroy_func_inst_data(ai->func[i]);
473 destroy_app_info(ai->app_info);
481 /* ============================================================================
483 * ============================================================================
485 struct us_inst_data *create_us_inst_data(struct msg_buf *mb)
487 struct us_inst_data *ui;
488 struct app_inst_data *ai;
491 print_parse_debug("us_inst_data:\n");
493 print_parse_debug("app count:");
494 if (get_u32(mb, &cnt)) {
495 print_err("failed to read count of applications\n");
499 if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt) {
500 print_err("to match count of applications(%u)\n", cnt);
504 ui = kmalloc(sizeof(struct us_inst_data), GFP_KERNEL);
506 print_err("out of memory\n");
510 ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
512 if (ui->app_inst == NULL) {
513 print_err("out of memory\n");
517 for (i = 0; i < cnt; ++i) {
518 print_parse_debug("app #%d:\n",i+1);
519 ai = create_app_inst_data(mb);
523 ui->app_inst[i] = ai;
531 for (j = 0; j < i; ++j)
532 destroy_app_inst_data(ui->app_inst[j]);
541 void destroy_us_inst_data(struct us_inst_data *ui)
545 for (i = 0; i < ui->cnt; ++i)
546 destroy_app_inst_data(ui->app_inst[i]);