]> git.lyx.org Git - lyx.git/blob - development/Win32/vld/src/crtmfcpatch.h
visual leak detector: update add patch for msvc10
[lyx.git] / development / Win32 / vld / src / crtmfcpatch.h
1 ////////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //  Visual Leak Detector - CRT and MFC IAT Patch Functions Header\r
4 //  Copyright (c) 2009 Dan Moulding\r
5 //\r
6 //  This library is free software; you can redistribute it and/or\r
7 //  modify it under the terms of the GNU Lesser General Public\r
8 //  License as published by the Free Software Foundation; either\r
9 //  version 2.1 of the License, or (at your option) any later version.\r
10 //\r
11 //  This library is distributed in the hope that it will be useful,\r
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
14 //  Lesser General Public License for more details.\r
15 //\r
16 //  You should have received a copy of the GNU Lesser General Public\r
17 //  License along with this library; if not, write to the Free Software\r
18 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
19 //\r
20 //  See COPYING.txt for the full terms of the GNU Lesser General Public License.\r
21 //\r
22 ////////////////////////////////////////////////////////////////////////////////\r
23 \r
24 #pragma once\r
25 \r
26 #ifndef VLDBUILD\r
27 #error \\r
28 "This header should only be included by Visual Leak Detector when building it from source. \\r
29 Applications should never include this header."\r
30 #endif\r
31 \r
32 #include "vldint.h"\r
33 extern __declspec(dllexport) VisualLeakDetector vld;\r
34 \r
35 #define TEMPLATE_HEADER \\r
36 template<wchar_t const *crtddll, wchar_t const *mfcddll, wchar_t const *mfcuddll,\\r
37     char const *crtd_vector_new_name, char const *crtd_vector_new_dbg_name,\\r
38     char const *crtd_scalar_new_name, char const *crtd_scalar_new_dbg_name,\\r
39     int mfcd_vector_new_ordinal, int mfcd_vector_new_dbg_4p_ordinal, int mfcd_vector_new_dbg_3p_ordinal,\\r
40     int mfcd_scalar_new_ordinal, int mfcd_scalar_new_dbg_4p_ordinal, int mfcd_scalar_new_dbg_3p_ordinal,\\r
41     int mfcud_vector_new_ordinal, int mfcud_vector_new_dbg_4p_ordinal, int mfcud_vector_new_dbg_3p_ordinal,\\r
42     int mfcud_scalar_new_ordinal, int mfcud_scalar_new_dbg_4p_ordinal, int mfcud_scalar_new_dbg_3p_ordinal>\r
43 \r
44 #define TEMPLATE_ARGS \\r
45     crtddll, mfcddll, mfcuddll,\\r
46     crtd_vector_new_name, crtd_vector_new_dbg_name,\\r
47     crtd_scalar_new_name, crtd_scalar_new_dbg_name,\\r
48     mfcd_vector_new_ordinal, mfcd_vector_new_dbg_4p_ordinal, mfcd_vector_new_dbg_3p_ordinal,\\r
49     mfcd_scalar_new_ordinal, mfcd_scalar_new_dbg_4p_ordinal, mfcd_scalar_new_dbg_3p_ordinal,\\r
50     mfcud_vector_new_ordinal, mfcud_vector_new_dbg_4p_ordinal, mfcud_vector_new_dbg_3p_ordinal,\\r
51     mfcud_scalar_new_ordinal, mfcud_scalar_new_dbg_4p_ordinal, mfcud_scalar_new_dbg_3p_ordinal\r
52 \r
53 TEMPLATE_HEADER\r
54 class CrtMfcPatch\r
55 {\r
56 public:\r
57     static void* __cdecl crtd__calloc_dbg (size_t num, size_t size, int type, char const *file, int line);\r
58     static void* __cdecl crtd__malloc_dbg (size_t size, int type, const char *file, int line);\r
59     static void* __cdecl crtd__realloc_dbg (void *mem, size_t size, int type, char const *file, int line);\r
60     static void* __cdecl crtd__scalar_new_dbg (size_t size, int type, char const *file, int line);\r
61     static void* __cdecl crtd__vector_new_dbg (size_t size, int type, char const *file, int line);\r
62     static void* __cdecl crtd_calloc (size_t num, size_t size);\r
63     static void* __cdecl crtd_malloc (size_t size);\r
64     static void* __cdecl crtd_realloc (void *mem, size_t size);\r
65     static void* __cdecl crtd_scalar_new (size_t size);\r
66     static void* __cdecl crtd_vector_new (size_t size);\r
67 \r
68     template<char const *procname>\r
69     static void* __cdecl crtd_new_dbg (SIZE_T fp, size_t size, int type, char const *file, int line);\r
70     template<char const *procname>\r
71     static void* __cdecl crtd_new (SIZE_T fp, size_t size);\r
72 \r
73     static void* __cdecl mfcd_vector_new (size_t size);\r
74     static void* __cdecl mfcd__vector_new_dbg_4p (size_t size, int type, char const *file, int line);\r
75     static void* __cdecl mfcd__vector_new_dbg_3p (size_t size, char const *file, int line);\r
76     static void* __cdecl mfcd_scalar_new (size_t size);\r
77     static void* __cdecl mfcd__scalar_new_dbg_4p (size_t size, int type, char const *file, int line);\r
78     static void* __cdecl mfcd__scalar_new_dbg_3p (size_t size, char const *file, int line);\r
79     static void* __cdecl mfcud_vector_new (size_t size);\r
80     static void* __cdecl mfcud__vector_new_dbg_4p (size_t size, int type, char const *file, int line);\r
81     static void* __cdecl mfcud__vector_new_dbg_3p (size_t size, char const *file, int line);\r
82     static void* __cdecl mfcud_scalar_new (size_t size);\r
83     static void* __cdecl mfcud__scalar_new_dbg_4p (size_t size, int type, char const *file, int line);\r
84     static void* __cdecl mfcud__scalar_new_dbg_3p (size_t size, char const *file, int line);\r
85 \r
86     template<wchar_t const *mfcdll, int ordinal>\r
87     static void* __cdecl mfcd_new_dbg (SIZE_T fp, size_t size, int type, char const *file, int line);\r
88     template<wchar_t const *mfcdll, int ordinal>\r
89     static void* __cdecl mfcd_new_dbg (SIZE_T fp, size_t size, char const *file, int line);\r
90     template<wchar_t const *mfcdll, int ordinal>\r
91     static void* __cdecl mfcd_new (SIZE_T fp, size_t size);\r
92 };\r
93 \r
94 \r
95 ////////////////////////////////////////////////////////////////////////////////\r
96 //\r
97 // Visual Studio DLLs\r
98 //\r
99 ////////////////////////////////////////////////////////////////////////////////\r
100 \r
101 // crtd__calloc_dbg - Calls to _calloc_dbg from msvcrXXd.dll are patched\r
102 //   through to this function.\r
103 //\r
104 //  - mem (IN): Pointer to the memory block to be reallocated.\r
105 //\r
106 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
107 //\r
108 //  - type (IN): The CRT "use type" of the block to be allocated.\r
109 //\r
110 //  - file (IN): The name of the file from which this function is being called.\r
111 //\r
112 //  - line (IN): The line number, in the above file, at which this function is\r
113 //      being called.\r
114 //\r
115 //  Return Value:\r
116 //\r
117 //    Returns the value returned by _calloc_dbg.\r
118 //\r
119 TEMPLATE_HEADER\r
120 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__calloc_dbg (size_t      num,\r
121                                                     size_t      size,\r
122                                                     int         type,\r
123                                                     char const *file,\r
124                                                     int         line)\r
125 {\r
126     static _calloc_dbg_t pcrtxxd__calloc_dbg = NULL;\r
127 \r
128     SIZE_T  fp;\r
129     HMODULE msvcrxxd;\r
130 \r
131     FRAMEPOINTER(fp);\r
132 \r
133     if (pcrtxxd__calloc_dbg == NULL) {\r
134         // This is the first call to this function. Link to the real\r
135         // _calloc_dbg.\r
136         msvcrxxd = GetModuleHandle(crtddll);\r
137         pcrtxxd__calloc_dbg = (_calloc_dbg_t)GetProcAddress(msvcrxxd, "_calloc_dbg");\r
138     }\r
139 \r
140     return vld.__calloc_dbg(pcrtxxd__calloc_dbg, fp, num, size, type, file, line);\r
141 }\r
142 \r
143 // crtd__malloc_dbg - Calls to _malloc_dbg from msvcrXXd.dll are patched\r
144 //   through to this function.\r
145 //\r
146 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
147 //\r
148 //  - type (IN): The CRT "use type" of the block to be allocated.\r
149 //\r
150 //  - file (IN): The name of the file from which this function is being called.\r
151 //\r
152 //  - line (IN): The line number, in the above file, at which this function is\r
153 //      being called.\r
154 //\r
155 //  Return Value:\r
156 //\r
157 //    Returns the value returned by _malloc_dbg.\r
158 //\r
159 TEMPLATE_HEADER\r
160 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__malloc_dbg (size_t      size,\r
161                                                     int         type,\r
162                                                     char const *file,\r
163                                                     int         line)\r
164 {\r
165     static _malloc_dbg_t pcrtxxd__malloc_dbg = NULL;\r
166 \r
167     SIZE_T  fp;\r
168     HMODULE msvcrxxd;\r
169 \r
170     FRAMEPOINTER(fp);\r
171 \r
172     if (pcrtxxd__malloc_dbg == NULL) {\r
173         // This is the first call to this function. Link to the real\r
174         // _malloc_dbg.\r
175         msvcrxxd = GetModuleHandle(crtddll);\r
176         pcrtxxd__malloc_dbg = (_malloc_dbg_t)GetProcAddress(msvcrxxd, "_malloc_dbg");\r
177     }\r
178 \r
179     return vld.__malloc_dbg(pcrtxxd__malloc_dbg, fp, size, type, file, line);\r
180 }\r
181 \r
182 // crtd__realloc_dbg - Calls to _realloc_dbg from msvcrXXd.dll are patched\r
183 //   through to this function.\r
184 //\r
185 //  - mem (IN): Pointer to the memory block to be reallocated.\r
186 //\r
187 //  - size (IN): The size of the memory block to reallocate.\r
188 //\r
189 //  - type (IN): The CRT "use type" of the block to be reallocated.\r
190 //\r
191 //  - file (IN): The name of the file from which this function is being called.\r
192 //\r
193 //  - line (IN): The line number, in the above file, at which this function is\r
194 //      being called.\r
195 //\r
196 //  Return Value:\r
197 //\r
198 //    Returns the value returned by _realloc_dbg.\r
199 //\r
200 TEMPLATE_HEADER\r
201 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__realloc_dbg (void       *mem,\r
202                                                      size_t     size,\r
203                                                      int        type,\r
204                                                      char const *file,\r
205                                                      int        line)\r
206 {\r
207     static _realloc_dbg_t pcrtxxd__realloc_dbg = NULL;\r
208 \r
209     SIZE_T fp;\r
210     HMODULE msvcrxxd;\r
211 \r
212     FRAMEPOINTER(fp);\r
213 \r
214     if (pcrtxxd__realloc_dbg == NULL) {\r
215         // This is the first call to this function. Link to the real\r
216         // _realloc_dbg.\r
217         msvcrxxd = GetModuleHandle(crtddll);\r
218         pcrtxxd__realloc_dbg = (_realloc_dbg_t)GetProcAddress(msvcrxxd, "_realloc_dbg");\r
219     }\r
220 \r
221     return vld.__realloc_dbg(pcrtxxd__realloc_dbg, fp, mem, size, type, file, line);\r
222 }\r
223 \r
224 // crtd__scalar_new_dbg - Calls to the CRT's debug scalar new operator from\r
225 //   msvcrXXd.dll are patched through to this function.\r
226 //\r
227 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
228 //\r
229 //  - type (IN): The CRT "use type" of the block to be allocated.\r
230 //\r
231 //  - file (IN): The name of the file from which this function is being called.\r
232 //\r
233 //  - line (IN): The line number, in the above file, at which this function is\r
234 //      being called.\r
235 //\r
236 //  Return Value:\r
237 //\r
238 //    Returns the value returned by the CRT debug scalar new operator.\r
239 //\r
240 TEMPLATE_HEADER\r
241 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__scalar_new_dbg (size_t      size,\r
242                                                         int         type,\r
243                                                         char const *file,\r
244                                                         int         line)\r
245 {\r
246     SIZE_T  fp;\r
247     FRAMEPOINTER(fp);\r
248 \r
249     return crtd_new_dbg<crtd_scalar_new_dbg_name>(fp, size, type, file, line);\r
250 }\r
251 \r
252 // crtd__vector_new_dbg - Calls to the CRT's debug vector new operator from\r
253 //   msvcrXXd.dll are patched through to this function.\r
254 //\r
255 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
256 //\r
257 //  - type (IN): The CRT "use type" of the block to be allocated.\r
258 //\r
259 //  - file (IN): The name of the file from which this function is being called.\r
260 //\r
261 //  - line (IN): The line number, in the above file, at which this function is\r
262 //      being called.\r
263 //\r
264 //  Return Value:\r
265 //\r
266 //    Returns the value returned by the CRT debug vector new operator.\r
267 //\r
268 TEMPLATE_HEADER\r
269 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__vector_new_dbg (size_t      size,\r
270                                                         int         type,\r
271                                                         char const *file,\r
272                                                         int         line)\r
273 {\r
274     SIZE_T  fp;\r
275     FRAMEPOINTER(fp);\r
276 \r
277     return crtd_new_dbg<crtd_vector_new_dbg_name>(fp, size, type, file, line);\r
278 }\r
279 \r
280 // crtd_calloc - Calls to calloc from msvcrXXd.dll are patched through to\r
281 //   this function.\r
282 //\r
283 //  - dll (IN): The name of the dll\r
284 //\r
285 //  - num (IN): The number of blocks, of size 'size', to be allocated.\r
286 //\r
287 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
288 //\r
289 //  Return Value:\r
290 //\r
291 //    Returns the valued returned from calloc.\r
292 //\r
293 TEMPLATE_HEADER\r
294 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_calloc (size_t num, size_t size)\r
295 {\r
296     static calloc_t pcrtxxd_calloc = NULL;\r
297 \r
298     SIZE_T  fp;\r
299     HMODULE msvcrxxd;\r
300 \r
301     FRAMEPOINTER(fp);\r
302 \r
303     if (pcrtxxd_calloc == NULL) {\r
304         // This is the first call to this function. Link to the real malloc.\r
305         msvcrxxd = GetModuleHandle(crtddll);\r
306         pcrtxxd_calloc = (calloc_t)GetProcAddress(msvcrxxd, "calloc");\r
307     }\r
308 \r
309     return vld._calloc(pcrtxxd_calloc, fp, num, size);\r
310 }\r
311 \r
312 // crtd_malloc - Calls to malloc from msvcrXXd.dll are patched through to\r
313 //   this function.\r
314 //\r
315 //  - dll (IN): The name of the dll\r
316 //\r
317 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
318 //\r
319 //  Return Value:\r
320 //\r
321 //    Returns the valued returned from malloc.\r
322 //\r
323 TEMPLATE_HEADER\r
324 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_malloc (size_t size)\r
325 {\r
326     static malloc_t pcrtxxd_malloc = NULL;\r
327 \r
328     SIZE_T  fp;\r
329     HMODULE msvcrxxd;\r
330 \r
331     FRAMEPOINTER(fp);\r
332 \r
333     if (pcrtxxd_malloc == NULL) {\r
334         // This is the first call to this function. Link to the real malloc.\r
335         msvcrxxd = GetModuleHandle(crtddll);\r
336         pcrtxxd_malloc = (malloc_t)GetProcAddress(msvcrxxd, "malloc");\r
337     }\r
338 \r
339     return vld._malloc(pcrtxxd_malloc, fp, size);\r
340 }\r
341 \r
342 // crtd_realloc - Calls to realloc from msvcrXXd.dll are patched through to\r
343 //   this function.\r
344 //\r
345 //  - dll (IN): The name of the dll\r
346 //\r
347 //  - mem (IN): Pointer to the memory block to reallocate.\r
348 //\r
349 //  - size (IN): Size of the memory block to reallocate.\r
350 //\r
351 //  Return Value:\r
352 //\r
353 //    Returns the value returned from realloc.\r
354 //\r
355 TEMPLATE_HEADER\r
356 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_realloc (void *mem, size_t size)\r
357 {\r
358     static realloc_t pcrtxxd_realloc = NULL;\r
359 \r
360     SIZE_T  fp;\r
361     HMODULE msvcrxxd;\r
362 \r
363     FRAMEPOINTER(fp);\r
364 \r
365     if (pcrtxxd_realloc == NULL) {\r
366         // This is the first call to this function. Link to the real realloc.\r
367         msvcrxxd = GetModuleHandle(crtddll);\r
368         pcrtxxd_realloc = (realloc_t)GetProcAddress(msvcrxxd, "realloc");\r
369     }\r
370 \r
371     return vld._realloc(pcrtxxd_realloc, fp, mem, size);\r
372 }\r
373 \r
374 // crtd_scalar_new - Calls to the CRT's scalar new operator from msvcrXXd.dll\r
375 //   are patched through to this function.\r
376 //\r
377 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
378 //\r
379 //  Return Value:\r
380 //\r
381 //    Returns the value returned by the CRT scalar new operator.\r
382 //\r
383 TEMPLATE_HEADER\r
384 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_scalar_new (size_t size)\r
385 {\r
386     SIZE_T  fp;\r
387     FRAMEPOINTER(fp);\r
388 \r
389     return crtd_new<crtd_scalar_new_name>(fp, size);\r
390 }\r
391 \r
392 // crtd_vector_new - Calls to the CRT's vector new operator from msvcrXXd.dll\r
393 //   are patched through to this function.\r
394 //\r
395 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
396 //\r
397 //  Return Value:\r
398 //\r
399 //    Returns the value returned by the CRT vector new operator.\r
400 //\r
401 TEMPLATE_HEADER\r
402 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_vector_new (size_t size)\r
403 {\r
404     SIZE_T  fp;\r
405     FRAMEPOINTER(fp);\r
406 \r
407     return crtd_new<crtd_vector_new_name>(fp, size);\r
408 }\r
409 \r
410 // crtd_new_dbg - A template function for implementation of patch functions to\r
411 //   the CRT's debug new operator from msvcrXXd.dll\r
412 //\r
413 //  - procname (IN): The debug new operator's name\r
414 //\r
415 //  - fp (IN): Frame pointer from the call that initiated this allocation.\r
416 //\r
417 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
418 //\r
419 //  - type (IN): The CRT "use type" of the block to be allocated.\r
420 //\r
421 //  - file (IN): The name of the file from which this function is being called.\r
422 //\r
423 //  - line (IN): The line number, in the above file, at which this function is\r
424 //      being called.\r
425 //\r
426 //  Return Value:\r
427 //\r
428 //    Returns the value returned by the CRT debug new operator.\r
429 //\r
430 TEMPLATE_HEADER\r
431 template<char const *procname>\r
432 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_new_dbg (SIZE_T      fp,\r
433                                                 size_t      size,\r
434                                                 int         type,\r
435                                                 char const *file,\r
436                                                 int         line)\r
437 {\r
438     static new_dbg_crt_t pcrtxxd_new_dbg = NULL;\r
439 \r
440     HMODULE msvcrxxd;\r
441 \r
442     if (pcrtxxd_new_dbg == NULL) {\r
443         // This is the first call to this function. Link to the real CRT debug\r
444         // new operator.\r
445         msvcrxxd = GetModuleHandle(crtddll);\r
446         pcrtxxd_new_dbg = (new_dbg_crt_t)GetProcAddress(msvcrxxd, procname);\r
447     }\r
448 \r
449     return vld.new_dbg_crt(pcrtxxd_new_dbg, fp, size, type, file, line);\r
450 }\r
451 \r
452 // crt_new - A template function for implementing patch functions to the\r
453 //   CRT's new operator from msvcrXXd.dll\r
454 //\r
455 //  - dll (IN): The name of the dll\r
456 //\r
457 //  - procname (IN): The debug new operator's name\r
458 //\r
459 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
460 //\r
461 //  Return Value:\r
462 //\r
463 //    Returns the value returned by the CRT new operator.\r
464 //\r
465 TEMPLATE_HEADER\r
466 template<char const *procname>\r
467 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_new (SIZE_T fp, size_t size)\r
468 {\r
469     static new_t pcrtxxd_scalar_new = NULL;\r
470 \r
471     HMODULE msvcrxxd;\r
472 \r
473     if (pcrtxxd_scalar_new == NULL) {\r
474         // This is the first call to this function. Link to the real CRT new\r
475         // operator.\r
476         msvcrxxd = GetModuleHandle(crtddll);\r
477         pcrtxxd_scalar_new = (new_t)GetProcAddress(msvcrxxd, procname);\r
478     }\r
479 \r
480     return vld._new(pcrtxxd_scalar_new, fp, size);\r
481 }\r
482 \r
483 ////////////////////////////////////////////////////////////////////////////////\r
484 //\r
485 // MFC DLLs\r
486 //\r
487 ////////////////////////////////////////////////////////////////////////////////\r
488 \r
489 // mfcd__scalar_new_dbg_3p - Calls to the MFC debug scalar new operator from\r
490 //   mfcXXd.dll are patched through to this function.\r
491 //\r
492 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
493 //\r
494 //  - type (IN): The "use type" of the block to be allocated.\r
495 //\r
496 //  - file (IN): The name of the file from which this function is being called.\r
497 //\r
498 //  - line (IN): The line number, in the above file, at which this function is\r
499 //      being called.\r
500 //\r
501 //  Return Value:\r
502 //\r
503 //    Returns the value returned by the MFC debug scalar new operator.\r
504 //\r
505 TEMPLATE_HEADER\r
506 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd__scalar_new_dbg_4p (size_t       size,\r
507                                                            int          type,\r
508                                                            char const  *file,\r
509                                                            int          line)\r
510 {\r
511     SIZE_T  fp;\r
512     FRAMEPOINTER(fp);\r
513 \r
514     return mfcd_new_dbg<mfcddll, mfcd_scalar_new_dbg_4p_ordinal>\r
515                        (fp, size, type, file, line);\r
516 }\r
517 \r
518 // mfcd__scalar_new_dbg_3p - Calls to the MFC debug scalar new operator from\r
519 //   mfcXXd.dll are patched through to this function.\r
520 //\r
521 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
522 //\r
523 //  - file (IN): The name of the file from which this function is being called.\r
524 //\r
525 //  - line (IN): The line number, in the above file, at which this function is\r
526 //      being called.\r
527 //\r
528 //  Return Value:\r
529 //\r
530 //    Returns the value returned by the MFC debug scalar new operator.\r
531 //\r
532 TEMPLATE_HEADER\r
533 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd__scalar_new_dbg_3p (size_t       size,\r
534                                                            char const  *file,\r
535                                                            int          line)\r
536 {\r
537     SIZE_T  fp;\r
538     FRAMEPOINTER(fp);\r
539 \r
540     return mfcd_new_dbg<mfcddll, mfcd_scalar_new_dbg_3p_ordinal>\r
541                        (fp, size, file, line);\r
542 }\r
543 \r
544 // mfcd__vector_new_dbg_4p - Calls to the MFC debug vector new operator from\r
545 //   mfcXXd.dll are patched through to this function.\r
546 //\r
547 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
548 //\r
549 //  - type (IN): The "use type" of the block to be allocated.\r
550 //\r
551 //  - file (IN): The name of the file from which this function is being called.\r
552 //\r
553 //  - line (IN): The line number, in the above file, at which this function is\r
554 //      being called.\r
555 //\r
556 //  Return Value:\r
557 //\r
558 //    Returns the value returned by the MFC debug vector new operator.\r
559 //\r
560 TEMPLATE_HEADER\r
561 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd__vector_new_dbg_4p (size_t       size,\r
562                                                            int          type,\r
563                                                            char const  *file,\r
564                                                            int          line)\r
565 {\r
566     SIZE_T  fp;\r
567     FRAMEPOINTER(fp);\r
568 \r
569     return mfcd_new_dbg<mfcddll, mfcd_vector_new_dbg_4p_ordinal>\r
570                        (fp, size, type, file, line);\r
571 }\r
572 \r
573 // mfcd__vector_new_dbg_3p - Calls to the MFC debug vector new operator from\r
574 //   mfcXXd.dll are patched through to this function.\r
575 //\r
576 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
577 //\r
578 //  - file (IN): The name of the file from which this function is being called.\r
579 //\r
580 //  - line (IN): The line number, in the above file, at which this function is\r
581 //      being called.\r
582 //\r
583 //  Return Value:\r
584 //\r
585 //    Returns the value returned by the MFC debug vector new operator.\r
586 //\r
587 TEMPLATE_HEADER\r
588 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd__vector_new_dbg_3p (size_t       size,\r
589                                                            char const  *file,\r
590                                                            int          line)\r
591 {\r
592     SIZE_T  fp;\r
593     FRAMEPOINTER(fp);\r
594 \r
595     return mfcd_new_dbg<mfcddll, mfcd_vector_new_dbg_3p_ordinal>\r
596                        (fp, size, file, line);\r
597 }\r
598 \r
599 // mfcd_scalar_new - Calls to the MFC scalar new operator from mfcXXd.dll are\r
600 //   patched through to this function.\r
601 //\r
602 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
603 //\r
604 //  Return Value:\r
605 //\r
606 //    Returns the value returned by the MFC scalar new operator.\r
607 //\r
608 TEMPLATE_HEADER\r
609 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_scalar_new (size_t size)\r
610 {\r
611     SIZE_T  fp;\r
612     FRAMEPOINTER(fp);\r
613 \r
614     return mfcd_new<mfcddll, mfcd_scalar_new_ordinal>(fp, size);\r
615 }\r
616 \r
617 // mfcd_vector_new - Calls to the MFC vector new operator from mfcXXd.dll are\r
618 //   patched through to this function.\r
619 //\r
620 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
621 //\r
622 //  Return Value:\r
623 //\r
624 //    Returns the value returned by the MFC vector new operator.\r
625 //\r
626 TEMPLATE_HEADER\r
627 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_vector_new (size_t size)\r
628 {\r
629     SIZE_T  fp;\r
630     FRAMEPOINTER(fp);\r
631 \r
632     return mfcd_new<mfcddll, mfcd_vector_new_ordinal>(fp, size);\r
633 }\r
634 \r
635 // mfcud__scalar_new_dbg_4p - Calls to the MFC debug scalar new operator from\r
636 //   mfcXXud.dll are patched through to this function.\r
637 //\r
638 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
639 //\r
640 //  - type (IN): The "use type" of the block to be allocated.\r
641 //\r
642 //  - file (IN): The name of the file from which this function is being called.\r
643 //\r
644 //  - line (IN): The line number, in the above file, at which this function is\r
645 //      being called.\r
646 //\r
647 //  Return Value:\r
648 //\r
649 //    Returns the value returned by the MFC debug scalar new operator.\r
650 //\r
651 TEMPLATE_HEADER\r
652 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud__scalar_new_dbg_4p (size_t      size,\r
653                                                             int         type,\r
654                                                             char const *file,\r
655                                                             int         line)\r
656 {\r
657     SIZE_T  fp;\r
658     FRAMEPOINTER(fp);\r
659 \r
660     return mfcd_new_dbg<mfcuddll, mfcud_scalar_new_dbg_4p_ordinal>\r
661                        (fp, size, type, file, line);\r
662 }\r
663 \r
664 // mfcud__scalar_new_dbg_3p - Calls to the MFC debug scalar new operator from\r
665 //   mfcXXud.dll are patched through to this function.\r
666 //\r
667 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
668 //\r
669 //  - file (IN): The name of the file from which this function is being called.\r
670 //\r
671 //  - line (IN): The line number, in the above file, at which this function is\r
672 //      being called.\r
673 //\r
674 //  Return Value:\r
675 //\r
676 //    Returns the value returned by the MFC debug scalar new operator.\r
677 //\r
678 TEMPLATE_HEADER\r
679 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud__scalar_new_dbg_3p (size_t      size,\r
680                                                             char const *file,\r
681                                                             int         line)\r
682 {\r
683     SIZE_T  fp;\r
684     FRAMEPOINTER(fp);\r
685 \r
686     return mfcd_new_dbg<mfcuddll, mfcud_scalar_new_dbg_3p_ordinal>\r
687                        (fp, size, file, line);\r
688 }\r
689 \r
690 // mfcud__vector_new_dbg_4p - Calls to the MFC debug vector new operator from\r
691 //   mfcXXud.dll are patched through to this function.\r
692 //\r
693 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
694 //\r
695 //  - type (IN): The "use type" of the block to be allocated.\r
696 //\r
697 //  - file (IN): The name of the file from which this function is being called.\r
698 //\r
699 //  - line (IN): The line number, in the above file, at which this function is\r
700 //      being called.\r
701 //\r
702 //  Return Value:\r
703 //\r
704 //    Returns the value returned by the MFC debug vector new operator.\r
705 //\r
706 TEMPLATE_HEADER\r
707 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud__vector_new_dbg_4p (size_t      size,\r
708                                                             int         type,\r
709                                                             char const *file,\r
710                                                             int         line)\r
711 {\r
712     SIZE_T  fp;\r
713     FRAMEPOINTER(fp);\r
714 \r
715     return mfcd_new_dbg<mfcuddll, mfcud_vector_new_dbg_4p_ordinal>\r
716                        (fp, size, type, file, line);\r
717 }\r
718 \r
719 // mfcud__vector_new_dbg_3p - Calls to the MFC debug vector new operator from\r
720 //   mfcXXud.dll are patched through to this function.\r
721 //\r
722 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
723 //\r
724 //  - file (IN): The name of the file from which this function is being called.\r
725 //\r
726 //  - line (IN): The line number, in the above file, at which this function is\r
727 //      being called.\r
728 //\r
729 //  Return Value:\r
730 //\r
731 //    Returns the value returned by the MFC debug vector new operator.\r
732 //\r
733 TEMPLATE_HEADER\r
734 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud__vector_new_dbg_3p (size_t      size,\r
735                                                             char const *file,\r
736                                                             int         line)\r
737 {\r
738     SIZE_T  fp;\r
739     FRAMEPOINTER(fp);\r
740 \r
741     return mfcd_new_dbg<mfcuddll, mfcud_vector_new_dbg_3p_ordinal>\r
742                        (fp, size, file, line);\r
743 }\r
744 \r
745 // mfcud_scalar_new - Calls to the MFC scalar new operator from mfcXXud.dll are\r
746 //   patched through to this function.\r
747 //\r
748 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
749 //\r
750 //  Return Value:\r
751 //\r
752 //    Returns the value returned by the MFC scalar new operator.\r
753 //\r
754 TEMPLATE_HEADER\r
755 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud_scalar_new (size_t size)\r
756 {\r
757     SIZE_T  fp;\r
758     FRAMEPOINTER(fp);\r
759 \r
760     return mfcd_new<mfcuddll, mfcud_scalar_new_ordinal>(fp, size);\r
761 }\r
762 \r
763 // mfcud_vector_new - Calls to the MFC vector new operator from mfcXXud.dll are\r
764 //   patched through to this function.\r
765 //\r
766 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
767 //\r
768 //  Return Value:\r
769 //\r
770 //    Returns the value returned by the MFC vector new operator.\r
771 //\r
772 TEMPLATE_HEADER\r
773 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud_vector_new (size_t size)\r
774 {\r
775     SIZE_T  fp;\r
776     FRAMEPOINTER(fp);\r
777 \r
778     return mfcd_new<mfcuddll, mfcud_vector_new_ordinal>(fp, size);\r
779 }\r
780 \r
781 // mfcd_new_dbg - A generic function for implementing patch functions to the MFC\r
782 //   debug new operators:\r
783 //   void* __cdecl operator new[](size_t size, int type, char const *file, int line)\r
784 //   void* __cdecl operator new(size_t size, int type, char const *file, int line)\r
785 //\r
786 //  - mfcdll (IN): The name of the MFC DLL\r
787 //\r
788 //  - ordinal (IN): The debug new operator's ordinal value\r
789 //\r
790 //  - type (IN): The "use type" of the block to be allocated.\r
791 //\r
792 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
793 //\r
794 //  - file (IN): The name of the file from which this function is being called.\r
795 //\r
796 //  - line (IN): The line number, in the above file, at which this function is\r
797 //      being called.\r
798 //\r
799 //  Return Value:\r
800 //\r
801 //    Returns the value returned by the MFC debug new operator.\r
802 //\r
803 TEMPLATE_HEADER\r
804 template<wchar_t const *mfcdll, int ordinal>\r
805 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_new_dbg (SIZE_T      fp,\r
806                                                 size_t      size,\r
807                                                 int         type,\r
808                                                 char const *file,\r
809                                                 int         line)\r
810 {\r
811     static new_dbg_crt_t pmfcxxd__new_dbg = NULL;\r
812 \r
813     HMODULE mfcxxd;\r
814 \r
815     if (pmfcxxd__new_dbg == NULL) {\r
816         // This is the first call to this function. Link to the real MFC debug\r
817         // new operator.\r
818         mfcxxd = GetModuleHandle(mfcdll);\r
819         pmfcxxd__new_dbg = (new_dbg_crt_t)GetProcAddress(mfcxxd, (LPCSTR)ordinal);\r
820     }\r
821 \r
822     return vld.new_dbg_mfc(pmfcxxd__new_dbg, fp, size, type, file, line);\r
823 }\r
824 \r
825 // mfcd_new_dbg - A generic function for implementing patch functions to the MFC\r
826 //   debug new operators:\r
827 //   void* __cdecl operator new[](size_t size, char const *file, int line)\r
828 //   void* __cdecl operator new(size_t size, char const *file, int line)\r
829 //\r
830 //  - mfcdll (IN): The name of the MFC DLL\r
831 //\r
832 //  - ordinal (IN): The debug new operator's ordinal value\r
833 //\r
834 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
835 //\r
836 //  - file (IN): The name of the file from which this function is being called.\r
837 //\r
838 //  - line (IN): The line number, in the above file, at which this function is\r
839 //      being called.\r
840 //\r
841 //  Return Value:\r
842 //\r
843 //    Returns the value returned by the MFC debug new operator.\r
844 //\r
845 TEMPLATE_HEADER\r
846 template<wchar_t const *mfcdll, int ordinal>\r
847 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_new_dbg (SIZE_T      fp,\r
848                                                 size_t      size,\r
849                                                 char const *file,\r
850                                                 int         line)\r
851 {\r
852     static new_dbg_mfc_t pmfcxxd__new_dbg = NULL;\r
853 \r
854     HMODULE mfcxxd;\r
855 \r
856     if (pmfcxxd__new_dbg == NULL) {\r
857         // This is the first call to this function. Link to the real MFC debug\r
858         // new operator.\r
859         mfcxxd = GetModuleHandle(mfcdll);\r
860         pmfcxxd__new_dbg = (new_dbg_mfc_t)GetProcAddress(mfcxxd, (LPCSTR)ordinal);\r
861     }\r
862 \r
863     return vld.new_dbg_mfc(pmfcxxd__new_dbg, fp, size, file, line);\r
864 }\r
865 \r
866 // mfcd_new - A generic function for implementing patch functions to the MFC new\r
867 //   operators.\r
868 //\r
869 //  - mfcdll (IN): The name of the MFC DLL\r
870 //\r
871 //  - ordinal (IN): The new operator's ordinal value\r
872 //\r
873 //  - size (IN): The size, in bytes, of the memory block to be allocated.\r
874 //\r
875 //  Return Value:\r
876 //\r
877 //    Returns the value returned by the MFC new operator.\r
878 //\r
879 TEMPLATE_HEADER\r
880 template<wchar_t const *mfcdll, int ordinal>\r
881 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_new (SIZE_T fp, size_t size)\r
882 {\r
883     static new_t pmfcxxd_new = NULL;\r
884 \r
885     HMODULE mfcxxd;\r
886 \r
887     if (pmfcxxd_new == NULL) {\r
888         // This is the first call to this function. Link to the real CRT new\r
889         // operator.\r
890         mfcxxd = GetModuleHandle(mfcdll);\r
891         pmfcxxd_new = (new_t)GetProcAddress(mfcxxd, (LPCSTR)ordinal);\r
892     }\r
893 \r
894     return vld._new(pmfcxxd_new, fp, size);\r
895 }\r
896 \r
897 #undef TEMPLATE_HEADER\r
898 #undef TEMPLATE_ARGS\r
899 \r
900 const extern char    scalar_new_dbg_name[] = "??2@YAPAXIHPBDH@Z";\r
901 const extern char    vector_new_dbg_name[] = "??_U@YAPAXIHPBDH@Z";\r
902 const extern char    scalar_new_name[] = "??2@YAPAXI@Z";\r
903 const extern char    vector_new_name[] = "??_U@YAPAXI@Z";\r
904 const extern wchar_t msvcrtd_dll[]  = L"msvcrtd.dll";\r
905 const extern wchar_t mfc42d_dll[]   = L"mfc42d.dll";\r
906 const extern wchar_t mfc42ud_dll[]  = L"mfc42ud.dll";\r
907 const extern wchar_t msvcr70d_dll[] = L"msvcr70d.dll";\r
908 const extern wchar_t mfc70d_dll[]   = L"mfc70d.dll";\r
909 const extern wchar_t mfc70ud_dll[]  = L"mfc70ud.dll";\r
910 const extern wchar_t msvcr71d_dll[] = L"msvcr71d.dll";\r
911 const extern wchar_t mfc71d_dll[]   = L"mfc71d.dll";\r
912 const extern wchar_t mfc71ud_dll[]  = L"mfc71ud.dll";\r
913 const extern wchar_t msvcr80d_dll[] = L"msvcr80d.dll";\r
914 const extern wchar_t mfc80d_dll[]   = L"mfc80d.dll";\r
915 const extern wchar_t mfc80ud_dll[]  = L"mfc80ud.dll";\r
916 const extern wchar_t msvcr90d_dll[] = L"msvcr90d.dll";\r
917 const extern wchar_t mfc90d_dll[]   = L"mfc90d.dll";\r
918 const extern wchar_t mfc90ud_dll[]  = L"mfc90ud.dll";\r
919 const extern wchar_t msvcr100d_dll[] = L"msvcr100d.dll";\r
920 const extern wchar_t mfc100d_dll[]   = L"mfc100d.dll";\r
921 const extern wchar_t mfc100ud_dll[]  = L"mfc100ud.dll";\r
922 \r
923 // Visual Studio 6.0\r
924 typedef CrtMfcPatch<msvcrtd_dll, mfc42d_dll, mfc42ud_dll,\r
925                     vector_new_name, vector_new_dbg_name,\r
926                     scalar_new_name, scalar_new_dbg_name,\r
927                     0, 0, 0, 711, 712, 714,\r
928                     0, 0, 0, 711, 712, 714>\r
929         VS60;\r
930 // Visual Studio .NET 2002\r
931 typedef CrtMfcPatch<msvcr70d_dll, mfc70d_dll, mfc70ud_dll,\r
932                     vector_new_name, vector_new_dbg_name,\r
933                     scalar_new_name, scalar_new_dbg_name,\r
934                     257, 258, 259, 832, 833, 834,\r
935                     258, 259, 260, 833, 834, 835>\r
936         VS70;\r
937 // Visual Studio .NET 2003\r
938 typedef CrtMfcPatch<msvcr71d_dll, mfc71d_dll, mfc71ud_dll,\r
939                     vector_new_name, vector_new_dbg_name,\r
940                     scalar_new_name, scalar_new_dbg_name,\r
941                     267, 268, 269, 893, 894, 895,\r
942                     267, 268, 269, 893, 894, 895>\r
943         VS71;\r
944 // Visual Studio 2005\r
945 typedef CrtMfcPatch<msvcr80d_dll, mfc80d_dll, mfc80ud_dll,\r
946                     vector_new_name, vector_new_dbg_name,\r
947                     scalar_new_name, scalar_new_dbg_name,\r
948                     267, 268, 269, 893, 894, 895,\r
949                     267, 268, 269, 893, 894, 895>\r
950         VS80;\r
951 // Visual Studio 2008\r
952 typedef CrtMfcPatch<msvcr90d_dll, mfc90d_dll, mfc90ud_dll,\r
953                     vector_new_name, vector_new_dbg_name,\r
954                     scalar_new_name, scalar_new_dbg_name,\r
955                     267, 268, 269, 931, 932, 933,\r
956                     267, 268, 269, 935, 936, 937>\r
957         VS90;\r
958 \r
959 // Visual Studio 2010\r
960 typedef CrtMfcPatch<msvcr100d_dll, mfc100d_dll, mfc100ud_dll,\r
961                     vector_new_name, vector_new_dbg_name,\r
962                                         scalar_new_name, scalar_new_dbg_name,\r
963                                         267, 268, 269, 1405, 1406, 1407,\r
964                                         267, 268, 269, 1412, 1413, 1414>\r
965         VS100;