home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff240.lzh / MemLib / mempriv.h < prev    next >
C/C++ Source or Header  |  1989-08-28  |  5KB  |  120 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989 The Software Distillery.                    *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by Doug Walker                               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           235 Trillingham Lane                                 *
  7. * ======             Cary, NC 27513                                       *
  8. *                    BBS:(919)-471-6436                                   *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <exec/ports.h>
  14. #include <proto/exec.h>
  15. #include <proto/dos.h>
  16. #include <string.h>
  17.  
  18. #define MWDEBUG
  19. #include "memwatch.h"
  20.  
  21. #ifdef AllocMem
  22. #undef AllocMem
  23. #endif
  24.  
  25. #ifdef FreeMem
  26. #undef FreeMem
  27. #endif
  28.  
  29. #if 0
  30. /* Change this to #if 1 if you want debug msgs from the memlib */
  31. /* routines themselves for some reason - djw                   */
  32. #define BUG(a) printf a ;
  33. #endif
  34.  
  35. #define MSG(fh, msg) Write(fh, msg, strlen(msg))
  36.  
  37. #define MWT_CHIP 0
  38. #define MWT_FAST 1
  39.  
  40. struct MWGlobal
  41. {
  42.    LONG flags;          /* Various MWF_ flags, see below                */
  43.    LONG num[2];         /* Current number of allocations, chip and fast */
  44.    LONG sum[2];         /* Current amount allocated, chip and fast      */
  45.    LONG max[2];         /* Max amount allocated, chip and fast          */
  46.    LONG lim[2];         /* Limit on allocations, chip and fast          */
  47.    BPTR dbfh;           /* File to send debug output to                 */
  48.    struct MWAlc *first; /* List of active memory allocations            */
  49.    struct MWAlc *freed; /* List of free memory extents                  */
  50.    struct MWAlc *lfree; /* Last allocation freed with free()            */
  51.    struct Task *task;   /* Pointer to owning task's Task structure      */
  52. };
  53.  
  54. struct MWMsg
  55. {
  56.    struct Message msgpart;    /* Linkage                  */
  57.    int type;                  /* MWM_ types - see defines */
  58.    int interval;              /* Interval to check        */
  59.    struct MWGlobal *mwg;      /* Our global mem struct    */
  60. };
  61.  
  62. struct MWAlc
  63. {
  64.    struct MWAlc *next;  /* Next memory block in chain           */
  65.    LONG size;           /* Size of allocation in bytes          */
  66.    LONG flags;          /* MEMF_ Flags memory was allocated with*/
  67.    LONG myflags;        /* my flags, see defines below          */
  68.    char *file;          /* Filename containing allocation point */
  69.    LONG line;           /* Line number of allocation            */
  70.    char *ffile;         /* Filename of free point               */
  71.    char *fline;         /* Line number of free point            */
  72.    char header[4];      /* Header sentinal                      */
  73.    char memory[4];      /* Actual allocation comes here         */
  74.                         /* 4 extra bytes covers trailer sentinal*/
  75. };
  76.  
  77. /* Defines for use with MWAlc.myflags */
  78. /* if myflags&MWF_REPMASK == MWF_REPORTED,   */
  79. /* This alloc already reported as trashed    */
  80. /* Use multiple bits in case the 'myflags'   */
  81. /* are trashed, odds are better of detecting */
  82. /* If we ever need more myflag bits, just    */
  83. /* define MWF_REPMASK not to include them    */
  84.  
  85. #define MWF_REPORTED 0xaa55aa55
  86. #define MWF_REPMASK  0xffffffff
  87.  
  88. #define MWHEADER     "MWHD"  /* Beginning sentinal                       */
  89. #define MWTRAILER    "MWTR"  /* Trailing sentinal                        */
  90.  
  91. #define MWATRASH     0xaa  /* Trash allocated memory with this           */
  92. #define MWFTRASH     0x55  /* Trash freed memory with this               */
  93.  
  94. /* Message types to external memory debugger                             */
  95. #define MWM_CONTROL  0x00000000 /* MWII-type message                     */
  96. #define MWM_INIT     0x00000001 /* Install new global struct             */
  97. #define MWM_TERM     0x00000002 /* Remove old global struct              */
  98. #define MWM_KILLME   0x00000003 /* An error has occurred; hold my task   */
  99. #define MWM_BURY     0x00000004 /* Return the killed task                */
  100. #define MWM_RESET    0x00000005 /* Restart everything, forget current    */
  101. #define MWM_CONTINUE 0x00000006 /* Revive the killed task                */
  102.  
  103. #define MWM_REPLY    0x00001000 /* Reply to msg if set (except KILLME)   */
  104.  
  105. /* Message type return codes, returned in msg->type                      */
  106. #define MWM_OK       0x00010000 /* OK                                    */
  107. #define MWM_FULL     0x00020000 /* Table full, couldn't add              */
  108. #define MWM_INVALID  0x00030000 /* Unspecified error                     */
  109. #define MWM_NONE     0x00040000 /* MWM_BURY sent, no process killed      */
  110. #define MWM_BADCMD   0x00050000 /* Unrecognized msg type                 */
  111.  
  112. #define MWPORTNAME   "MWIII_Port"
  113.  
  114. int MWSend   MWARGS((int));
  115. void MWHold  MWARGS((void));
  116. void MWPurge MWARGS((void));
  117. void MWPanic MWARGS((char *));
  118. void MWPrint MWARGS((struct MWAlc *, int, LONG, LONG));
  119.  
  120.