+/*
+ * SWAP Parser
+ * modules/parser/msg_parser.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2013
+ *
+ * 2013 Vyacheslav Cherkashin, Vitaliy Cherepanov: SWAP Parser implement
+ *
+ */
+
+
#include <linux/slab.h>
#include "msg_parser.h"
#include "msg_buf.h"
+#include "parser_defs.h"
static int str_to_u32(const char* str, u32 *val)
u32 app_type;
char *ta_id, *exec_path;
+ print_parse_debug("app_info:\n");
+
+ print_parse_debug("type:");
ret = get_u32(mb, &app_type);
- if (ret)
+ if (ret) {
+ print_err("failed to read target application type\n");
return NULL;
+ }
+ print_parse_debug("id:");
ret = get_string(mb, &ta_id);
- if (ret)
+ if (ret) {
+ print_err("failed to read target application ID\n");
return NULL;
+ }
+ print_parse_debug("exec path:");
ret = get_string(mb, &exec_path);
- if (ret)
+ if (ret) {
+ print_err("failed to read executable path\n");
goto free_ta_id;
+ }
ai = kmalloc(sizeof(*ai), GFP_KERNEL);
- if (ai == NULL)
+ if (ai == NULL) {
+ print_err("out of memory\n");
goto free_exec_path;
+ }
switch (app_type) {
case AT_TIZEN_NATIVE_APP:
+ case AT_TIZEN_WEB_APP:
case AT_COMMON_EXEC:
- ai->at_data = ta_id;
+ ai->tgid = 0;
break;
case AT_PID: {
- u32 pid;
- ret = str_to_u32(ta_id, &pid);
- if (ret)
- goto free_ai;
-
- ai->at_data = (void *)pid;
+ u32 tgid = 0;
+
+ if (*ta_id != '\0') {
+ ret = str_to_u32(ta_id, &tgid);
+ if (ret) {
+ print_err("converting string to PID, "
+ "str='%s'\n", ta_id);
+ goto free_ai;
+ }
+ }
+
+ ai->tgid = tgid;
break;
}
default:
+ print_err("wrong application type(%u)\n", app_type);
ret = -EINVAL;
goto free_ai;
}
ai->app_type = (enum APP_TYPE)app_type;
ai->exec_path = exec_path;
+ put_string(ta_id);
+
return ai;
free_ai:
kfree(ai);
free_exec_path:
- put_strung(exec_path);
+ put_string(exec_path);
free_ta_id:
- put_strung(ta_id);
+ put_string(ta_id);
return NULL;
}
void destroy_app_info(struct app_info_data *ai)
{
- switch (ai->app_type) {
- case AT_TIZEN_NATIVE_APP:
- case AT_COMMON_EXEC:
- put_strung(ai->at_data);
- break;
-
- case AT_PID:
- break;
-
- default:
- printk("### BUG()\n");
- break;
- }
-
- put_strung(ai->exec_path);
+ put_string(ai->exec_path);
kfree(ai);
}
struct conf_data *create_conf_data(struct msg_buf *mb)
{
struct conf_data *conf;
- u64 uf;
+ u64 use_features0, use_features1;
u32 stp, dmp;
- if (get_u64(mb, &uf))
+ print_parse_debug("conf_data:\n");
+
+ print_parse_debug("features:");
+ if (get_u64(mb, &use_features0)) {
+ print_err("failed to read use_features\n");
return NULL;
+ }
- if (get_u32(mb, &stp))
+ if (get_u64(mb, &use_features1)) {
+ print_err("failed to read use_features\n");
return NULL;
+ }
- if (get_u32(mb, &dmp))
+ print_parse_debug("sys trace period:");
+ if (get_u32(mb, &stp)) {
+ print_err("failed to read sys trace period\n");
return NULL;
+ }
+
+ print_parse_debug("data msg period:");
+ if (get_u32(mb, &dmp)) {
+ print_err("failed to read data message period\n");
+ return NULL;
+ }
conf = kmalloc(sizeof(*conf), GFP_KERNEL);
- if (conf == NULL)
+ if (conf == NULL) {
+ print_err("out of memory\n");
return NULL;
+ }
- conf->use_features = uf;
+ conf->use_features0 = use_features0;
+ conf->use_features1 = use_features1;
conf->sys_trace_period = stp;
conf->data_msg_period = dmp;
kfree(conf);
}
+static struct conf_data config;
+void save_config(const struct conf_data *conf)
+{
+ memcpy(&config, conf, sizeof(config));
+}
+void restore_config(struct conf_data *conf)
+{
+ memcpy(conf, &config, sizeof(*conf));
+}
struct func_inst_data *fi;
u64 addr;
char *args;
+ char ret_type;
- if (get_u64(mb, &addr))
+ print_parse_debug("func addr:");
+ if (get_u64(mb, &addr)) {
+ print_err("failed to read data function address\n");
return NULL;
+ }
- if (get_string(mb, &args))
+ print_parse_debug("funct args:");
+ if (get_string(mb, &args)) {
+ print_err("failed to read data function arguments\n");
return NULL;
+ }
+
+ print_parse_debug("funct ret type:");
+ if (get_u8(mb, (u8 *)&ret_type)) {
+ print_err("failed to read data function arguments\n");
+ goto free_args;
+ }
fi = kmalloc(sizeof(*fi), GFP_KERNEL);
if (fi == NULL) {
- put_strung(args);
- return NULL;
+ print_err("out of memory\n");
+ goto free_args;
}
fi->addr = addr;
fi->args = args;
+ fi->ret_type = ret_type;
return fi;
+
+free_args:
+ put_string(args);
+ return NULL;
}
void destroy_func_inst_data(struct func_inst_data *fi)
{
- put_strung(fi->args);
+ put_string(fi->args);
kfree(fi);
}
char *path;
u32 cnt, j, i = 0;
- if (get_string(mb, &path))
+ print_parse_debug("bin path:");
+ if (get_string(mb, &path)) {
+ print_err("failed to read path of binary\n");
return NULL;
+ }
- if (get_u32(mb, &cnt))
- return NULL;
+ print_parse_debug("func count:");
+ if (get_u32(mb, &cnt)) {
+ print_err("failed to read count of functions\n");
+ goto free_path;
+ }
- if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt)
- return NULL;
+ if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt) {
+ print_err("to match count of functions(%u)\n", cnt);
+ goto free_path;
+ }
li = kmalloc(sizeof(*li), GFP_KERNEL);
if (li == NULL)
+ if (li == NULL) {
+ print_err("out of memory\n");
goto free_path;
+ }
li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
if (li->func == NULL)
+ if (li->func == NULL) {
+ print_err("out of memory\n");
goto free_li;
+ }
for (i = 0; i < cnt; ++i) {
+ print_parse_debug("func #%d:\n", i + 1);
fi = create_func_inst_data(mb);
if (fi == NULL)
goto free_func;
kfree(li);
free_path:
- put_strung(path);
+ put_string(path);
return NULL;
}
{
int i;
- put_strung(li->path);
+ put_string(li->path);
for (i = 0; i < li->cnt_func; ++i)
destroy_func_inst_data(li->func[i]);
if (app_info == NULL)
return NULL;
- if (get_u32(mb, &cnt_func))
+ print_parse_debug("func count:");
+ if (get_u32(mb, &cnt_func)) {
+ print_err("failed to read count of functions\n");
goto free_app_info;
+ }
- if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func)
+ if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func) {
+ print_err("to match count of functions(%u)\n", cnt_func);
goto free_app_info;
+ }
app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
- if (app_inst == NULL)
+ if (app_inst == NULL) {
+ print_err("out of memory\n");
goto free_app_info;
+ }
app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
GFP_KERNEL);
- if (app_inst->func == NULL)
+ if (app_inst->func == NULL) {
+ print_err("out of memory\n");
goto free_app_inst;
+ }
for (i_func = 0; i_func < cnt_func; ++i_func) {
+ print_parse_debug("func #%d:\n", i_func + 1);
func = create_func_inst_data(mb);
if (func == NULL)
goto free_func;
app_inst->func[i_func] = func;
}
- if (get_u32(mb, &cnt_lib))
+ print_parse_debug("lib count:");
+ if (get_u32(mb, &cnt_lib)) {
+ print_err("failed to read count of libraries\n");
goto free_func;
+ }
- if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib)
+ if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib) {
+ print_err("to match count of libraries(%u)\n", cnt_lib);
goto free_func;
+ }
app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
GFP_KERNEL);
- if (app_inst->lib == NULL)
+ if (app_inst->lib == NULL) {
+ print_err("out of memory\n");
goto free_func;
+ }
for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
+ print_parse_debug("lib #%d:\n", i_lib + 1);
lib = create_lib_inst_data(mb);
if (lib == NULL)
goto free_lib;
app_inst->lib[i_lib] = lib;
}
+ app_inst->app_info = app_info;
app_inst->cnt_func = cnt_func;
app_inst->cnt_lib = cnt_lib;
struct app_inst_data *ai;
u32 cnt, j, i = 0;
- if (get_u32(mb, &cnt))
+ print_parse_debug("us_inst_data:\n");
+
+ print_parse_debug("app count:");
+ if (get_u32(mb, &cnt)) {
+ print_err("failed to read count of applications\n");
return NULL;
+ }
- if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt)
+ if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt) {
+ print_err("to match count of applications(%u)\n", cnt);
return NULL;
+ }
ui = kmalloc(sizeof(struct us_inst_data), GFP_KERNEL);
- if (ui == NULL)
+ if (ui == NULL) {
+ print_err("out of memory\n");
return NULL;
+ }
ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
GFP_KERNEL);
- if (ui->app_inst == NULL)
+ if (ui->app_inst == NULL) {
+ print_err("out of memory\n");
goto free_ui;
+ }
for (i = 0; i < cnt; ++i) {
+ print_parse_debug("app #%d:\n",i+1);
ai = create_app_inst_data(mb);
if (ai == NULL)
goto free_app_inst;