mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innodb_plugin / include / mem0dbg.h
blob1c387706c98ac1de6735f938f5283eb2e628c177
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.,
15 51 Franklin 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 */
30 #ifdef UNIV_MEM_DEBUG
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),\
39 UNIV_MEM_ALIGNMENT)
40 #define MEM_FIELD_TRAILER_SIZE sizeof(ulint)
41 #else
42 #define MEM_FIELD_HEADER_SIZE 0
43 #endif
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. */
50 #ifdef UNIV_MEM_DEBUG
51 #define MEM_SPACE_NEEDED(N) ut_calc_align((N) + MEM_FIELD_HEADER_SIZE\
52 + MEM_FIELD_TRAILER_SIZE, UNIV_MEM_ALIGNMENT)
53 #else
54 #define MEM_SPACE_NEEDED(N) ut_calc_align((N), UNIV_MEM_ALIGNMENT)
55 #endif
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
63 of blocks. */
64 UNIV_INTERN
65 void
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
74 the debug version */
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.
89 @return TRUE if ok */
90 UNIV_INTERN
91 ibool
92 mem_heap_validate(
93 /*==============*/
94 mem_heap_t* heap); /*!< in: memory heap */
95 #endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
96 #ifdef UNIV_DEBUG
97 /**************************************************************//**
98 Checks that an object is a memory heap (or a block of it)
99 @return TRUE if ok */
100 UNIV_INTERN
101 ibool
102 mem_heap_check(
103 /*===========*/
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 */
110 UNIV_INTERN
111 ibool
112 mem_all_freed(void);
113 /*===============*/
114 /*****************************************************************//**
115 Validates the dynamic memory
116 @return TRUE if error */
117 UNIV_INTERN
118 ibool
119 mem_validate_no_assert(void);
120 /*=========================*/
121 /************************************************************//**
122 Validates the dynamic memory
123 @return TRUE if ok */
124 UNIV_INTERN
125 ibool
126 mem_validate(void);
127 /*===============*/
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. */
132 UNIV_INTERN
133 void
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. */
140 UNIV_INTERN
141 void
142 mem_print_info(void);
143 /*================*/
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. */
147 UNIV_INTERN
148 void
149 mem_print_new_info(void);
150 /*====================*/