capi: use multiprobe 69/155269/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 12 Oct 2017 12:51:06 +0000 (15:51 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 12 Oct 2017 14:31:29 +0000 (17:31 +0300)
Change-Id: I91d75d5026719834216f635ceae2128c561ff66c
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
Makefile
helper/got_patching.c
helper/loader.c
helper/multiprobe_helper.cpp
probe_capi/capi_appfw.c
probe_capi/capi_appfw.h [deleted file]
probe_capi/capi_probes_list.h [deleted file]
probe_capi/probe_capi.c [deleted file]
probe_capi/probe_capi.h [deleted file]

index da2f033..f7cad7f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -156,8 +156,7 @@ PROBE_UI_SRCS = \
        ./probe_ui/probe_ui.c
 
 PROBE_CAPI_SRCS = \
-       ./probe_capi/capi_appfw.c               \
-       ./probe_capi/probe_capi.c
+       ./probe_capi/capi_appfw.c
 
 PROBE_SCREENSHOT_SRCS = ./probe_screenshot/dacapture_generic.c
 
index 07003e5..cbfff4e 100644 (file)
@@ -10,7 +10,6 @@
 #include "probeinfo.h"
 #include "probe_screenshot.h"
 #include "probe_helper.h"
-#include "probe_capi.h"
 #include "probe_event.h"
 #include "probe_file.h"
 #include "probe_graphics.h"
index bfe60cd..dd28d18 100644 (file)
@@ -31,7 +31,6 @@
 #include "dahelper.h"
 #include "probe_screenshot.h"
 #include "probe_helper.h"
-#include "probe_capi.h"
 #include "probe_event.h"
 #include "probe_file.h"
 #include "probe_graphics.h"
index df04336..0e147aa 100644 (file)
 
 #include "multiprobe_helper.h"
 #include <probeinfo.h>
+#include <multiprobe.h>
 
+#include <app.h>// for ui_app_lifecycle_callback_s
+
+
+static int mprobe_ui_app_main(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data);
 
 static struct probe_desc_t probes[] = {
-    // add probes describe
+    {
+        .handler_ptr = (ElfW(Addr))&mprobe_ui_app_main,
+        .orig_name = "ui_app_main",
+        .flags = GT_TARGET_PROBE,
+        .orig_ptr = (ElfW(Addr))0,
+    },
 };
 
 struct feature_desc_t multiprobe_helper_feature = {
@@ -36,3 +46,20 @@ struct feature_desc_t multiprobe_helper_feature = {
     .cnt = sizeof(probes) / sizeof(probes[0]),
     .probes = probes,
 };
+
+
+static int mprobe_ui_app_main(int argc, char **argv,
+                              ui_app_lifecycle_callback_s *callback, void *user_data)
+{
+    typedef int (*func_t)(int, char **, ui_app_lifecycle_callback_s *, void *);
+    static void *handle = nullptr;
+
+    if (!handle) {
+        struct probe_desc_t *probe = &probes[0];
+
+        multiprobe_set_default_handler(probe->orig_name, (void *)probe->orig_ptr);
+        handle = multiprobe_reg(probe->orig_name, (void *)mprobe_ui_app_main, true);
+    }
+
+    return MULTIPROBE_CALL(handle, func_t, argc, argv, callback, user_data);
+}
index 10a0abf..ffbb154 100644 (file)
 
 #include <app.h>
 #include <Ecore.h>
-#include "daprobe.h"
-#include "dahelper.h"
-#include "probeinfo.h"
 #include "binproto.h"
-#include "common_probe_init.h"
-#include "capi_probes_list.h"
-#include "probe_capi.h"
+#include <multiprobe.h>
 
 
 
@@ -122,13 +117,13 @@ static void _ui_dalc_app_control(app_control_h handle, void *user_data)
                                 voidp_to_uint64(user_data));
 }
 
-int PROBE_NAME(ui_app_main)(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data)
+static void *handle_ui_app_main;
+
+static int handler_ui_app_main(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data)
 {
-       int (*ui_app_mainp)(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data);
+       typedef int (*func_t)(int, char **, ui_app_lifecycle_callback_s *, void *);
        int ret;
 
-       ui_app_mainp = (void *)GET_ORIG_FUNC(capi_feature, ui_app_main);
-
        uiAppCallback.create = callback->create;
        uiAppCallback.terminate = callback->terminate;
        uiAppCallback.pause = callback->pause;
@@ -148,7 +143,7 @@ int PROBE_NAME(ui_app_main)(int argc, char **argv, ui_app_lifecycle_callback_s *
        if (callback->app_control)
                callback->app_control = _ui_dalc_app_control;
 
-       ret = ui_app_mainp(argc, argv, callback, user_data);
+       ret = MULTIPROBE_CALL(handle_ui_app_main, func_t, argc, argv, callback, user_data);
 
        callback->create = uiAppCallback.create;
        callback->terminate = uiAppCallback.terminate;
@@ -158,3 +153,8 @@ int PROBE_NAME(ui_app_main)(int argc, char **argv, ui_app_lifecycle_callback_s *
 
        return ret;
 }
+
+static void __attribute__((constructor)) ctor()
+{
+       handle_ui_app_main = multiprobe_reg("ui_app_main", (void *)handler_ui_app_main, true);
+}
diff --git a/probe_capi/capi_appfw.h b/probe_capi/capi_appfw.h
deleted file mode 100644 (file)
index d239fcb..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef __CAPI_APPFW_H__
-#define __CAPI_APPFW_H__
-
-
-int PROBE_NAME(ui_app_main)(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data);
-
-#endif /* __CAPI_APPFW_H__ */
diff --git a/probe_capi/capi_probes_list.h b/probe_capi/capi_probes_list.h
deleted file mode 100644 (file)
index 4a9b60e..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __CAPI_PROBES_LIST_H__
-#define __CAPI_PROBES_LIST_H__
-
-
-/* TODO generate PROBES_LIST with api_names.txt */
-
-#define PROBES_LIST \
-       X(PROBE_NAME(ui_app_main), ui_app_main)
-
-
-#define X(func_name, orig_name)         \
-       GET_FUNC_ID(func_name, orig_name),
-enum capi_funcs_id_t {
-       PROBES_LIST
-};
-#undef X
-
-enum capi_funcs_id_t get_capi_feature_id(void *ptr);
-
-#endif /* __CAPI_PROBES_LIST_H__ */
diff --git a/probe_capi/probe_capi.c b/probe_capi/probe_capi.c
deleted file mode 100644 (file)
index f346033..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <stddef.h>
-#include "api_names_global.h"
-#include "probeinfo.h"
-#include "daprobe.h"
-
-#include "capi_probes_list.h"
-
-/* X-macros replaced by function defenitions */
-/* We need this only to get symbol address - so don't care
- * about real prototype */
-#define X(func_name, orig_name) \
-       void func_name(void);
-
-PROBES_LIST
-
-#undef X
-
-
-/* This function returns function's id by its pointer */
-#define X(func_name, orig_name)                 \
-       if (ptr == & func_name)                 \
-               return GET_FUNC_ID(func_name, orig_name);
-
-enum capi_funcs_id_t get_capi_feature_id(void *ptr)
-{
-       PROBES_LIST
-
-       PRINTERR("Invalid function pointer %p at <%s>!\n", ptr, __func__);
-
-       return 0;
-}
-
-#undef X
-
-
-/* X-macros replaced by structures defenitions */
-/* Used only for probes from target file */
-#define X(func_name, orig_name)         \
-        { (ElfW(Addr)) & func_name, #orig_name, GT_ALWAYS_PROBE, (ElfW(Addr))0 },
-
-static struct probe_desc_t capi_probes[] = {
-       PROBES_LIST
-};
-
-#undef X
-
-/* X-macros replaced by counted additions */
-#define X(func_name, orig_name) +1
-
-struct feature_desc_t capi_feature = {
-       /* Always feature */
-       .feature = 0xffffffff,
-       .cnt = (PROBES_LIST),
-       .probes = capi_probes
-};
-
-#undef X
-
-#undef PROBES_LIST
diff --git a/probe_capi/probe_capi.h b/probe_capi/probe_capi.h
deleted file mode 100644 (file)
index 04a4c52..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __PROBE_CAPI_H__
-#define __PROBE_CAPI_H__
-
-extern struct feature_desc_t capi_feature;
-
-#endif /* __PROBE_CAPI_H__*/