MySQL 9.1.0
Source Code Documentation
memory_debugging.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MEMORY_DEBUGGING_INCLUDED
25#define MEMORY_DEBUGGING_INCLUDED
26
27/**
28 @file memory_debugging.h
29
30 Various macros useful for communicating with memory debuggers,
31 such as Valgrind.
32*/
33
34#include <string.h>
35
36#ifdef HAVE_VALGRIND
37#include <valgrind/valgrind.h>
38
39#define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) \
40 VALGRIND_MALLOCLIKE_BLOCK(p1, p2, p3, p4)
41#define MEM_FREELIKE_BLOCK(p1, p2) VALGRIND_FREELIKE_BLOCK(p1, p2)
42#include <valgrind/memcheck.h>
43
44#define MEM_UNDEFINED(a, len) VALGRIND_MAKE_MEM_UNDEFINED(a, len)
45#define MEM_DEFINED_IF_ADDRESSABLE(a, len) \
46 VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(a, len)
47#define MEM_NOACCESS(a, len) VALGRIND_MAKE_MEM_NOACCESS(a, len)
48#define MEM_CHECK_ADDRESSABLE(a, len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a, len)
49
50#else /* HAVE_VALGRIND */
51
52#define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) \
53 do { \
54 } while (0)
55#define MEM_FREELIKE_BLOCK(p1, p2) \
56 do { \
57 } while (0)
58#define MEM_UNDEFINED(a, len) ((void)0)
59#define MEM_DEFINED_IF_ADDRESSABLE(a, len) ((void)0)
60#define MEM_NOACCESS(a, len) ((void)0)
61#define MEM_CHECK_ADDRESSABLE(a, len) ((void)0)
62
63#endif
64
65#if !defined(NDEBUG) || defined(HAVE_VALGRIND)
66
67/**
68 Put bad content in memory to be sure it will segfault if dereferenced.
69 With Valgrind, verify that memory is addressable, and mark it undefined.
70*/
71inline void TRASH(void *ptr, size_t length) {
73 memset(ptr, 0x8F, length);
75}
76
77#else
78
79inline void TRASH(void *, size_t) {}
80
81#endif
82
83#endif // MEMORY_DEBUGGING_INCLUDED
#define MEM_CHECK_ADDRESSABLE(a, len)
Definition: memory_debugging.h:61
void TRASH(void *ptr, size_t length)
Put bad content in memory to be sure it will segfault if dereferenced.
Definition: memory_debugging.h:71
#define MEM_UNDEFINED(a, len)
Definition: memory_debugging.h:58
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:76