MEMCHECK.H (89039B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 17 /* #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# 18 19 MemCheck 3.0 Professional for DOS 20 21 Copyright (c) 1990-1994, StratosWare Corporation. 22 All rights reserved. 23 24 1-800-WE-DEBUG 25 26 Note to Developers: 27 -------------------- 28 This file should be #included AFTER any other #includes in 29 each source file which is to be memory checked, and BEFORE 30 any code that performs any operations on allocated pointers. 31 If it isn't, MemCheck will not pick up source file and line 32 information for intercepted functions. 33 34 The MCCONFIG.EXE utility distributed with MemCheck 3.0 35 will do this safely and quickly for you. 36 37 Most specifically, this header file MUST NOT come before 38 any prototypes of routines that MemCheck intercepts, like 39 malloc(), free(), strcpy(), and so on. 40 41 The Final Cut: 42 --------------- 43 To ENTIRELY remove MemCheck from your code, just #define 44 the constant "NOMEMCHECK", or equivalently, "NOMC". 45 46 This header file will then automatically 'evaporate' all 47 MemCheck 3.0 calls. This is MUCH PREFERABLE to placing 48 #if-#endif's around the header file's inclusion, as in 49 50 #ifdef DEBUG // DON'T DO THIS! 51 #include <memcheck.h> 52 #endif 53 54 Using the "#ifdef DEBUG" as above doesn't allow the 55 MemCheck header file to evaporate the MemCheck 3.0 API 56 calls you may have placed in your code, like mc_startcheck() 57 and mc_endcheck(). You would then have to surround 58 each MemCheck API call with additional #if-#endif's. 59 60 Modification History 61 62 WHO WHEN WHAT 63 KWB 07/28/93 Gussy for beta 64 KWB 09/11/93 Add new placement overload, NEW() C++ stuff 65 KWB 11/08/93 Final QA/QC for initial release 66 KWB 12/02/93 LINT -save added 67 KWB 02/19/94 Fixed function inlining holes, added macros 68 for underscore func variants under MSC 7+ 69 KWB 07/08/94 Added defines for BC extender (_CC_POWERPACK_) 70 KWB 07/09/94 Added special case for STACKTOP, END under PowerPack 71 KWB 08/04/94 Added cdecl modifier to stklen, atopsp etc. decls 72 KWB 08/11/94 Associated _CC32_ with _PROTECTED_ in ccdefs section; 73 Changed method of determining compiler model, 74 e.g. _CC_MSC6_ from if == to if >= 75 Associated DOSX286 with _PROTECTED_ for Phar Lap 76 Added MC_SET_EXCEPTF, mc_set/get_exceptf() 77 KWB 08/17/94 Added new[] support filtering (_CPP_ANSI20_) 78 KWB 08/18/94 Changed _MCFARCALL to _MCFARGLUE 79 KWB 09/13/94 Added erf_printf as alias for erf_stdout 80 KWB 09/14/94 Added endf_summary 81 KWB 09/21/94 Added MCCRITF and mc_set_critf() & related 82 KWB 10/10/94 Added #if !defined(setmem) etc. for BC DPMI32 83 KWB 10/11/94 Added _CC_BORLANDx_ comp def, 'x' = major ver 84 85 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# */ 86 87 88 /* Avoid multiple inclusions */ 89 #ifndef _MEMCHECK_H_ 90 #define _MEMCHECK_H_ 91 92 /* Prevent inclusion in Windows(tm) compilations */ 93 #if defined(_Windows) || defined(WINDOWS) || defined(_WINDOWS) 94 # if !defined (__DPMI16__) && !defined (__DPMI32__) && !defined (DOSX286) 95 # error DOS version of MemCheck header file #included! 96 # endif 97 #endif 98 99 /* Shorthand equivalence, V2.0 backwards compatibility... */ 100 #if defined (NOMC) || defined (NOMEMCHK) 101 # define NOMEMCHECK 102 #endif 103 104 /* C++ new interception -- see note later and 105 read the MemCheck 3.0 User's Manual, section 106 "Integration With C++." Uncommenting the next line 107 and following simple instructions allows seamless 108 transmission of the exact file and line location 109 of new's in your source code. 110 */ 111 /* #define NEW_OVERLOADED */ 112 113 114 /* *** Backwards compatibility with V2.0 *** */ 115 116 #define mc_isactive mc_is_active /* standardize naming... */ 117 #define mc_getmode mc_get_mode 118 #define mc_errorstatus mc_error_flags 119 #define mc_verify_memory mc_check_buffers 120 121 #define MC_USEDISK MC_USING_DISK 122 #define MC_USEMEM MC_USING_MEMORY 123 124 125 /* *** Backwards compatibility with V2.1 *** */ 126 127 #define MCLINENO MCSL /* "MemCheck Source Line" */ 128 #define MFUNC ERF /* error reporting function */ 129 130 #define mc_set_msgfunc mc_set_erf /* "Message funcs" are now */ 131 #define mc_get_msgfunc mc_get_erf /* universally referred to as */ 132 #define mc_error_status mc_error_flags /* "error reporting functions"*/ 133 134 /* Maintain source code compatibility with version 2.1. 135 Buffer registration is simplified to 136 just calling "mc_register", regardless of model. 137 Same with buffer checking, e.g. "mc_check_far" 138 and "mc_check_near" are rolled into "mc_check". 139 */ 140 #define mc_register_near(p,s) mc_register((void _MCFAR *)(p),s) 141 #define mc_register_far(p,s) mc_register((void _MCFAR *)(p),s) 142 #define mc_unregister_near(p) mc_unregister((void _MCFAR *)(p)) 143 #define mc_unregister_far(p) mc_unregister((void _MCFAR *)(p)) 144 #define mc_check_near(p) mc_check((void _MCFAR *)(p)) 145 #define mc_check_far(p) mc_check((void _MCFAR *)(p)) 146 147 /* Error Number Definitions 148 Returned by mc_endcheck() and mc_error_flags(). 149 In MemCheck 3.0, there's now a global error number much 150 like the "errno" variable in standard C. 151 */ 152 #define MCE_NO_ERROR 0 /* it's debugging time & all well */ 153 #define MCE_NULL_SOURCE 1 /* null source ptr on copy */ 154 #define MCE_NULL_DEST 2 /* null dest ptr on copy */ 155 #define MCE_UNDERWRITE 3 /* allocated buf underwritten (front) */ 156 #define MCE_OVERWRITE 4 /* allocated buf overwritten (end) */ 157 #define MCE_LEAK 5 /* forgot to free alloc'd memory */ 158 #define MCE_LEAKAGE MCE_LEAK 159 #define MCE_UNFREED_MEMORY MCE_LEAK 160 #define MCE_NULL_PTR_ASSIGN 6 /* assigned data through null ptr */ 161 #define MCE_BAD_STACK_PTR 7 /* bad stack pointer */ 162 #define MCE_STACK_OVERWRITE 8 /* copy trashes stack frame */ 163 #define MCE_INTERNAL 9 /* internal error msg */ 164 #define MCE_OVERLAPPING_COPY 10 /* source overlaps dest on copy */ 165 #define MCE_INVALID_PTR 11 /* bad ptr on free, realloc */ 166 #define MCE_DEST_OVERWRITE 12 /* copy too big for dest buffer */ 167 #define MCE_OUT_OF_MEMORY 13 /* out of memory */ 168 #define MCE_OOM MCE_OUT_OF_MEMORY 169 #define MCE_GPF_PTR 14 /* ptr caused GPF */ 170 171 172 /* MemCheck Error Flags 173 174 The MemCheck error flag is just an unsigned long 175 (specifically, a MCEFLAGS typedef) with "sticky" bits 176 corresponding to the above MCE_... error numbers. 177 You can use the error flags macro MC_EFLAG(e) to 178 test the global MC_Errno double flag word. 179 */ 180 /* Returns a long word with the e-th bit set */ 181 #define MC_EFLAG(e) ( (e) ? ((MCEFLAGS)1 << (e-1)) : (MCEFLAGS)0) 182 183 #define EFLAG_NULL_PTR MC_EFLAG(MCE_NULL_DEST) 184 #define EFLAG_BAD_PTR MC_EFLAG(MCE_UNALLOCED_PTR) 185 #define EFLAG_FRONT_MAGIC MC_EFLAG(MCE_UNDERWRITE) 186 #define EFLAG_BACK_MAGIC MC_EFLAG(MCE_OVERWRITE) 187 #define EFLAG_PTRS_NOT_FREED MC_EFLAG(MCE_LEAK) 188 #define EFLAG_TRACK_FILE 0 /*obsolete in 3.0+*/ 189 #define EFLAG_NULL_ASSIGN MCE_FLAG(MCE_NULL_PTR_ASSIGN) 190 191 /* *** End Compatibility Section *** */ 192 193 194 /* *** MemCheck Compiler Constant Definitions *** */ 195 196 /* 197 Compiler Defines 198 -------- ------- 199 Microsoft _CC_MSC_, _CC_MSC_COMPATIBLE_ 200 V8.x _CC_MSC8_ 201 V7.x _CC_MSC7_ 202 V6.x _CC_MSC6_ 203 V5.x _CC_MSC5_ 204 Borland* _CC_BORLAND_, _CC_BCC_ 205 V3.x _CC_BORLAND3_ 206 V4.x _CC_BORLAND4_ 207 PowerPack/16 _CC_POWERPACK_, _CC_POWERPACK16_ 208 PowerPack/32 _CC_POWERPACK_, _CC_POWERPACK32_, _CC32_ 209 WATCOM _CC_WATCOM_, _CC_MSC_COMPATIBLE_ 210 WAT/386 _CC_WATCOM32_, _CC32_ 211 212 * Borland has no good way of determining compiler 213 version. __BORLANDC__ returns some truly funky 214 hex constant that "will increase in future versions." 215 216 Define Meaning 217 ------ -------- 218 _CC32_ * 32-bit compile 219 _PROTECTED_ 16- or 32-bit protected mode compile 220 LCODE Defined if large code model 221 LDATA Defined if large data model 222 STACKTOP Highest stack address (top) 223 STACKEND Lowest stack address 224 STACKLEN Stack length (top - end) 225 _CPP_ANSI20_ Compiler supports C++ 2.0, e.g. new[] 226 227 * If _CC32_ is defined, _PROTECTED_ is also defined 228 */ 229 230 231 #ifndef _CCDEFS_H_ 232 #define _CCDEFS_H_ 233 234 #ifdef __cplusplus 235 extern "C" { 236 #endif 237 238 /* NOTE: Microsoft C 5.x users have to "#define _MSC_VER 500" 239 at the top of this file. 240 */ 241 #if defined(_MSC_VER) 242 /* 243 _MSC_VER Microsoft C version; currently defined as 700. 244 M_I86 _M_I86 Member of the I86 processor family. 245 M_I86mM _M_I86mM Memory model type: 246 <m>= T Tiny 247 S Small (default) 248 C Compact model 249 M Medium model 250 L Large model 251 H Huge model 252 Identifiers defined by /AT, /AS, /AC, /AM, 253 /AL, and /AH, respectively. 254 _MSDOS MS-DOS operating system. 255 _QC Microsoft QuickC Compiler. 256 _WINDLL Windows protected-mode dynamic-link library 257 is selected with /GD. 258 _WINDOWS Windows protected-mode is selected with /GA, 259 /Gn, /GW, /Mq, or /GD. 260 */ 261 # define _CC_MSC_ 262 # define _CC_MSC_COMPATIBLE_ 263 264 # if (_MSC_VER >= 800) 265 # define _CC_MSC8_ 266 # elif (_MSC_VER >= 700) 267 # define _CC_MSC7_ 268 # elif (_MSC_VER >= 600) 269 # define _CC_MSC6_ 270 # elif (_MSC_VER >= 500) /* see note above */ 271 # define _CC_MSC5_ 272 # else 273 # error MemCheck.h: unrecognized version of Microsoft compiler! 274 # endif 275 276 #elif defined(__BORLANDC__) 277 # define _CC_BORLAND_ /* Borland product */ 278 # define _CC_BCC_ /* Borland C compiler */ 279 280 /* Major compiler rev */ 281 # if (__BORLANDC__ >= 0x0450) 282 # define _CC_BORLAND4_ 283 # elif (__BORLANDC__ >= 0x400) 284 # define _CC_BORLAND3_ 285 # else 286 /* not needed */ 287 # endif 288 289 /* Borland 4.0 PowerPack BCC.EXE defines (-WX): 290 __DPMI16__ _Windows 291 292 With -WXD, -WXDE: 293 __DLL__ __DPMI16__ _Windows 294 295 Borland 4.0 PowerPack BCC21.EXE defines (-WX): 296 __CONSOLE__ __DPMI32__ __FLAT__ __WIN32__ _Windows 297 298 With -WXD: 299 __DLL__ __CONSOLE__ __DPMI32__ __FLAT__ __WIN32__ _Windows 300 */ 301 # if defined(__DPMI16__) 302 # define _CC_POWERPACK_ 303 # define _CC_POWERPACK16_ 304 # define _PROTECTED_ 305 # endif 306 # if defined(__DPMI32__) 307 # define _CC_POWERPACK_ 308 # define _CC_POWERPACK32_ 309 # define _CC32_ /* flat model */ 310 # endif 311 312 /* Turbo C++ */ 313 #elif defined(MCTCP) /* homebrew */ 314 # define _CC_BORLAND_ /* Borland product */ 315 # define _CC_TCP_ /* Turbo C++ */ 316 317 #elif defined(__TURBOC__) 318 /* 319 __TURBOC__ Gives the current Turbo C version 320 number, a hexadecimal number. Version 321 1.0 id 0x1000; version 1.2 is 0x0102, etc. 322 __TINY__, __SMALL__, __MEDIUM__, 323 __COMPACT__, __LARGE__, __HUGE__ 324 Model defintions 325 __MSDOS__ Signals that we're not yet in the 326 twenty-first century 327 */ 328 # define _CC_BORLAND_ /* Borland C product */ 329 # define _CC_TCC_ /* Turbo C/C++ compiler */ 330 331 332 #elif defined(_INTELC32_) 333 /* 334 _INTELC32_ has the value 1. 335 _ARCHITECTURE_ is 386 if the nomod486 pragma is ineffect, 336 486 otherwise. 337 */ 338 # define _CC_INTEL_ /* Intel Code Builder */ 339 # define _CC_MSC_COMPATIBLE_ 340 # define _CC32_ /* flat model */ 341 342 #elif defined(__WATCOMC__) 343 /* 344 __WATCOMC__ Used to determine if the WATCOM C 345 or C/386 compiler is compiling 346 __386__ identifies the target machine as an 347 Intel 80386 under the WATCOM C/386 compiler 348 MSDOS Signals that we're not yet in the 349 twenty-first century 350 __FLAT__, __SMALL__, __MEDIUM__, 351 __COMPACT__, __LARGE__ 352 Model defintions (flat is default) 353 Also id's MSC-compatible model defines 354 355 8.5 and later: 356 __WINDOWS__ Identifies 16-bit Windows ("zw" or "zW" opts) 357 __WINDOWS_386__ 32-bit Microsoft Windows "zW" opt 358 __NETWARE_386__ Novell Netware 386, defined by the 359 Novell/Watcom C 360 __OS2__ IBM OS/2-hosted version of Watcom 361 */ 362 # define _CC_WATCOM_ /* Watcom C product */ 363 # define _CC_MSC_COMPATIBLE_ 364 # ifdef __386__ 365 # define _CC32_ /* flat model */ 366 # define _CC_WATCOM32_ 367 # endif 368 369 370 #elif defined(__STDC__) /* Standard ANSI C */ 371 # define _CC_ANSI_ 372 # define _CC32_ /* no segmentation via far/near */ 373 # define far 374 # define near 375 # define huge 376 # define cdecl 377 378 /* Avoids parameter mismatches from _far, etc. */ 379 # define _far 380 # define _near 381 # define _huge 382 # define _cdecl 383 384 #else /* UNSUPPORTED / UNRECOGNIZED COMPILER */ 385 386 #error MemCheck 3.0: unrecognized compiler 387 /* 388 If you're using Microsoft C5.1, you must 389 define the constant _MSC_VER, e.g. 390 391 #define _MSC_VER 500 392 393 Place this statement at the top of this 394 header file or in your project header file 395 BEFORE the MemCheck header file is included. 396 397 Microsoft C 5.0 is NOT supported (it's non-ANSI). 398 */ 399 400 #endif /* compiler constant definitions */ 401 402 /* END of _CC..._ name setups; ripple & alias */ 403 404 /* Sheer utility & avoidance of !_CC32_ */ 405 #ifndef _CC32_ 406 # define _CC16_ 407 #endif 408 409 /* 32-bit compilers are always protected mode */ 410 #ifdef _CC32_ 411 #ifndef _PROTECTED_ 412 # define _PROTECTED_ 413 #endif 414 #endif /* CC32 */ 415 416 /* Phar Lap support */ 417 #ifdef DOSX286 418 #ifndef _PROTECTED_ 419 # define _PROTECTED_ 420 #endif 421 #endif /* DOSX286 */ 422 423 /* C++ 2.0 compliance: _CPP_ANSI20_ */ 424 #if defined(_CC_BORLAND_) 425 /* Only BC++ 4.x and later, but Borland has 426 seriously mangled version info (__BORLANDC__) */ 427 # if defined (__BCPLUSPLUS__) 428 # if (__BCPLUSPLUS__ > 0x0310) /* after 3.1 */ 429 # define _CPP_ANSI20_ 430 # endif 431 # elif defined(_CC_POWERPACK_) 432 # define _CPP_ANSI20_ 433 # endif 434 #elif defined (_CC_MSC_) 435 /* Current release through 8.x doesn't support new[] */ 436 #elif defined (_CC_WATCOM_) 437 # if (__WATCOMC__ >= 1000) /* 10.x */ 438 # define _CPP_ANSI20_ 439 # endif 440 #endif 441 442 443 /*******************************************************************/ 444 /*******************************************************************/ 445 446 /* *** Code and Data Size Constants *** 447 LCODE not used by this header file. 448 LDATA *is* used, however. 449 450 May be commented out if these constants are already defined. 451 */ 452 453 /* #ifndef LCODE */ 454 #if defined(M_I86MM) || defined(M_I86LM) || defined(M_I86HM) 455 # define LCODE 1 456 #elif defined(__MEDIUM__) || defined(__LARGE__) || defined(__HUGE__) 457 # define LCODE 1 458 #endif 459 /* #endif */ 460 461 #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__) 462 # define LDATA 1 463 #elif defined(M_I86CM) || defined(M_I86LM) || defined(M_I86HM) 464 # define LDATA 1 465 #endif 466 467 /* Macro "aliases" */ 468 469 #ifndef _LCODE 470 # ifdef LCODE 471 # define _LCODE LCODE 472 # endif 473 #endif 474 475 #ifndef _LDATA 476 # ifdef LDATA 477 # define _LDATA LDATA 478 # endif 479 #endif 480 481 /*******************************************************************/ 482 /*******************************************************************/ 483 484 /* *** Physical Stack Address *** */ 485 486 #if defined(_CC_BORLAND_) /* -------------------------- */ 487 488 /* 489 BORLAND RTL Notes: 490 ;---------------------------------------------------------------------- 491 ; In large data models, the stack is in its own segment. The stack 492 ; starts at SS:__stklen and grows down to SS:0. 493 ; 494 ; In small data models, the stack is in the DGROUP, and grows down 495 ; to meet the heap. The end of the heap is marked by ___brklvl. 496 (KWB: Note that the brklvl is adjusted upwards until it meets 497 _stklen...) 498 ;---------------------------------------------------------------------- 499 */ 500 501 # define STACKSLOP 256 502 extern unsigned cdecl _stklen; 503 504 # if defined(_CC_POWERPACK_) 505 # define STACKTOP (mc_stacktop()) 506 # define STACKEND (mc_stackend()) 507 # else /* not P-Pack */ 508 # ifdef LDATA 509 /* Compact, Large, Huge Models ... 510 511 The stack starts at SS:_stklen and 512 grows downward to SS:0 513 */ 514 # define STACKTOP ((unsigned) _stklen) 515 # define STACKEND ((unsigned) 0 + STACKSLOP) 516 517 # else 518 /* Small, Medium Models ... 519 520 The stack starts at SS:0xFFFE and grows 521 downwards _stklen bytes. 522 */ 523 # define STACKTOP ((unsigned) 0xFFFE) 524 # define STACKEND (STACKTOP - _stklen + STACKSLOP) 525 # endif 526 # endif /* not PowerPack */ 527 528 #elif defined (_CC_MSC_) /* ------------------------------- */ 529 530 extern char cdecl end; /* end of stack */ 531 extern unsigned cdecl _atopsp; /* top of stack */ 532 533 # define STACKTOP _atopsp 534 # define STACKSLOP 256 535 536 # ifdef LDATA 537 /* If in far data, stack could be in its own 538 seg. tho not usually. see /FARSTACK */ 539 # define STACKEND ((unsigned) ((unsigned long)&end) + STACKSLOP) 540 # else 541 /* If near data, must be in DS; use near ptr */ 542 # define STACKEND ((unsigned)&end + STACKSLOP) 543 # endif 544 545 #elif defined (_CC_WATCOM_) /* ------------------------------- */ 546 547 extern unsigned _STACKLOW; /* end of stack */ 548 extern unsigned _STACKTOP; /* top of stack */ 549 550 # define STACKTOP (_STACKTOP) 551 # define STACKSLOP 256 552 553 # ifdef LDATA 554 # define STACKEND ((unsigned) (_STACKLOW + STACKSLOP)) 555 # else 556 # define STACKEND ((unsigned) (_STACKLOW + STACKSLOP)) 557 # endif 558 559 #else /* Unknown compiler ---------------- */ 560 561 #error Unknown compiler at __FILE__(__LINE__) 562 563 #endif /* defining stack top, end */ 564 565 /*******************************************************************/ 566 /*******************************************************************/ 567 568 #ifdef __cplusplus 569 } 570 #endif 571 572 #endif /* _ccdefs already #included */ 573 574 /* End CCDEFS */ 575 576 577 #if !defined (NULL) /* pull in stdio.h if not already */ 578 # include <stdio.h> 579 #endif 580 581 /* Backup... sometimes NULL defined in other headers */ 582 #if !defined (_IOFBF) /* pull in stdio.h if not already */ 583 # include <stdio.h> 584 #endif 585 586 587 /* *** MemCheck Constants *** */ 588 589 /* Standard from MemCheck 3.0 onwards. 590 Access major version and revision 591 via mc_version() and mc_revision() macros. 592 */ 593 #define _MC_VERSION 0x0300 /* welcome 3.0 the powerful */ 594 595 #define mc_version() ((int)((_MC_VERSION & 0xFF00) >> 8)) 596 #define mc_revision() ((int)(_MC_VERSION & 0x00FF)) 597 598 #if defined (_CC32_) /* 32-bit Intel target */ 599 #define PRT_FP "0x%p" 600 #else 601 #define PRT_FP "%Fp" 602 #endif 603 604 /* *** MCID Macro *** */ 605 606 /* Allows later flexibility in assigning mapping... 607 Also makes MCIDs formulaic 608 */ 609 #define _MCID(f) (MCID)(__paste(MCID_,f)) 610 611 /* 612 MemCheck Function ID's (MCID's) 613 614 These are the indices used to retrieve information 615 about specific runtime library calls. 616 */ 617 /* --- MEMCHECK INTERNAL FUNCTIONS --- */ 618 619 #define _MCID_FIRST_INTERNAL 0 /* index of first internal func */ 620 621 #define MCID_mc_startcheck 0 622 #define MCID_mc_endcheck 1 623 #define MCID_mc_check_buffers 2 624 #define MCID_mc_check 3 625 #define MCID_mc_register 4 626 #define MCID_mc_unregister 5 627 #define MCID_mc_set_alignsize 6 628 #define MCID_mc_set_checkbytes 7 629 #define MCID_mc_nullcheck 8 630 #define MCID_mc_breakpoint 9 631 #define MCID_mc_debug 10 632 #define MCID_mc_set_location 11 633 #define MCID_mc_stack_trace 12 634 #define MCID_mc_report 13 635 636 #define _MCID_LAST_INTERNAL 14 /* Set = to last internal ID */ 637 638 639 /* *************** STANDARD C ROUTINES ******************* */ 640 641 #define _MCID_FIRST_ANSI (_MCID_LAST_INTERNAL+1) 642 643 #define MCID_calloc (_MCID_FIRST_ANSI + 0) 644 #define MCID_free (_MCID_FIRST_ANSI + 1) 645 #define MCID_malloc (_MCID_FIRST_ANSI + 2) 646 #define MCID_memcpy (_MCID_FIRST_ANSI + 3) 647 #define MCID_memmove (_MCID_FIRST_ANSI + 4) 648 #define MCID_memset (_MCID_FIRST_ANSI + 5) 649 #define MCID_realloc (_MCID_FIRST_ANSI + 6) 650 #define MCID_sprintf (_MCID_FIRST_ANSI + 7) 651 #define MCID_strcat (_MCID_FIRST_ANSI + 8) 652 #define MCID_strcpy (_MCID_FIRST_ANSI + 9) 653 #define MCID_strncat (_MCID_FIRST_ANSI + 10) 654 #define MCID_strncpy (_MCID_FIRST_ANSI + 11) 655 #define MCID_vsprintf (_MCID_FIRST_ANSI + 12) 656 657 #define _MCID_LAST_ANSI MCID_vsprintf /* define to last ANSI */ 658 659 660 /* *************** MICROSOFT C ******************* */ 661 662 #if defined(_CC_MSC_COMPATIBLE_) 663 664 #define _MCID_FIRST_MSC (_MCID_LAST_ANSI + 1) 665 666 # define MCID__expand (_MCID_FIRST_MSC + 0) 667 # define MCID__ffree (_MCID_FIRST_MSC + 1) 668 # define MCID__fcalloc (_MCID_FIRST_MSC + 2) 669 # define MCID__fmalloc (_MCID_FIRST_MSC + 3) 670 # define MCID__fmsize (_MCID_FIRST_MSC + 4) 671 # define MCID__frealloc (_MCID_FIRST_MSC + 5) 672 # define MCID__fexpand (_MCID_FIRST_MSC + 6) 673 # define MCID__msize (_MCID_FIRST_MSC + 7) 674 675 # define MCID__fmemmove (_MCID_FIRST_MSC + 8) 676 # define MCID__fmemcpy (_MCID_FIRST_MSC + 9) 677 # define MCID__fmemset (_MCID_FIRST_MSC + 10) 678 # define MCID__fmemccpy (_MCID_FIRST_MSC + 11) 679 # define MCID__fstrcat (_MCID_FIRST_MSC + 12) 680 # define MCID__fstrncat (_MCID_FIRST_MSC + 13) 681 # define MCID__fstrcpy (_MCID_FIRST_MSC + 14) 682 # define MCID__fstrncpy (_MCID_FIRST_MSC + 15) 683 # define MCID__fstrdup (_MCID_FIRST_MSC + 16) 684 # define MCID__fstrset (_MCID_FIRST_MSC + 17) 685 # define MCID__fstrnset (_MCID_FIRST_MSC + 18) 686 687 # define MCID__nfree (_MCID_FIRST_MSC + 19) 688 # define MCID__nmalloc (_MCID_FIRST_MSC + 20) 689 # define MCID__ncalloc (_MCID_FIRST_MSC + 21) 690 # define MCID__nrealloc (_MCID_FIRST_MSC + 22) 691 # define MCID__nexpand (_MCID_FIRST_MSC + 23) 692 # define MCID__nmsize (_MCID_FIRST_MSC + 24) 693 # define MCID__nstrdup (_MCID_FIRST_MSC + 25) 694 695 # define MCID__dos_setvect (_MCID_FIRST_MSC + 26) 696 # define MCID__getdcwd (_MCID_FIRST_MSC + 27) 697 698 /* Here starts the Great ANSI Divide. 699 MSC6 and earlier have no underscores; 700 MSC7 and later *have* underscores to emphasize 701 departure from ANSI... 702 */ 703 #if defined(_CC_MSC_) && !defined (MSC6) /* not MSC6-compatible */ 704 705 # define MCID__getcwd (_MCID_FIRST_MSC + 28) 706 # define MCID__cgets (_MCID_FIRST_MSC + 29) 707 # define MCID__halloc (_MCID_FIRST_MSC + 30) 708 # define MCID__hfree (_MCID_FIRST_MSC + 31) 709 # define MCID__memccpy (_MCID_FIRST_MSC + 32) 710 # define MCID__strdup (_MCID_FIRST_MSC + 33) 711 # define MCID__strnset (_MCID_FIRST_MSC + 34) 712 # define MCID__strset (_MCID_FIRST_MSC + 35) 713 # define MCID__swab (_MCID_FIRST_MSC + 36) 714 # define MCID__tempnam (_MCID_FIRST_MSC + 37) 715 716 #else /*** MSC6 and before; WATCOM ***/ 717 718 /* No leading underscores */ 719 720 # define MCID_getcwd (_MCID_FIRST_MSC + 28) 721 # define MCID_cgets (_MCID_FIRST_MSC + 29) 722 # define MCID_halloc (_MCID_FIRST_MSC + 30) 723 # define MCID_hfree (_MCID_FIRST_MSC + 31) 724 # define MCID_memccpy (_MCID_FIRST_MSC + 32) 725 # define MCID_strdup (_MCID_FIRST_MSC + 33) 726 # define MCID_strnset (_MCID_FIRST_MSC + 34) 727 # define MCID_strset (_MCID_FIRST_MSC + 35) 728 # define MCID_swab (_MCID_FIRST_MSC + 36) 729 # define MCID_tempnam (_MCID_FIRST_MSC + 37) 730 731 #endif /* MSC6 ANSI calls */ 732 733 # define MCID_new (_MCID_FIRST_MSC + 38) 734 # define MCID_delete (_MCID_FIRST_MSC + 39) 735 # define MCID__fullpath (_MCID_FIRST_MSC + 40) 736 737 #endif /* Microsoft C-compatible calls */ 738 739 740 /* *************** BORLAND C ******************* */ 741 742 #if defined (_CC_BORLAND_) 743 744 #define _MCID_FIRST_BC (_MCID_LAST_ANSI + 1) 745 746 # define MCID__fmemmove (_MCID_FIRST_BC + 0) 747 # define MCID__fmemcpy (_MCID_FIRST_BC + 1) 748 # define MCID__fmemset (_MCID_FIRST_BC + 2) 749 # define MCID__fmemccpy (_MCID_FIRST_BC + 3) 750 # define MCID__fstrcat (_MCID_FIRST_BC + 4) 751 # define MCID__fstrncat (_MCID_FIRST_BC + 5) 752 # define MCID__fstrcpy (_MCID_FIRST_BC + 6) 753 # define MCID__fstrncpy (_MCID_FIRST_BC + 7) 754 # define MCID__fstrdup (_MCID_FIRST_BC + 8) 755 # define MCID__fstrset (_MCID_FIRST_BC + 9) 756 # define MCID__fstrnset (_MCID_FIRST_BC + 10) 757 758 # define MCID__dos_setvect (_MCID_FIRST_BC + 11) 759 # define MCID__getdcwd (_MCID_FIRST_BC + 12) 760 761 # define MCID_getcwd (_MCID_FIRST_BC + 13) 762 # define MCID_cgets (_MCID_FIRST_BC + 14) 763 # define MCID_memccpy (_MCID_FIRST_BC + 15) 764 # define MCID_strdup (_MCID_FIRST_BC + 16) 765 # define MCID_strnset (_MCID_FIRST_BC + 17) 766 # define MCID_strset (_MCID_FIRST_BC + 18) 767 # define MCID_swab (_MCID_FIRST_BC + 19) 768 # define MCID_tempnam (_MCID_FIRST_BC + 20) 769 770 # define MCID_farmalloc (_MCID_FIRST_BC + 21) 771 # define MCID_farrealloc (_MCID_FIRST_BC + 22) 772 # define MCID_farfree (_MCID_FIRST_BC + 23) 773 # define MCID_farcalloc (_MCID_FIRST_BC + 24) 774 # define MCID_movmem (_MCID_FIRST_BC + 25) 775 # define MCID_setmem (_MCID_FIRST_BC + 26) 776 # define MCID_setvect (_MCID_FIRST_BC + 27) 777 # define MCID_stpcpy (_MCID_FIRST_BC + 28) 778 # define MCID__fmovmem (_MCID_FIRST_BC + 29) 779 # define MCID__fsetmem (_MCID_FIRST_BC + 30) 780 # define MCID_new (_MCID_FIRST_BC + 31) 781 # define MCID_delete (_MCID_FIRST_BC + 32) 782 # define MCID__fullpath (_MCID_FIRST_BC + 33) 783 784 #endif 785 786 787 /* 788 'TOUCH' macro so high warning levels don't generate 789 'unreferenced variable' warnings, especially when 790 making Production libraries... All MemCheck code 791 compiles without a whymper. 792 */ 793 #if defined (_CC_WATCOM_) 794 # define TOUCH(var) var = var 795 #elif defined (_CC_BORLAND4_) 796 # define TOUCH(var) var = var 797 #else 798 # define TOUCH(var) if (var) 799 #endif 800 801 802 /* Default log name used by stock erf_logfile() and variants... */ 803 #define MEMCHECK_LOG "MEMCHECK.LOG" 804 805 #define MAX_MEMORY 1000 /* 1000K is more than ever possible */ 806 807 /* User-Modifiable Defaults */ 808 809 #define D_CheckByteCt sizeof(int) /* word size is default */ 810 #define D_AlignSize sizeof(int) /* align returned memory ptrs */ 811 812 /* Number of bytes to copy from null segment (to determine null 813 pointer assignments) 814 */ 815 #define D_NULLCHECK_BYTES_FAR 16 /* at 0000:0000 (far NULL) */ 816 #define D_NULLCHECK_BYTES_NEAR 16 /* at DS:0000 (near NULL) */ 817 #define MAX_NULLCHECK_BYTES_FAR 1024 /* extent of irupt vect tbl */ 818 #define MAX_NULLCHECK_BYTES_NEAR 66 /* reserved in DS */ 819 820 /* Unroll the double-negative */ 821 /* 822 Debugging code specific to MemCheck can be 823 conditionally compiled by placing it within 824 #if-#endif sections: (NOTE that this is NOT 825 required when just using API functions) 826 827 #ifdef MEMCHECK 828 829 void _MCCALLBACK trackf_special (int op, MEMRECP memrecp) 830 { 831 (... your custom callback code ...) 832 } 833 834 #endif 835 836 instead of the more arcane 837 838 #ifndef NOMEMCHECK 839 : 840 #endif 841 842 (Both approaches work equally well, however...) 843 */ 844 #ifndef NOMEMCHECK /* MemCheck active */ 845 #define MEMCHECK 846 #endif 847 848 849 /* *** Calling Conventions *** */ 850 851 #if !defined (_CC_ANSI_) 852 #define _MCAPI pascal /* MemCheck API functions */ 853 #define _FASTAPI pascal /* speed-critical functions */ 854 #define _MCCDECL cdecl /* MemCheck varargs API */ 855 #define _MCCALLBACK cdecl /* callback functions */ 856 #define _MCVAR cdecl /* MemCheck global variable */ 857 #else 858 #define _MCAPI /* MemCheck API functions */ 859 #define _FASTAPI /* speed-critical functions */ 860 #define _MCCDECL /* MemCheck varargs API */ 861 #define _MCCALLBACK /* callback functions */ 862 #define _MCVAR /* MemCheck global variable */ 863 #endif 864 865 #if !defined(_CC_WATCOM_) 866 # define _RTL _MCCDECL /* RTL calling conv */ 867 #else 868 # define _RTL /* RTL calling conv */ 869 870 /* WATCOM C++ does not currently (2/17/94) 871 accept "cdecl" as a modifier on variables... 872 */ 873 # undef _MCVAR 874 # define _MCVAR 875 #endif /* _CC_WATCOM_ */ 876 877 /* 32-bit compiler-independent stuff */ 878 #if !defined(_CC32_) 879 #define _MCFAR far 880 #define _MCFARCALL far 881 #define _MCNEAR near 882 #define _MCNEARCALL near 883 #define _MCHUGE huge 884 #else 885 #define _MCFAR 886 #define _MCFARCALL 887 #define _MCNEAR 888 #define _MCNEARCALL 889 #define _MCHUGE 890 #endif /* _CC32_ */ 891 892 /* 893 MSC declares the following routines as "far"... 894 So does Borland. WATCOM does not; define glue. 895 896 _fstrset _fstrnset _fstrcpy 897 _fstrncpy _fstrcat _fstrncat 898 _fmemset _fmemmove _fmemccpy 899 */ 900 #if !defined(_CC_WATCOM_) 901 # define _MCFARGLUE far 902 #else 903 # define _MCFARGLUE 904 #endif 905 906 907 /* Microsoft C7 and later will not have 908 have a malloc_mc, only _fmalloc_mc; likewise 909 with free_mc. 910 The RTLMALLOC and RTLFREE macros are used 911 to refer to a generically present back-end malloc 912 and free. 913 */ 914 #if defined (_CC_MSC_) 915 # if defined (LDATA) 916 # define RTLMALLOC RTL(_fmalloc) 917 # define RTLFREE RTL(_ffree) 918 # else 919 # define RTLMALLOC RTL(_nmalloc) 920 # define RTLFREE RTL(_nfree) 921 # endif 922 #else /* non-MSC */ 923 # define RTLMALLOC RTL(malloc) 924 # define RTLFREE RTL(free) 925 #endif 926 927 928 /* WATCOM defines its atexit funcs as a "register", 929 which causes a param type mismatch. 930 _ATEXITFUNC calling convention smooths this out. 931 */ 932 #if defined (_CC_WATCOM_) 933 # define _ATEXITFUNC 934 #else 935 # define _ATEXITFUNC _MCCDECL 936 #endif 937 938 939 /* MemCheck Tracking Mode 940 941 Returned by mc_get_mode(). 942 Indicates whether information on each allocation 943 is being stored in memory or on disk. 944 */ 945 #define MC_USING_MEMORY 1 946 #define MC_USING_DISK 2 947 948 949 /* Min, max orders for each node in the B-tree */ 950 951 #define BT_ORDER_MIN 5 952 #define BT_ORDER_MAX 255 /* maximum tree order */ 953 #define BT_ORDER_DEFAULT 19 /* default tree order */ 954 955 /* 956 Returned by mc_get_speed(). 957 Pass as params to mc_set_speed(). 958 */ 959 #define MC_RUN_NORMAL 1 960 #define MC_RUN_FAST 2 961 962 /* For mc_report(): 963 "Flags" field of the MEMREC structure 964 is set to REPORT_START or REPORT_END 965 to indicate begin and end of report. 966 967 NOTE: If REPORT_START or REPORT_END conflicts 968 with defines in your project, just comment 969 them out and use the MC_... variants instead. 970 */ 971 #define REPORT_START (MRFLAGS)0xFE 972 #define REPORT_END (MRFLAGS)0xFD 973 974 #define MC_REPORT_START (MRFLAGS)0xFE /* alternates in case of conflict */ 975 #define MC_REPORT_END (MRFLAGS)0xFD 976 977 978 /* 979 Maximum number of breakpoints that 980 can be set via mc_breakpoint(). 981 */ 982 #define MC_MAX_BREAKS 50 983 984 985 /* "Optype" parameter on Tracking function callback. */ 986 #define TRACKF_ADD 1 /* record being added to tree */ 987 #define TRACKF_DEL 2 /* record being deleted from tree */ 988 989 /* Used for the mcflags field of MEMREC to indicate 990 whether file & line are exact or approximate 991 */ 992 #define MRFLAG_EXACT_LOC ( (MRFLAGS) 0x01) 993 994 /* 995 Set if the values for a MEMREC are already converted 996 to "user" values. 997 */ 998 #define MRFLAG_USER_SPECS ( (MRFLAGS) 0x02) 999 #define MRFLAG_NO_CHECKBYTES ( (MRFLAGS) 0x04) 1000 1001 /* Alternate name */ 1002 #define mc_message mc_debug 1003 1004 /* 1005 Parameter to mc_check_transfer() that 1006 specifies that the given data transfer function cannot 1007 have overlapping source & destination. 1008 (MCID's are unsigned bytes.) 1009 */ 1010 #define MCF_NO_OVERLAP ((unsigned)0x8000) 1011 #define NO_OVERLAP(mcid) ((mcid) | MCF_NO_OVERLAP) 1012 1013 /* Parameter to mc_check_transfer indicating that 1014 the found memory record is not needed */ 1015 #define NO_MEMREC ((MEMRECP)NULL) 1016 #define NOMEMREC NO_MEMREC 1017 1018 /* Parameter to mc_check_transfer indicating that 1019 there is no source pointer operand associated 1020 with the data transfer being checked: e.g. memset. */ 1021 #define NO_SOURCE ((void _MCFAR *)0xFFFFFFFA) 1022 1023 1024 /* *** TYPEDEFS *** */ 1025 1026 typedef char * MCSF; /* MemCheck source file */ 1027 typedef unsigned int MCSL; /* MemCheck source line */ 1028 typedef unsigned char MCID; /* MemCheck function ID */ 1029 1030 typedef unsigned long MCEFLAGS; /* MemCheck error flags */ 1031 typedef void _MCFAR * MCPTR; /* type of ptr stored in tree */ 1032 typedef unsigned char MRFLAGS; /* flags in MEMRECORD */ 1033 typedef unsigned long MCFLAGS; /* MemCheck settings flags */ 1034 1035 /* MemCheck Rocket allocator prototypes */ 1036 typedef void _MCFAR * (_MCFAR *ROCKETALLOCF) (size_t); 1037 typedef void (_MCFAR *ROCKETFREEF) (void _MCFAR *); 1038 1039 #pragma pack(1) 1040 /* 1041 Memory Tracking Structure (MEMREC) 1042 1043 This is the data structure for buffers being 1044 tracked by MemCheck. 1045 */ 1046 typedef struct MemRecord 1047 { 1048 MCPTR ptr; /* heap/registered ptr */ 1049 MCID mcid; /* MemCheck function ID */ 1050 MRFLAGS flags; /* internal MC flags */ 1051 unsigned long allocno; /* cardinality of allocation */ 1052 unsigned long size; /* size of block */ 1053 MCSF file; /* source file */ 1054 MCSL line; /* source line */ 1055 1056 } MEMREC, _MCFAR *MEMRECP; 1057 1058 1059 /* *** SETTINGS *** */ 1060 /* These are values that describe the life of a MemCheck run. */ 1061 1062 typedef struct MCSETTINGS { 1063 /* 1064 Bit Flag What 1065 --- --------------- ----------------------------------- 1066 0 MCF_ACTIVE MemCheck active or off 1067 1 MCF_FAST_MODE Fast mode or normal 1068 2 MCF_PROTECTED_MODE Protected mode or real 1069 3 MCF_FAR_NULL_CHECK Check for far NULL ptr assigns * 1070 4 MCF_NEAR_NULL_CHECK Check for far NULL ptr assigns * 1071 5 MCF_STANDARD_STACK Standard stack frame * 1072 6 MCF_AUTOINIT Start up automatically * 1073 7 MCF_CLEAR_ON_FREE Clear buffers when freed 1074 8 MCF_DISK_ROCKET Use DiskRocket options 1075 9 MCF_IDX_IN_MEMORY Use memory only for Rocket indexes * 1076 (only if DiskRocket linked) 1077 10 MCF_SOURCE_ONLY Intercept in source code only 1078 1079 11 - 31 Reserved 1080 */ 1081 MCFLAGS Flags; /* Main settings flags */ 1082 1083 unsigned short MaxMem; /* Max mem for tree usage, in K */ 1084 unsigned short NearNullBytes; /* bytes to check in near null */ 1085 unsigned short FarNullBytes; /* " " " " far " */ 1086 unsigned char CheckByteCt; /* check byte count */ 1087 unsigned char AlignSize; /* alignment boundary size */ 1088 char TrackingDir[36]; /* Rocket stores temp files here */ 1089 1090 } MCSETTINGS, *MCSETTINGSP; 1091 1092 1093 /* Random 32-bit .CFG file sentinel */ 1094 #define MC_CFG_FILE_SENTINEL ( (unsigned long) 0x10F23BC4 ) 1095 1096 typedef struct MCCfgInfo { 1097 1098 unsigned long sentinel; /* always MC_CFG_FILE_SENTINEL */ 1099 MCSETTINGS MemCheckSettings; /* saved by user */ 1100 1101 } MCCFGINFO, *MCCFGINFOP; 1102 1103 1104 #ifndef _CC32_ 1105 1106 /* 16-bit exception stack */ 1107 typedef struct { 1108 1109 unsigned xRetIP; 1110 unsigned xRetCS; 1111 unsigned xErr; 1112 unsigned xIP; 1113 unsigned xCS; 1114 unsigned xFlags; 1115 unsigned xSP; 1116 unsigned xSS; 1117 1118 } MCEXCEPTINFO; 1119 1120 #else 1121 1122 /* 32-bit exception stack */ 1123 typedef struct { 1124 1125 unsigned long xRetEIP; 1126 unsigned short xRsvd1; 1127 unsigned short xRetCS; 1128 unsigned long xErr; 1129 unsigned long xEIP; 1130 unsigned short xRsvd2; 1131 unsigned short xCS; 1132 unsigned long xFlags; 1133 unsigned long xESP; 1134 unsigned short xRsvd3; 1135 unsigned short xSS; 1136 1137 } MCEXCEPTINFO; 1138 1139 #endif /* _CC32_ */ 1140 1141 /* Values for MCCRITSECT.action */ 1142 #define MCCS_ENTER_SECTION 0 1143 #define MCCS_LEAVE_SECTION 1 1144 1145 #define MCCS_ACTION(pMCCS) (pMCCS->nAction) 1146 #define MCCS_ENTER(pMCCS) ((*(pMCCS->pLocked))++) /* inc flag */ 1147 #define MCCS_LEAVE(pMCCS) ((*(pMCCS->pLocked))--) /* dec flag */ 1148 1149 /* 1150 Critical section object - ptr to this passed to crit sect callback 1151 WARNING: access these fields ONLY via the MCCS_...() macros. 1152 To do otherwise subjects you to changes in implementation 1153 of the underlying coordination of critical section locking. 1154 */ 1155 typedef struct { 1156 int nAction; /* MCCS_ENTER/LEAVE_SECTION */ 1157 int * pLocked; /* # times entered */ 1158 unsigned long ulRsvd; /* internal use */ 1159 } MCCRITSECT; 1160 1161 #pragma pack() 1162 1163 1164 #define MC_FEXIT ( (MCID) 0xFF ) 1165 1166 1167 /* Error Reporting Function typedef */ 1168 #ifndef _ERF_DEFINED 1169 #define _ERF_DEFINED 1170 typedef void (_MCCALLBACK *ERF) (char *); 1171 #endif 1172 1173 1174 /* *** Callback Functions *** */ 1175 1176 /* Interception callback (on every interception) */ 1177 typedef void (_MCCALLBACK * GLOBALF) (void); 1178 1179 /* Called whenever nodes added to or deleted from MC database */ 1180 typedef void (_MCCALLBACK *TRACKF) (int, MEMRECP); 1181 1182 /* User-definable check function to add to transfer checking */ 1183 typedef void (_MCCALLBACK * CHECKF) ( 1184 int , /* 0 or MCE_... error val for this xfer op */ 1185 void _MCFAR *, /* user ptr dest */ 1186 long /* bytes to copy to dest */ 1187 ); 1188 1189 /* Funcs called at startup or shutdown */ 1190 typedef void (_MCCALLBACK *STARTF) (void); 1191 typedef void (_MCCALLBACK *ENDF) (void); 1192 1193 /* Report function type passed to mc_report() */ 1194 typedef void (_MCCALLBACK *REPORTF) (MEMRECP); 1195 1196 /* Additional heap pointer verification (troubleshoot only) */ 1197 typedef int (_MCCALLBACK *VERIFYF) (void _MCFAR *); 1198 1199 typedef void (*MCVOIDFP) (void); 1200 1201 /* Exception handler */ 1202 typedef void (_MCCALLBACK _MCFAR *MCEXCEPTF) (void); 1203 1204 /* Multitasking enter/exit critical section callback. 1205 Specify as param to mc_set_critf() at beginning of program; 1206 callback function will be called with MCCS_ENTER_SECTION 1207 on entry to MemCheck, or MCCS_LEAVE_SECTION on exit. 1208 1209 NOT TO BE CONFUSED WITH A MEMCHECK "GLOBAL" FUNCTION. 1210 Global functions (GLOBALF's) are used to perform any 1211 actions on the interception of a runtime function; 1212 CRITF's must be used ONLY to serialize access to MemCheck. 1213 */ 1214 typedef void (_MCCALLBACK * MCCRITF) (MCCRITSECT *); 1215 1216 1217 /* Stack Frame Handler 1218 1219 You can define your own function to 1220 record, analyze, or inspect each stack frame 1221 when mc_stack_trace() is called. 1222 1223 You *cannot* modify ANY of the values passed 1224 in, as the "const" typing indicates. If you need to 1225 modify a value, make a copy. See the MemCheck 3.0 1226 documentation for more details on stack frame handlers. 1227 */ 1228 1229 typedef void (_MCFAR _MCCDECL *_SSFRAMEHANDLER ) ( 1230 short const , /* AX: near/far/error flag */ 1231 unsigned short const , /* CX: near (default) rtn CS */ 1232 unsigned short const , /* ES: far rtn CS */ 1233 unsigned const , /* DI: rtn offset from stack */ 1234 short const /* DX: frame count */ 1235 ); 1236 1237 /* Values for "flag" constant parameter to a 1238 stack frame handler. 1239 */ 1240 #define TRACE_BAD_FRAME 0x00 /* couldn't recognize frame */ 1241 #define TRACE_FAR_CALL 0x01 /* frame represents a far call */ 1242 #define TRACE_NEAR_CALL 0x02 /* " " " near " */ 1243 #define TRACE_BAD_CHAIN 0x03 /* frame BP chewed up */ 1244 #define TRACE_BEGIN 0x80 /* signals begin walk */ 1245 #define TRACE_END 0x81 /* signals end of walk */ 1246 1247 1248 /* MC Settings Structure, "flags" member: */ 1249 #define MCF_ACTIVE (MCFLAGS)(0x01) 1250 #define MCF_FAST_MODE (MCFLAGS)(0x02) 1251 #define MCF_PROTECTED_MODE (MCFLAGS)(0x04) 1252 #define MCF_FAR_NULL_CHECK (MCFLAGS)(0x08) 1253 #define MCF_NEAR_NULL_CHECK (MCFLAGS)(0x10) 1254 #define MCF_STANDARD_STACK (MCFLAGS)(0x20) 1255 #define MCF_AUTOINIT (MCFLAGS)(0x40) 1256 #define MCF_CLEAR_ON_FREE (MCFLAGS)(0x80) 1257 #define MCF_DISK_ROCKET (MCFLAGS)(0x100) 1258 #define MCF_IDX_IN_MEMORY (MCFLAGS)(0x200) 1259 #define MCF_SOURCE_ONLY (MCFLAGS)(0x400) 1260 1261 1262 /* *** Conditional Compilation *** */ 1263 1264 /* -------------------------------------------------------------- 1265 If MEMCHECK is not being `compiled out' (via definition 1266 of the constant NOMEMCHECK), include this section... 1267 -------------------------------------------------------------- */ 1268 1269 #if !defined(MEMCHECK) 1270 1271 /* Include Section for `MemCheck Not Active' */ 1272 1273 /* ***************************** 1274 MemCheck Not Active Section 1275 ***************************** 1276 1277 This section completely removes or 1278 "evaporates" all MemCheck function references 1279 from your projects when you compile with 1280 NOMEMCHECK #defined. 1281 1282 There's no need to remove any MemCheck 1283 headers or statements from your code 1284 to produce a full production version 1285 of your application. 1286 1287 o 1288 ooo 1289 ooooooo 1290 ooooooooo 1291 ooooooooooo 1292 ooo 1293 ooo 1294 ooo 1295 ooo 1296 */ 1297 1298 #ifndef MEMCHECK_MODULE 1299 1300 /* Evaporate all MemCheck 3.0 API 1301 statements to do nothing, safely... */ 1302 1303 # define mc_alloc_count() 0L 1304 # define mc_blocks_allocated() 0L 1305 # define mc_blocks_freed() 0L 1306 # define mc_breakpoint(fi) 0 1307 # define mc_bytes_allocated() 0L 1308 # define mc_bytes_freed() 0L 1309 # define mc_check(p) 0 1310 # define mc_check_buffers() 0 1311 # define mc_cur_file() "No file" 1312 # define mc_cur_line() 0 1313 # define mc_debug(s) 1314 # define mc_debugf(_args) 1315 # define mc_debug_on() 1316 # define mc_debug_off() 1317 # define mc_endcheck() (MCEFLAGS)0 1318 # define mc_errno() MCE_NO_ERROR 1319 # define mc_error_flags() (MCEFLAGS)0 1320 # define mc_error_text(e) "MemCheck not active" 1321 # define mc_except_text(e) "MemCheck not active" 1322 # define mc_file() "No file" 1323 # define mc_find_buffer(p,mr) 0 1324 # define mc_func() (MCID)0 1325 # define mc_func_name(mcid) ("") 1326 # define mc_get_erf() (ERF)NULL 1327 # define mc_get_mode() 0 1328 # define mc_get_speed() 0 1329 # define mc_in_source() 0 1330 # define mc_is_active() 0 1331 # define mc_line() 0 1332 # define mc_load_debugger() 1333 # define mc_location_text() "MemCheck not active" 1334 # define mc_memory_leaked() 0L 1335 # define mc_memrec() (MEMRECP)NULL 1336 # define mc_memrec_text() "MemCheck not active" 1337 # define mc_msg_continued() 0 1338 # define mc_nullcheck() 0 1339 # define mc_null_snapshot() 1340 # define mc_register(p,s) 1341 # define mc_report(_f) 1342 # define mc_set_alignsize(_s) 1343 # define mc_set_breakfile(_f) 1344 # define mc_set_checkbytes(_cb) 1345 # define mc_set_checkf(_f) (CHECKF)NULL 1346 # define mc_set_critf(_f) 1347 # define mc_set_endf(erf) (ENDF)NULL 1348 # define mc_set_erf(erf) (ERF)NULL 1349 # define mc_set_globalf(_f) (GLOBALF)NULL 1350 # define mc_set_globalexitf(_f) (GLOBALF)NULL 1351 # define mc_set_speed(_s) 1352 # define mc_set_location() 1353 # define mc_set_trackf(_f) (TRACKF)NULL 1354 # define mc_set_tracefile(_f) 1355 # define mc_set_tree_order(_q) 1356 # define mc_set_track_dir(_dir) 1357 # define mc_source_ptr() (MCPTR)NULL 1358 # define mc_stack_trace(_memo) 0 1359 # define mc_startcheck(_erf) 1360 # define mc_unregister(p) 1361 # define mc_set_exceptf(f) 1362 # define mc_get_exceptf() ((MCEXCEPTF)NULL) 1363 1364 /* *** Stock error reporting functions *** */ 1365 # define erf_default(_msg) 1366 # define erf_standard(_msg) 1367 # define erf_logfile(_msg) 1368 # define erf_log_only(_msg) 1369 # define erf_trace(_msg) 1370 1371 /* Internal Helpers */ 1372 # define _direct_output(_s) 1373 # define _mcsl(_f,_l) 1374 # define _mcsl_delete(_f,_l) 1375 # define _mcsl_new(_f,_l) 1376 # define _mcslx(_f,_l,_s) 1377 # define _mc_set_delflag() 1378 # define _mc_set_location(_f,_l) 1379 # define _mc_set_newflag() 1380 1381 /* Link-time compileouts */ 1382 # define MC_SET_AUTOINIT(_toggle) 1383 # define MC_SET_CHECK_FREQ(_freq) 1384 # define MC_SET_CHECKF(_f) 1385 # define MC_SET_CRITF(_f) 1386 # define MC_SET_ENDF(_f) 1387 # define MC_SET_ENV_VAR(_envvarname) 1388 # define MC_SET_ERF(_f) 1389 # define MC_SET_GLOBALF(_f) 1390 # define MC_SET_GLOBALEXITF(_f) 1391 # define MC_SET_LOGFILE(_logfilename) 1392 # define MC_SET_PANIC_BUFFERS(_q) 1393 # define MC_SET_SSFH(_f) 1394 # define MC_SET_STARTF(_f) 1395 # define MC_SET_TRACKF(_f) 1396 # define MC_SET_VERIFYF(_f) 1397 1398 /* Back-end direct */ 1399 #define RTL(_f) _f 1400 1401 /* *** C++ *** */ 1402 #ifdef __cplusplus 1403 1404 #define NEW(_object) new _object 1405 #define DELETE(_object) delete _object 1406 #define DELETE_ARR(_arr) delete[] _arr 1407 1408 #define cpp_malloc(_s) malloc(_s) 1409 #define cpp_calloc(_n,_s) calloc(_n,_s) 1410 #define cpp_free(_p) free(_p) 1411 1412 /* Borland C++ */ 1413 #define cpp_farmalloc(_s) farmalloc(_s) 1414 #define cpp_farfree(_fp) farfree(_fp) 1415 1416 /* Microsoft C++-compatibles */ 1417 #define cpp__fmalloc(_s) _fmalloc(_s) 1418 #define cpp__ffree(_fp) _ffree(_fp) 1419 1420 #endif /* C++ */ 1421 1422 #endif /* not MEMCHECK_MODULE */ 1423 1424 1425 /* #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# */ 1426 1427 #else /* MEMCHECK is defined */ 1428 1429 /* #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# */ 1430 1431 #pragma message ("MemCheck V3.0") 1432 1433 /* 1434 ************************* 1435 MemCheck Active Section 1436 ************************* 1437 1438 The rest of this header file deals with 1439 MemCheck's being compiled into an application. 1440 1441 */ 1442 1443 /* Specify that vars and funcs are straight C.. */ 1444 #ifdef __cplusplus 1445 extern "C" { 1446 #endif 1447 1448 1449 /* *** ANSI Location Defines *** */ 1450 1451 #define _MC_NO_FILE ((MCSF) 0) /* just in case... */ 1452 #define _MC_NO_LINE ((MCSL) 0) 1453 1454 1455 /* Allow for the possibility of _MCSF_ being 1456 defined to reference a single, static module 1457 filename. This prevents a multiplicity of 1458 static filenames getting added to the DGROUP, e.g. 1459 1460 static char *_thisfile = __FILE__; 1461 #define _MCSF_ ((MCSF)thisfile) 1462 #include <memcheck.h> 1463 1464 This is only needed under MSC pre-VC++. 1465 Borland has "-d" Merge duplicate strings. 1466 VC++ has "/Gf" Elim duplicate strings. 1467 */ 1468 #if !defined (_MCSF_) 1469 # ifdef __FILE__ 1470 # define _MCSF_ (MCSF)__FILE__ 1471 # else 1472 # define _MCSF_ _MC_NO_FILE 1473 # endif 1474 #endif 1475 1476 #ifdef __LINE__ 1477 # define _MCSL_ (MCSL)__LINE__ 1478 #else 1479 # define _MCSL_ _MC_NO_LINE 1480 #endif 1481 1482 1483 /* *** Standard ANSI C Includes *** 1484 1485 For va_list function call args 1486 Inclusion of this header won't change 1487 the behavior of host code. 1488 */ 1489 #if !defined (va_start) /* avoid multiple inclusion... */ 1490 # include <stdarg.h> 1491 #endif 1492 1493 1494 /* *** Compiler-specific includes *** */ 1495 1496 /*lint -save -e537 Repeated include files (if necessary) */ 1497 #if defined(_CC_MSC_COMPATIBLE_) 1498 1499 # if !defined (_INC_MALLOC) /* C7.x and later optimization */ 1500 # include <malloc.h> 1501 # endif 1502 1503 # if !defined (_INC_STRING) /* C7.x and later optimization */ 1504 # include <string.h> 1505 # endif 1506 1507 #elif defined(_CC_BORLAND_) 1508 1509 # if !defined (__ALLOC_H) 1510 # include <alloc.h> 1511 # endif 1512 1513 /* String functions must be proto'd before pragmas */ 1514 # if !defined (__STRING_H) 1515 # include <string.h> 1516 # endif 1517 1518 #endif /* Compiler-specific includes */ 1519 /*lint -restore */ 1520 1521 #if defined (_CC_POWERPACK32_) 1522 extern void cdecl mcinitfp_startcheck (void); 1523 extern void cdecl mcexitfp_endcheck (void); 1524 #pragma startup mcinitfp_startcheck 16 1525 #pragma exit mcexitfp_endcheck 16 1526 #endif 1527 1528 /***************************************/ 1529 /* *** MemCheck 3.0 API Prototypes *** */ 1530 /***************************************/ 1531 1532 /* Internal helper macro - proto shorthand */ 1533 #define _LOCP MCSF,MCSL 1534 1535 extern unsigned long _MCAPI mc_alloc_count (void); 1536 extern unsigned long _MCAPI mc_blocks_allocated (void); 1537 extern unsigned long _MCAPI mc_blocks_freed (void); 1538 extern unsigned long _MCAPI mc_bytes_allocated (void); 1539 extern unsigned long _MCAPI mc_bytes_freed (void); 1540 extern int _MCAPI mc_check (void _MCFAR *); 1541 extern int _MCAPI mc_check_buffers (void); 1542 extern MCSF _MCAPI mc_cur_file (void); 1543 extern MCSL _MCAPI mc_cur_line (void); 1544 extern void _MCCDECL mc_debugv (const char *, ...); 1545 extern void _MCAPI mc_debug (const char *); 1546 extern MCEFLAGS _MCAPI mc_endcheck (void); 1547 extern MCEFLAGS _MCAPI mc_error_flags (void); 1548 extern char * _MCAPI mc_error_text (int); 1549 extern int _MCAPI mc_errno (void); 1550 extern char * _MCAPI mc_except_text (unsigned); 1551 extern MCSF _MCAPI mc_file (void); 1552 extern int _MCAPI mc_find_buffer(void _MCFAR *realptr,MEMRECP memrecp); 1553 extern MCID _MCAPI mc_func (void); 1554 extern char * _MCAPI mc_func_name(MCID); 1555 extern ERF _MCAPI mc_get_erf (void); 1556 extern MCEXCEPTF _MCAPI mc_get_exceptf (void); 1557 extern int _MCAPI mc_get_mode (void); 1558 extern int _MCAPI mc_get_speed (void); 1559 extern char * _MCAPI mc_get_tracefile (void); 1560 extern int _MCAPI mc_in_source (void); 1561 extern int _MCAPI mc_is_active (void); 1562 extern MCSL _MCAPI mc_line (void); 1563 extern char * _MCAPI mc_location_text (void); 1564 #define mc_load_debugger() _asm int 3 1565 extern unsigned long _MCAPI mc_memory_leaked (void); 1566 extern char * _MCAPI mc_memrec_text (MEMRECP); 1567 extern MEMRECP _MCAPI mc_memrec (void); 1568 extern int _MCAPI mc_msg_continued (void); 1569 extern int _MCAPI mc_nullcheck (void); 1570 extern void _MCAPI mc_null_snapshot (void); 1571 extern void _MCAPI mc_register (void _MCFAR *, unsigned long); 1572 extern void _MCAPI mc_report (REPORTF); 1573 extern void _MCAPI mc_set_alignsize (unsigned int); 1574 extern void _MCAPI mc_set_breakfile (char *); 1575 extern void _MCAPI mc_set_checkbytes (unsigned int); 1576 extern CHECKF _MCAPI mc_set_checkf (CHECKF); 1577 extern void _MCAPI mc_set_critf (MCCRITF); 1578 extern ENDF _MCAPI mc_set_endf (ENDF); 1579 extern ERF _MCAPI mc_set_erf (ERF); 1580 extern MCEXCEPTF _MCAPI mc_set_exceptf (MCEXCEPTF); 1581 extern GLOBALF _MCAPI mc_set_globalf (GLOBALF); 1582 extern GLOBALF _MCAPI mc_set_globalexitf (GLOBALF); 1583 #define mc_set_location() _mc_set_location(_MCSF_,_MCSL_) 1584 extern MCPTR _MCAPI mc_source_ptr (void); 1585 extern void _MCAPI mc_set_speed (int); 1586 extern void _MCAPI mc_set_tracefile (char *); 1587 extern void _MCAPI mc_set_track_dir (char *); 1588 extern TRACKF _MCAPI mc_set_trackf (TRACKF); 1589 extern void _MCAPI mc_set_tree_order (int); 1590 extern int _MCAPI mc_stack_trace (char *); 1591 extern void _MCAPI mc_startcheck (_LOCP, ERF); 1592 extern void _ATEXITFUNC mc_endcheck_at_exit (void); 1593 extern void _MCAPI mc_unregister (void _MCFAR *); 1594 1595 /* Debugging versions of the MemCheck library only */ 1596 extern void _MCAPI mc_debug_on (void); 1597 extern void _MCAPI mc_debug_off (void); 1598 extern int _MCCALLBACK mc_search_heap (void _MCFAR *); 1599 1600 /* *** INTERNAL API HELPERS *** */ 1601 extern void _MCAPI _mc_set_location (_LOCP); 1602 extern void _FASTAPI _mcsl (MCSF,MCSL); /* location run-ahead */ 1603 extern void _FASTAPI _mcslx (MCSF,MCSL,size_t); /* location run-ahead */ 1604 extern void _FASTAPI _mcsl_new (MCSF,MCSL); /* location run-ahead */ 1605 extern void _FASTAPI _mcsl_delete (MCSF,MCSL); /* location run-ahead */ 1606 extern void _FASTAPI _mc_set_newflag (void); /* new's a'comin' */ 1607 extern void _FASTAPI _mc_set_delflag (void); /* delete's a'comin' */ 1608 1609 /* Misc - uses INT 9 to output directly to screen */ 1610 #if !defined (_CC_WATCOM32_) 1611 extern void _MCCDECL _MCFAR _direct_output (char _MCFAR *); 1612 #else 1613 #define _direct_output(s) printf ("%s\n", s) /* ALERT */ 1614 #endif 1615 1616 /* 1617 mc_breakpoint() is now a MemCheck Tracking function (TRACKF). 1618 Tracking functions get called every time 1619 MemCheck adds or deletes from its database. 1620 */ 1621 #define mc_breakpoint(_f) \ 1622 mc_set_trackf( (mc_set_breakfile (_f), trackf_breakpoint) ) 1623 #define mc_breakpoint_trace(_f) \ 1624 mc_set_trackf( (mc_set_tracefile (_f), trackf_breakpoint_trace) ) 1625 1626 1627 /* *** Advanced-user API extenders *** */ 1628 1629 /* extern int _MCAPI mc_find_buffer(void _MCFAR *, MEMRECP); */ 1630 extern int _MCAPI mc_check_transfer( 1631 void _MCFAR *, 1632 void _MCFAR *, 1633 unsigned long, 1634 unsigned, 1635 unsigned, 1636 MEMRECP); 1637 1638 /* mc_get_settings 1639 1640 Write your own "get settings" routine 1641 to override the one shipped with MemCheck. 1642 You can hard-wire any settings you like, e.g. 1643 always ON for versions of your app shipped to 1644 testers/QA stations, etc. 1645 */ 1646 extern void _MCCALLBACK mc_get_settings (MCSETTINGS *); 1647 1648 1649 /* *** Callbacks / Functionality Extenders *** 1650 1651 Function Type Called... 1652 -------------- ------------------------------ 1653 Error reporting To handle each MemCheck error message 1654 Global Interception On each MemCheck interception 1655 Checking On every data transfer check 1656 Tracking On every allocation/deallocation 1657 Start On mc_startcheck or AutoInit 1658 End At mc_endcheck or MemCheck shutdown 1659 1660 Refer to your MemCheck 3.0 manual for further details. 1661 1662 *** STOCK FUNCTIONS *** 1663 These functions are available in the MemCheck 1664 libraries as "ready-made" for your programming 1665 pleasure in the categories above. 1666 */ 1667 1668 /* *** Stock error reporting functions *** */ 1669 1670 extern void _MCCALLBACK erf_default (char *); 1671 extern void _MCCALLBACK erf_standard (char *); 1672 extern void _MCCALLBACK erf_logfile (char *); 1673 extern void _MCCALLBACK erf_log_only (char *); 1674 extern void _MCCALLBACK erf_trace (char *); 1675 extern void _MCCALLBACK erf_trace_all (char *); 1676 extern void _MCCALLBACK erf_trace_obj (char *); 1677 extern void _MCCALLBACK erf_stdout (char *); 1678 extern void _MCCALLBACK erf_stderr (char *); 1679 extern void _MCCALLBACK erf_find_leaks (char *); 1680 1681 #define erf_printf erf_stdout /* alias*/ 1682 1683 /* *** Stock Tracking Functions *** */ 1684 1685 extern void _MCCALLBACK trackf_default (int, MEMRECP); 1686 extern void _MCCALLBACK trackf_all (int, MEMRECP); 1687 extern void _MCCALLBACK trackf_all_2 (int, MEMRECP); 1688 extern void _MCCALLBACK trackf_breakpoint (int, MEMRECP); 1689 extern void _MCCALLBACK trackf_breakpoint_trace (int, MEMRECP); 1690 extern void _MCCALLBACK trackf_big_alloc (int, MEMRECP); 1691 1692 /* *** Stock End Functions *** */ 1693 1694 extern void _MCCALLBACK endf_default (void); /* does nothing */ 1695 extern void _MCCALLBACK endf_info (void); /* write run info to log */ 1696 extern void _MCCALLBACK endf_alert (void); /* warn if run errs */ 1697 extern void _MCCALLBACK endf_summary (void); /* warn if run errs */ 1698 1699 /* *** Stock Start functions *** */ 1700 1701 extern void _MCCALLBACK startf_default (void); /* does nothing */ 1702 extern void _MCCALLBACK startf_info (void); /* write options to log */ 1703 1704 /* *** Stock Check Functions *** */ 1705 1706 extern void _MCCALLBACK checkf_default (int,void _MCFAR *,long); 1707 extern void _MCCALLBACK checkf_dataseg ( 1708 int, /* 0 or MCE_... error val for this xfer op */ 1709 void _MCFAR *, /* user ptr dest */ 1710 long /* bytes to copy to dest */ 1711 ); 1712 extern void _MCCALLBACK checkf_verify_heap (int,void _MCFAR *,long); 1713 1714 /* *** Stock Global Interception Functions *** */ 1715 1716 extern void _MCCALLBACK globalf_default (void); /* does nothing */ 1717 extern void _MCCALLBACK globalf_supercheck (void); 1718 extern void _MCCALLBACK globalf_check_buffers (void); 1719 extern void _MCCALLBACK globalf_heapcheck (void); 1720 1721 /* *** Stock Report Functions *** */ 1722 extern void _MCCALLBACK reportf_default (MEMRECP); 1723 1724 /* *** Stock Exception Handlers *** */ 1725 extern void _MCCALLBACK _MCFAR exceptf_default (void); 1726 1727 /* *** Stock Stack Frame Handlers *** */ 1728 extern void _MCFAR _MCCDECL ssfh_info ( 1729 short const, unsigned short const, unsigned short const, unsigned const, short const); 1730 1731 extern void _MCFAR _MCCDECL ssfh_fast ( 1732 short const, unsigned short const, unsigned short const, unsigned const, short const); 1733 /* int const _flag, */ 1734 1735 extern void _MCFAR _MCCDECL ssfh_standard ( 1736 short const, unsigned short const, unsigned short const, unsigned const, short const); 1737 1738 extern void _MCFAR _MCCDECL ssfh_debug ( 1739 short const, unsigned short const, unsigned short const, unsigned const, short const); 1740 1741 /* */ 1742 extern unsigned int _MCAPI mc_stacktop (void); /* high address */ 1743 extern unsigned int _MCAPI mc_stackend (void); /* low address */ 1744 1745 1746 /* Function external variables. 1747 1748 These are used effectively with MemCheck 3.0's AutoInit 1749 setting. Under AutoInit, MemCheck fires itself up automatically 1750 on its first interception. Under these circumstances, 1751 there's no chance to have changed any defaults (like the 1752 ERF or error reporting function). These variables provide 1753 a link-level method of setting these functions: 1754 1755 #include <memcheck.h> 1756 : 1757 // Sets custom erf at link-time 1758 MC_SET_ERF (erf_custom_startup); 1759 : 1760 */ 1761 /* *** GLOBALS *** */ 1762 1763 extern ERF _MCVAR MC_ERF; /* error reporting func ptr */ 1764 extern CHECKF _MCVAR MC_CheckF; /* transfer check func */ 1765 extern MCCRITF _MCVAR MC_CritF; /* crit section enter/exit */ 1766 extern GLOBALF _MCVAR MC_GlobalF; /* global interception callback */ 1767 extern GLOBALF _MCVAR MC_GlobalExitF; /* called on exit interception */ 1768 extern TRACKF _MCVAR MC_TrackF; /* alloc/dealloc callback */ 1769 extern STARTF _MCVAR MC_StartF; /* startup callback */ 1770 extern ENDF _MCVAR MC_EndF; /* shutdown callback */ 1771 1772 extern VERIFYF _MCVAR MC_VerifyF; /* troubleshooting */ 1773 1774 extern char * _MCVAR MC_LogFile; /* log file name used */ 1775 extern char _MCVAR MC_UserAutoInit; 1776 extern int _MCVAR MC_CheckFreq; /* for globalf_supercheck() et al */ 1777 extern char * _MCVAR MC_EnvVar; /* Env var to detect 'active' */ 1778 extern unsigned short _MCVAR MC_DataSeg; /* DS value */ 1779 1780 extern int _MCVAR MC_MaxTraceDepth; 1781 extern char * _MCVAR MCST_Desc; /* trace descrip to mc_..trc() */ 1782 1783 extern MCSETTINGS _MCVAR MC_DefaultSettings; /* default settings */ 1784 extern MCSETTINGS _MCVAR MC_Settings; /* real settings-- 1785 USE WITH CARE!!! */ 1786 1787 extern MCVOIDFP _MCVAR MC_PMMap1; /* p-mode func in map seg 1 */ 1788 1789 /* Protected mode exception handling */ 1790 extern unsigned char _MCVAR MC_ExceptList[]; /* exceptions to handle */ 1791 extern MCEXCEPTINFO _MCVAR MC_ExceptInfo; /* in exception */ 1792 extern MCEXCEPTF _MCVAR MC_ExceptF; /* installed hdler */ 1793 1794 /* Rocket Guidance Systems */ 1795 extern ROCKETALLOCF _MCVAR MC_RocketAllocF; 1796 extern ROCKETFREEF _MCVAR MC_RocketFreeF; 1797 extern unsigned char _MCVAR MC_PanicBufCount; /* anti-tree failure */ 1798 1799 /* This char is used to fill freed buffers 1800 if the "ClearOnFree" option in effect. 1801 Default buffer clear char is 0. 1802 */ 1803 extern unsigned char _MCVAR MC_FreedBufferFillChar; 1804 1805 /* Link-time defaults. 1806 1807 These macros are "covers" to insulate you, the developer, 1808 from the underlying implementation, as well as to provide 1809 such bennies as compiling clean out of your code when 1810 NOMEMCHECK or NOMC is defined. 1811 1812 Use instead of accessing vars directly! 1813 1814 To use, place the following in ONE MODULE e.g. your main module 1815 (any *one* module will work fine) after the MemCheck 1816 header file has been included: 1817 1818 #include <memcheck.h> 1819 MC_SET_...(params); 1820 1821 For example, to change the default log file that MemCheck 1822 uses at runtime to C:\MYDEV\MYPROG.LOG: 1823 1824 #include <memcheck.h> 1825 MC_SET_LOGFILE ("C:\\MYDEV\\MPROG.LOG"); 1826 1827 Most of these macros have runtime function equivalents, 1828 such as mc_set_erf() for MC_SET_ERF(), etc. Notable 1829 exceptions to this are the following values that 1830 must generally have link-time initializations: 1831 1832 MC_SET_LOGFILE() 1833 MC_SET_AUTOINIT() 1834 MC_SET_STARTF() 1835 */ 1836 #define MC_SET_AUTOINIT(_toggle) \ 1837 char _MCVAR MC_UserAutoInit = (_toggle); 1838 #define MC_SET_CHECKF(_f) \ 1839 CHECKF _MCVAR MC_CheckF = (_f) 1840 #define MC_SET_CHECK_FREQ(_freq) \ 1841 int _MCVAR MC_CheckFreq = (_freq) 1842 #define MC_SET_CRITF(_f) \ 1843 MCCRITF _MCVAR MC_CritF = (_f) 1844 #define MC_SET_ENDF(_f) \ 1845 ENDF _MCVAR MC_EndF = (_f) 1846 #define MC_SET_ENV_VAR(_envvarname) \ 1847 char * _MCVAR MC_EnvVar = (_envvarname) 1848 #define MC_SET_ERF(_f) \ 1849 ERF _MCVAR MC_ERF = (_f) 1850 #define MC_SET_EXCEPTF(_f) \ 1851 MCEXCEPTF _MCVAR MC_ExceptF = (_f) 1852 #define MC_SET_GLOBALF(_f) \ 1853 GLOBALF _MCVAR MC_GlobalF = (_f) 1854 #define MC_SET_GLOBALEXITF(_f) \ 1855 GLOBALF _MCVAR MC_GlobalExitF = (_f) 1856 #define MC_SET_LOGFILE(_f) \ 1857 char * _MCVAR MC_LogFile = (_f) 1858 #define MC_SET_PANIC_BUFFERS(_q) \ 1859 unsigned char _MCVAR MC_PanicBufCount = (_q) 1860 #define MC_SET_SSFH(_f) \ 1861 _SSFRAMEHANDLER _MCVAR near MC_SFrameHandler = (_f) 1862 #define MC_SET_STARTF(_f) \ 1863 STARTF _MCVAR MC_StartF = (_f) 1864 #define MC_SET_TRACKF(_f) \ 1865 TRACKF _MCVAR MC_TrackF = (_f) 1866 #define MC_SET_VERIFYF(_f) \ 1867 VERIFYF _MCVAR MC_VerifyF = (_f) 1868 1869 /* Use the MC_BEGIN_EXCEPTLIST, MC_HANDLE_EXCEPTION, 1870 and MC_END_EXCEPTLIST macros to change the exceptions 1871 MemCheck handles in protected mode by default. 1872 1873 Usage (exactly as typed): 1874 #include <memcheck.h> 1875 : 1876 MC_BEGIN_EXCEPTLIST 1877 MC_HANDLE_EXCEPTION (0x0) 1878 MC_HANDLE_EXCEPTION (0xD) 1879 MC_END_EXCEPTLIST 1880 1881 NOTE: 1882 To turn off MemCheck's exception handling completely, use 1883 1884 MC_SET_EXCEPTF(NULL); 1885 1886 instead of trying to define an empty EXCEPTLIST... 1887 */ 1888 #define MC_BEGIN_EXCEPTLIST \ 1889 unsigned char _MCVAR MC_ExceptList[] = { 1890 #define MC_HANDLE_EXCEPTION(e) \ 1891 (unsigned char)(e), 1892 #define MC_END_EXCEPTLIST \ 1893 (unsigned char)0xFF }; /* 0xFF MUST end list */ 1894 1895 /* ------------- End MemCheck 3.0 Library Calls --------------- */ 1896 1897 /* Formulaic rogue varargs interceptions; 1898 most host-code-compatible method... 1899 "Are you experienced?" 1900 1901 "It is better to be mugged than 1902 to live in fear." - Anon. 1903 */ 1904 #define _VA_DEF(f,r,p) \ 1905 typedef r (_RTL *p_##f) p; \ 1906 extern p_##f _MCAPI _loc_##f (_LOCP); 1907 1908 /* Declare sprintf helper function */ 1909 _VA_DEF(sprintf,int,(char *, const char *, ...)) 1910 1911 /* * * * * * * * * * * * * * * * * * * * * * * 1912 ************************* 1913 Back-End RTL 1914 ************************* 1915 */ 1916 1917 /* *** Back-end functions *** */ 1918 1919 /* Macro to access true back-end RTL. 1920 Used internally by the MemCheck API functions. 1921 */ 1922 #define __paste(x,y) x ## y 1923 #define RTL(func) __paste(func,_mc) 1924 1925 /* Macro to encapsulate the declaration of 1926 the renamed (zapped) back-end rtl 1927 */ 1928 #define _RTLDECL(f,rctype,params) \ 1929 extern rctype _RTL RTL(f) params 1930 1931 1932 /* For the conversion that MSC underwent 1933 from C 6 to 7, where non-ANSI calls 1934 have underbars 1935 */ 1936 #if defined (_CC_MSC_) && !defined (MSC6) 1937 #if (_MSC_VER >= 700) 1938 # define _C7A 1939 #endif 1940 #endif 1941 1942 #ifdef _C7A 1943 #define C7ANSI(func) _##func 1944 #else 1945 #define C7ANSI(func) func 1946 #endif 1947 1948 #undef _C7A 1949 1950 1951 /* ---------------------------------------------- */ 1952 /* These are the renamed ("zapped") RTL functions */ 1953 /* ---------------------------------------------- */ 1954 1955 /* *** ANSI *** */ 1956 1957 _RTLDECL(malloc, void *, (size_t)); 1958 _RTLDECL(calloc, void *, (size_t, size_t)); 1959 _RTLDECL(realloc, void *, (void *, size_t)); 1960 _RTLDECL(free, void, (void *)); 1961 _RTLDECL(memcpy, void *, (void *,const void *,size_t)); 1962 _RTLDECL(memmove, void *, (void *,const void *,size_t)); 1963 _RTLDECL(memset, void *, (void *,int,size_t)); 1964 _RTLDECL(strcpy, char *, (char *,const char *)); 1965 _RTLDECL(strncpy, char *, (char *,const char *,size_t)); 1966 _RTLDECL(strcat, char *, (char *,const char *)); 1967 _RTLDECL(strncat, char *, (char *,const char *,size_t)); 1968 _RTLDECL(vsprintf, int, (char *,const char *,va_list)); 1969 _RTLDECL(sprintf, int, (char *,const char *,...)); 1970 1971 #if !defined (_CC_ANSI_) 1972 /* *** MSC *** */ 1973 1974 /* WATCOM doesn't support these... */ 1975 #if !defined(_CC32_) 1976 _RTLDECL(_fmalloc, void far *, (size_t)); 1977 _RTLDECL(_fcalloc, void far *, (size_t, size_t)); 1978 _RTLDECL(_ffree, void, (void far *)); 1979 _RTLDECL(_fmsize, size_t, (void far *)); 1980 #endif 1981 1982 _RTLDECL(_nmalloc, void _MCNEAR *,(size_t)); 1983 _RTLDECL(_nfree, void, (void _MCNEAR *)); 1984 1985 /* *** Borland *** */ 1986 1987 #if !defined(_CC_POWERPACK32_) 1988 _RTLDECL(farmalloc, void _MCFAR *, (unsigned long)); 1989 _RTLDECL(farcalloc, void _MCFAR *, (unsigned long, unsigned long)); 1990 _RTLDECL(farfree, void, (void _MCFAR *)); 1991 1992 /* *** General Porpoise *** */ 1993 1994 _RTLDECL(_fmemset, void far * _MCFARGLUE, (void far *,int,size_t)); 1995 _RTLDECL(_fmemcpy, void far * _MCFARGLUE, (void far *,const void far *,size_t )); 1996 _RTLDECL(_fstrcpy, char far * _MCFARGLUE, (char far *,const void far *)); 1997 #endif /* not _CC_POWERPACK32_ */ 1998 1999 #endif /* not STDC/ANSI */ 2000 2001 /***************************************************************** 2002 * -------- Function Call Interception Definitions --------- * 2003 *****************************************************************/ 2004 2005 #ifndef MEMCHECK_MODULE 2006 2007 /* 2008 This section targets user's code only 2009 */ 2010 2011 /* Func interceptors... */ 2012 #define _INTERCEPT(_f) (_mcsl(_MCSF_,_MCSL_),_f) 2013 #define _VA_INTERCEPT(_f) (*_loc_##_f(_MCSF_,_MCSL_)) 2014 #define _SETLOC(_f) (mc_set_location(),_f) 2015 2016 /* NOTE near _mcsl with #if (_MCC_NEAR_INTERCEPT == 0) */ 2017 2018 /* 2019 MC_NO_TRANSFER_SIZE is used to eliminate errors or warnings 2020 like "sizeof returns 0" or "Not allowed type in sizeof <expr>". 2021 These occur for unsized variables declared like 2022 2023 extern unsigned char gHelpString[]; 2024 2025 The optimal solution is to "size" the extern, e.g. 2026 2027 extern unsigned char gHelpString[80]; 2028 2029 but where this may not be practical, MC_NO_TRANSFER_SIZE may 2030 be defined on a module-by-module OR project-wide basis. 2031 */ 2032 #ifdef MC_NO_XFER_SIZE /* beta compat */ 2033 # define MC_NO_TRANSFER_SIZE 2034 #endif 2035 #ifdef NO_TRANSFER_SIZE /* alternate */ 2036 # define MC_NO_TRANSFER_SIZE 2037 #endif 2038 2039 #if defined (MC_NO_TRANSFER_SIZE) 2040 # define _INTERCEPTX(_f,_d) _INTERCEPT(_f) 2041 #else /* standard; transmit sizeof dest */ 2042 # define _INTERCEPTX(_f,_d) (_mcslx(_MCSF_,_MCSL_,sizeof(_d)),_f) 2043 #endif 2044 2045 2046 /* Intrinsic Function Disabling 2047 2048 It's important to disable function inlining for 2049 all intercepted functions. 2050 */ 2051 2052 #if defined(_CC_MSC_) 2053 2054 /* Intrinsics (== in-line functions) not permissible 2055 since they're implemented as macros... 2056 */ 2057 #pragma function(strcat) 2058 #pragma function(strcpy) 2059 #pragma function(memcpy) 2060 #pragma function(memset) 2061 2062 #pragma function(strset) 2063 2064 #if defined(_MSC_VER) 2065 #if (_MSC_VER >= 700) 2066 #pragma function(_fmemcpy) 2067 #pragma function(_fmemset) 2068 #pragma function(_fstrcat) 2069 #pragma function(_fstrcpy) 2070 #pragma function(_fstrset) 2071 #pragma function(_strset) 2072 #endif 2073 #endif /* defined _MSC_VER */ 2074 2075 #elif defined(_CC_BORLAND_) 2076 2077 /* Turbo C not like pragmae */ 2078 #if !defined (_CC_TCC_) 2079 2080 /* Eliminate duplicate strings. 2081 This can save a bit of space in large 2082 programs particularly, since each call to 2083 MemCheck references an otherwise separate 2084 copy of the current filename. 2085 */ 2086 #pragma option -d 2087 2088 /* Intrinsics (== in-line functions) not permissible 2089 since they're implemented as macros, for one... 2090 */ 2091 #pragma intrinsic -strcat 2092 #pragma intrinsic -strncat 2093 #pragma intrinsic -strcpy 2094 #pragma intrinsic -strncpy 2095 #pragma intrinsic -stpcpy 2096 #pragma intrinsic -strset 2097 #pragma intrinsic -strnset 2098 #pragma intrinsic -memcpy 2099 #pragma intrinsic -memset 2100 2101 #endif /* not Turbo C */ 2102 2103 /* end Borland compiler intrinsics */ 2104 2105 #elif defined (_CC_WATCOM_) 2106 2107 /* NOTE: unfortunately, WATCOM C/C++ compilers 2108 force inlining of the strcpy() function regardless 2109 of whether you want it inlined or not, all the time. 2110 So this pragma, while it should ensure that 2111 strcpy() is a function call, does not... :{ 2112 2113 So we take other measures below: see _mcwatcom_strcpy() 2114 */ 2115 #pragma function(strcpy) 2116 2117 #pragma function(strcat) 2118 #pragma function(memcpy) 2119 #pragma function(memset) 2120 2121 #pragma function(_fmemcpy) 2122 #pragma function(_fmemset) 2123 #pragma function(_fstrcat) 2124 #pragma function(_fstrcpy) 2125 2126 #endif 2127 2128 /* End disable function inlining */ 2129 2130 2131 /*lint -save -e652 Define of symbol declared previously */ 2132 #if defined (MC_NO_INTERCEPT) 2133 #define NO_INTERCEPT 2134 #endif 2135 2136 #if !defined (NO_INTERCEPT) 2137 2138 /* *** ANSI Standard C *** */ 2139 2140 #define calloc(n,_sz) _INTERCEPT(calloc(n,_sz)) 2141 #define malloc(_sz) _INTERCEPT(malloc(_sz)) 2142 #define realloc(p,s) _INTERCEPT(realloc(p,s)) 2143 #define free(p) _INTERCEPT(free(p)) 2144 2145 #define memcpy(d,s,n) _INTERCEPTX(memcpy(d,s,n),d) 2146 #define memmove(d,s,n) _INTERCEPTX(memmove(d,s,n),d) 2147 #define memset(p,c,n) _INTERCEPTX(memset(p,c,n),p) 2148 #define strcat(s1,s2) _INTERCEPTX(strcat(s1,s2),s1) 2149 #if defined(_CC_WATCOM_) 2150 /* WATCOM forces inlining of strcpy()... see note above */ 2151 # define strcpy(d,s) _INTERCEPTX(_mcwatcom_strcpy(d,s),d) 2152 extern char * _RTL _mcwatcom_strcpy (char *, const char *); 2153 #else 2154 # define strcpy(d,s) _INTERCEPTX(strcpy(d,s),d) 2155 #endif 2156 #define strncat(s1,s2,n) _INTERCEPTX(strncat(s1,s2,n),s1) 2157 #define strncpy(d,s,n) _INTERCEPTX(strncpy(d,s,n),d) 2158 #define vsprintf(s,f,a) _INTERCEPTX(vsprintf(s,f,a),s) 2159 2160 /* #define sprintf _VA_INTERCEPT(sprintf) */ 2161 #ifndef _lint 2162 #define sprintf _INTERCEPT(sprintf) 2163 #endif 2164 2165 #if defined(_CC_MSC_COMPATIBLE_) /* *** Microsoft C *** */ 2166 2167 #define _expand(_p,_s) _INTERCEPT(_expand(_p,_s)) 2168 #define _fcalloc(n,_sz) _INTERCEPT(_fcalloc(n,_sz)) 2169 #define _fexpand(_p,_s) _INTERCEPT(_fexpand(_p,_s)) 2170 #define _ffree(p) _INTERCEPT(_ffree(p)) 2171 #define _fmalloc(_sz) _INTERCEPT(_fmalloc(_sz)) 2172 #define _frealloc(p,s) _INTERCEPT(_frealloc(p,s)) 2173 #define _fmsize(p) _INTERCEPT(_fmsize(p)) 2174 #define _msize(p) _INTERCEPT(_msize(p)) 2175 #define _nfree(p) _INTERCEPT(_nfree(p)) 2176 #define _nmalloc(_sz) _INTERCEPT(_nmalloc(_sz)) 2177 #define _nrealloc(p,s) _INTERCEPT(_nrealloc(p,s)) 2178 #define _ncalloc(n,_sz) _INTERCEPT(_ncalloc(n,_sz)) 2179 #define _nexpand(_p,_s) _INTERCEPT(_nexpand(_p,_s)) 2180 #define _nmsize(p) _INTERCEPT(_nmsize(p)) 2181 #define _nstrdup(s) _INTERCEPT(_nstrdup(s)) 2182 /* #define halloc(n,_sz) _INTERCEPT(halloc(n,_sz)) */ 2183 /* #define _halloc(n,_sz) _INTERCEPT(halloc(n,_sz)) */ 2184 /* #define hfree(p) _INTERCEPT(hfree(p)) */ 2185 /* #define _hfree(p) _INTERCEPT(hfree(p)) */ 2186 2187 #define cgets(s) _INTERCEPTX(cgets(s),s) 2188 #define _cgets(s) _INTERCEPTX(_cgets(s),s) 2189 #define memccpy(d,s,c,n) _INTERCEPTX(memccpy(d,s,c,n),d) 2190 #define _memccpy(d,s,c,n) _INTERCEPTX(_memccpy(d,s,c,n),d) 2191 #define strdup(s) _INTERCEPT(strdup(s)) 2192 #define _strdup(s) _INTERCEPT(_strdup(s)) 2193 #define _strnset(s,c,n) _INTERCEPTX(_strnset(s,c,n),s) 2194 #define strnset(s,c,n) _INTERCEPTX(strnset(s,c,n),s) 2195 #define strset(s,c) _INTERCEPTX(strset(s,c),s) 2196 #define _strset(s,c) _INTERCEPTX(_strset(s,c),s) 2197 #define swab(s,d,n) _INTERCEPTX(swab(s,d,n),d) 2198 #define _swab(s,d,n) _INTERCEPTX(_swab(s,d,n),d) 2199 #define tempnam(d,pfx) _INTERCEPT(tempnam(d,pfx)) 2200 #define _tempnam(d,pfx) _INTERCEPT(_tempnam(d,pfx)) 2201 2202 #define _fmemcpy(d,s,n) _INTERCEPTX(_fmemcpy(d,s,n),d) 2203 #define _fmemmove(d,s,n) _INTERCEPTX(_fmemmove(d,s,n),d) 2204 #define _fmemset(d,c,n) _INTERCEPTX(_fmemset(d,c,n),d) 2205 #define _fmemccpy(d,s,c,n) _INTERCEPTX(_fmemccpy(d,s,c,n),d) 2206 #define _fstrcat(s1,s2) _INTERCEPTX(_fstrcat(s1,s2),s1) 2207 #define _fstrcpy(d,s) _INTERCEPTX(_fstrcpy(d,s),d) 2208 #define _fstrncat(s1,s2,n) _INTERCEPTX(_fstrncat(s1,s2,n),s1) 2209 #define _fstrncpy(d,s,n) _INTERCEPTX(_fstrncpy(d,s,n),d) 2210 #define _fstrdup(s) _INTERCEPT(_fstrdup(s)) 2211 #define _fstrnset(d,c,n) _INTERCEPTX(_fstrnset(d,c,n),d) 2212 #define _fstrset(d,c) _INTERCEPTX(_fstrset(d,c),d) 2213 2214 #define getcwd(d,n) _INTERCEPTX(getcwd(d,n),d) 2215 #define _getcwd(d,n) _INTERCEPTX(getcwd(d,n),d) 2216 #define _getdcwd(r,d,n) _INTERCEPTX(_getdcwd(r,d,n),d) 2217 #define _dos_setvect(_i,_h) _INTERCEPT(_dos_setvect(_i,_h)) 2218 #define _fullpath(b,p,n) _INTERCEPTX(_fullpath(b,p,n),b) 2219 2220 /* ----- END Microsoft C/C++ interceptions ----- */ 2221 2222 #elif defined (_CC_BORLAND_) /* *** Borland C/C++ *** */ 2223 2224 #ifndef _CC_POWERPACK32_ 2225 #define farfree(p) _INTERCEPT(farfree(p)) 2226 #define farmalloc(s) _INTERCEPT(farmalloc(s)) 2227 #define farcalloc(n,s) _INTERCEPT(farcalloc(n,s)) 2228 #define farrealloc(p,s) _INTERCEPT(farrealloc(p,s)) 2229 #endif /* not _CC_POWERPACK32_ */ 2230 2231 #define cgets(s) _INTERCEPTX(cgets(s),s) 2232 #define memccpy(d,s,c,n) _INTERCEPTX(memccpy(d,s,c,n),d) 2233 #if !defined(movmem) 2234 #define movmem(s,d,l) _INTERCEPTX(movmem(s,d,l),d) 2235 #endif 2236 #if !defined(setmem) 2237 #define setmem(d,c,v) _INTERCEPTX(setmem(d,c,v),d) 2238 #endif 2239 #define setvect(i,v) _INTERCEPT(setvect(i,v)) 2240 #define stpcpy(d,s) _INTERCEPTX(stpcpy(d,s),d) 2241 #define _stpcpy(d,s) _INTERCEPTX(_stpcpy(d,s),d) 2242 #define strdup(s) _INTERCEPT(strdup(s)) 2243 #define strnset(s,c,n) _INTERCEPTX(strnset(s,c,n),s) 2244 #define strset(s,c) _INTERCEPTX(strset(s,c),s) 2245 #define swab(s,d,n) _INTERCEPTX(swab(s,d,n),d) 2246 #define tempnam(d,pfx) _INTERCEPT(tempnam(d,pfx)) 2247 2248 #define getcwd(d,n) _INTERCEPTX(getcwd(d,n),d) 2249 #define _getdcwd(r,d,n) _INTERCEPTX(_getdcwd(r,d,n),d) 2250 #define _dos_setvect(_i,_h) _INTERCEPT(_dos_setvect(_i,_h)) 2251 2252 #ifndef _CC_POWERPACK32_ 2253 #define _fmemcpy(d,s,n) _INTERCEPTX(_fmemcpy(d,s,n),d) 2254 #define _fmemmove(d,s,n) _INTERCEPTX(_fmemmove(d,s,n),d) 2255 #define _fmemset(d,c,n) _INTERCEPTX(_fmemset(d,c,n),d) 2256 #define _fmemccpy(d,s,c,n) _INTERCEPTX(_fmemccpy(d,s,c,n),d) 2257 #define _fmovmem(s,d,l) _INTERCEPTX(_fmovmem(s,d,l),s) 2258 #define _fsetmem(d,c,v) _INTERCEPTX(_fsetmem(d,c,v),d) 2259 #define _fstrcat(s1,s2) _INTERCEPTX(_fstrcat(s1,s2),s1) 2260 #define _fstrcpy(d,s) _INTERCEPTX(_fstrcpy(d,s),d) 2261 #define _fstrncat(s1,s2,n) _INTERCEPTX(_fstrncat(s1,s2,n),s1) 2262 #define _fstrncpy(d,s,n) _INTERCEPTX(_fstrncpy(d,s,n),d) 2263 #define _fstrdup(s) _INTERCEPT(_fstrdup(s)) 2264 #define _fstrnset(d,c,n) _INTERCEPTX(_fstrnset(d,c,n),d) 2265 #define _fstrset(d,c) _INTERCEPTX(_fstrset(d,c),d) 2266 #endif /* not _CC_POWERPACK32_ */ 2267 2268 /* 2269 #define freemem(g) _INTERCEPT(freemem(g)) 2270 #define vsscanf(d,f,a) _INTERCEPTX(vsscanf(d,f,a),d) 2271 */ 2272 2273 /* ----- END Borland C/C++ interceptions ----- */ 2274 2275 #else 2276 2277 #error Unknown compiler in MemCheck.h 2278 2279 #endif /* Compiler-specific Function Mapping Section */ 2280 2281 /* Location Transmitters 2282 2283 You can add any non-intercepted functions to 2284 this bunch... Just updates MemCheck's file and line 2285 information via mc_set_location(), which is thousands 2286 of times faster than anything that does I/O. 2287 The only time this section could be a problem is 2288 if the header file is included before any other header 2289 files which prototype these routines. 2290 2291 Borland's TD (Turbo Debugger) also has problems here (see note). 2292 */ 2293 #ifndef _lint /* LINT not like */ 2294 2295 /* Borland's Turbo Debugger gets confoosed and executes 2296 a `Run' instead of a `Step' when _SETLOC macro is used... 2297 */ 2298 #if !defined (_CC_BORLAND_) 2299 #if 1 /* Change this to '0' to omit this section */ 2300 2301 #define printf _SETLOC(printf) 2302 2303 #define fopen _SETLOC(fopen) 2304 #define fprintf _SETLOC(fprintf) 2305 #define fread _SETLOC(fread) 2306 #define fwrite _SETLOC(fwrite) 2307 #define fclose _SETLOC(fclose) 2308 2309 #define system _SETLOC(system) 2310 #define exec _SETLOC(exec) 2311 #define spawnl _SETLOC(spawnl) 2312 #define spawnlp _SETLOC(spawnlp) 2313 #define spawnle _SETLOC(spawnle) 2314 #define spawnlpe _SETLOC(spawnlpe) 2315 #define spawnv _SETLOC(spawnv) 2316 #define spawnvp _SETLOC(spawnvp) 2317 #define spawnve _SETLOC(spawnve) 2318 #define spawnvpe _SETLOC(spawnvpe) 2319 2320 #endif /* end location transmission section */ 2321 #endif /* not Borland C++ */ 2322 #endif /* not def _lint */ 2323 2324 2325 /* **** THIRD-PARTY MAPPINGS **** */ 2326 2327 /* Vermont Views V3.xx 2328 2329 The following code will transmit the exact file 2330 and line of any mem_get() and mem_free() calls to 2331 MemCheck, so that it can report on the location where 2332 these functions are called, instead of the location of 2333 the calloc() or free(). 2334 2335 If you've used MCCONFIG to configure the Vermont Views source 2336 code, you *must* either NOT include the MemCheck header file 2337 in the MEM_GET.C and MEM_FREE.C modules, or, if you do, then 2338 #define NO_INTERCEPT beforehand, e.g. 2339 2340 Module MEM_GET.C ... 2341 : 2342 #define NO_INTERCEPT 2343 #include <memcheck.h> 2344 : 2345 2346 MCCONFIG may be used to configure even the shrouded 2347 Vermont Views source code. 2348 2349 See also: TechNote "Using MemCheck 3.0 Professional 2350 With Vermont Views", available on the StratosWare 2351 BBS (313) 996-2993 as VIEWS.TXT, or by fax. 2352 */ 2353 #if defined (VV_SYS) /* should do the trick */ 2354 # define mem_get(s) _INTERCEPT(mem_get(s)) 2355 # define mem_free(p) _INTERCEPT(mem_free(p)) 2356 #endif 2357 2358 2359 /* **** APPLICATION-SPECIFIC MAPPINGS **** */ 2360 2361 /* 2362 If your application uses allocation "cover" routines, 2363 MemCheck will by default report errors and leaks by 2364 the file and line of the malloc or free within the 2365 cover module. To get MemCheck to report by file and 2366 line where the cover function is actually called, follow 2367 the instructtions in MemCheck TechNote "Transmitting File 2368 and Line to MemCheck 3.0 Professional Through Cover Functions." 2369 2370 This is where you can place the cover function macros. 2371 */ 2372 2373 2374 /* end APPLICATION-SPECIFIC MAPPINGS */ 2375 2376 #endif /* not NO_INTERCEPT */ 2377 2378 /* Calls that xmit source file, line number if called in source */ 2379 /* *** MemCheck API file & line transmittal *** */ 2380 #define mc_startcheck(erf) mc_startcheck(_MCSF_,_MCSL_,erf) 2381 #define mc_stack_trace(_memo) _INTERCEPT(mc_stack_trace(_memo)) 2382 #define mc_debug(s) _INTERCEPT(mc_debug(s)) 2383 #define mc_debugf(arglist) mc_debugv arglist 2384 #define mc_debugv _mcsl(_MCSF_,_MCSL_),mc_debugv 2385 #define mc_endcheck() _INTERCEPT(mc_endcheck()) 2386 #define mc_check_buffers() _INTERCEPT(mc_check_buffers()) 2387 #define mc_check(p) _INTERCEPT(mc_check(p)) 2388 #define mc_register(p,s) _INTERCEPT(mc_register(p,s)) 2389 #define mc_unregister(p) _INTERCEPT(mc_unregister(p)) 2390 #define mc_nullcheck() _INTERCEPT(mc_nullcheck()) 2391 #define mc_report(f) _INTERCEPT(mc_report(f)) 2392 2393 /*lint -restore 652 Define of symbol declared prev */ 2394 2395 #endif /* not MEMCHECK_MODULE, function interceptions */ 2396 2397 2398 /* End "C" call wrapper */ 2399 #ifdef __cplusplus 2400 } 2401 2402 2403 /* C++ MemCheck Class 2404 2405 This class can be used as an alternative to 2406 AutoInit, or to placing the mc_startcheck() and 2407 mc_endcheck() calls in your main() program. 2408 Just declaring an object of class 'MemCheck' 2409 will start MemCheck up; usually you will place 2410 this 'above' any other global or statically declared 2411 C++ objects in your main module. 2412 2413 Here are some examples of starting MemCheck up 2414 via object mechanics: 2415 2416 MemCheck On; 2417 MemCheck Active; 2418 MemCheck Rules; 2419 2420 Use your imagination! Note that if AutoInit is ON, 2421 any calls to mc_startcheck() and mc_endcheck() are 2422 ignored. 2423 */ 2424 #if !defined (NO_INTERCEPT) /* must not have this def'd */ 2425 2426 /* This class def causes a warning under MSC if not used */ 2427 #if !defined (_CC_MSC_) 2428 2429 class MemCheck { 2430 public: 2431 MemCheck () { mc_startcheck (NULL); } 2432 ~MemCheck () { mc_endcheck (); } 2433 }; 2434 2435 #endif 2436 2437 #endif /* NO_INTERCEPT */ 2438 2439 2440 /* *** For use in new and delete modules only *** */ 2441 /* 2442 Replace 'mallocs' with 'cpp_mallocs', etc. 2443 In new and delete modules, NO_INTERCEPT should be #defined, e.g. 2444 2445 #define NO_INTERCEPT 2446 #include <memcheck.h> 2447 : 2448 void * operator new ( size_t size ) 2449 { 2450 if (!size) size = 1; 2451 return (cpp_malloc (size)); 2452 } 2453 etc. 2454 */ 2455 #define cpp_malloc(_s) (_mc_set_newflag(), malloc(_s)) 2456 #define cpp_calloc(_n,_s) (_mc_set_newflag(), calloc(_n,_s)) 2457 #define cpp_free(_p) (_mc_set_delflag(), free(_p)) 2458 2459 /* Borland C++ */ 2460 #define cpp_farmalloc(_s) (_mc_set_newflag(), farmalloc(_s)) 2461 #define cpp_farfree(_fp) (_mc_set_delflag(), farfree(_fp)) 2462 2463 /* Microsoft C++-compatibles */ 2464 #define cpp__fmalloc(_s) (_mc_set_newflag(), _fmalloc(_s)) 2465 #define cpp__ffree(_fp) (_mc_set_delflag(), _ffree(_fp)) 2466 2467 2468 /* C++ */ 2469 #if !defined (NO_INTERCEPT) 2470 #if !defined (NO_CPP) 2471 2472 /* 2473 This method is off by default, because it 2474 requires definition of a new operator like: 2475 2476 void * new (size_t size, char *file, int lineno); 2477 2478 Such a new operator is included in your SOURCE\CPP 2479 directory. To have this method used for all modules, 2480 #define NEW_OVERLOADED at the top of this header file 2481 or in your project #include file, BEFORE the MemCheck 2482 header file is #included. 2483 2484 The substitutions for the new operator 2485 may not work in all situations. To disable 2486 MemCheck's interception of new on a module-by- 2487 module basis by undefining NEW_OVERLOADED. 2488 */ 2489 #if defined (NEW_OVERLOADED) 2490 2491 /* Method 1: Placement Operators 2492 2493 Use placement operators to trap file and line location transparently 2494 on calls to new. 2495 2496 Thanks for this tip to Dan Saks, 2497 C and C++ writer, author, teacher, and columnist--buy his books. 2498 He came through when no one else had a clue! 2499 2500 Please consult your manual, MemCheck technotes, 2501 or StratosWare Technical Support (1-800-WE-DEBUG) 2502 for details on how to configure your project for 2503 use with an overloaded new placement operator. 2504 */ 2505 2506 /* Declare overloaded new with placement operators */ 2507 void *operator new (size_t _sz, char *file, int lineno); 2508 #if defined (_CPP_ANSI20_) 2509 /* Array version; only under supporting compilers 2510 COMMENT LINE OUT if it causes a compile error. 2511 */ 2512 void *operator new[] (size_t _sz, char *file, int lineno); 2513 #endif 2514 2515 #if !defined (_CC_MSC_) 2516 #define new new((char *)__FILE__,(int)__LINE__) 2517 #else 2518 #define new new(__FILE__,__LINE__) 2519 #endif 2520 2521 /* NOTE: 2522 This placement operator interception syntax has been 2523 known to cause syntax errors (in VC++ 1.0) for no apparent reason 2524 on statements like 2525 2526 Domain *d = new Domain (); 2527 2528 Workaround is to change line (sorry!) to equivalent 2529 2530 Domain *d = new Domain; 2531 */ 2532 2533 /* Backwards compatibility with the V2.1 C++ macros */ 2534 #ifndef NEW 2535 #define NEW(_object) new _object 2536 #endif 2537 #ifdef DELETE 2538 #define DELETE(_object) delete _object 2539 #endif 2540 #define DELETE_ARR(_arr) delete[] _arr 2541 2542 #else /* !NEW_OVERLOADED - end of Placement Operator intercept */ 2543 2544 /* New and Delete Interception, Method 2: NEW() and DELETE() 2545 2546 The NEW() and DELETE() macros may be used to transmit file 2547 and line of new and delete. These macros, which require 2548 modification of source code, i.e. "NEW(object)" for "new object", 2549 should probably be used only if the above overloaded new does 2550 not work for your code base. 2551 2552 Please consult your manual, MemCheck technotes, 2553 or StratosWare Technical Support (1-800-WE-DEBUG) 2554 for details on how to configure your project for 2555 use with NEW() and DELETE(). 2556 2557 If calling, please have your MemCheck serial number handy. 2558 */ 2559 #ifndef NEW 2560 #define NEW(_object) (_mcsl_new(_MCSF_,_MCSL_), new _object) 2561 #endif 2562 #ifndef DELETE /* WINNT.H under BC DPMI32 defines DELETE */ 2563 #define DELETE(_object) (_mcsl_delete(_MCSF_,_MCSL_), delete _object) 2564 #endif 2565 #define DELETE_ARR(_arr) (_mcsl_delete(_MCSF_,_MCSL_), delete[] _arr) 2566 2567 #endif /* !NEW_OVERLOADED */ 2568 2569 #define delete _mcsl_delete(_MCSF_,_MCSL_), delete 2570 2571 2572 /* *** FAILURES *** */ 2573 2574 /* These macros failed in the purpose of 2575 intercepting new transparently in some 2576 situation or other. 2577 */ 2578 2579 /* Failed on " * new expr " (TV) */ 2580 /* #define new (mc_set_location(),0) ? NULL : new */ 2581 2582 /* Failed on " x = new Object " (TV) */ 2583 /* #define new ((mc_set_location(),0) ? NULL : new) */ 2584 /* #define new new (mc_set_location(),0) ? NULL : */ 2585 2586 #endif /* !NO_CPP */ 2587 #endif /* NO_INTERCEPT */ 2588 #endif /* cplusplus */ 2589 /******** End C++ ************/ 2590 2591 2592 #endif /* End of Section for MEMCHECK Defined */ 2593 2594 /* -------------------------------------------------------------------------- */ 2595 2596 #endif /* _MEMCHECK_H_ */ 2597 2598 2599 /******************************** 2600 * End of MemCheck 3.0 Header * 2601 ********************************/ 2602