1 #include <linux/namei.h>
2 #include <us_manager/us_manager_common.h>
3 #include <us_manager/pf/pf_group.h>
4 #include <us_manager/sspt/sspt_page.h>
5 #include <us_manager/sspt/sspt_file.h>
6 #include <us_manager/sspt/sspt_proc.h>
7 #include <us_manager/sspt/sspt_ip.h>
8 #include <us_manager/callbacks.h>
9 #include <us_manager/probes/probe_info_new.h>
10 #include <writer/kernel_operations.h>
11 #include <master/swap_initializer.h>
12 #include <writer/swap_msg.h>
13 #include <loader/loader.h>
15 #include "uihv_module.h"
16 #include "uihv_debugfs.h"
18 #define page_to_proc(page) ((page)->file->proc)
19 #define ip_to_proc(ip) page_to_proc((ip)->page)
20 #define urp_to_ip(rp) container_of(rp, struct sspt_ip, retprobe)
22 static struct dentry *uihv_dentry = NULL;
24 static inline struct pd_t *__get_process_data(struct uretprobe *rp)
26 struct sspt_ip *ip = urp_to_ip(rp);
27 struct sspt_proc *proc = ip_to_proc(ip);
33 /* ============================================================================
35 * ============================================================================
38 /* main handler for ui viewer */
39 static int uihv_main_eh(struct uretprobe_instance *ri, struct pt_regs *regs);
40 static int uihv_main_rh(struct uretprobe_instance *ri, struct pt_regs *regs);
41 static struct probe_desc pin_main = MAKE_URPROBE(uihv_main_eh,
44 struct ui_viewer_data {
45 struct dentry *app_dentry;
46 struct probe_new p_main;
50 static struct ui_viewer_data __ui_data;
52 static int uihv_data_inst(void)
57 pfg = get_pf_group_by_dentry(__ui_data.app_dentry,
58 (void *)__ui_data.app_dentry);
62 ret = pin_register(&__ui_data.p_main, pfg, __ui_data.app_dentry);
76 struct dentry *get_dentry(const char *filepath)
79 struct dentry *dentry = NULL;
81 if (kern_path(filepath, LOOKUP_FOLLOW, &path) == 0) {
82 dentry = dget(path.dentry);
89 void put_dentry(struct dentry *dentry)
94 int uihv_data_set(const char *app_path, unsigned long main_addr)
96 struct dentry *dentry;
98 dentry = dentry_by_path(app_path);
102 __ui_data.app_dentry = dentry;
103 __ui_data.p_main.desc = &pin_main;
104 __ui_data.p_main.offset = main_addr;
105 __ui_data.pfg = NULL;
107 return uihv_data_inst();
110 int uihv_set_handler(char *path)
112 struct dentry *dentry;
115 if (uihv_dentry != NULL)
116 put_dentry(uihv_dentry);
118 dentry = get_dentry(path);
119 if (dentry == NULL) {
120 printk(KERN_WARNING UIHV_PREFIX "Error! Cannot get handler %s\n",
125 ret = loader_add_handler(path);
129 uihv_dentry = dentry;
136 /* ============================================================================
137 * = ui viewer handlers =
138 * ============================================================================
140 static int uihv_main_eh(struct uretprobe_instance *ri, struct pt_regs *regs)
142 struct pd_t *pd = __get_process_data(ri->rp);
144 unsigned long old_pc = swap_get_instr_ptr(regs);
145 unsigned long vaddr = 0;
147 if (uihv_dentry == NULL)
150 hd = lpd_get_hd(pd, uihv_dentry);
154 if (lpd_get_state(hd) == NOT_LOADED)
155 vaddr = loader_not_loaded_entry(ri, regs, pd, hd);
157 loader_set_priv_origin(ri, vaddr);
159 /* PC change check */
160 return old_pc != swap_get_instr_ptr(regs);
163 static int uihv_main_rh(struct uretprobe_instance *ri, struct pt_regs *regs)
165 struct pd_t *pd = __get_process_data(ri->rp);
168 if (uihv_dentry == NULL)
171 hd = lpd_get_hd(pd, uihv_dentry);
175 if (lpd_get_state(hd) == LOADING)
176 loader_loading_ret(ri, regs, pd, hd);
181 static int uihv_init(void)
185 ret = uihv_dfs_init();
190 static void uihv_exit(void)
192 if (uihv_dentry != NULL)
193 put_dentry(uihv_dentry);
196 SWAP_LIGHT_INIT_MODULE(NULL, uihv_init, uihv_exit, NULL, NULL);
197 MODULE_LICENSE("GPL");
198 MODULE_DESCRIPTION("SWAP UI Hierarchy Viewer");
199 MODULE_AUTHOR("Alexander Aksenov <a.aksenov@samsung.com>, Anastasia Lypa");