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;
40 INIT_LIST_HEAD(&procs->file_list);
46 void sspt_procs_free(struct sspt_procs *procs)
48 struct sspt_file *file, *n;
49 list_for_each_entry_safe(file, n, &procs->file_list, list) {
50 list_del(&file->list);
57 // TODO: remove "us_proc_info"
58 #include "../storage.h"
59 extern inst_us_proc_t us_proc_info;
61 void sspt_procs_free_all(void)
63 // is user-space instrumentation
64 if (us_proc_info.path == NULL) {
68 if (strcmp(us_proc_info.path,"*") == 0) {
70 sspt_procs_free(us_proc_info.pp);
71 us_proc_info.pp = NULL;
74 struct sspt_procs *procs, *n;
75 list_for_each_entry_safe(procs, n, &proc_probes_list, list) {
76 list_del(&procs->list);
77 sspt_procs_free(procs);
82 static void sspt_procs_add_file(struct sspt_procs *procs, struct sspt_file *file)
84 list_add(&file->list, &procs->file_list);
88 struct sspt_file *sspt_procs_find_file_or_new(struct sspt_procs *procs,
89 struct dentry *dentry, char *name)
91 struct sspt_file *file;
93 list_for_each_entry(file, &procs->file_list, list) {
94 if (file->dentry == dentry) {
99 file = sspt_file_create(name, dentry, 10);
100 sspt_procs_add_file(procs, file);
105 void sspt_procs_add_ip_data(struct sspt_procs *procs, struct dentry* dentry,
106 char *name, struct ip_data *ip_d)
108 struct sspt_file *file = sspt_procs_find_file_or_new(procs, dentry, name);
109 sspt_file_add_ip(file, ip_d);
112 struct sspt_procs *sspt_procs_copy(struct sspt_procs *procs, struct task_struct *task)
114 struct sspt_file *file;
115 struct sspt_procs *procs_out = sspt_procs_create(procs->dentry, task->tgid);
117 list_for_each_entry(file, &procs->file_list, list) {
118 sspt_procs_add_file(procs_out, sspt_file_copy(file));
124 struct sspt_file *sspt_procs_find_file(struct sspt_procs *procs, struct dentry *dentry)
126 struct sspt_file *file;
128 list_for_each_entry(file, &procs->file_list, list) {
129 if (dentry == file->dentry) {