my_valgrind.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Copyright (C) 2010 Monty Program Ab
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. #ifdef HAVE_valgrind
  13. #define IF_VALGRIND(A,B) A
  14. #else
  15. #define IF_VALGRIND(A,B) B
  16. #endif
  17. #if defined(HAVE_VALGRIND) && defined(HAVE_valgrind)
  18. # include <valgrind/memcheck.h>
  19. # define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
  20. # define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
  21. # define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
  22. # define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len)
  23. #else /* HAVE_VALGRIND */
  24. # define MEM_UNDEFINED(a,len) ((void) 0)
  25. # define MEM_NOACCESS(a,len) ((void) 0)
  26. # define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
  27. # define MEM_CHECK_DEFINED(a,len) ((void) 0)
  28. #endif /* HAVE_VALGRIND */
  29. #ifndef DBUG_OFF
  30. #define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); memset(A, C, trash_tmp); MEM_UNDEFINED(A, trash_tmp); } while (0)
  31. #else
  32. #define TRASH_FILL(A,B,C) do{ const size_t trash_tmp __attribute__((unused)) = (B) ; MEM_CHECK_ADDRESSABLE(A,trash_tmp);MEM_UNDEFINED(A,trash_tmp);} while (0)
  33. #endif
  34. #define TRASH_ALLOC(A,B) TRASH_FILL(A,B,0xA5)
  35. #define TRASH_FREE(A,B) TRASH_FILL(A,B,0x8F)
  36. #define TRASH(A,B) TRASH_FREE(A,B)