Commit 7b59ec6f authored by Eugene Kosov's avatar Eugene Kosov Committed by Sergei Golubchik

MDEV-17799 Add ASAN-poisoned redzones for MEM_ROOT and mem_heap_t

This patch is for MEM_ROOT only.
In debug mode add 8 byte of poisoned memory before every allocated chunk.
On the right of every chunk there will be either 1-7 trailing poisoned bytes, or
next chunk's redzone, or poisoned non allocated memory or redzone of a
malloc()ed buffer.
parent 2c9844a4
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#ifndef _my_valgrind_h
#define _my_valgrind_h
/* clang -> gcc */ /* clang -> gcc */
#ifndef __has_feature #ifndef __has_feature
# define __has_feature(x) 0 # define __has_feature(x) 0
...@@ -49,9 +52,13 @@ ...@@ -49,9 +52,13 @@
#endif /* HAVE_VALGRIND */ #endif /* HAVE_VALGRIND */
#ifndef DBUG_OFF #ifndef DBUG_OFF
static const size_t REDZONE_SIZE= 8;
#define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0) #define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0)
#else #else
static const size_t REDZONE_SIZE= 0;
#define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0) #define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0)
#endif #endif
#define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0) #define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0)
#define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0) #define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0)
#endif /* _my_valgrind_h */
...@@ -197,7 +197,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) ...@@ -197,7 +197,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
DBUG_SET("-d,simulate_out_of_memory"); DBUG_SET("-d,simulate_out_of_memory");
DBUG_RETURN((void*) 0); /* purecov: inspected */ DBUG_RETURN((void*) 0); /* purecov: inspected */
}); });
length= ALIGN_SIZE(length); length= ALIGN_SIZE(length) + REDZONE_SIZE;
if ((*(prev= &mem_root->free)) != NULL) if ((*(prev= &mem_root->free)) != NULL)
{ {
if ((*prev)->left < length && if ((*prev)->left < length &&
...@@ -242,6 +242,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) ...@@ -242,6 +242,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
mem_root->used= next; mem_root->used= next;
mem_root->first_block_usage= 0; mem_root->first_block_usage= 0;
} }
point+= REDZONE_SIZE;
TRASH_ALLOC(point, original_length); TRASH_ALLOC(point, original_length);
DBUG_PRINT("exit",("ptr: 0x%lx", (ulong) point)); DBUG_PRINT("exit",("ptr: 0x%lx", (ulong) point));
DBUG_RETURN((void*) point); DBUG_RETURN((void*) point);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment