tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / kernel / swap / us_manager / sspt / ip.c
1 /*
2  *  Dynamic Binary Instrumentation Module based on KProbes
3  *  modules/driver/sspt/ip.c
4  *
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.
9  *
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.
14  *
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.
18  *
19  * Copyright (C) Samsung Electronics, 2013
20  *
21  * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
22  *
23  */
24
25 #include <linux/slab.h>
26 #include <linux/module.h>
27 #include "ip.h"
28 #include "sspt_page.h"
29 #include "sspt_file.h"
30 #include <us_manager/probes/use_probes.h>
31
32 /**
33  * @brief Create us_ip struct
34  *
35  * @param page User page
36  * @param offset Function offset from the beginning of the page
37  * @param probe_i Pointer to the probe data.
38  * @param page Pointer to the parent sspt_page struct
39  * @return Pointer to the created us_ip struct
40  */
41 struct us_ip *create_ip(unsigned long offset, const struct probe_info *info,
42                         struct sspt_page *page)
43 {
44         struct us_ip *ip;
45         struct probe_info *info_new;
46
47         info_new = probe_info_dup(info);
48         if (info_new == NULL) {
49                 printk("Cannot probe_info_dup in %s function!\n", __func__);
50                 return NULL;
51         }
52
53         ip = kmalloc(sizeof(*ip), GFP_ATOMIC);
54         if (ip != NULL) {
55                 memset(ip, 0, sizeof(*ip));
56
57                 INIT_LIST_HEAD(&ip->list);
58                 ip->offset = offset;
59                 ip->page = page;
60
61                 probe_info_copy(info, info_new);
62                 probe_info_init(info_new, ip);
63                 ip->info = info_new;
64         } else {
65                 printk(KERN_INFO "Cannot kmalloc in create_ip function!\n");
66                 probe_info_free(info_new);
67         }
68
69         return ip;
70 }
71
72 /**
73  * @brief Remove us_ip struct
74  *
75  * @param ip remove object
76  * @return Void
77  */
78 void free_ip(struct us_ip *ip)
79 {
80         probe_info_uninit(ip->info, ip);
81         probe_info_free(ip->info);
82         kfree(ip);
83 }