2 * Dynamic Binary Instrumentation Module based on KProbes
3 * modules/driver/sspt/sspt_procs.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, 2013
21 * 2013 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
25 #include "sspt_procs.h"
26 #include <linux/slab.h>
27 #include <linux/list.h>
29 extern struct list_head proc_probes_list;
31 struct sspt_procs *sspt_procs_create(struct dentry* dentry, pid_t tgid)
33 struct sspt_procs *procs = kmalloc(sizeof(*procs), GFP_ATOMIC);
36 INIT_LIST_HEAD(&procs->list);
38 procs->dentry = dentry;
39 INIT_LIST_HEAD(&procs->file_list);
45 void sspt_procs_free(struct sspt_procs *procs)
47 struct sspt_file *file, *n;
48 list_for_each_entry_safe(file, n, &procs->file_list, list) {
49 list_del(&file->list);
56 // TODO: remove "us_proc_info"
57 #include "../storage.h"
58 extern inst_us_proc_t us_proc_info;
60 void sspt_procs_free_all(void)
62 // is user-space instrumentation
63 if (us_proc_info.path == NULL) {
67 if (strcmp(us_proc_info.path,"*") == 0) {
69 sspt_procs_free(us_proc_info.pp);
70 us_proc_info.pp = NULL;
73 struct sspt_procs *procs, *n;
74 list_for_each_entry_safe(procs, n, &proc_probes_list, list) {
75 list_del(&procs->list);
76 sspt_procs_free(procs);
81 static void sspt_procs_add_file(struct sspt_procs *procs, struct sspt_file *file)
83 list_add(&file->list, &procs->file_list);
87 struct sspt_file *sspt_procs_find_file_or_new(struct sspt_procs *procs,
88 struct dentry *dentry, char *name)
90 struct sspt_file *file;
92 list_for_each_entry(file, &procs->file_list, list) {
93 if (file->dentry == dentry) {
98 file = sspt_file_create(name, dentry, 10);
99 sspt_procs_add_file(procs, file);
104 void sspt_procs_add_ip_data(struct sspt_procs *procs, struct dentry* dentry,
105 char *name, struct ip_data *ip_d)
107 struct sspt_file *file = sspt_procs_find_file_or_new(procs, dentry, name);
108 sspt_file_add_ip(file, ip_d);
111 struct sspt_procs *sspt_procs_copy(struct sspt_procs *procs, struct task_struct *task)
113 struct sspt_file *file;
114 struct sspt_procs *procs_out = sspt_procs_create(procs->dentry, task->tgid);
116 list_for_each_entry(file, &procs->file_list, list) {
117 sspt_procs_add_file(procs_out, sspt_file_copy(file));
123 struct sspt_file *sspt_procs_find_file(struct sspt_procs *procs, struct dentry *dentry)
125 struct sspt_file *file;
127 list_for_each_entry(file, &procs->file_list, list) {
128 if (dentry == file->dentry) {