Skip to content
Permalink
Browse files

MDEV-19471 Add ASAN-poisoned redzones for mem_heap_t

Store REDZONE_SIZE poined bytes before every allocated chunk of memory
  • Loading branch information...
kevgs committed Jul 19, 2019
1 parent d9dcb8b commit 53a3594b909a16dd57fa760ab6f729f0b7a19f41
Showing with 9 additions and 4 deletions.
  1. +1 −1 storage/innobase/include/mem0mem.h
  2. +7 −2 storage/innobase/include/mem0mem.ic
  3. +1 −1 storage/innobase/log/log0recv.cc
@@ -73,7 +73,7 @@ allocations of small buffers. */

/** If a memory heap is allowed to grow into the buffer pool, the following
is the maximum size for a single allocated buffer: */
#define MEM_MAX_ALLOC_IN_BUF (UNIV_PAGE_SIZE - 200)
#define MEM_MAX_ALLOC_IN_BUF (UNIV_PAGE_SIZE - 200 + REDZONE_SIZE)

/** Space needed when allocating for a user a field of length N.
The space is allocated only in multiples of UNIV_MEM_ALIGNMENT. */
@@ -183,13 +183,15 @@ mem_heap_alloc(
ulint n)
{
mem_block_t* block;
void* buf;
byte* buf;
ulint free;

ut_d(mem_block_validate(heap));

block = UT_LIST_GET_LAST(heap->base);

n += REDZONE_SIZE;

ut_ad(!(block->type & MEM_HEAP_BUFFER) || (n <= MEM_MAX_ALLOC_IN_BUF));

/* Check if there is enough space in block. If not, create a new
@@ -212,7 +214,8 @@ mem_heap_alloc(

mem_block_set_free(block, free + MEM_SPACE_NEEDED(n));

UNIV_MEM_ALLOC(buf, n);
buf = buf + REDZONE_SIZE;
UNIV_MEM_ALLOC(buf, n - REDZONE_SIZE);
return(buf);
}

@@ -341,6 +344,8 @@ mem_heap_free_top(

ut_d(mem_block_validate(heap));

n += REDZONE_SIZE;

block = UT_LIST_GET_LAST(heap->base);

/* Subtract the free field of block */
@@ -61,7 +61,7 @@ Created 9/20/1997 Heikki Tuuri

/** Log records are stored in the hash table in chunks at most of this size;
this must be less than UNIV_PAGE_SIZE as it is stored in the buffer pool */
#define RECV_DATA_BLOCK_SIZE (MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t))
#define RECV_DATA_BLOCK_SIZE (MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t) - REDZONE_SIZE)

/** Read-ahead area in applying log records to file pages */
#define RECV_READ_AHEAD_AREA 32

0 comments on commit 53a3594

Please sign in to comment.
You can’t perform that action at this time.