MEMCHECK.H 87 KB

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