1 ////////////////////////////////////////////////////////////////////////////////
3 // Visual Leak Detector - Internal C++ Heap Management Definitions
4 // Copyright (c) 2006 Dan Moulding
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 // See COPYING.txt for the full terms of the GNU Lesser General Public License.
22 ////////////////////////////////////////////////////////////////////////////////
28 "This header should only be included by Visual Leak Detector when building it from source. \
29 Applications should never include this header."
36 // Memory block header structure used internally by the debug CRT. All blocks
37 // allocated by the CRT are allocated from the CRT heap and, in debug mode, they
38 // have this header prepended to them (there's also a trailer appended at the
39 // end, but we're not interested in that).
40 typedef struct crtdbgblockheader_s
42 struct crtblockheader_s *next; // Pointer to the next block in the list of blocks allocated from the CRT heap.
43 struct crtblockheader_s *prev; // Pointer to the previous block in the list of blocks allocated from the CRT heap.
44 char *file; // Source file where this block was allocated.
45 int line; // Line of code, within the above file, where this block was allocated.
47 int use; // This block's "use type": see below.
48 size_t size; // Size of the data portion of the block.
50 size_t size; // Size of the data portion of the block.
51 int use; // This block's "use type":
53 #define CRT_USE_FREE 0 // This block has been freed.
54 #define CRT_USE_NORMAL 1 // This is a normal (user) block.
55 #define CRT_USE_INTERNAL 2 // This block is used internally by the CRT.
56 #define CRT_USE_IGNORE 3 // This block is a specially tagged block that is ignored during some debug error checking.
57 #define CRT_USE_CLIENT 4 // This block is a specially tagged block with special use defined by the user application.
58 long request; // This block's "request" number. Basically a serial number.
59 unsigned char gap [GAPSIZE]; // No-man's land buffer zone, for buffer overrun/underrun checking.
60 } crtdbgblockheader_t;
62 // Macro to strip off any sub-type information stored in a block's "use type".
63 #define CRT_USE_TYPE(use) (use & 0xFFFF)
65 // Memory block header structure used internally by VLD. All internally
66 // allocated blocks are allocated from VLD's private heap and have this header
68 typedef struct vldblockheader_s
70 struct vldblockheader_s *next; // Pointer to the next block in the list of internally allocated blocks.
71 struct vldblockheader_s *prev; // Pointer to the preceding block in the list of internally allocated blocks.
72 const char *file; // Name of the file where this block was allocated.
73 int line; // Line number within the above file where this block was allocated.
74 size_t size; // The size of this memory block, not including this header.
75 SIZE_T serialnumber; // Each block is assigned a unique serial number, starting from zero.
78 // Data-to-Header and Header-to-Data conversion
79 #define CRTDBGBLOCKHEADER(d) (crtdbgblockheader_t*)(((PBYTE)d) - sizeof(crtdbgblockheader_t))
80 #define CRTDBGBLOCKDATA(h) (LPVOID)(((PBYTE)h) + sizeof(crtdbgblockheader_t))
81 #define VLDBLOCKHEADER(d) (vldblockheader_t*)(((PBYTE)d) - sizeof(vldblockheader_t))
82 #define VLDBLOCKDATA(h) (LPVOID)(((PBYTE)h) + sizeof(vldblockheader_t))
84 // new and delete operators for allocating from VLD's private heap.
85 void operator delete (void *block);
86 void operator delete [] (void *block);
87 void operator delete (void *block, const char *file, int line);
88 void operator delete [] (void *block, const char *file, int line);
89 void* operator new (size_t size, const char *file, int line);
90 void* operator new [] (size_t size, const char *file, int line);
92 // All calls to the new operator from within VLD are mapped to the version of
93 // new that allocates from VLD's private heap.
94 #define new new(__FILE__, __LINE__)