| 1 |
/** |
| 2 |
* This file contains wrapper functions for macro-defined valgrind routines. |
| 3 |
* |
| 4 |
* Copyright: Copyright: Copyright (C) D Language Foundation 2023 |
| 5 |
* License: Distributed under the |
| 6 |
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). |
| 7 |
* (See accompanying file LICENSE) |
| 8 |
* Source: $(DRUNTIMESRC etc/valgrind/valgrind.c) |
| 9 |
*/ |
| 10 |
|
| 11 |
/* NOTE: This file has been patched from the original DMD distribution to |
| 12 |
* work with the GDC compiler. |
| 13 |
*/ |
| 14 |
#include "config.h" |
| 15 |
|
| 16 |
#ifdef ENABLE_VALGRIND_CHECKING |
| 17 |
|
| 18 |
#ifdef HAVE_STDDEF_H |
| 19 |
# include <stddef.h> |
| 20 |
#endif |
| 21 |
#ifdef HAVE_STDINT_H |
| 22 |
# include <stdint.h> |
| 23 |
#endif |
| 24 |
#ifdef HAVE_INTTYPES_H |
| 25 |
# include <inttypes.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#ifdef HAVE_VALGRIND_MEMCHECK_H |
| 29 |
# include <valgrind/memcheck.h> |
| 30 |
#elif defined HAVE_MEMCHECK_H |
| 31 |
# include <memcheck.h> |
| 32 |
#else |
| 33 |
# include <valgrind.h> |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef VALGRIND_MAKE_MEM_NOACCESS |
| 37 |
# define VALGRIND_MAKE_MEM_NOACCESS VALGRIND_MAKE_NOACCESS |
| 38 |
#endif |
| 39 |
#ifndef VALGRIND_MAKE_MEM_UNDEFINED |
| 40 |
# define VALGRIND_MAKE_MEM_UNDEFINED VALGRIND_MAKE_WRITABLE |
| 41 |
#endif |
| 42 |
#ifndef VALGRIND_MAKE_MEM_DEFINED |
| 43 |
# define VALGRIND_MAKE_MEM_DEFINED VALGRIND_MAKE_READABLE |
| 44 |
#endif |
| 45 |
|
| 46 |
#ifndef VALGRIND_GET_VBITS |
| 47 |
# define VALGRIND_GET_VBITS(a,b,l) 0 |
| 48 |
#endif |
| 49 |
#ifndef VALGRIND_SET_VBITS |
| 50 |
# define VALGRIND_SET_VBITS(a,b,l) 0 |
| 51 |
#endif |
| 52 |
#ifndef VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE |
| 53 |
# define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,l) |
| 54 |
#endif |
| 55 |
#ifndef VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE |
| 56 |
# define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,l) |
| 57 |
#endif |
| 58 |
|
| 59 |
#define MAYBE_UNUSED __attribute__((unused)) |
| 60 |
|
| 61 |
void _d_valgrind_make_mem_noaccess(const void* addr, size_t len) |
| 62 |
{ |
| 63 |
VALGRIND_DISCARD(VALGRIND_MAKE_MEM_NOACCESS(addr, len)); |
| 64 |
} |
| 65 |
|
| 66 |
void _d_valgrind_make_mem_undefined(const void* addr, size_t len) |
| 67 |
{ |
| 68 |
VALGRIND_DISCARD(VALGRIND_MAKE_MEM_UNDEFINED(addr, len)); |
| 69 |
} |
| 70 |
|
| 71 |
void _d_valgrind_make_mem_defined(const void* addr, size_t len) |
| 72 |
{ |
| 73 |
VALGRIND_DISCARD(VALGRIND_MAKE_MEM_DEFINED(addr, len)); |
| 74 |
} |
| 75 |
|
| 76 |
unsigned _d_valgrind_get_vbits(const void* addr MAYBE_UNUSED, |
| 77 |
char* bits MAYBE_UNUSED, |
| 78 |
size_t len MAYBE_UNUSED) |
| 79 |
{ |
| 80 |
return VALGRIND_GET_VBITS(addr, bits, len); |
| 81 |
} |
| 82 |
|
| 83 |
unsigned _d_valgrind_set_vbits(const void* addr MAYBE_UNUSED, |
| 84 |
char* bits MAYBE_UNUSED, |
| 85 |
size_t len MAYBE_UNUSED) |
| 86 |
{ |
| 87 |
return VALGRIND_SET_VBITS(addr, bits, len); |
| 88 |
} |
| 89 |
|
| 90 |
void _d_valgrind_disable_addr_reporting_in_range(const void* addr MAYBE_UNUSED, |
| 91 |
size_t len MAYBE_UNUSED) |
| 92 |
{ |
| 93 |
VALGRIND_DISCARD(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(addr, len)); |
| 94 |
} |
| 95 |
|
| 96 |
void _d_valgrind_enable_addr_reporting_in_range(const void* addr MAYBE_UNUSED, |
| 97 |
size_t len MAYBE_UNUSED) |
| 98 |
{ |
| 99 |
VALGRIND_DISCARD(VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(addr, len)); |
| 100 |
} |
| 101 |
|
| 102 |
#endif /* ENABLE_VALGRIND_CHECKING */ |