[FIX] sending unmap message
[platform/kernel/swap-modules.git] / us_manager / img / img_ip.c
1 /*
2  *  SWAP uprobe manager
3  *  modules/us_manager/img/img_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: SWAP us_manager implement
22  *
23  */
24
25
26 #include "img_ip.h"
27 #include <us_manager/probes/use_probes.h>
28 #include <linux/slab.h>
29
30 /**
31  * @brief Create img_ip struct
32  *
33  * @param addr Function address
34  * @param probe_i Pointer to the probe info data.
35  * @return Pointer to the created img_ip struct
36  */
37 struct img_ip *create_img_ip(unsigned long addr, struct probe_info *info)
38 {
39         struct img_ip *ip;
40
41         ip = kmalloc(sizeof(*ip), GFP_ATOMIC);
42         if (ip) {
43                 struct probe_info *info_new;
44
45                 info_new = probe_info_dup(info);
46                 if (info_new == NULL) {
47                         kfree(ip);
48                         return NULL;
49                 }
50
51                 probe_info_copy(info, info_new);
52
53                 INIT_LIST_HEAD(&ip->list);
54                 ip->addr = addr;
55                 ip->info = info_new;
56         }
57
58         return ip;
59 }
60
61 /**
62  * @brief Remove img_ip struct
63  *
64  * @param ip remove object
65  * @return Void
66  */
67 void free_img_ip(struct img_ip *ip)
68 {
69         probe_info_cleanup(ip->info);
70         probe_info_free(ip->info);
71         kfree(ip);
72 }
73
74 /**
75  * @brief For debug
76  *
77  * @param ip Pointer to the img_ip struct
78  * @return Void
79  */
80
81 /* debug */
82 void img_ip_print(struct img_ip *ip)
83 {
84         if (ip->info->probe_type == SWAP_RETPROBE)
85                 printk(KERN_INFO "###            addr=8%lx, args=%s\n",
86                        ip->addr, ip->info->rp_i.args);
87 }
88 /* debug */