Merge commit 'cc09f10e84d5' into kernel
[kernel/swap-modules.git] / driver / us_proc_inst.c
1 ////////////////////////////////////////////////////////////////////////////////////
2 //
3 //      FILE:           us_proc_inst.c
4 //
5 //      DESCRIPTION:
6 //      This file is C source for SWAP driver.
7 //
8 //      SEE ALSO:       us_proc_inst.h
9 //      AUTHOR:         A.Gerenkov, E. Gorelkina
10 //      COMPANY NAME:   Samsung Research Center in Moscow
11 //      DEPT NAME:      Advanced Software Group
12 //      CREATED:        2008.06.02
13 //      VERSION:        1.0
14 //      REVISION DATE:  2008.12.02
15 //
16 ////////////////////////////////////////////////////////////////////////////////////
17
18 #include "module.h"
19 #include "us_proc_inst.h"
20
21 #include "../kprobe/dbi_kprobes_deps.h"
22 #include "../uprobe/swap_uprobes.h"
23
24 #include "sspt/sspt.h"
25 #include "helper.h"
26 #include "us_slot_manager.h"
27
28 #define print_event(fmt, args...)                                               \
29 {                                                                               \
30         char *buf[1024];                                                        \
31         sprintf(buf, fmt, ##args);                                              \
32         pack_event_info(US_PROBE_ID, RECORD_ENTRY, "ds", 0x0badc0de, buf);      \
33 }
34
35 struct dentry *dentry_by_path(const char *path)
36 {
37         struct dentry *dentry;
38 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)
39         struct path st_path;
40         if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) {
41 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
42         struct nameidata nd;
43         if (path_lookup(path, LOOKUP_FOLLOW, &nd) != 0) {
44 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
45                 EPRINTF("failed to lookup dentry for path %s!", path);
46                 return NULL;
47         }
48
49 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
50         dentry = nd.dentry;
51         path_release(&nd);
52 #elif LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 38)
53         dentry = nd.path.dentry;
54         path_put(&nd.path);
55 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
56         dentry = st_path.dentry;
57         path_put(&st_path);
58 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) */
59         return dentry;
60 }
61
62 void print_vma(struct mm_struct *mm);
63
64 void print_vma(struct mm_struct *mm)
65 {
66         struct vm_area_struct *vma;
67         printk("### print_vma: START\n");\
68         printk("### print_vma: START\n");
69
70         for (vma = mm->mmap; vma; vma = vma->vm_next) {
71                 char *x = vma->vm_flags & VM_EXEC ? "x" : "-";
72                 char *r = vma->vm_flags & VM_READ ? "r" : "-";
73                 char *w = vma->vm_flags & VM_WRITE ? "w" : "-";
74                 char *name = vma->vm_file ? (char *)vma->vm_file->f_dentry->d_iname : "N/A";
75
76                 printk("### [%8lx..%8lx] %s%s%s pgoff=\'%8lu\' %s\n",
77                                 vma->vm_start, vma->vm_end, x, r, w, vma->vm_pgoff, name);
78         }
79         printk("### print_vma:  END\n");
80 }