Java instrumentation first approach implemented (#285)
[kernel/swap-modules.git] / driver / storage.h
1 ////////////////////////////////////////////////////////////////////////////////////
2 //
3 //      FILE:           storage.h
4 //
5 //      DESCRIPTION:
6 //      This file is C source for SWAP.
7 //
8 //      SEE ALSO:       storage.c
9 //      AUTHOR:         L.Komkov, S.Dianov, A.Gerenkov
10 //      COMPANY NAME:   Samsung Research Center in Moscow
11 //      DEPT NAME:      Advanced Software Group 
12 //      CREATED:        2008.02.15
13 //      VERSION:        1.0
14 //      REVISION DATE:  2008.12.03
15 //
16 ////////////////////////////////////////////////////////////////////////////////////
17
18 #if !defined(__STORAGE_H__)
19 #define __STORAGE_H__
20
21 #include <linux/mount.h>
22 #include "picl.h"
23 #include "ec_ioctl.h"
24 #include "ec_probe.h"
25 #include "probes_manager.h"
26 #include "probes.h"
27 #include "event_tmpl.h"
28
29 ///////////////////////////////////////////////////////////////////////////////////////////////////
30
31 #ifndef __DISABLE_RELAYFS
32 extern struct rchan* GetRelayChannel(void);
33 extern struct dentry* GetRelayDir(void);
34 #endif //__DISABLE_RELAYFS
35
36 extern int EnableMultipleBuffer(void);
37 extern int DisableMultipleBuffer(void);
38 extern int EnableContinuousRetrieval(void);
39 extern int DisableContinuousRetrieval(void);
40
41 ///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 extern unsigned int GetBufferSize(void);
44 extern int SetBufferSize(unsigned int nSize);
45 extern int ResetBuffer(void);
46
47 extern int SetPid(unsigned int pid);
48
49 //extern spinlock_t buffer_spinlock;
50
51 ///////////////////////////////////////////////////////////////////////////////////////////////////
52
53 /*
54     Functions "storage_init()" and "storage_down()" are for initialization and
55     shutdown respectively.
56 */
57 extern int storage_init (void);
58 extern void storage_down (void);
59
60 /*
61     Function "pack_event_info()" saves information about event into buffer. It
62     is used in 'probes' to pack and save event data.
63 */
64 extern void pack_event_info (probe_id_t probe_id, record_type_t record_type, const char *fmt, ...);
65
66 /* Set most links from us_proc_info to data in the bundle */
67 int link_bundle(void);
68
69 /* Undo the actions of link_bundle() */
70 void unlink_bundle(void);
71
72 /*
73     Adds non-predefined kernel probe to the list.
74 */
75 extern int add_probe_to_list (unsigned long addr, kernel_probe_t ** pprobe);
76
77 /*
78     Removes non-predefined kernel probe from the list.
79 */
80 extern int remove_probe_from_list (unsigned long addr);
81
82 /*
83     Searches non-predefined kernel probe in the list.
84 */
85 extern kernel_probe_t *find_probe (unsigned long addr);
86
87 /*
88     Copies event from user space to buffer and updates its pid/tid/cpu/time.
89 */
90 extern int put_us_event (char *data, unsigned long len);
91
92 /*
93     Sets event mask.
94 */
95 extern int set_event_mask (int new_mask);
96
97 /*
98     Gets event mask.
99 */
100 extern int get_event_mask (int *mask);
101
102 /*
103     Sets predefined user space probes info.
104 */
105 extern int set_predef_uprobes (ioctl_predef_uprobes_info_t *data);
106 /*
107     Gets predefined user space probes info length.
108 */
109 extern int get_predef_uprobes_size(int *size);
110 /*
111     Gets predefined user space probes info.
112 */
113 extern int get_predef_uprobes(ioctl_predef_uprobes_info_t *data);
114
115
116 // internal bookkeeping of storage
117 extern char *p_buffer;
118
119 // list of selected non-predefined kernel probes
120 extern struct hlist_head kernel_probes;
121
122 /* list of on-the-go installed kernel probes */
123 extern struct hlist_head otg_kernel_probes;
124
125 extern struct list_head otg_us_proc_info;
126
127 // event mask
128 extern int event_mask;
129
130 // process pid to instrument
131 extern unsigned int inst_pid;
132
133 typedef struct
134 {
135         char *name;
136         int installed;
137         struct jprobe jprobe;
138         struct kretprobe retprobe;
139         unsigned long offset;
140 } us_proc_ip_t;
141
142 typedef struct
143 {
144         us_proc_ip_t ip;
145         pid_t tgid;
146         struct list_head list;
147 } us_proc_otg_ip_t;
148
149 typedef struct
150 {
151         int installed;
152         struct jprobe jprobe;
153         unsigned long addr;
154         struct list_head list;
155 } us_proc_vtp_t;
156
157 typedef struct
158 {
159         //char *name;
160         char type;
161         unsigned long size;
162         signed char reg;        // -1 - memory, 0..127 - register number  
163         long off;
164         struct list_head list;
165 } us_proc_vtp_data_t;
166
167 typedef struct dentry *STRUCT_DENTRY_PTR;
168 typedef struct vfsmount *STRUCT_VFSMOUNT_PTR;
169
170 typedef struct
171 {
172         char *path;
173         STRUCT_DENTRY_PTR m_f_dentry;
174         STRUCT_VFSMOUNT_PTR m_vfs_mount;
175         unsigned ips_count;
176         us_proc_ip_t *p_ips;
177         unsigned vtps_count;
178         us_proc_vtp_t *p_vtps;
179         int loaded;
180 } us_proc_lib_t;
181
182 typedef struct
183 {
184         char *path;
185         STRUCT_DENTRY_PTR m_f_dentry;
186         pid_t tgid;
187         unsigned unres_ips_count;
188         unsigned unres_vtps_count;
189         //kprobe_opcode_t *mapped_codelets;
190         unsigned libs_count;
191         us_proc_lib_t *p_libs;
192 #ifdef __ANDROID
193         unsigned long libdvm_start;
194         unsigned long libdvm_end;
195         us_proc_ip_t libdvm_entry_ip;
196         us_proc_ip_t libdvm_return_ip;
197 #endif /* __ANDROID */
198 } inst_us_proc_t;
199
200 typedef struct
201 {
202         unsigned int addr;
203         unsigned int inst_type;
204         char *name;
205         char *class_name;
206         char *method_name;
207         char *prototype;
208
209 }dex_proc_ip_t;
210
211 typedef struct
212 {
213         char *path;
214         unsigned ips_count;
215         dex_proc_ip_t *p_ips;
216
217 }inst_dex_proc_t;
218
219
220 struct cond {
221         /* cond data itself */
222         struct event_tmpl tmpl;
223         /* linked list */
224         struct list_head list;
225         /* has been applied (for start and stop conditions) */
226         int applied;
227 };
228
229 extern struct cond cond_list;
230
231 /* macros for testing flags */
232 #define ET_FIELD_CLR(flags, field) (flags &= ~field)
233 #define ET_FIELD_SET(flags, field) (flags |= field)
234 #define ET_FIELD_ISSET(flags, field) ((flags & field) != 0)
235
236 extern inst_us_proc_t us_proc_info;
237 extern inst_dex_proc_t dex_proc_info;
238
239 #endif /* !defined(__STORAGE_H__) */