[FIX] malloc probing from ld lib 40/31740/4
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Tue, 9 Dec 2014 08:21:43 +0000 (11:21 +0300)
committerVitaliy Andreevich <v.cherepanov@samsung.com>
Tue, 23 Dec 2014 12:28:47 +0000 (04:28 -0800)
replace malloc by real_malloc call

Change-Id: I34afa51e5190d6ce903d73676bd26889862f6064
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
24 files changed:
Makefile
custom_chart/da_chart.c
helper/common_probe_init.c
helper/dacapture.c
helper/damaps.c
helper/libdaprobe.c
helper/real_functions.c [new file with mode: 0644]
include/dacollection.h
include/dahelper.h
include/khash.h
include/real_functions.h [new file with mode: 0644]
probe_capi/capi_appfw.c
probe_event/da_event.c
probe_event/keytouch.c
probe_file/da_io_posix.c
probe_file/da_io_stdc.c
probe_graphics/da_evas_gl.c
probe_graphics/da_gl_api_init.c
probe_graphics/da_gles20_native.cpp
probe_memory/libdamemmanage.c
probe_socket/libdasocket.c
probe_third/libdaemon.c
probe_thread/libdasync.c
probe_thread/libdathread.c

index 3b85a57d090e32fa1a79debc7f1f3dc77ee4a2b6..2b0cb5fab07a9951c745cd595880bc714e3d5948 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -68,6 +68,7 @@ ASMFLAG = -O0 -g
 
 COMMON_SRCS = $(UTILITY_SRCS) $(PROBE_SRCS)
 UTILITY_SRCS =                         \
+       ./helper/real_functions.c       \
        ./helper/libdaprobe.c           \
        ./helper/dahelper.c             \
        ./helper/btsym.c                \
index 5dc255ded8753eb417797a5bc15cf5ae248214ee..78f80a7ab04e7a52583067d60ad33074ec368d5c 100755 (executable)
@@ -46,6 +46,7 @@
 #include "da_chart.h"
 
 #include "binproto.h"
+#include "real_functions.h"
 
 #define ERR_THREAD_CREATE_FAIL -2001   // thread creation fail
 
@@ -226,7 +227,7 @@ static void add_to_callback_list(chart_interval interval, da_handle charthandle,
 {
        chart_interval_callback* newelem;
 
-       newelem = (chart_interval_callback*)malloc(sizeof(chart_interval_callback));
+       newelem = (chart_interval_callback*)real_malloc(sizeof(chart_interval_callback));
        newelem->chart_handle = charthandle;
        newelem->series_handle = series_handle;
        newelem->callback = callback;
index 8bae7668fa83e0b7c903b22de71642261aebf59b..4a94789ec1e9755e20eda65c9d336dfd45d98847 100644 (file)
@@ -30,6 +30,7 @@
 #include "da_gles20.h"
 #include "binproto.h"
 #include "common_probe_init.h"
+#include "real_functions.h"
 
 //#define EGL_TEST
 Evas_GL_API *__gl_api;
index 29aa6228fe7d66ca6bbf6d34e72b9b4c87a5ae88..f363987b288adae2f5e7ca0e50b74d1e191cb00d 100755 (executable)
@@ -50,6 +50,7 @@
 #include <Evas.h>
 #include <Evas_Engine_Buffer.h>
 
+#include "real_functions.h"
 #include "daprobe.h"
 #include "dahelper.h"
 
@@ -269,7 +270,7 @@ static Evas* create_canvas(int width, int height)
        }
 
        // ARGB32 is sizeof(int), that is 4 bytes, per pixel
-       pixels = malloc(width * height * sizeof(int));
+       pixels = real_malloc(width * height * sizeof(int));
        if (unlikely(pixels == NULL)) {
                //fputs("ERROR: could not allocate canvas pixels!\n", stderr);
                evas_free(canvas);
index b5b350439d41ff5a6ec52268f91ec1c588dbc446..ac4da2d105fb2ad26307966a1fedbd3ba1669a7c 100755 (executable)
@@ -28,6 +28,7 @@
 
 #include <unistd.h>
 #include "dahelper.h"
+#include "real_functions.h"
 
 struct data_list_t {
        union {
index eb0fd91dc252346aa00f8bc9469f10d414170a54..bc1b5e6203be0ff31ce288d5fef4bee1251dd528 100755 (executable)
@@ -62,6 +62,7 @@
 #include "damaps.h"
 #include "dastdout.h"
 #include "common_probe_init.h"
+#include "real_functions.h"
 
 #define APP_INSTALL_PATH               "/opt/apps"
 #define TISEN_APP_POSTFIX                      ".exe"
@@ -83,8 +84,6 @@ int getExecutableMappingAddress();
 
 bool printLog(log_t* log, int msgType);
 
-void *(*real_malloc)(size_t) = NULL;
-
 /******************************************************************************
  * internal functions
    (this means that these functions do not need to set enter/exit flag)
@@ -530,6 +529,10 @@ unlock_exit:
 void __attribute__((constructor)) _init_probe()
 {
 
+       if (_init_real_functions()) {
+               PRINTERR("cannot init real functions\n");
+               exit(1);
+       }
        rtdl_next_set_once(real_malloc, "malloc");
 
         /* init maps */
diff --git a/helper/real_functions.c b/helper/real_functions.c
new file mode 100644 (file)
index 0000000..ac287fc
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  DA probe
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * Vitaliy Cherepanov <v.cherepanov@samsung.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <stdint.h>                    // fot uint32_t,uint64_t
+#include "daprobe.h"
+
+void *(*real_malloc)(size_t) = NULL;
+
+int _init_real_functions()
+{
+       rtdl_next_set_once(real_malloc, "malloc");
+       return 0;
+}
index f45aea4ec7664e4baa9bea4d5c55ca4ab6939f9d..e67da498f7ea2ec29f45615f834450952487d5cc 100755 (executable)
@@ -34,6 +34,7 @@
 #include <pthread.h>                   // for pthread_mutex_t
 
 #include "khash.h"
+#include "real_functions.h"
 
 #ifdef __cplusplus
 extern "C"{
index 38ac463cbcfcd00d89239bab165a981935863e44..fa956bcc2a1e059a22579caa51ef211e6a052e61 100755 (executable)
@@ -200,9 +200,6 @@ int get_map_address(void* symbol, void** map_start, void** map_end);
 char** da_backtrace_symbols (void* const* array, int size);
 char** cached_backtrace_symbols (void* const* array, int size);
 
-/* real malloc function pointer */
-extern void *(*real_malloc)(size_t);
-
 /* pid/tid values */
 pid_t _getpid();
 pid_t _gettid();
index bc728c95797cf620204a257d6eeb688024f67e0b..a92ec5e1011c72bc338b50a8ebb506596416ecd1 100755 (executable)
@@ -163,7 +163,7 @@ static const double __ac_HASH_UPPER = 0.77;
             }                                                           \
             if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; \
             else {                                                      \
-                new_flags = (uint32_t*)malloc(((new_n_buckets>>4) + 1) * sizeof(uint32_t)); \
+                new_flags = (uint32_t*)real_malloc(((new_n_buckets>>4) + 1) * sizeof(uint32_t)); \
                 memset(new_flags, 0xaa, ((new_n_buckets>>4) + 1) * sizeof(uint32_t)); \
                 if (h->n_buckets < new_n_buckets) {                     \
                     h->keys = (khkey_t*)realloc(h->keys, new_n_buckets * sizeof(khkey_t)); \
diff --git a/include/real_functions.h b/include/real_functions.h
new file mode 100644 (file)
index 0000000..b06904e
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  DA probe
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * Vitaliy Cherepanov <v.cherepanov@samsung.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef _REAL_FUNCTIONS_H_
+#define _REAL_FUNCTIONS_H_
+
+/* real malloc function pointer */
+extern void *(*real_malloc)(size_t);
+
+extern int _init_real_functions();
+#endif /* _REAL_FUNCTIONS_H_ */
index 1188433de765b056291dc62f98c3464bf96805c3..9c9b68aad52d5ebf94f4a105e2e54b0c23b14531 100644 (file)
@@ -37,6 +37,7 @@
 #include "dahelper.h"
 #include "probeinfo.h"
 #include "binproto.h"
+#include "real_functions.h"
 #include "common_probe_init.h"
 #include "api_config.h"
 
index e0476d8dbc6551bda5dabc758731d00c42f880af..935f5b6666cf937db6ed294c4777d67ea40b36cc 100755 (executable)
@@ -42,6 +42,7 @@
 #include "da_event.h"
 
 #include "binproto.h"
+#include "real_functions.h"
 
 static int external_angle = 0;
 static int internal_angle = 0;
index 1ac3d913fde45dd077fd9cd799ba67aedaacd57a..bf15682f85ef08389f894fa4b5af9514a83ff28b 100755 (executable)
@@ -51,6 +51,7 @@
 #include "da_event.h"
 
 #include "binproto.h"
+#include "real_functions.h"
 
 bool touch_pressed = false;
 
index 7b7b6754a0c2aa75bf3a0bbd0da960e0fb6b54be..1be30482555005e331b08a5a5da29ae4c53e8ea4 100755 (executable)
@@ -51,6 +51,7 @@
 #include <errno.h>
 
 #include "binproto.h"
+#include "real_functions.h"
 
 static enum DaOptions _sopt = OPT_FILE;
 
index 19bc150cac12091e2e606a6d77e62dff7effdcf1..35ebd4ff9efa4fb6cbea7862b7d45fdcd46509d2 100644 (file)
@@ -43,6 +43,7 @@
 #include "da_io.h"
 
 #include "binproto.h"
+#include "real_functions.h"
 
 static enum DaOptions _sopt = OPT_FILE;
 
index 6ddccdc6688aeb484362a02a5a2bd8f08510db70..b1facc054c22e35c719f7a5e2ceb109505f76c8a 100644 (file)
@@ -30,6 +30,7 @@
 #include "daprobe.h"
 #include "binproto.h"
 #include "common_probe_init.h"
+#include "real_functions.h"
 
 static enum DaOptions _sopt = OPT_GLES;
 
index 30d068379a2ca5c4a46fe2ff32a3b0dce2e10a16..1edfee85e5086fe2f478746863d616d07f344a99 100644 (file)
@@ -30,6 +30,7 @@
 #include "da_gles20.h"
 #include "binproto.h"
 #include "common_probe_init.h"
+#include "real_functions.h"
 
 /* GL __local_* functions prototypes */
 #define X(func) extern void __local_##func(void);
@@ -45,7 +46,7 @@ Evas_GL_API *__gl_api = NULL;
 void __init_gl_api__(void)
 {
        if (__gl_api == NULL)
-               __gl_api = malloc(sizeof(*__gl_api));
+               __gl_api = real_malloc(sizeof(*__gl_api));
        memset(__gl_api, 0, sizeof(*__gl_api));
 }
 
index 11549da3afeb3eb38a7dafc8cac2f7619c53df09..ed84d1016444dc7b88d2f8d966e1197a2c43ea82 100644 (file)
@@ -32,6 +32,7 @@
 #include "da_gles20.h"
 #include "daprobe.h"
 #include "binproto.h"
+#include "real_functions.h"
 #include "common_probe_init.h"
 
 #ifndef REAL_NAME
index 117259fe0f6e8bb0be32c7c45c89abf090159481..d0fb3fafdd8fcfaeadb3abb32f79d73dac40397c 100644 (file)
@@ -43,6 +43,7 @@
 #include "da_memory.h"
 #include "binproto.h"
 #include "common_probe_init.h"
+#include "real_functions.h"
 
 static enum DaOptions _sopt = OPT_ALLOC;
 
index abe79c8089b23446f1ce72d20dac7d8c338a3c5a..939d72ab93f6266b915aed6b247649d2ff8dcaf2 100644 (file)
@@ -52,6 +52,7 @@
 #include "dahelper.h"
 #include "api_id_mapping.h"
 #include "binproto.h"
+#include "real_functions.h"
 
 #define OBJ_DUMMY 0
 
@@ -375,7 +376,7 @@ ssize_t recvmsg(int socket, struct msghdr *message, int flags) {
        }
 
        int sendMaxSize = SOCKET_SEND_SIZE;
-       char* out = (char*) malloc(sendMaxSize + 5);
+       char* out = (char*) real_malloc(sendMaxSize + 5);
        if (sret <= 0) {
                out[0] = '\0';
        } else {
@@ -418,7 +419,7 @@ ssize_t sendmsg(int socket, const struct msghdr *message, int flags) {
                memset(&message, 0, sizeof(message));
        }
        int sendMaxSize = SOCKET_SEND_SIZE;
-       char* out = (char*) malloc(sendMaxSize + 5);
+       char* out = (char*) real_malloc(sendMaxSize + 5);
        if (sret <= 0) {
                out[0] = '\0';
        } else {
index 65b46005024b5e2b504881dff04e52d1cc2805a5..8778cadb9b379c4669d6baa9293c4642be5b6533 100644 (file)
  *
  */
 
-#include <stdlib.h>    // for malloc
 #include <string.h>    // for memcpy
 #include <errno.h>     // for errno
 
 #include "daprobe.h"
 #include "dahelper.h"
 
+#include "real_functions.h"
+
 int daemon_close_allv(const int except_fds[])
 {
        static int (*daemon_close_allvp)(const int except_fds[]);
@@ -52,7 +53,7 @@ int daemon_close_allv(const int except_fds[])
        }
 
        // allocate memory for new except fds
-       fds = (int*)malloc((i + 2) * sizeof(int));
+       fds = (int*)real_malloc((i + 2) * sizeof(int));
 
        // copy fds
        if(fds)
index 94c1bc943ba4ee605ed33824b3678715d5542037..2823b2ce9b564a3c81defad3e9dc8a136ca91d35 100644 (file)
@@ -39,6 +39,7 @@
 #include "da_sync.h"
 
 #include "binproto.h"
+#include "real_functions.h"
 
 static enum DaOptions _sopt = OPT_THREAD;
 
index 942f86e089fd14c36f1ce76ab7abb2e412be0ad5..018a23ab2fd84748bfdadf78d7ba384a4022c2fe 100644 (file)
@@ -38,6 +38,7 @@
 #include "da_thread.h"
 #include "da_sync.h"
 #include "binproto.h"
+#include "real_functions.h"
 
 typedef struct thread_routine_call_t {
        void *(*thread_routine)(void *);
@@ -143,7 +144,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
        {
                probeBlockStart();
                thread_routine_call *ptrc =
-                       (thread_routine_call *) malloc(sizeof(thread_routine_call));
+                       (thread_routine_call *) real_malloc(sizeof(thread_routine_call));
                ptrc->thread_routine = start_routine;
                ptrc->argument = arg;
                probeBlockEnd();