3 * modules/us_manager/probes/probes.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, 2014
21 * 2014 Alexander Aksenov: Probes interface implement
26 #include "register_probes.h"
27 #include "use_probes.h"
29 #include <linux/slab.h>
30 #include <linux/kernel.h>
31 #include <linux/errno.h>
32 #include <linux/module.h>
35 struct probe_info *probe_info_malloc(size_t size, enum probe_t type)
37 struct probe_info *info;
39 info = kmalloc(sizeof(*info) + size, GFP_ATOMIC);
41 info->probe_type = type;
47 EXPORT_SYMBOL_GPL(probe_info_malloc);
49 struct probe_info *probe_info_dup(const struct probe_info *info)
51 struct probe_info *info_new;
52 size_t size = info->size;
54 info_new = probe_info_malloc(size, info->probe_type);
56 memcpy(info_new->data, info->data, size);
60 EXPORT_SYMBOL_GPL(probe_info_dup);
62 void probe_info_free(struct probe_info *info)
66 EXPORT_SYMBOL_GPL(probe_info_free);
69 static struct probe_iface *probes_methods[SWAP_PROBE_MAX_VAL] = { NULL };
71 /* 1 - correct probe type
74 static inline int correct_probe_type(enum probe_t probe_type)
76 if (probe_type >= SWAP_PROBE_MAX_VAL)
82 static inline int methods_exist(enum probe_t probe_type)
84 if (!correct_probe_type(probe_type))
87 if (probes_methods[probe_type] == NULL)
94 * @brief Calls specified probe type init method.
96 * @param pi Pointer to the probe_info.
97 * @param ip Pointer to the probe us_ip struct.
100 void probe_info_init(struct probe_info *pi, struct us_ip *ip)
102 enum probe_t probe_type = pi->probe_type;
104 if (!methods_exist(probe_type)) {
105 printk(KERN_WARNING "SWAP US_MANAGER: Wrong probe type!\n");
109 probes_methods[probe_type]->init(ip);
113 * @brief Calls specified probe type uninit method.
115 * @param pi Pointer to the probe_info.
116 * @param ip Pointer to the probe us_ip struct.
119 void probe_info_uninit(struct probe_info *pi, struct us_ip *ip)
121 enum probe_t probe_type = pi->probe_type;
123 if (!methods_exist(probe_type)) {
124 printk(KERN_WARNING "SWAP US_MANAGER: Wrong probe type!\n");
128 probes_methods[probe_type]->uninit(ip);
132 * @brief Calls specified probe type register method.
134 * @param pi Pointer to the probe_info.
135 * @param ip Pointer to the probe us_ip struct.
136 * @return -EINVAL on wrong probe type, method result otherwise.
138 int probe_info_register(struct probe_info *pi, struct us_ip *ip)
140 enum probe_t probe_type = pi->probe_type;
142 if (!methods_exist(probe_type)) {
143 printk(KERN_WARNING "SWAP US_MANAGER: Wrong probe type!\n");
147 return probes_methods[probe_type]->reg(ip);
151 * @brief Calls specified probe type unregister method.
153 * @param pi Pointer to the probe_info.
154 * @param ip Pointer to the probe us_ip struct.
155 * @param disarm Disarm flag.
158 void probe_info_unregister(struct probe_info *pi, struct us_ip *ip, int disarm)
160 enum probe_t probe_type = pi->probe_type;
162 if (!methods_exist(probe_type)) {
163 printk(KERN_WARNING "SWAP US_MANAGER: Wrong probe type!\n");
167 probes_methods[probe_type]->unreg(ip, disarm);
171 * @brief Calls specified probe type get underlying uprobe method.
173 * @param pi Pointer to the probe_info.
174 * @param ip Pointer to the probe us_ip struct.
175 * @return Pointer to the uprobe struct, NULL on error.
177 struct uprobe *probe_info_get_uprobe(struct probe_info *pi, struct us_ip *ip)
179 enum probe_t probe_type = pi->probe_type;
181 if (!methods_exist(probe_type)) {
182 printk(KERN_WARNING "SWAP US_MANAGER: Wrong probe type!\n");
186 return probes_methods[probe_type]->get_uprobe(ip);
190 * @brief Calls specified probe type copy method.
192 * @param pi Pointer to the source probe_info.
193 * @param dest Pointer to the probe us_ip struct.
194 * @return -EINVAL on error, method result otherwise.
196 int probe_info_copy(const struct probe_info *pi, struct probe_info *dest)
198 enum probe_t probe_type = pi->probe_type;
200 if (!methods_exist(probe_type)) {
201 printk(KERN_WARNING "SWAP US_MANAGER: Wrong probe type!\n");
205 return probes_methods[probe_type]->copy(dest, pi);
209 * @brief Calls specified probe type cleanup method.
211 * @param pi Pointer to the source probe_info.
214 void probe_info_cleanup(struct probe_info *pi)
216 enum probe_t probe_type = pi->probe_type;
218 if (!methods_exist(probe_type)) {
219 printk(KERN_WARNING "SWAP US_MANAGER: Wrong probe type!\n");
223 probes_methods[probe_type]->cleanup(pi);
227 * @brief Registers probe type.
229 * @param probe_type Number, associated with this probe type.
230 * @param pi Pointer to the probe interface structure
231 * @return 0 on succes, error code on error.
233 int swap_register_probe_type(enum probe_t probe_type, struct probe_iface *pi)
235 if (!correct_probe_type(probe_type)) {
236 printk(KERN_ERR "SWAP US_MANAGER: Wrong probe type!\n");
240 if (probes_methods[probe_type] != NULL)
241 printk(KERN_WARNING "SWAP US_MANAGER: Re-registering probe %d\n",
244 probes_methods[probe_type] = pi;
248 EXPORT_SYMBOL_GPL(swap_register_probe_type);
251 * @brief Unregisters probe type.
253 * @param probe_type Probe type that should be unregistered.
256 void swap_unregister_probe_type(enum probe_t probe_type)
258 if (!correct_probe_type(probe_type)) {
259 printk(KERN_ERR "SWAP US_MANAGER: Wrong probe type!\n");
263 probes_methods[probe_type] = NULL;
265 EXPORT_SYMBOL_GPL(swap_unregister_probe_type);