1
/*****************************************************************************
3
Copyright (C) 1994, 2010, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/mem0dbg.h
21
The memory management: the debug code. This is not a compilation module,
22
but is included in mem0mem.* !
24
Created 6/9/1994 Heikki Tuuri
25
*******************************************************/
27
/* In the debug version each allocated field is surrounded with
28
check fields whose sizes are given below */
31
# ifndef UNIV_HOTBACKUP
32
/* The mutex which protects in the debug version the hash table
33
containing the list of live memory heaps, and also the global
34
variables in mem0dbg.c. */
35
extern mutex_t mem_hash_mutex;
36
# endif /* !UNIV_HOTBACKUP */
38
#define MEM_FIELD_HEADER_SIZE ut_calc_align(2 * sizeof(ulint),\
40
#define MEM_FIELD_TRAILER_SIZE sizeof(ulint)
42
#define MEM_FIELD_HEADER_SIZE 0
46
/* Space needed when allocating for a user a field of
47
length N. The space is allocated only in multiples of
48
UNIV_MEM_ALIGNMENT. In the debug version there are also
49
check fields at the both ends of the field. */
51
#define MEM_SPACE_NEEDED(N) ut_calc_align((N) + MEM_FIELD_HEADER_SIZE\
52
+ MEM_FIELD_TRAILER_SIZE, UNIV_MEM_ALIGNMENT)
54
#define MEM_SPACE_NEEDED(N) ut_calc_align((N), UNIV_MEM_ALIGNMENT)
57
#if defined UNIV_MEM_DEBUG || defined UNIV_DEBUG
58
/***************************************************************//**
59
Checks a memory heap for consistency and prints the contents if requested.
60
Outputs the sum of sizes of buffers given to the user (only in
61
the debug version), the physical size of the heap and the number of
62
blocks in the heap. In case of error returns 0 as sizes and number
66
mem_heap_validate_or_print(
67
/*=======================*/
68
mem_heap_t* heap, /*!< in: memory heap */
69
byte* top, /*!< in: calculate and validate only until
70
this top pointer in the heap is reached,
71
if this pointer is NULL, ignored */
72
ibool print, /*!< in: if TRUE, prints the contents
73
of the heap; works only in
75
ibool* error, /*!< out: TRUE if error */
76
ulint* us_size,/*!< out: allocated memory
77
(for the user) in the heap,
78
if a NULL pointer is passed as this
79
argument, it is ignored; in the
80
non-debug version this is always -1 */
81
ulint* ph_size,/*!< out: physical size of the heap,
82
if a NULL pointer is passed as this
83
argument, it is ignored */
84
ulint* n_blocks); /*!< out: number of blocks in the heap,
85
if a NULL pointer is passed as this
86
argument, it is ignored */
87
/**************************************************************//**
88
Validates the contents of a memory heap.
94
mem_heap_t* heap); /*!< in: memory heap */
95
#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
97
/**************************************************************//**
98
Checks that an object is a memory heap (or a block of it)
104
mem_heap_t* heap); /*!< in: memory heap */
105
#endif /* UNIV_DEBUG */
106
#ifdef UNIV_MEM_DEBUG
107
/*****************************************************************//**
108
TRUE if no memory is currently allocated.
109
@return TRUE if no heaps exist */
114
/*****************************************************************//**
115
Validates the dynamic memory
116
@return TRUE if error */
119
mem_validate_no_assert(void);
120
/*=========================*/
121
/************************************************************//**
122
Validates the dynamic memory
123
@return TRUE if ok */
128
#endif /* UNIV_MEM_DEBUG */
129
/************************************************************//**
130
Tries to find neigboring memory allocation blocks and dumps to stderr
131
the neighborhood of a given pointer. */
134
mem_analyze_corruption(
135
/*===================*/
136
void* ptr); /*!< in: pointer to place of possible corruption */
137
/*****************************************************************//**
138
Prints information of dynamic memory usage and currently allocated memory
139
heaps or buffers. Can only be used in the debug version. */
142
mem_print_info(void);
144
/*****************************************************************//**
145
Prints information of dynamic memory usage and currently allocated memory
146
heaps or buffers since the last ..._print_info or..._print_new_info. */
149
mem_print_new_info(void);
150
/*====================*/