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 ret = get_u32(mb, &app_type);
42 print_err("failed to read target application type\n");
46 ret = get_string(mb, &ta_id);
48 print_err("failed to read target application ID\n");
52 ret = get_string(mb, &exec_path);
54 print_err("failed to read executable path\n");
58 ai = kmalloc(sizeof(*ai), GFP_KERNEL);
60 print_err("out of memory\n");
65 case AT_TIZEN_NATIVE_APP:
71 ret = str_to_u32(ta_id, &tgid);
73 print_err("converting string to PID, str='%s'\n", ta_id);
81 print_err("wrong application type(%u)\n", app_type);
86 ai->app_type = (enum APP_TYPE)app_type;
87 ai->exec_path = exec_path;
97 put_strung(exec_path);
105 void destroy_app_info(struct app_info_data *ai)
107 put_strung(ai->exec_path);
115 /* ============================================================================
117 * ============================================================================
119 struct conf_data *create_conf_data(struct msg_buf *mb)
121 struct conf_data *conf;
125 if (get_u64(mb, &uf)) {
126 print_err("failed to read use_features\n");
130 if (get_u32(mb, &stp)) {
131 print_err("failed to read sys trace period\n");
135 if (get_u32(mb, &dmp)) {
136 print_err("failed to read data message period\n");
140 conf = kmalloc(sizeof(*conf), GFP_KERNEL);
142 print_err("out of memory\n");
146 conf->use_features = uf;
147 conf->sys_trace_period = stp;
148 conf->data_msg_period = dmp;
153 void destroy_conf_data(struct conf_data *conf)
162 /* ============================================================================
164 * ============================================================================
166 struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
168 struct func_inst_data *fi;
172 if (get_u64(mb, &addr)) {
173 print_err("failed to read data function address\n");
177 if (get_string(mb, &args)) {
178 print_err("failed to read data function arguments\n");
182 fi = kmalloc(sizeof(*fi), GFP_KERNEL);
184 print_err("out of memory\n");
195 void destroy_func_inst_data(struct func_inst_data *fi)
197 put_strung(fi->args);
205 /* ============================================================================
207 * ============================================================================
209 struct lib_inst_data *create_lib_inst_data(struct msg_buf *mb)
211 struct lib_inst_data *li;
212 struct func_inst_data *fi;
216 if (get_string(mb, &path)) {
217 print_err("failed to read path of binary\n");
221 if (get_u32(mb, &cnt)) {
222 print_err("failed to read count of functions\n");
226 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt) {
227 print_err("to match count of functions(%u)\n", cnt);
231 li = kmalloc(sizeof(*li), GFP_KERNEL);
234 print_err("out of memory\n");
238 li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
239 if (li->func == NULL)
240 if (li->func == NULL) {
241 print_err("out of memory\n");
245 for (i = 0; i < cnt; ++i) {
246 fi = create_func_inst_data(mb);
259 for (j = 0; j < i; ++j)
260 destroy_func_inst_data(li->func[j]);
272 void destroy_lib_inst_data(struct lib_inst_data *li)
276 put_strung(li->path);
278 for (i = 0; i < li->cnt_func; ++i)
279 destroy_func_inst_data(li->func[i]);
289 /* ============================================================================
291 * ============================================================================
293 struct app_inst_data *create_app_inst_data(struct msg_buf *mb)
295 struct app_inst_data *app_inst;
296 struct app_info_data *app_info;
297 struct func_inst_data *func;
298 struct lib_inst_data *lib;
299 u32 cnt_func, i_func = 0, cnt_lib, i_lib = 0, i;
301 app_info = create_app_info(mb);
302 if (app_info == NULL)
305 if (get_u32(mb, &cnt_func)) {
306 print_err("failed to read count of functions\n");
310 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func) {
311 print_err("to match count of functions(%u)\n", cnt_func);
315 app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
316 if (app_inst == NULL) {
317 print_err("out of memory\n");
321 app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
323 if (app_inst->func == NULL) {
324 print_err("out of memory\n");
328 for (i_func = 0; i_func < cnt_func; ++i_func) {
329 func = create_func_inst_data(mb);
333 app_inst->func[i_func] = func;
336 if (get_u32(mb, &cnt_lib)) {
337 print_err("failed to read count of libraries\n");
341 if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib) {
342 print_err("to match count of libraries(%u)\n", cnt_lib);
346 app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
348 if (app_inst->lib == NULL) {
349 print_err("out of memory\n");
353 for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
354 lib = create_lib_inst_data(mb);
358 app_inst->lib[i_lib] = lib;
361 app_inst->app_info = app_info;
362 app_inst->cnt_func = cnt_func;
363 app_inst->cnt_lib = cnt_lib;
368 for (i = 0; i < i_lib; ++i)
369 destroy_lib_inst_data(app_inst->lib[i]);
370 kfree(app_inst->lib);
373 for (i = 0; i < i_func; ++i)
374 destroy_func_inst_data(app_inst->func[i]);
375 kfree(app_inst->func);
381 destroy_app_info(app_info);
386 void destroy_app_inst_data(struct app_inst_data *ai)
390 for (i = 0; i < ai->cnt_lib; ++i)
391 destroy_lib_inst_data(ai->lib[i]);
394 for (i = 0; i < ai->cnt_func; ++i)
395 destroy_func_inst_data(ai->func[i]);
398 destroy_app_info(ai->app_info);
406 /* ============================================================================
408 * ============================================================================
410 struct us_inst_data *create_us_inst_data(struct msg_buf *mb)
412 struct us_inst_data *ui;
413 struct app_inst_data *ai;
416 if (get_u32(mb, &cnt)) {
417 print_err("failed to read count of applications\n");
421 if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt) {
422 print_err("to match count of applications(%u)\n", cnt);
426 ui = kmalloc(sizeof(struct us_inst_data), GFP_KERNEL);
428 print_err("out of memory\n");
432 ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
434 if (ui->app_inst == NULL) {
435 print_err("out of memory\n");
439 for (i = 0; i < cnt; ++i) {
440 ai = create_app_inst_data(mb);
444 ui->app_inst[i] = ai;
452 for (j = 0; j < i; ++j)
453 destroy_app_inst_data(ui->app_inst[j]);
462 void destroy_us_inst_data(struct us_inst_data *ui)
466 for (i = 0; i < ui->cnt; ++i)
467 destroy_app_inst_data(ui->app_inst[i]);