Add calling patch app memory area after lib map 92/151092/1 tizen_3.0_dev
authorAlexander Aksenov <a.aksenov@samsung.com>
Tue, 19 Sep 2017 15:47:55 +0000 (18:47 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Tue, 19 Sep 2017 15:51:44 +0000 (18:51 +0300)
Change-Id: Iafa451d395b76c9bc8c6e85b75c3189820c6207d
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
got_patcher/gt_debugfs.c
got_patcher/gt_module.c
got_patcher/gt_module.h

index 628c264..362c5d1 100644 (file)
@@ -26,6 +26,7 @@ static const char GT_LIST_TARGETS[] = "list_targets";
 static const char GT_HANDLER[] = "handler";
 static const char GT_HANDLER_FIXUP_OFF[] = "fixup_handler_off";
 static const char GT_HANDLER_RELOC_OFF[] = "reloc_handler_off";
+static const char GT_PROC_FEATURES_OFF[] = "proc_features_off";
 static const char GT_PTHREAD[] = "pthread";
 static const char GT_MINIMAL_INIT[] = "minimal_init_off";
 
@@ -156,6 +157,13 @@ static ssize_t handler_reloc_off_write(struct file *file,
        return get_ul_and_call(buf, len, gtm_set_handler_reloc_off);
 }
 
+static ssize_t proc_features_off_write(struct file *file,
+                                      const char __user *buf, size_t len,
+                                      loff_t *ppos)
+{
+       return get_ul_and_call(buf, len, gtm_set_proc_features_off);
+}
+
 static const struct file_operations handler_path_fops = {
        .owner = THIS_MODULE,
        .write = handler_path_write,
@@ -171,6 +179,11 @@ static const struct file_operations handler_reloc_off_fops = {
        .write = handler_reloc_off_write,
 };
 
+static const struct file_operations proc_features_off_fops = {
+       .owner = THIS_MODULE,
+       .write = proc_features_off_write,
+};
+
 /* ===========================================================================
  * =                              TARGETS                                    =
  * ===========================================================================
@@ -557,6 +570,14 @@ int gtd_init(void)
                goto remove;
        }
 
+       dentry = swap_debugfs_create_file(GT_PROC_FEATURES_OFF,
+                                         GT_DEFAULT_PERMS, handler, NULL,
+                                         &proc_features_off_fops);
+       if (IS_ERR_OR_NULL(dentry)) {
+               ret = -ENOMEM;
+               goto remove;
+       }
+
        pthread = swap_debugfs_create_dir(GT_PTHREAD, root);
        if (IS_ERR_OR_NULL(pthread)) {
                ret = -ENOMEM;
index 7125cc6..0779177 100644 (file)
@@ -60,6 +60,7 @@ static struct bin_data_t _linker_fixup;
 static struct bin_data_t _linker_reloc;
 static struct bin_data_t _handler_fixup;
 static struct bin_data_t _handler_reloc;
+static struct bin_data_t _proc_features;
 static struct bin_data_t _pthread_init;
 
 
@@ -92,7 +93,8 @@ static inline bool _is_linker_data_available(void)
 static inline bool _is_handler_data_available(void)
 {
        return _is_bin_data_available(&_handler_fixup) &&
-              _is_bin_data_available(&_handler_reloc);
+              _is_bin_data_available(&_handler_reloc) &&
+              _is_bin_data_available(&_proc_features);
 }
 
 static inline bool _is_pthread_data_available(void)
@@ -191,7 +193,6 @@ static unsigned long _redirect_to_handler(struct uretprobe_instance *ri,
 
        vaddr = base + off;
        loader_module_prepare_ujump(ri, regs, vaddr);
-       _set_in_handler(true);
 
        return vaddr;
 }
@@ -210,6 +211,13 @@ static unsigned long _redirect_to_reloc_handler(struct uretprobe_instance *ri,
        return _redirect_to_handler(ri, regs, hd, _handler_reloc.off);
 }
 
+static unsigned long _redirect_to_proc_features(struct uretprobe_instance *ri,
+                                               struct pt_regs *regs,
+                                               struct hd_t *hd)
+{
+       return _redirect_to_handler(ri, regs, hd, _proc_features.off);
+}
+
 
 
 static int _process_eh(struct uretprobe_instance *ri, struct pt_regs *regs,
@@ -228,10 +236,12 @@ static int _process_eh(struct uretprobe_instance *ri, struct pt_regs *regs,
                goto out_set_orig;
 
        if ((lpd_get_state(hd) == NOT_LOADED || lpd_get_state(hd) == FAILED) &&
-           lpd_get_init_state(pd))
+           lpd_get_init_state(pd)) {
                vaddr = loader_not_loaded_entry(ri, regs, pd, hd);
-       else if (lpd_get_state(hd) == LOADED)
+       } else if (lpd_get_state(hd) == LOADED) {
+               _set_in_handler(true);
                vaddr = rh(ri, regs, hd);
+       }
 
 out_set_orig:
        loader_set_priv_origin(ri, vaddr);
@@ -272,8 +282,9 @@ static int _process_rh(struct uretprobe_instance *ri, struct pt_regs *regs,
                break;
        case LOADING:
                loader_loading_ret(ri, regs, pd, hd);
-               rh(ri, regs, hd); /* TODO Think about: Possible only if we
-                                  * do not need _set_in_handler() */
+               /* Patch all binaries */
+               if (lpd_get_state(hd))
+                       rh(ri, regs, hd);
                break;
        case LOADED:
                /* TODO Check does we need this if library is loaded
@@ -291,15 +302,15 @@ static int _process_rh(struct uretprobe_instance *ri, struct pt_regs *regs,
        return 0;
 }
 
-static int dl_fixup_rh(struct uretprobe_instance *ri, struct pt_regs *regs)
+static int common_rh(struct uretprobe_instance *ri, struct pt_regs *regs)
 {
-       return _process_rh(ri, regs, &_redirect_to_fixup_handler,
-                          _handler_fixup.dentry);
+       return _process_rh(ri, regs, &_redirect_to_proc_features,
+                          _proc_features.dentry);
 }
 
 /* TODO Make ordinary interface. Now real data_size is set in init, because
  * it is unknown in this module during compile time. */
-static struct probe_desc pin_fixup = MAKE_URPROBE(dl_fixup_eh, dl_fixup_rh, 0);
+static struct probe_desc pin_fixup = MAKE_URPROBE(dl_fixup_eh, common_rh, 0);
 
 
 static int dl_reloc_eh(struct uretprobe_instance *ri, struct pt_regs *regs)
@@ -308,15 +319,9 @@ static int dl_reloc_eh(struct uretprobe_instance *ri, struct pt_regs *regs)
                           _handler_reloc.dentry);
 }
 
-static int dl_reloc_rh(struct uretprobe_instance *ri, struct pt_regs *regs)
-{
-       return _process_rh(ri, regs, &_redirect_to_reloc_handler,
-                          _handler_reloc.dentry);
-}
-
 /* TODO Make ordinary interface. Now real data_size is set in init, because
  * it is unknown in this module during compile time. */
-static struct probe_desc pin_reloc = MAKE_URPROBE(dl_reloc_eh, dl_reloc_rh, 0);
+static struct probe_desc pin_reloc = MAKE_URPROBE(dl_reloc_eh, common_rh, 0);
 
 
 static int pthread_init_eh(struct uretprobe_instance *ri, struct pt_regs *regs)
@@ -952,16 +957,18 @@ int gtm_set_handler_path(char *path)
        if (dentry == NULL)
                return -EINVAL;
 
-       if (_handler_fixup.dentry != NULL ||
-           _handler_reloc.dentry != NULL) {
-               if (_handler_fixup.dentry != NULL)
-                       swap_put_dentry(_handler_fixup.dentry);
-               else
-                       swap_put_dentry(_handler_reloc.dentry);
-       }
+       if (_handler_fixup.dentry)
+               swap_put_dentry(_handler_fixup.dentry);
+
+       if (_handler_reloc.dentry)
+               swap_put_dentry(_handler_reloc.dentry);
+
+       if (_proc_features.dentry)
+               swap_put_dentry(_proc_features.dentry);
 
        _handler_fixup.dentry = dentry;
        _handler_reloc.dentry = dentry;
+       _proc_features.dentry = dentry;
 
        /* TODO Do smth with this:
         * make interface for loader to remove handlers
@@ -986,6 +993,13 @@ int gtm_set_handler_reloc_off(unsigned long offset)
        return 0;
 }
 
+int gtm_set_proc_features_off(unsigned long offset)
+{
+       _proc_features.off = offset;
+
+       return 0;
+}
+
 int gtm_set_pthread_path(char *path)
 {
        struct dentry *dentry;
index a89dbee..7e1b151 100644 (file)
@@ -31,6 +31,7 @@ ssize_t gtm_get_targets(char **targets);
 int gtm_set_handler_path(char *path);
 int gtm_set_handler_fixup_off(unsigned long offset);
 int gtm_set_handler_reloc_off(unsigned long offset);
+int gtm_set_proc_features_off(unsigned long offset);
 
 /* Pthread data */
 int gtm_set_pthread_path(char *path);