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:
101 ret = str_to_u32(ta_id, &tgid);
103 print_err("converting string to PID, str='%s'\n", ta_id);
111 print_err("wrong application type(%u)\n", app_type);
116 ai->app_type = (enum APP_TYPE)app_type;
117 ai->exec_path = exec_path;
127 put_string(exec_path);
135 void destroy_app_info(struct app_info_data *ai)
137 put_string(ai->exec_path);
145 /* ============================================================================
147 * ============================================================================
149 struct conf_data *create_conf_data(struct msg_buf *mb)
151 struct conf_data *conf;
155 print_parse_debug("conf_data:\n");
157 print_parse_debug("features:");
158 if (get_u64(mb, &uf)) {
159 print_err("failed to read use_features\n");
163 print_parse_debug("sys trace period:");
164 if (get_u32(mb, &stp)) {
165 print_err("failed to read sys trace period\n");
169 print_parse_debug("data msg period:");
170 if (get_u32(mb, &dmp)) {
171 print_err("failed to read data message period\n");
175 conf = kmalloc(sizeof(*conf), GFP_KERNEL);
177 print_err("out of memory\n");
181 conf->use_features = uf;
182 conf->sys_trace_period = stp;
183 conf->data_msg_period = dmp;
188 void destroy_conf_data(struct conf_data *conf)
197 /* ============================================================================
199 * ============================================================================
201 struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
203 struct func_inst_data *fi;
207 print_parse_debug("func addr:");
208 if (get_u64(mb, &addr)) {
209 print_err("failed to read data function address\n");
213 print_parse_debug("funct args:");
214 if (get_string(mb, &args)) {
215 print_err("failed to read data function arguments\n");
219 fi = kmalloc(sizeof(*fi), GFP_KERNEL);
221 print_err("out of memory\n");
232 void destroy_func_inst_data(struct func_inst_data *fi)
234 put_string(fi->args);
242 /* ============================================================================
244 * ============================================================================
246 struct lib_inst_data *create_lib_inst_data(struct msg_buf *mb)
248 struct lib_inst_data *li;
249 struct func_inst_data *fi;
253 print_parse_debug("bin path:");
254 if (get_string(mb, &path)) {
255 print_err("failed to read path of binary\n");
259 print_parse_debug("func count:");
260 if (get_u32(mb, &cnt)) {
261 print_err("failed to read count of functions\n");
265 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt) {
266 print_err("to match count of functions(%u)\n", cnt);
270 li = kmalloc(sizeof(*li), GFP_KERNEL);
273 print_err("out of memory\n");
277 li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
278 if (li->func == NULL)
279 if (li->func == NULL) {
280 print_err("out of memory\n");
284 for (i = 0; i < cnt; ++i) {
285 print_parse_debug("func #%d:\n", i + 1);
286 fi = create_func_inst_data(mb);
299 for (j = 0; j < i; ++j)
300 destroy_func_inst_data(li->func[j]);
312 void destroy_lib_inst_data(struct lib_inst_data *li)
316 put_string(li->path);
318 for (i = 0; i < li->cnt_func; ++i)
319 destroy_func_inst_data(li->func[i]);
329 /* ============================================================================
331 * ============================================================================
333 struct app_inst_data *create_app_inst_data(struct msg_buf *mb)
335 struct app_inst_data *app_inst;
336 struct app_info_data *app_info;
337 struct func_inst_data *func;
338 struct lib_inst_data *lib;
339 u32 cnt_func, i_func = 0, cnt_lib, i_lib = 0, i;
341 app_info = create_app_info(mb);
342 if (app_info == NULL)
345 print_parse_debug("func count:");
346 if (get_u32(mb, &cnt_func)) {
347 print_err("failed to read count of functions\n");
351 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func) {
352 print_err("to match count of functions(%u)\n", cnt_func);
356 app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
357 if (app_inst == NULL) {
358 print_err("out of memory\n");
362 app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
364 if (app_inst->func == NULL) {
365 print_err("out of memory\n");
369 for (i_func = 0; i_func < cnt_func; ++i_func) {
370 print_parse_debug("func #%d:\n", i_func + 1);
371 func = create_func_inst_data(mb);
375 app_inst->func[i_func] = func;
378 print_parse_debug("lib count:");
379 if (get_u32(mb, &cnt_lib)) {
380 print_err("failed to read count of libraries\n");
384 if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib) {
385 print_err("to match count of libraries(%u)\n", cnt_lib);
389 app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
391 if (app_inst->lib == NULL) {
392 print_err("out of memory\n");
396 for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
397 print_parse_debug("lib #%d:\n", i_lib + 1);
398 lib = create_lib_inst_data(mb);
402 app_inst->lib[i_lib] = lib;
405 app_inst->app_info = app_info;
406 app_inst->cnt_func = cnt_func;
407 app_inst->cnt_lib = cnt_lib;
412 for (i = 0; i < i_lib; ++i)
413 destroy_lib_inst_data(app_inst->lib[i]);
414 kfree(app_inst->lib);
417 for (i = 0; i < i_func; ++i)
418 destroy_func_inst_data(app_inst->func[i]);
419 kfree(app_inst->func);
425 destroy_app_info(app_info);
430 void destroy_app_inst_data(struct app_inst_data *ai)
434 for (i = 0; i < ai->cnt_lib; ++i)
435 destroy_lib_inst_data(ai->lib[i]);
438 for (i = 0; i < ai->cnt_func; ++i)
439 destroy_func_inst_data(ai->func[i]);
442 destroy_app_info(ai->app_info);
450 /* ============================================================================
452 * ============================================================================
454 struct us_inst_data *create_us_inst_data(struct msg_buf *mb)
456 struct us_inst_data *ui;
457 struct app_inst_data *ai;
460 print_parse_debug("us_inst_data:\n");
462 print_parse_debug("app count:");
463 if (get_u32(mb, &cnt)) {
464 print_err("failed to read count of applications\n");
468 if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt) {
469 print_err("to match count of applications(%u)\n", cnt);
473 ui = kmalloc(sizeof(struct us_inst_data), GFP_KERNEL);
475 print_err("out of memory\n");
479 ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
481 if (ui->app_inst == NULL) {
482 print_err("out of memory\n");
486 for (i = 0; i < cnt; ++i) {
487 print_parse_debug("app #%d:\n",i+1);
488 ai = create_app_inst_data(mb);
492 ui->app_inst[i] = ai;
500 for (j = 0; j < i; ++j)
501 destroy_app_inst_data(ui->app_inst[j]);
510 void destroy_us_inst_data(struct us_inst_data *ui)
514 for (i = 0; i < ui->cnt; ++i)
515 destroy_app_inst_data(ui->app_inst[i]);