Skip to content

Commit

Permalink
Fixed CORE-5284: Firebird fails to build with USE_VALGRIND
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPeshkoff committed Jul 11, 2016
1 parent 8962c08 commit 44e97a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion builds/posix/prefix.linux_amd64
Expand Up @@ -23,7 +23,7 @@ OPTIMIZE_FLAGS=-O3 -fno-omit-frame-pointer
WARN_FLAGS=-Wall -Wno-switch -Wno-parentheses -Wno-unknown-pragmas -Wno-unused-variable -Wno-invalid-offsetof -Wno-narrowing -Wno-unused-local-typedefs

PROD_FLAGS=$(COMMON_FLAGS) $(OPTIMIZE_FLAGS)
#DEV_FLAGS=-DUSE_VALGRIND $(COMMON_FLAGS) $(WARN_FLAGS)
#DEV_FLAGS=-DUSE_VALGRIND $(COMMON_FLAGS) $(WARN_FLAGS) -fmax-errors=8
DEV_FLAGS=$(COMMON_FLAGS) $(WARN_FLAGS) -fmax-errors=8

# This file must be compiled with SSE4.2 support
Expand Down
28 changes: 15 additions & 13 deletions src/common/classes/alloc.cpp
Expand Up @@ -77,7 +77,7 @@ static void* stopAddress = (void*) 0x2254938;
***/

#undef MEM_DEBUG
#ifdef DEBUG_GDS_ALLOC
#if defined(DEBUG_GDS_ALLOC) && !defined(USE_VALGRIND)
#define MEM_DEBUG
#endif

Expand All @@ -97,6 +97,14 @@ T absVal(T n) throw ()
}

#ifdef USE_VALGRIND
// When memory block is deallocated by user from the pool it must pass queue of this
// length before it is actually deallocated and access protection from it removed.
#define DELAYED_FREE_COUNT 1024

// When memory extent is deallocated when pool is destroying it must pass through
// queue of this length before it is actually returned to system
#define DELAYED_EXTENT_COUNT 32

// Circular FIFO buffer of read/write protected extents pending free operation
// Race protected via cache_mutex.
struct DelayedExtent
Expand Down Expand Up @@ -182,16 +190,10 @@ namespace SemiDoubleLink

#ifdef USE_VALGRIND
// Size of Valgrind red zone applied before and after memory block allocated for user
#define VALGRIND_REDZONE 0 //8
// When memory block is deallocated by user from the pool it must pass queue of this
// length before it is actually deallocated and access protection from it removed.
#define DELAYED_FREE_COUNT 1024
// When memory extent is deallocated when pool is destroying it must pass through
// queue of this length before it is actually returned to system
#define DELAYED_EXTENT_COUNT 32
#define VALGRIND_REDZONE 8
#undef MEM_DEBUG // valgrind works instead
#else
#define VALGRIND_REDZONE 8
#define VALGRIND_REDZONE 0
#endif

typedef SLONG INT32;
Expand Down Expand Up @@ -225,7 +227,7 @@ class MemHeader
const char *fileName;
#endif
#if defined(USE_VALGRIND) && (VALGRIND_REDZONE != 0)
const char mbk_valgrind_redzone[VALGRIND_REDZONE];
char mbk_valgrind_redzone[VALGRIND_REDZONE];
#endif

MemHeader(size_t size)
Expand Down Expand Up @@ -1862,7 +1864,7 @@ MemPool::~MemPool(void)
VALGRIND_DISCARD(
VALGRIND_MAKE_MEM_DEFINED(block, offsetof(MemBlock, body)));
VALGRIND_DISCARD(
VALGRIND_MAKE_WRITABLE(object, block->length));
VALGRIND_MAKE_WRITABLE(object, block->getSize()));
}
#endif

Expand Down Expand Up @@ -2102,10 +2104,10 @@ void MemPool::release(void* object, bool flagDecr) throw ()
// Remove protection from memory block
#ifdef VALGRIND_FIX_IT
VALGRIND_DISCARD(
VALGRIND_MAKE_MEM_DEFINED(object, block->length - VALGRIND_REDZONE));
VALGRIND_MAKE_MEM_DEFINED(object, block->getSize() - VALGRIND_REDZONE));
#else
VALGRIND_DISCARD(
VALGRIND_MAKE_WRITABLE(object, block->length - VALGRIND_REDZONE));
VALGRIND_MAKE_WRITABLE(object, block->getSize() - VALGRIND_REDZONE));
#endif

// Replace element in circular buffer
Expand Down

0 comments on commit 44e97a7

Please sign in to comment.