~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
4
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.
8
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.
12
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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
19
/******************************************************
20
The memory management: the debug code. This is not a compilation module,
21
but is included in mem0mem.* !
22
23
Created 6/9/1994 Heikki Tuuri
24
*******************************************************/
25
26
/* In the debug version each allocated field is surrounded with
27
check fields whose sizes are given below */
28
29
#ifdef UNIV_MEM_DEBUG
30
#define MEM_FIELD_HEADER_SIZE	ut_calc_align(2 * sizeof(ulint),\
31
						UNIV_MEM_ALIGNMENT)
32
#define MEM_FIELD_TRAILER_SIZE	sizeof(ulint)
33
#else
34
#define MEM_FIELD_HEADER_SIZE	0
35
#endif
36
37
38
/* Space needed when allocating for a user a field of
39
length N. The space is allocated only in multiples of
40
UNIV_MEM_ALIGNMENT. In the debug version there are also
41
check fields at the both ends of the field. */
42
#ifdef UNIV_MEM_DEBUG
43
#define MEM_SPACE_NEEDED(N) ut_calc_align((N) + MEM_FIELD_HEADER_SIZE\
44
		 + MEM_FIELD_TRAILER_SIZE, UNIV_MEM_ALIGNMENT)
45
#else
46
#define MEM_SPACE_NEEDED(N) ut_calc_align((N), UNIV_MEM_ALIGNMENT)
47
#endif
48
49
#if defined UNIV_MEM_DEBUG || defined UNIV_DEBUG
50
/*******************************************************************
51
Checks a memory heap for consistency and prints the contents if requested.
52
Outputs the sum of sizes of buffers given to the user (only in
53
the debug version), the physical size of the heap and the number of
54
blocks in the heap. In case of error returns 0 as sizes and number
55
of blocks. */
56
UNIV_INTERN
57
void
58
mem_heap_validate_or_print(
59
/*=======================*/
60
	mem_heap_t*	heap,	/* in: memory heap */
61
	byte*		top,	/* in: calculate and validate only until
62
				this top pointer in the heap is reached,
63
				if this pointer is NULL, ignored */
64
	ibool		 print,	 /* in: if TRUE, prints the contents
65
				of the heap; works only in
66
				the debug version */
67
	ibool*		 error,	 /* out: TRUE if error */
68
	ulint*		us_size,/* out: allocated memory
69
				(for the user) in the heap,
70
				if a NULL pointer is passed as this
71
				argument, it is ignored; in the
72
				non-debug version this is always -1 */
73
	ulint*		ph_size,/* out: physical size of the heap,
74
				if a NULL pointer is passed as this
75
				argument, it is ignored */
76
	ulint*		n_blocks); /* out: number of blocks in the heap,
77
				if a NULL pointer is passed as this
78
				argument, it is ignored */
79
/******************************************************************
80
Validates the contents of a memory heap. */
81
UNIV_INTERN
82
ibool
83
mem_heap_validate(
84
/*==============*/
85
				/* out: TRUE if ok */
86
	mem_heap_t*   heap);	/* in: memory heap */
87
#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
88
#ifdef UNIV_DEBUG
89
/******************************************************************
90
Checks that an object is a memory heap (or a block of it) */
91
UNIV_INTERN
92
ibool
93
mem_heap_check(
94
/*===========*/
95
				/* out: TRUE if ok */
96
	mem_heap_t*   heap);	/* in: memory heap */
97
#endif /* UNIV_DEBUG */
98
#ifdef UNIV_MEM_DEBUG
99
/*********************************************************************
100
TRUE if no memory is currently allocated. */
101
UNIV_INTERN
102
ibool
103
mem_all_freed(void);
104
/*===============*/
105
			/* out: TRUE if no heaps exist */
106
/*********************************************************************
107
Validates the dynamic memory */
108
UNIV_INTERN
109
ibool
110
mem_validate_no_assert(void);
111
/*=========================*/
112
			/* out: TRUE if error */
113
/****************************************************************
114
Validates the dynamic memory */
115
UNIV_INTERN
116
ibool
117
mem_validate(void);
118
/*===============*/
119
			/* out: TRUE if ok */
120
#endif /* UNIV_MEM_DEBUG */
121
/****************************************************************
122
Tries to find neigboring memory allocation blocks and dumps to stderr
123
the neighborhood of a given pointer. */
124
UNIV_INTERN
125
void
126
mem_analyze_corruption(
127
/*===================*/
128
	void*	ptr);	/* in: pointer to place of possible corruption */
129
/*********************************************************************
130
Prints information of dynamic memory usage and currently allocated memory
131
heaps or buffers. Can only be used in the debug version. */
132
UNIV_INTERN
133
void
134
mem_print_info(void);
135
/*================*/
136
/*********************************************************************
137
Prints information of dynamic memory usage and currently allocated memory
138
heaps or buffers since the last ..._print_info or..._print_new_info. */
139
UNIV_INTERN
140
void
141
mem_print_new_info(void);
142
/*====================*/