MEMCHECK.H 87 KB

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