mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
Make useful infrastructure from aset.c generally available.
An upcoming patch introduces a new type of memory context. To avoid duplicating debugging infrastructure within aset.c, move useful pieces to memdebug.[ch]. While touching aset.c, fix printf format code in AllocFree* debug macros. Author: Tomas Vondra Reviewed-By: Andres Freund Discussion: https://postgr.es/m/b3b2245c-b37a-e1e5-ebc4-857c914bc747@2ndquadrant.com
This commit is contained in:
@@ -31,4 +31,52 @@
|
||||
#define VALGRIND_MEMPOOL_CHANGE(context, optr, nptr, size) do {} while (0)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CLOBBER_FREED_MEMORY
|
||||
|
||||
/* Wipe freed memory for debugging purposes */
|
||||
static inline void
|
||||
wipe_mem(void *ptr, size_t size)
|
||||
{
|
||||
VALGRIND_MAKE_MEM_UNDEFINED(ptr, size);
|
||||
memset(ptr, 0x7F, size);
|
||||
VALGRIND_MAKE_MEM_NOACCESS(ptr, size);
|
||||
}
|
||||
|
||||
#endif /* CLOBBER_FREED_MEMORY */
|
||||
|
||||
#ifdef MEMORY_CONTEXT_CHECKING
|
||||
|
||||
static inline void
|
||||
set_sentinel(void *base, Size offset)
|
||||
{
|
||||
char *ptr = (char *) base + offset;
|
||||
|
||||
VALGRIND_MAKE_MEM_UNDEFINED(ptr, 1);
|
||||
*ptr = 0x7E;
|
||||
VALGRIND_MAKE_MEM_NOACCESS(ptr, 1);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
sentinel_ok(const void *base, Size offset)
|
||||
{
|
||||
const char *ptr = (const char *) base + offset;
|
||||
bool ret;
|
||||
|
||||
VALGRIND_MAKE_MEM_DEFINED(ptr, 1);
|
||||
ret = *ptr == 0x7E;
|
||||
VALGRIND_MAKE_MEM_NOACCESS(ptr, 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* MEMORY_CONTEXT_CHECKING */
|
||||
|
||||
#ifdef RANDOMIZE_ALLOCATED_MEMORY
|
||||
|
||||
void randomize_mem(char *ptr, size_t size);
|
||||
|
||||
#endif /* RANDOMIZE_ALLOCATED_MEMORY */
|
||||
|
||||
|
||||
#endif /* MEMDEBUG_H */
|
||||
|
||||
Reference in New Issue
Block a user