lsan: save mapped address instead of original addr 58/153358/1
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 8 Dec 2016 13:22:26 +0000 (16:22 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 27 Sep 2017 12:54:58 +0000 (15:54 +0300)
Addresses returned by allocation funcitons should be changed
before saving to library hash because of
lsan search addresses in process memory

Change-Id: Icd197343826c1cfec19d406858e676622ebc8794
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
probe_memory/da_memory.h
probe_memory/libdamemalloc.c
probe_memory/libdanew.cpp

index a8ae788..7963e83 100644 (file)
  *
  ********************************************************************/
 
+
+static inline void *convert_addr_to_hash(void *ptr)
+{
+       return (void *)((void *)0 - ptr);
+}
+
+
 #endif // __DA_MEMORY_H__
index 2885ed2..7f8b644 100755 (executable)
@@ -100,7 +100,7 @@ HANDLER_WRAPPERS(memory_feature, void *, malloc, size_t, size)
        pret = (*mallocp)(size);
 
        if(pret != NULL)
-               add_memory_hash(pret, size, MEMTYPE_ALLOC,
+               add_memory_hash(convert_addr_to_hash(pret), size, MEMTYPE_ALLOC,
                                PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
@@ -134,7 +134,7 @@ HANDLER_WRAPPERS_VOID(memory_feature, void, free, void*, ptr)
        PRE_PROBEBLOCK();
 
        if(ptr != NULL)
-               del_memory_hash(ptr, MEMTYPE_FREE, NULL);
+               del_memory_hash(convert_addr_to_hash(ptr), MEMTYPE_FREE, NULL);
 
        (*freep)(ptr);
 
@@ -168,13 +168,14 @@ HANDLER_WRAPPERS(memory_feature, void *, realloc, void *, memblock, size_t, size
        PRE_PROBEBLOCK();
 
        if(memblock != NULL)
-               del_memory_hash(memblock, MEMTYPE_FREE, NULL);
+               del_memory_hash(convert_addr_to_hash(memblock),
+                               MEMTYPE_FREE, NULL);
 
        pret = (*reallocp)(memblock, size);
 
        if(pret != NULL)
-               add_memory_hash(pret, size, MEMTYPE_ALLOC,
-                               PROBE_GET_CALL_TYPE(probe_data));
+               add_memory_hash(convert_addr_to_hash(pret), size,
+                               MEMTYPE_ALLOC, PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
 
@@ -231,8 +232,8 @@ HANDLER_WRAPPERS(memory_feature, void *, calloc, size_t, nelem, size_t, elsize)
        pret = (*callocp)(nelem, elsize);
 
        if(pret != NULL)
-               add_memory_hash(pret, nelem * elsize, MEMTYPE_ALLOC,
-                               PROBE_GET_CALL_TYPE(probe_data));
+               add_memory_hash(convert_addr_to_hash(pret), nelem * elsize,
+                               MEMTYPE_ALLOC, PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
 
@@ -272,8 +273,8 @@ HANDLER_WRAPPERS(memory_feature, int, posix_memalign, void**, memptr,
        iret = (*posix_memalignp)(memptr, alignment, size);
 
        if (iret == 0)
-               add_memory_hash(*memptr, size, MEMTYPE_ALLOC,
-                               PROBE_GET_CALL_TYPE(probe_data));
+               add_memory_hash(convert_addr_to_hash(*memptr), size,
+                               MEMTYPE_ALLOC, PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
 
@@ -310,7 +311,7 @@ HANDLER_WRAPPERS(memory_feature, char *, strdup, const char*, s)
        pret = (*strdupp)(s);
 
        if (pret == 0)
-               add_memory_hash(pret, size, MEMTYPE_ALLOC,
+               add_memory_hash(convert_addr_to_hash(pret), size, MEMTYPE_ALLOC,
                                PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
index 10add65..976418f 100644 (file)
@@ -100,7 +100,7 @@ HANDLER_WRAPPERS_THROW(memory_feature, void *, new, (std::bad_alloc), std::size_
        pret = newp(size);
 
        if(pret != NULL)
-               add_memory_hash(pret, size, MEMTYPE_NEW,
+               add_memory_hash(convert_addr_to_hash(pret), size, MEMTYPE_NEW,
                               (unsigned short)PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
@@ -137,7 +137,7 @@ HANDLER_WRAPPERS_THROW(memory_feature, void *, new_array, (std::bad_alloc), std:
        pret = newp(size);
 
        if(pret != NULL)
-               add_memory_hash(pret, size, MEMTYPE_NEW,
+               add_memory_hash(convert_addr_to_hash(pret), size, MEMTYPE_NEW,
                                PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
@@ -174,7 +174,8 @@ HANDLER_WRAPPERS_THROW(memory_feature, void, delete, (), void *, ptr)
        if(ptr != NULL)
        {
                /* TODO call_type rewrited as it was previously. Is it needed? */
-               ret = del_memory_hash(ptr, MEMTYPE_DELETE, &ct);
+               ret = del_memory_hash(convert_addr_to_hash(ptr),
+                                     MEMTYPE_DELETE, &ct);
                if(blockresult == 0 && ret == 0 && ct == EXTERNAL_CALL)
                {
                        inc_current_event_index();
@@ -216,7 +217,7 @@ HANDLER_WRAPPERS_THROW(memory_feature, void, delete_array, (), void *, ptr)
        if(ptr != NULL)
        {
                /* TODO call_type rewrited as it was previously. Is it needed? */
-               ret = del_memory_hash(ptr, MEMTYPE_DELETE, &ct);
+               ret = del_memory_hash(convert_addr_to_hash(ptr), MEMTYPE_DELETE, &ct);
                if(blockresult == 0 && ret == 0 &&
                   PROBE_GET_CALL_TYPE(probe_data) == EXTERNAL_CALL)
                {
@@ -261,7 +262,7 @@ HANDLER_WRAPPERS_THROW(memory_feature, void *, new_nothrow, (), std::size_t, siz
        pret = newp(size, nothrow);
 
        if(pret != NULL)
-               add_memory_hash(pret, size, MEMTYPE_NEW,
+               add_memory_hash(convert_addr_to_hash(pret), size, MEMTYPE_NEW,
                               (unsigned short)PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
@@ -300,7 +301,7 @@ HANDLER_WRAPPERS_THROW(memory_feature, void *, new_array_nothrow, (), std::size_
        pret = newp(size, nothrow);
 
        if(pret != NULL)
-               add_memory_hash(pret, size, MEMTYPE_NEW,
+               add_memory_hash(convert_addr_to_hash(pret), size, MEMTYPE_NEW,
                                PROBE_GET_CALL_TYPE(probe_data));
 
        POST_PACK_PROBEBLOCK_BEGIN();
@@ -339,7 +340,7 @@ HANDLER_WRAPPERS_THROW(memory_feature, void, delete_nothrow, (), void *, ptr,
        if(ptr != NULL)
        {
                /* TODO call_type rewrited as it was previously. Is it needed? */
-               ret = del_memory_hash(ptr, MEMTYPE_DELETE, &ct);
+               ret = del_memory_hash(convert_addr_to_hash(ptr), MEMTYPE_DELETE, &ct);
                if(blockresult == 0 && ret == 0 &&
                   PROBE_GET_CALL_TYPE(probe_data) == EXTERNAL_CALL)
                {
@@ -384,7 +385,7 @@ HANDLER_WRAPPERS_THROW(memory_feature, void, delete_array_nothrow, (), void *, p
        if(ptr != NULL)
        {
                /* TODO call_type rewrited as it was previously. Is it needed? */
-               ret = del_memory_hash(ptr, MEMTYPE_DELETE, &ct);
+               ret = del_memory_hash(convert_addr_to_hash(ptr), MEMTYPE_DELETE, &ct);
                if(blockresult == 0 && ret == 0 &&
                   PROBE_GET_CALL_TYPE(probe_data) == EXTERNAL_CALL)
                {