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