MySQL 8.0.29
Source Code Documentation
memory_debugging.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MEMORY_DEBUGGING_INCLUDED
24#define MEMORY_DEBUGGING_INCLUDED
25
26/**
27 @file memory_debugging.h
28
29 Various macros useful for communicating with memory debuggers,
30 such as Valgrind.
31*/
32
33#include <string.h>
34
35#ifdef HAVE_VALGRIND
36#include <valgrind/valgrind.h>
37
38#define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) \
39 VALGRIND_MALLOCLIKE_BLOCK(p1, p2, p3, p4)
40#define MEM_FREELIKE_BLOCK(p1, p2) VALGRIND_FREELIKE_BLOCK(p1, p2)
41#include <valgrind/memcheck.h>
42
43#define MEM_UNDEFINED(a, len) VALGRIND_MAKE_MEM_UNDEFINED(a, len)
44#define MEM_DEFINED_IF_ADDRESSABLE(a, len) \
45 VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(a, len)
46#define MEM_NOACCESS(a, len) VALGRIND_MAKE_MEM_NOACCESS(a, len)
47#define MEM_CHECK_ADDRESSABLE(a, len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a, len)
48
49#else /* HAVE_VALGRIND */
50
51#define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) \
52 do { \
53 } while (0)
54#define MEM_FREELIKE_BLOCK(p1, p2) \
55 do { \
56 } while (0)
57#define MEM_UNDEFINED(a, len) ((void)0)
58#define MEM_DEFINED_IF_ADDRESSABLE(a, len) ((void)0)
59#define MEM_NOACCESS(a, len) ((void)0)
60#define MEM_CHECK_ADDRESSABLE(a, len) ((void)0)
61
62#endif
63
64#if !defined(NDEBUG) || defined(HAVE_VALGRIND)
65
66/**
67 Put bad content in memory to be sure it will segfault if dereferenced.
68 With Valgrind, verify that memory is addressable, and mark it undefined.
69*/
70inline void TRASH(void *ptr, size_t length) {
72 memset(ptr, 0x8F, length);
74}
75
76#else
77
78inline void TRASH(void *, size_t) {}
79
80#endif
81
82#endif // MEMORY_DEBUGGING_INCLUDED
#define MEM_CHECK_ADDRESSABLE(a, len)
Definition: memory_debugging.h:60
void TRASH(void *ptr, size_t length)
Put bad content in memory to be sure it will segfault if dereferenced.
Definition: memory_debugging.h:70
#define MEM_UNDEFINED(a, len)
Definition: memory_debugging.h:57
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75