home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / extras / memlib / mempriv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  5.4 KB  |  138 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989, 1990, 1991 The Software Distillery.        *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by Doug Walker                               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           405 B3 Gooseneck Drive                               *
  7. * ======             Cary, NC 27513                                       *
  8. *                                                                         *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10.  
  11.  
  12.  
  13.  
  14.  
  15. /**************************************************************************/
  16. /**************************************************************************/
  17. /**************************************************************************/
  18. /*                                                                        */
  19. /* DO NOT INCLUDE THIS FILE IN YOUR PROGRAM.  IT IS FOR MEMLIB'S INTERNAL */
  20. /* USE ONLY.  USE THE FILE "memwatch.h" FOR YOUR PROGRAM FILES.           */
  21. /*                                                                        */
  22. /**************************************************************************/
  23. /**************************************************************************/
  24. /**************************************************************************/
  25.  
  26.  
  27.  
  28.  
  29. #include <exec/types.h>
  30. #include <exec/memory.h>
  31. #include <exec/ports.h>
  32. #include <proto/exec.h>
  33. #include <proto/dos.h>
  34. #include <string.h>
  35. #include <stdarg.h>
  36.  
  37. #define MWDEBUG 1   /* MWDEBUG is always defined for the library itself */
  38. #include "memwatch.h"
  39.  
  40.  
  41. #ifdef AllocMem
  42. #undef AllocMem
  43. #endif
  44.  
  45. #ifdef FreeMem
  46. #undef FreeMem
  47. #endif
  48.  
  49. #define MWT_CHIP 0
  50. #define MWT_FAST 1
  51.  
  52. #define MW_HEADLEN  4  /* Number of bytes for header sentinel */
  53.  
  54. /* The following string must be >= MW_HEADLEN bytes */
  55. #define MWHEADSTR "HEAD"
  56.                  /*0123*/
  57.  
  58. #define MW_TRAILLEN 8  /* Number of bytes for trailer sentinel */
  59.  
  60. /* The following string must be >= MW_TRAILLEN bytes */
  61. #define MWTRAILSTR "\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB"
  62.  
  63. struct MWGlobal
  64. {
  65.    LONG flags;          /* Various MWF_ flags, see memwatch.h           */
  66.    LONG num[2];         /* Current number of allocations, chip and fast */
  67.    LONG sum[2];         /* Current amount allocated, chip and fast      */
  68.    LONG max[2];         /* Max amount allocated, chip and fast          */
  69.    LONG lim[2];         /* Limit on allocations, chip and fast          */
  70.    BPTR dbfh;           /* File to send debug output to                 */
  71.    struct MWAlc *first; /* List of active memory allocations            */
  72.    struct MWAlc *freed; /* List of free memory extents                  */
  73.    struct MWAlc *lfree; /* Last allocation freed with free()            */
  74.    struct Task *task;   /* Pointer to owning task's Task structure      */
  75.    char *dbnm;          /* name of debug log file                       */
  76.    int headlen,         /* Length of header sentinel                    */
  77.        traillen;        /* Length of trailer sentinel                   */
  78. };
  79.  
  80. struct MWAlc
  81. {
  82.    struct MWAlc *next;  /* Next memory block in chain           */
  83.    LONG size;           /* Size of allocation in bytes          */
  84.    LONG flags;          /* MEMF_ Flags memory was allocated with*/
  85.    LONG internal;       /* internal flags, see MWI_ defines     */
  86.    char *file;          /* Filename containing allocation point */
  87.    LONG line;           /* Line number of allocation            */
  88.    char *ffile;         /* Filename of free point               */
  89.    long fline;         /* Line number of free point            */
  90.    char header[MW_HEADLEN];     /* Header sentinal              */
  91.    char memory[MW_TRAILLEN+3];  /* Actual allocation comes here */
  92.                         /* extra bytes cover trailer sentinal   */
  93. };
  94.  
  95. /* Defines for use with MWAlc.internal       */
  96. /* if internal&MWI_REPMASK == MWI_REPORTED,  */
  97. /* This alloc already reported as trashed    */
  98. /* Use multiple bits in case 'internal'      */
  99. /* are trashed, odds are better of detecting */
  100. /* If we ever need more myflag bits, just    */
  101. /* define MWI_REPMASK not to include them    */
  102.  
  103. #define MWI_REPORTED 0xaa55aa50
  104. #define MWI_REPMASK  0xfffffff0
  105.  
  106.  
  107. #define MWATRASH     0xaa  /* Trash allocated memory with this           */
  108. #define MWFTRASH     0x55  /* Trash freed memory with this               */
  109.  
  110. void MWHold   (void);
  111. void MWPurge  (void);
  112. void MWPanic  (char *);
  113. void MWPrintf (char *, ...);
  114. int MWCheckA  (struct MWAlc *);
  115.  
  116. /* If you want debugging to use the serial port, you must have */
  117. /* Commodore's debug.lib.  If you do, change the #define below */
  118. /* to a 1 and add debug.lib to your link line.                 */
  119. #define USEDEBUGLIB 0
  120. #if USEDEBUGLIB
  121. /* Defined in Commodore's debug.lib */
  122. void __stdargs KPutStr(char *string);
  123. #else
  124. #define KPutStr(x)
  125. #endif
  126.  
  127. #define MWPrintAlc(mwa) \
  128.    {MWPrintf("0x%08lx length %ld allocated line %ld file \"%s\"\n", \
  129.             (mwa)->memory, (mwa)->size, (mwa)->line, (mwa)->file); \
  130.     if((mwa)->ffile) MWPrintf("Freed line %ld file \"%s\"\n", \
  131.        (mwa)->fline, (mwa)->ffile);}
  132.  
  133. #define ALCFAMILY(x) ((x) & MWI_MALLOC ? "malloc"    : \
  134.                       (x) & MWI_VEC    ? "AllocVec"  : "AllocMem")
  135.  
  136. #define FREFAMILY(x) ((x) & MWI_MALLOC ? "free"     : \
  137.                       (x) & MWI_VEC    ? "FreeVec"  : "FreeMem")
  138.