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