-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbgint.h
236 lines (179 loc) · 6.08 KB
/
dbgint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/***
*dbgint.h - Supports debugging features of the C runtime library.
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Support CRT debugging features.
*
* [Internal]
*
****/
#if _MSC_VER > 1000
#pragma once
#endif /* _MSC_VER > 1000 */
#ifndef _INC_DBGINT
#define _INC_DBGINT
#ifndef _CRTBLD
/*
* This is an internal C runtime header file. It is used when building
* the C runtimes only. It is not to be used as a public header file.
*/
#error ERROR: Use of C runtime library internal header file.
#endif /* _CRTBLD */
#include <crtdbg.h>
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#ifndef _DEBUG
/****************************************************************************
*
* Debug OFF
* Debug OFF
* Debug OFF
*
***************************************************************************/
#ifdef __cplusplus
#define _new_crt new
#endif /* __cplusplus */
#define _malloc_crt malloc
#define _calloc_crt calloc
#define _realloc_crt realloc
#define _expand_crt _expand
#define _free_crt free
#define _msize_crt _msize
#define _malloc_base malloc
#define _nh_malloc_base _nh_malloc
#define _nh_malloc_dbg(s, n, t, f, l) _nh_malloc(s, n)
#define _heap_alloc_base _heap_alloc
#define _heap_alloc_dbg(s, t, f, l) _heap_alloc(s)
#define _calloc_base calloc
#define _realloc_base realloc
#define _expand_base _expand
#define _free_base free
#define _msize_base _msize
#define _aligned_malloc_base _aligned_malloc
#define _aligned_realloc_base _aligned_realloc
#define _aligned_offset_malloc_base _aligned_offset_malloc
#define _aligned_offset_realloc_base _aligned_offset_realloc
#define _aligned_free_base _aligned_free
#ifdef _MT
#define _calloc_dbg_lk(c, s, t, f, l) _calloc_lk(c, s)
#define _realloc_dbg_lk(p, s, t, f, l) _realloc_lk(p, s)
#define _free_base_lk _free_lk
#define _free_dbg_lk(p, t) _free_lk(p)
#else /* _MT */
#define _calloc_dbg_lk(c, s, t, f, l) calloc(c, s)
#define _realloc_dbg_lk(p, s, t, f, l) realloc(p, s)
#define _free_base_lk free
#define _free_dbg_lk(p, t) free(p)
#endif /* _MT */
#else /* _DEBUG */
/****************************************************************************
*
* Debug ON
* Debug ON
* Debug ON
*
***************************************************************************/
#define _THISFILE __FILE__
#ifdef __cplusplus
#define _new_crt new (_CRT_BLOCK, _THISFILE, __LINE__)
#endif /* __cplusplus */
#define _malloc_crt(s) _malloc_dbg(s, _CRT_BLOCK, _THISFILE, __LINE__)
#define _calloc_crt(c, s) _calloc_dbg(c, s, _CRT_BLOCK, _THISFILE, __LINE__)
#define _realloc_crt(p, s) _realloc_dbg(p, s, _CRT_BLOCK, _THISFILE, __LINE__)
#define _expand_crt(p, s) _expand_dbg(p, s, _CRT_BLOCK)
#define _free_crt(p) _free_dbg(p, _CRT_BLOCK)
#define _msize_crt(p) _msize_dbg(p, _CRT_BLOCK)
/*
* Prototypes for malloc, free, realloc, etc are in malloc.h
*/
/*void * __cdecl _malloc_base(
size_t
);
*/
void *__cdecl _nh_malloc_base(size_t, int);
void *__cdecl _nh_malloc_dbg(size_t, int, int, const char *, int);
void *__cdecl _heap_alloc_base(size_t);
void *__cdecl _heap_alloc_dbg(size_t, int, const char *, int);
/*void * __cdecl _calloc_base(
size_t,
size_t
);
void * __cdecl _realloc_base(
void *,
size_t
);
*/
void *__cdecl _expand_base(void *, size_t);
/*void __cdecl _free_base(
void *
);
size_t __cdecl _msize_base (
void *
);
*/
void __cdecl _aligned_free_base(void *);
void *__cdecl _aligned_malloc_base(size_t, size_t);
void *__cdecl _aligned_offset_malloc_base(size_t, size_t, size_t);
void *__cdecl _aligned_realloc_base(void *, size_t, size_t);
void *__cdecl _aligned_offset_realloc_base(void *, size_t, size_t, size_t);
#ifdef _MT
/*
* Prototypes and macros for multi-thread support
*/
void *__cdecl _calloc_dbg_lk(size_t, size_t, int, char *, int);
void *__cdecl _realloc_dbg_lk(void *, size_t, int, const char *, int);
void __cdecl _free_base_lk(void *);
void __cdecl _free_dbg_lk(void *, int);
#else /* _MT */
#define _calloc_dbg_lk _calloc_dbg
#define _realloc_dbg_lk _realloc_dbg
#define _free_base_lk _free_base
#define _free_dbg_lk _free_dbg
#endif /* _MT */
/*
* For diagnostic purpose, blocks are allocated with extra information and
* stored in a doubly-linked list. This makes all blocks registered with
* how big they are, when they were allocated, and what they are used for.
*/
#define nNoMansLandSize 4
typedef struct _CrtMemBlockHeader
{
struct _CrtMemBlockHeader *pBlockHeaderNext;
struct _CrtMemBlockHeader *pBlockHeaderPrev;
char *szFileName;
int nLine;
#ifdef _WIN64
/* These items are reversed on Win64 to eliminate gaps in the struct
* and ensure that sizeof(struct)%16 == 0, so 16-byte alignment is
* maintained in the debug heap.
*/
int nBlockUse;
size_t nDataSize;
#else /* _WIN64 */
size_t nDataSize;
int nBlockUse;
#endif /* _WIN64 */
long lRequest;
unsigned char gap[nNoMansLandSize];
/* followed by:
* unsigned char data[nDataSize];
* unsigned char anotherGap[nNoMansLandSize];
*/
} _CrtMemBlockHeader;
#define pbData(pblock) ((unsigned char *)((_CrtMemBlockHeader *)pblock + 1))
#define pHdr(pbData) (((_CrtMemBlockHeader *)pbData) - 1)
_CRTIMP void __cdecl _CrtSetDbgBlockType(void *, int);
#define _BLOCK_TYPE_IS_VALID(use) \
(_BLOCK_TYPE(use) == _CLIENT_BLOCK || (use) == _NORMAL_BLOCK || _BLOCK_TYPE(use) == _CRT_BLOCK || \
(use) == _IGNORE_BLOCK)
extern _CRT_ALLOC_HOOK _pfnAllocHook; /* defined in dbghook.c */
int __cdecl _CrtDefaultAllocHook(int, void *, size_t, int, long, const unsigned char *, int);
#endif /* _DEBUG */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _INC_DBGINT */