static const char UIHV_FOLDER[] = "uihv";
static const char UIHV_PATH[] = "path";
static const char UIHV_APP_INFO[] = "app_info";
+static const char UIHV_ENABLE[] = "enable";
static struct dentry *uihv_root;
static const struct file_operations uihv_app_info_file_ops = {
.owner = THIS_MODULE,
- .write = write_uihv_app_info,
+ .write = write_uihv_app_info,
};
+static ssize_t write_uihv_enable(struct file *file,
+ const char __user *user_buf,
+ size_t len, loff_t *ppos)
+{
+ ssize_t ret = len;
+ char *buf;
+
+ buf = kmalloc(len, GFP_KERNEL);
+ if (!buf) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ if (copy_from_user(buf, user_buf, len)) {
+ ret = -EINVAL;
+ goto free_buf;
+ }
+
+ buf[len - 1] = '\0';
+
+ if (buf[0] == '0')
+ ret = uihv_disable();
+ else
+ ret = uihv_enable();
+
+free_buf:
+ kfree(buf);
+
+out:
+ return ret;
+}
+
+static const struct file_operations uihv_enable_file_ops = {
+ .owner = THIS_MODULE,
+ .write = write_uihv_enable,
+};
int uihv_dfs_init(void)
{
- struct dentry *swap_dentry, *root, *path, *app_info;
+ struct dentry *swap_dentry, *root, *path, *app_info, *uihv_enable;
int ret;
ret = -ENODEV;
goto remove;
}
+ uihv_enable = debugfs_create_file(UIHV_ENABLE, UIHV_DEFAULT_PERMS,
+ root, NULL, &uihv_enable_file_ops);
+ if (IS_ERR_OR_NULL(uihv_enable)) {
+ ret = -ENOMEM;
+ goto remove;
+ }
+
return 0;
remove:
#define ip_to_proc(ip) page_to_proc((ip)->page)
#define urp_to_ip(rp) container_of(rp, struct sspt_ip, retprobe)
+static DEFINE_MUTEX(mutex_enable);
+
static struct dentry *uihv_dentry = NULL;
static inline struct pd_t *__get_process_data(struct uretprobe *rp)
struct dentry *app_dentry;
struct probe_new p_main;
struct pf_group *pfg;
+ bool enable;
};
static struct ui_viewer_data __ui_data;
static int uihv_data_inst(void)
{
- int ret;
struct pf_group *pfg;
pfg = get_pf_group_by_dentry(__ui_data.app_dentry,
(void *)__ui_data.app_dentry);
- if (pfg == NULL)
+ if (!pfg)
return -ENOMEM;
- ret = pin_register(&__ui_data.p_main, pfg, __ui_data.app_dentry);
- if (ret)
- goto put_g;
-
__ui_data.pfg = pfg;
return 0;
-put_g:
- put_pf_group(pfg);
- return ret;
}
-
-
struct dentry *get_dentry(const char *filepath)
{
struct path path;
{
struct dentry *dentry;
+ if (__ui_data.enable) {
+ pr_err("UIHV already enabled, can't set data\n");
+ return -EBUSY;
+ }
+
dentry = dentry_by_path(app_path);
if (dentry == NULL)
return -ENOENT;
__ui_data.app_dentry = dentry;
__ui_data.p_main.desc = &pin_main;
__ui_data.p_main.offset = main_addr;
- __ui_data.pfg = NULL;
return uihv_data_inst();
}
return 0;
}
+int uihv_enable(void)
+{
+ int ret = 0;
+
+ mutex_lock(&mutex_enable);
+ if (__ui_data.enable) {
+ pr_err("UIHV already enabled\n");
+ ret = -EBUSY;
+ goto out;
+ }
+
+ ret = pin_register(&__ui_data.p_main, __ui_data.pfg,
+ __ui_data.app_dentry);
+ if (ret)
+ goto out;
+
+ __ui_data.enable = true;
+
+out:
+ mutex_unlock(&mutex_enable);
+ return ret;
+}
+
+int uihv_disable(void)
+{
+ int ret = 0;
+
+ mutex_lock(&mutex_enable);
+ if (!__ui_data.enable) {
+ pr_err("UIHV already disabled\n");
+ ret = -EBUSY;
+ goto out;
+ }
+
+ ret = pin_unregister(&__ui_data.p_main, __ui_data.pfg,
+ __ui_data.app_dentry);
+ if (ret)
+ goto out;
+
+ put_pf_group(__ui_data.pfg);
+ __ui_data.pfg = NULL;
+ __ui_data.enable = false;
+
+out:
+ mutex_unlock(&mutex_enable);
+ return ret;
+}
+
static int uihv_init(void)
{
int ret;
{
if (uihv_dentry != NULL)
put_dentry(uihv_dentry);
+
+ uihv_dfs_exit();
}
SWAP_LIGHT_INIT_MODULE(NULL, uihv_init, uihv_exit, NULL, NULL);