1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile memdebug.h:
|
---|
4 | * header file for memdebug.c.
|
---|
5 | * See remarks there.
|
---|
6 | *
|
---|
7 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
8 | * numbering.
|
---|
9 | *
|
---|
10 | *@@include #include <os2.h>
|
---|
11 | *@@include #include "memdebug.h"
|
---|
12 | */
|
---|
13 |
|
---|
14 | /* Copyright (C) 2000 Ulrich Mller.
|
---|
15 | * This file is part of the "XWorkplace helpers" source package.
|
---|
16 | * This is free software; you can redistribute it and/or modify
|
---|
17 | * it under the terms of the GNU General Public License as published
|
---|
18 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
19 | * "COPYING" file of the XWorkplace main distribution.
|
---|
20 | * This program is distributed in the hope that it will be useful,
|
---|
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
23 | * GNU General Public License for more details.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #if __cplusplus
|
---|
27 | extern "C" {
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | #ifndef MEMDEBUG_HEADER_INCLUDED
|
---|
31 | #define MEMDEBUG_HEADER_INCLUDED
|
---|
32 |
|
---|
33 | #ifndef __stdlib_h // <stdlib.h>
|
---|
34 | #error stdlib.h must be included before memdebug.h.
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | typedef void (FNCBMEMDLOG)(const char*); // message
|
---|
38 | typedef FNCBMEMDLOG *PFNCBMEMDLOG;
|
---|
39 |
|
---|
40 | // global variable for memory error logger func
|
---|
41 | extern PFNCBMEMDLOG G_pMemdLogFunc;
|
---|
42 |
|
---|
43 | /* ******************************************************************
|
---|
44 | *
|
---|
45 | * Private declarations
|
---|
46 | *
|
---|
47 | ********************************************************************/
|
---|
48 |
|
---|
49 | #ifdef MEMDEBUG_PRIVATE
|
---|
50 |
|
---|
51 | BOOL memdLock(VOID);
|
---|
52 |
|
---|
53 | VOID memdUnlock(VOID);
|
---|
54 |
|
---|
55 | /*
|
---|
56 | *@@ HEAPITEM:
|
---|
57 | * informational structure created for each
|
---|
58 | * malloc() call by memdMalloc. These are stored
|
---|
59 | * in a global linked list (G_pHeapItemsRoot).
|
---|
60 | *
|
---|
61 | * We cannot use the linklist.c functions for
|
---|
62 | * managing the linked list because these use
|
---|
63 | * malloc in turn, which would lead to infinite
|
---|
64 | * loops.
|
---|
65 | *
|
---|
66 | *@@added V0.9.3 (2000-04-11) [umoeller]
|
---|
67 | */
|
---|
68 |
|
---|
69 | typedef struct _HEAPITEM
|
---|
70 | {
|
---|
71 | struct _HEAPITEM *pNext; // next item in linked list or NULL if last
|
---|
72 |
|
---|
73 | void *pAfterMagic; // memory pointer returned by memdMalloc;
|
---|
74 | // this points to after the magic string
|
---|
75 | unsigned long ulSize; // requested size (without magic head and tail)
|
---|
76 |
|
---|
77 | const char *pcszSourceFile; // as passed to memdMalloc
|
---|
78 | unsigned long ulLine; // as passed to memdMalloc
|
---|
79 | const char *pcszFunction; // as passed to memdMalloc
|
---|
80 |
|
---|
81 | DATETIME dtAllocated; // system date/time at time of memdMalloc call
|
---|
82 |
|
---|
83 | ULONG ulTID; // thread ID that memdMalloc was running on
|
---|
84 |
|
---|
85 | BOOL fFreed; // TRUE only after item has been freed by memdFree
|
---|
86 | } HEAPITEM, *PHEAPITEM;
|
---|
87 |
|
---|
88 | extern PHEAPITEM G_pHeapItemsRoot;
|
---|
89 | extern ULONG G_ulItemsReleased;
|
---|
90 | extern ULONG G_ulBytesReleased;
|
---|
91 |
|
---|
92 | #endif // MEMDEBUG_PRIVATE
|
---|
93 |
|
---|
94 | /* ******************************************************************
|
---|
95 | *
|
---|
96 | * Publics
|
---|
97 | *
|
---|
98 | ********************************************************************/
|
---|
99 |
|
---|
100 | void* memdMalloc(size_t stSize,
|
---|
101 | const char *pcszSourceFile,
|
---|
102 | unsigned long ulLine,
|
---|
103 | const char *pcszFunction);
|
---|
104 |
|
---|
105 | void* memdCalloc(size_t num,
|
---|
106 | size_t stSize,
|
---|
107 | const char *pcszSourceFile,
|
---|
108 | unsigned long ulLine,
|
---|
109 | const char *pcszFunction);
|
---|
110 |
|
---|
111 | void memdFree(void *p,
|
---|
112 | const char *pcszSourceFile,
|
---|
113 | unsigned long ulLine,
|
---|
114 | const char *pcszFunction);
|
---|
115 |
|
---|
116 | void* memdRealloc(void *p,
|
---|
117 | size_t stSize,
|
---|
118 | const char *pcszSourceFile,
|
---|
119 | unsigned long ulLine,
|
---|
120 | const char *pcszFunction);
|
---|
121 |
|
---|
122 | unsigned long memdReleaseFreed(void);
|
---|
123 |
|
---|
124 | #ifdef __XWPMEMDEBUG__
|
---|
125 |
|
---|
126 | #ifndef DONT_REPLACE_MALLOC
|
---|
127 | #define malloc(ul) memdMalloc(ul, __FILE__, __LINE__, __FUNCTION__)
|
---|
128 | #define calloc(n, size) memdCalloc(n, size, __FILE__, __LINE__, __FUNCTION__)
|
---|
129 | #define realloc(p, ul) memdRealloc(p, ul, __FILE__, __LINE__, __FUNCTION__)
|
---|
130 | #define free(p) memdFree(p, __FILE__, __LINE__, __FUNCTION__)
|
---|
131 |
|
---|
132 | #ifdef __string_h
|
---|
133 | // string.h included and debugging is on:
|
---|
134 | // redefine strdup to use memory debugging
|
---|
135 | #define strdup(psz) \
|
---|
136 | strcpy( (char*)memdMalloc(strlen(psz) + 1, __FILE__, __LINE__, __FUNCTION__), psz)
|
---|
137 | // the original crashes also if psz is NULL
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | #endif
|
---|
141 | #endif
|
---|
142 |
|
---|
143 | #ifdef PM_INCLUDED
|
---|
144 | /********************************************************************
|
---|
145 | *
|
---|
146 | * XFolder debugging helpers
|
---|
147 | *
|
---|
148 | ********************************************************************/
|
---|
149 |
|
---|
150 | #ifdef _PMPRINTF_
|
---|
151 | void memdDumpMemoryBlock(PBYTE pb,
|
---|
152 | ULONG ulSize,
|
---|
153 | ULONG ulIndent);
|
---|
154 | #else
|
---|
155 | // _PMPRINTF not #define'd: do nothing
|
---|
156 | #define memdDumpMemoryBlock(pb, ulSize, ulIndent)
|
---|
157 | #endif
|
---|
158 |
|
---|
159 | /* ******************************************************************
|
---|
160 | *
|
---|
161 | * Heap debugging window
|
---|
162 | *
|
---|
163 | ********************************************************************/
|
---|
164 |
|
---|
165 | MRESULT EXPENTRY memd_fnwpMemDebug(HWND hwndClient, ULONG msg, MPARAM mp1, MPARAM mp2);
|
---|
166 |
|
---|
167 | VOID memdCreateMemDebugWindow(VOID);
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | #endif
|
---|
171 |
|
---|
172 | #if __cplusplus
|
---|
173 | }
|
---|
174 | #endif
|
---|
175 |
|
---|