GOT patcher: separate Event feature 17/88217/8
authorAlexander Aksenov <a.aksenov@samsung.com>
Tue, 13 Sep 2016 10:19:19 +0000 (13:19 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Wed, 26 Oct 2016 18:31:34 +0000 (21:31 +0300)
Change-Id: Ibc2153566c117989e5a0a01ee4b8068c089b2bd4
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
Makefile
helper/dacapture.c
helper/got_patching.c
helper/got_patching.h
helper/libdaprobe.c
include/binproto.h
include/dahelper.h
packaging/swap-probe.spec
probe_event/da_event.c

index 8251836..bb24a29 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@ BIN_INSTALLDIR = /usr/local/bin
 HEADER_INSTALLDIR = /usr/local/include/
 
 TIZEN_TARGET = da_probe_tizen.so
+PROBE_EVENT_TARGET = swap_probe_event.so
 DUMMY_TARGET = libdaprobe.so
 PARSE_ELF_LIB_TARGET = libparserelf.so
 PARSE_ELF_BIN_TARGET = parse_elf
@@ -79,16 +80,15 @@ LDFLAGS = -shared           \
        -lrt                            \
        -ldl                            \
        -lwayland-client        \
-       -lsensor                        \
        -Wl,-z,noexecstack
 
 ASMFLAG = -O0 -g -Werror
 
 CFLAGS = $(WARN_CFLAGS) -fPIC
 CXXFLAGS = $(WARN_CFLAGS) -fPIC
-CPPFLAGS = $(INCLUDE_CPPFLAGS) -D_GNU_SOURCE -DSELF_LIB_NAME="\"/$(INSTALLDIR)/$(TIZEN_TARGET)\""
+CPPFLAGS = $(INCLUDE_CPPFLAGS) -D_GNU_SOURCE
 
-TIZEN_CPPFLAGS = -DTIZENAPP $(SWAP_PROBE_DEFS)
+TIZEN_CPPFLAGS = -DSELF_LIB_NAME="\"/$(INSTALLDIR)/$(TIZEN_TARGET)\"" -DTIZENAPP $(SWAP_PROBE_DEFS)
 TIZEN_LDFLAGS = -lstdc++
 
 
@@ -115,10 +115,6 @@ PROBE_SRCS =                                       \
        ./probe_memory/probe_memory.c           \
        ./probe_socket/libdasocket.c            \
        ./probe_socket/probe_socket.c           \
-       ./probe_event/gesture.c                 \
-       ./probe_event/da_event.c                \
-       ./probe_event/keytouch.c                \
-       ./probe_event/probe_event.c             \
        ./probe_third/libdaemon.c               \
        ./probe_thread/libdathread.c            \
        ./probe_thread/libdasync.c              \
@@ -127,9 +123,15 @@ PROBE_SRCS =                                       \
        ./probe_file/da_io_stdc.c               \
        ./probe_file/probe_file.c               \
 
+PROBE_EVENT_SRCS = \
+       ./probe_event/gesture.c                 \
+       ./probe_event/da_event.c                \
+       ./probe_event/keytouch.c                \
+       ./probe_event/probe_event.c
+
 ifeq ($(TIZEN_FEATURE_WAYLAND),y)
 UTILITY_SRCS += ./helper/dacapture.c
-PROBE_SRCS += ./probe_event/orientation.c
+PROBE_EVENT_SRCS += ./probe_event/orientation.c
 CFLAGS += -DTIZEN_FEATURE_WAYLAND
 CFLAGS += -I/usr/include/wayland-extension/
 LDFLAGS+=-lecore                       \
@@ -172,12 +174,13 @@ PARSE_ELF_BIN_SRC = ./elf_parsing/parse_elf.c
 ASM_OBJ = $(patsubst %.S,%.o, $(ASM_SRC))
 CAPI_OBJS = $(patsubst %.c,%.o, $(CAPI_SRCS)) $(ASM_OBJ)
 TIZEN_OBJS = $(patsubst %.cpp,%.o, $(patsubst %.c,%.o, $(TIZEN_SRCS))) $(ASM_OBJ)
+PROBE_EVENT_OBJS = $(patsubst %.cpp,%.o, $(patsubst %.c,%.o, $(PROBE_EVENT_SRCS)))
 DUMMY_OBJS = $(patsubst %.c,%.o, $(DUMMY_SRCS))
 PARSE_ELF_LIB_OBJ = $(patsubst %.c,%.o, $(PARSE_ELF_LIB_SRC))
 PARSE_ELF_BIN_OBJ = $(patsubst %.c,%.o, $(PARSE_ELF_BIN_SRC))
 
 
-all:           elflib capi tizen dummy elfparser
+all:           elflib capi tizen dummy event elfparser
 tizen:         headers $(TIZEN_TARGET)
 dummy:         headers $(DUMMY_TARGET)
 elflib:                $(PARSE_ELF_LIB_OBJ) $(PARSE_ELF_LIB_TARGET)
@@ -185,6 +188,8 @@ elfparser:  elflib $(PARSE_ELF_BIN_OBJ) $(PARSE_ELF_BIN_TARGET)
 lsan:
         $(MAKE) -C lsan
 
+event:         tizen $(PROBE_EVENT_TARGET)
+
 $(ASM_OBJ): $(ASM_SRC)
        $(CC) $(ASMFLAG) -c $^ -o $@
 
@@ -238,6 +243,18 @@ $(TIZEN_TARGET): CPPFLAGS+=$(DEBUG_FLAGS)
 $(TIZEN_TARGET): $(TIZEN_OBJS)
        $(CC) $(LDFLAGS) $^ -o $@
 
+PROBE_EVENT_LDFLAGS =   \
+       -L.             \
+       -lstdc++        \
+       -lsensor        \
+       -l:da_probe_tizen.so
+
+$(PROBE_EVENT_TARGET): LDFLAGS+=$(PROBE_EVENT_LDFLAGS)
+$(PROBE_EVENT_TARGET): CPPFLAGS+=-DSELF_LIB_NAME="\"/$(INSTALLDIR)/$(PROBE_EVENT_TARGET)\"" -DTIZENAPP $(SWAP_PROBE_DEFS)
+$(PROBE_EVENT_TARGET): CPPFLAGS+=$(DEBUG_FLAGS)
+$(PROBE_EVENT_TARGET): $(TIZEN_TARGET) $(PROBE_EVENT_OBJS)
+       $(CC) $(LDFLAGS) $^ -o $@
+
 $(DUMMY_TARGET): $(DUMMY_OBJS)
        $(CC) $(LDFLAGS) $^ -o $@
 
@@ -249,7 +266,7 @@ $(PARSE_ELF_BIN_TARGET): $(PARSE_ELF_BIN_OBJ) $(PARSE_ELF_LIB_TARGET)
 
 ldheader:      $(SOURCE_HEADERS) $(LINKER_HEADER)
 
-install: install_da install_ld install_elf install_lsan
+install: install_da install_event install_ld install_elf install_lsan
 
 install_da: all
        [ -d "$(DESTDIR)/$(INSTALLDIR)" ] || mkdir -p $(DESTDIR)/$(INSTALLDIR)
@@ -273,7 +290,12 @@ install_lsan: lsan
        [ -d "$(DESTDIR)/$(INSTALLDIR)" ] || mkdir -p $(DESTDIR)/$(INSTALLDIR)
        install $(LSAN_DIR)/$(LSAN_TARGET) $(DESTDIR)/$(INSTALLDIR)/
 
+install_event: event
+       [ -d "$(DESTDIR)/$(INSTALLDIR)" ] || mkdir -p $(DESTDIR)/$(INSTALLDIR)
+       install $(PROBE_EVENT_TARGET) $(DESTDIR)/$(INSTALLDIR)/
+
+
 clean:
-       rm -f *.so $(TIZEN_OBJS) $(PARSE_ELF_LIB_OBJ) $(PARSE_ELF_BIN_OBJ) $(GENERATED_HEADERS) $(API_NAME_LIST) $(SOURCE_HEADERS)
+       rm -f *.so $(TIZEN_OBJS) $(PROBE_EVENT_OBJS) $(PARSE_ELF_LIB_OBJ) $(PARSE_ELF_BIN_OBJ) $(GENERATED_HEADERS) $(API_NAME_LIST) $(SOURCE_HEADERS)
 
-.PHONY: all capi tizen dummy clean install_ld install_da install_elf install headers lsan
+.PHONY: all capi tizen dummy event clean install_ld install_da install_event install_elf install headers lsan
index 0dfaf81..49b9b97 100755 (executable)
@@ -84,6 +84,8 @@ struct screenshooter_output {
        struct wl_list link;
 };
 
+static int __current_angle = 0;
+
 static void
 display_handle_geometry(void __attribute__((unused)) *data,
                        struct wl_output *wl_output,
@@ -613,3 +615,12 @@ void _cb_render_post(void __unused * data, Evas __unused * e,
 {
        SCREENSHOT_DONE();
 }
+
+int current_angle_get()
+{
+       return __current_angle;
+}
+void current_angle_set(int angle)
+{
+       __current_angle = angle;
+}
index fddb464..1820821 100644 (file)
 
 /* Features list, defined in probe_* headers */
 #define FEATURES_LIST \
-       X(memory_feature) \
-       X(memory_feature_always) \
-       X(helper_feature) \
-       X(capi_feature) \
-       X(event_feature) \
-       X(file_feature) \
-       X(file_feature_always) \
-       X(graphics_feature) \
-       X(graphics_feature_always) \
-       X(network_feature) \
-       X(network_feature_always) \
-       X(thread_feature) \
-       X(thread_feature_always) \
-       X(ui_feature)
+       X(OPT_ALLOC,            memory_feature,                 "/usr/lib/da_probe_tizen.so") \
+       X(OPT_ALLOC_ALWAYS,     memory_feature_always,          "/usr/lib/da_probe_tizen.so") \
+       X(OPT_ALWAYSON,         helper_feature,                 "/usr/lib/da_probe_tizen.so") \
+       X(OPT_ALWAYSON,         capi_feature,                   "/usr/lib/da_probe_tizen.so") \
+       X(OPT_EVENT,            event_feature,                  "/usr/lib/swap_probe_event.so") \
+       X(OPT_FILE,             file_feature,                   "/usr/lib/da_probe_tizen.so") \
+       X(OPT_FILE_ALWAYS,      file_feature_always,            "/usr/lib/da_probe_tizen.so") \
+       X(OPT_GLES,             graphics_feature,               "/usr/lib/da_probe_tizen.so") \
+       X(OPT_GLES_ALWAYS,      graphics_feature_always,        "/usr/lib/da_probe_tizen.so") \
+       X(OPT_NETWORK,          network_feature,                "/usr/lib/da_probe_tizen.so") \
+       X(OPT_NETWORK_ALWAYS,   network_feature_always,         "/usr/lib/da_probe_tizen.so") \
+       X(OPT_THREAD,           thread_feature,                 "/usr/lib/da_probe_tizen.so") \
+       X(OPT_THREAD_ALWAYS,    thread_feature_always,          "/usr/lib/da_probe_tizen.so") \
+       X(OPT_UI,               ui_feature,                     "/usr/lib/da_probe_tizen.so")
 
 
 /* Declare array of features length */
-#define X(feature) +1
+#define X(flag, feat, file) +1
 
 static unsigned int features_cnt = (FEATURES_LIST);
+static void * feature_handles[(FEATURES_LIST)] = { NULL };
 static struct feature_desc_t *features[(FEATURES_LIST)] = { NULL };
 
 #undef X
 
 
 /* Declare array's indexes */
-#define X(feature) feature##_ind,
+#define X(flag, feat, file) feat##_ind,
 
 enum {
        FEATURES_LIST
@@ -61,11 +62,28 @@ enum {
 
 
 /* Declare array of features */
-#define X(feature) features[feature##_ind] = &feature;
+#define X(flag, feat, file)                            \
+       if (features[feat##_ind] == NULL ||             \
+           feature_handles[feat##_ind] != NULL)        \
+               features[feat##_ind] = dlsym(feature_handles[feat##_ind], #feat);
 
 /* Can be initialized only dynamically, because struct addresses are resolved
  * only at a runtime */
-static void _init_features_ptrs(void)
+static void _init_feature_ptrs(void)
+{
+       FEATURES_LIST
+}
+
+#undef X
+
+/* Declare array of feature's library handles */
+#define X(flag, feat, file)                                                  \
+       if (feature_handles[feat##_ind] == NULL && isOptionEnabled(flag))     \
+               feature_handles[feat##_ind] = dlopen(file, RTLD_NOW);
+
+/* Init features that are in already loaded binaries. */
+/* TODO make dlclose() on stop */
+static void _init_feature_handles(void)
 {
        FEATURES_LIST
 }
@@ -151,6 +169,7 @@ static inline bool _is_for_all_feature(struct feature_desc_t *feature)
 static inline bool _is_ignored(const char *path)
 {
        const char probe_lib[] = "/usr/lib/da_probe_tizen.so";
+       const char event_lib[] = "/usr/lib/swap_probe_event.so";
        const char uihv_lib[] = "/usr/lib/da_ui_viewer.so";
        const char linux_gate[] = "linux-gate.so.1";
        const char linker_2[] = "/lib/ld-linux.so.2";
@@ -167,6 +186,7 @@ static inline bool _is_ignored(const char *path)
 
        if (path[0] == '\0' ||
            !strcmp(probe_lib, path) ||
+           !strcmp(event_lib, path) ||
            !strcmp(uihv_lib, path) ||
            !strcmp(linux_gate, path) ||
            !strcmp(linker_2, path) ||
@@ -263,7 +283,8 @@ static void _process_features(void)
        unsigned int i;
 
        for (i = 0; i < features_cnt; i++) {
-               if (!isOptionEnabled(features[i]->feature))
+               if (features[i] == NULL ||
+                   !isOptionEnabled(features[i]->feature))
                        continue;
                _patch_target_bins(features[i]);
        }
@@ -327,7 +348,8 @@ __dl_fixup_wrapper (
 
        /* Iterate features to find target probe */
        for (i = 0; i < features_cnt; i++) {
-               if (!isOptionEnabled(features[i]->feature))
+               if (features[i] == NULL ||
+                   !isOptionEnabled(features[i]->feature))
                        continue;
 
                if ((!check_binary(l->l_name) &&
@@ -387,7 +409,8 @@ void __dl_reloc_wrapper(struct link_map *l, struct r_scope_elem *scope[],
         * another calls relocated function before we patch its address */
 
        for (i = 0; i < features_cnt; i++) {
-               if (!isOptionEnabled(features[i]->feature))
+               if (features[i] == NULL ||
+                   !isOptionEnabled(features[i]->feature))
                        continue;
 
                is_for_all = _is_for_all_feature(features[i]);
@@ -449,11 +472,16 @@ init_linker_addr_end:
        return ret;
 }
 
+void init_features(void)
+{
+       _init_feature_handles();
+       _init_feature_ptrs();
+}
+
 void process_got_patching(char *data)
 {
        if (!inited) {
                _init_linker_addr();
-               _init_features_ptrs();
                inited = true;
        }
        _process_target_bins(data);
index 61d0022..2f76fe3 100644 (file)
@@ -3,5 +3,6 @@
 
 void process_got_patching(char *data);
 void restore_got_patching(void);
+void init_features(void);
 
 #endif /* __GOT_PATCHING_H__ */
index eba5bf6..3508db6 100755 (executable)
@@ -98,6 +98,9 @@ static void _configure(char* configstr)
                SCREENSHOT_SET();
        else
                SCREENSHOT_UNSET();
+
+       init_features();
+
        PRINTMSG("configure in probe : %s, %llx\n", configstr, gTraceInfo.optionflag);
 }
 
@@ -541,8 +544,6 @@ void _uninit_(void)
                gTraceInfo.socket.daemonSock = -1;
        }
 
-       finalize_event();
-
        finalize_hash_table();
 
        for(i = 0; i < NUM_ORIGINAL_LIBRARY; i++)
index 4d208e0..9e08a0f 100644 (file)
@@ -669,7 +669,7 @@ _ret CONCAT(PROBE_NAME(_name), _always)(FUNC_DECL(__VA_ARGS__))
 #if 0 /* TODO Support old preload */
 
 #define PREPARE_LOCAL_BUF()                    \
-               char *LOCAL_BUF = (char *)(*real_malloc)(MAX_LOCAL_BUF_SIZE);   \
+               char *LOCAL_BUF = (char *)malloc(MAX_LOCAL_BUF_SIZE);   \
                char *BUF_PTR = LOCAL_BUF;                      \
                char *RET_PTR = NULL;                           \
                char *CALL_TYPE_PTR = NULL;                     \
@@ -678,7 +678,7 @@ _ret CONCAT(PROBE_NAME(_name), _always)(FUNC_DECL(__VA_ARGS__))
 #else
 
 #define PREPARE_LOCAL_BUF()                    \
-               char *LOCAL_BUF = (char *)(*real_malloc)(MAX_LOCAL_BUF_SIZE);   \
+               char *LOCAL_BUF = (char *)malloc(MAX_LOCAL_BUF_SIZE);   \
                char *BUF_PTR = LOCAL_BUF;                      \
                char *RET_PTR = NULL;
 
index 0e73e9a..26d2cde 100755 (executable)
@@ -190,8 +190,6 @@ char *absolutize_filepath(const char *fname, char *buf, size_t bufsiz);
 char *real_abs_path(int fd, char *buffer, size_t bufsiz);
 
 // event related functions
-int initialize_event();
-int finalize_event();
 int current_angle_get();
 void current_angle_set(int angle);
 void on_orientation_changed(int angle, bool capi);
index bffc94b..7a6b0a7 100644 (file)
@@ -128,6 +128,7 @@ mkdir -p %{buildroot}/usr/local/bin
 %manifest swap-probe.manifest
 %defattr(-,root,root,-)
 %{_prefix}/lib/da_probe_tizen.so
+%{_prefix}/lib/swap_probe_event.so
 %{_prefix}/lib/libdaprobe.so
 
 %files -n swap-probe-devel
index 10d0078..20c0fb4 100755 (executable)
 #include "binproto.h"
 #include "real_functions.h"
 
-static int __current_angle = 0;
-
-// ====================================================================
-// initialize and finalize event
-// ====================================================================
-
-int initialize_event()
-{
-       return 0;
-}
-
-int finalize_event()
-{
-       return 0;
-}
 
 // ===================================================================
 // orientation related functions
@@ -89,8 +74,6 @@ static int convert_angle(int angle)
 
 void on_orientation_changed(int angle, bool capi)
 {
-       __current_angle = angle;
-
        if (isOptionEnabled(OPT_EVENT)) {
                inc_current_event_index();
 
@@ -102,18 +85,9 @@ void on_orientation_changed(int angle, bool capi)
                /* Always feature */
                PACK_COMMON_END('v', 0, 0, 0, (uint64_t)0xffffffff);
                PACK_UIEVENT(_EVENT_ORIENTATION, 0, 0, 0, "",
-                            convert_angle(__current_angle));
+                            convert_angle(angle));
                FLUSH_LOCAL_BUF();
        }
 
        SCREENSHOT_SET();
 }
-
-int current_angle_get()
-{
-       return __current_angle;
-}
-void current_angle_set(int angle)
-{
-       __current_angle = angle;
-}