Merge branch 'tizen_2.4' into tizen_2.4_dev
[kernel/swap-modules.git] / us_manager / sspt / sspt.h
1 #ifndef __SSPT__
2 #define __SSPT__
3
4 /*
5  *  Dynamic Binary Instrumentation Module based on KProbes
6  *  modules/driver/sspt/sspt.h
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * Copyright (C) Samsung Electronics, 2013
23  *
24  * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
25  *
26  */
27
28 #include "ip.h"
29 #include "sspt_page.h"
30 #include "sspt_file.h"
31 #include "sspt_proc.h"
32 #include "sspt_debug.h"
33 #include <uprobe/swap_uprobes.h>
34
35
36 #include <us_manager/us_manager.h>
37 #include <us_manager/pf/pf_group.h>
38 #include <us_manager/probes/use_probes.h>
39
40
41 static inline int check_vma(struct vm_area_struct *vma)
42 {
43         return vma->vm_file &&
44                !(vma->vm_pgoff != 0 ||
45                  !(vma->vm_flags & VM_EXEC) ||
46                  !(vma->vm_flags & (VM_READ | VM_MAYREAD)));
47 }
48
49 static inline int sspt_register_usprobe(struct us_ip *ip)
50 {
51         int ret;
52         struct uprobe *up = NULL;
53
54         up = probe_info_get_uprobe(ip->desc->type, ip);
55
56         if (!up) {
57                 printk(KERN_INFO "SWAP US_MANAGER: failed getting uprobe!\n");
58                 return -EINVAL;
59         }
60
61         up->addr = (kprobe_opcode_t *)ip->orig_addr;
62         up->task = ip->page->file->proc->task;
63         up->sm = ip->page->file->proc->sm;
64         up->atomic_ctx = true;
65
66         ret = probe_info_register(ip->desc->type, ip);
67         if (ret) {
68                 struct sspt_file *file = ip->page->file;
69                 char *name = file->dentry->d_iname;
70                 unsigned long addr = (unsigned long)up->addr;
71                 unsigned long offset = addr - file->vm_start;
72
73                 printk(KERN_ERR "probe_info_register failed %d (%s:%lx|%lx)\n",
74                                 ret, name, offset,
75                                 (unsigned long)ip->retprobe.up.opcode);
76         }
77
78         return ret;
79 }
80
81 static inline int sspt_unregister_usprobe(struct task_struct *task,
82                                           struct us_ip *ip,
83                                           enum US_FLAGS flag)
84 {
85         struct uprobe *up = NULL;
86
87         switch (flag) {
88         case US_UNREGS_PROBE:
89                 probe_info_unregister(ip->desc->type, ip, 1);
90                 break;
91         case US_DISARM:
92                 up = probe_info_get_uprobe(ip->desc->type, ip);
93                 if (up)
94                         disarm_uprobe(up, task);
95                 break;
96         case US_UNINSTALL:
97                 probe_info_unregister(ip->desc->type, ip, 0);
98                 break;
99         default:
100                 panic("incorrect value flag=%d", flag);
101         }
102
103         return 0;
104 }
105
106 #endif /* __SSPT__ */