1 | #ifndef __RAS__H
|
---|
2 | #define __RAS__H
|
---|
3 |
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <string.h>
|
---|
7 | #include <stdarg.h>
|
---|
8 |
|
---|
9 | #include <odin.h>
|
---|
10 | #include <win32type.h>
|
---|
11 |
|
---|
12 | #define RAS
|
---|
13 |
|
---|
14 |
|
---|
15 | #ifdef RAS
|
---|
16 |
|
---|
17 | #ifdef __cplusplus
|
---|
18 | extern "C" {
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | /* The RAS subsystem initialization/deinitialization */
|
---|
22 |
|
---|
23 | int WIN32API RasInitialize (
|
---|
24 | HMODULE hmod /* the custom dll handle */
|
---|
25 | );
|
---|
26 |
|
---|
27 | void WIN32API RasUninitialize (
|
---|
28 | void
|
---|
29 | );
|
---|
30 |
|
---|
31 |
|
---|
32 | /* Generic RAS entry to be called from various places in Odin code.
|
---|
33 | */
|
---|
34 | void WIN32API RasEntry (
|
---|
35 | ULONG ulEvent, /* RAS event number */
|
---|
36 | void *p, /* pointer to event specific data */
|
---|
37 | ULONG cb /* size of event specific data */
|
---|
38 | );
|
---|
39 |
|
---|
40 | /* RAS events */
|
---|
41 | #define RAS_EVENT_Kernel32InitComplete (1)
|
---|
42 | #define RAS_EVENT_User32InitComplete (2)
|
---|
43 | #define RAS_EVENT_Gdi32InitComplete (3)
|
---|
44 |
|
---|
45 | /* External logging library functions typedefs */
|
---|
46 | typedef int WIN32API FNOLF (ULONG *ph, const char *logfilename);
|
---|
47 | typedef void WIN32API FNCLF (ULONG h);
|
---|
48 | typedef void WIN32API FNWL (ULONG h, char *buf, ULONG buflen);
|
---|
49 |
|
---|
50 | /* Tracked objects logging functions typedefs */
|
---|
51 | typedef void WIN32API_VA FNRASLOG_EXTERNAL (const char *fmt, ...);
|
---|
52 |
|
---|
53 | typedef ULONG WIN32API FNLOC (ULONG objident, ULONG objhandle, void *objdata, ULONG cbobjdata, FNRASLOG_EXTERNAL *pRasLog);
|
---|
54 | typedef ULONG WIN32API FNCOC (ULONG objhandle, void *objdata1, ULONG cbobjdata1, void *objdata2, ULONG cbobjdata);
|
---|
55 |
|
---|
56 | /* Object tracking handle */
|
---|
57 | typedef struct _RAS_TRACK RAS_TRACK;
|
---|
58 | typedef RAS_TRACK *RAS_TRACK_HANDLE;
|
---|
59 |
|
---|
60 | /* Object tracking flags */
|
---|
61 | #define RAS_TRACK_FLAG_LOGOBJECTCONTENT (0x1)
|
---|
62 | #define RAS_TRACK_FLAG_MEMORY (0x2)
|
---|
63 | #define RAS_TRACK_FLAG_LOG_AT_EXIT (0x4)
|
---|
64 | #define RAS_TRACK_FLAG_LOG_OBJECTS_AT_EXIT (0x8 | RAS_TRACK_FLAG_LOG_AT_EXIT)
|
---|
65 |
|
---|
66 | void WIN32API RasRegisterObjectTracking (
|
---|
67 | RAS_TRACK_HANDLE *ph, /* returned handle */
|
---|
68 | const char *objname, /* arbitrary distinguishable object name */
|
---|
69 | ULONG cbuserdata, /* extra data size */
|
---|
70 | ULONG flags, /* object tracking flags */
|
---|
71 | FNLOC *pfnLogObjectContent, /* custom function to log the object content */
|
---|
72 | FNCOC *pfnCompareObjectContent /* custom function to compare two objects */
|
---|
73 | );
|
---|
74 |
|
---|
75 | void WIN32API RasDeregisterObjectTracking (
|
---|
76 | RAS_TRACK_HANDLE h /* handle previously returned by RasRegisterObjectTracking */
|
---|
77 | );
|
---|
78 |
|
---|
79 | ULONG WIN32API RasAddObject ( /* returns unique object ident */
|
---|
80 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
81 | ULONG objhandle, /* distinctive handle of the object */
|
---|
82 | void *objdata, /* actual object pointer */
|
---|
83 | ULONG cbobjdata /* size of object */
|
---|
84 | );
|
---|
85 |
|
---|
86 | void WIN32API RasTrackMemAlloc (
|
---|
87 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
88 | ULONG size
|
---|
89 | );
|
---|
90 |
|
---|
91 | void WIN32API RasTrackMemRealloc (
|
---|
92 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
93 | ULONG oldsize,
|
---|
94 | ULONG newsize
|
---|
95 | );
|
---|
96 |
|
---|
97 | void WIN32API RasTrackMemFree (
|
---|
98 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
99 | ULONG size
|
---|
100 | );
|
---|
101 |
|
---|
102 | void WIN32API RasRemoveObject (
|
---|
103 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
104 | ULONG objhandle /* distinctive handle of the object */
|
---|
105 | );
|
---|
106 |
|
---|
107 | void WIN32API RasSetObjectUserData (
|
---|
108 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
109 | ULONG objident, /* unique object ident returned */
|
---|
110 | void *pdata, /* arbitrary data to be saved */
|
---|
111 | ULONG cbdata, /* size of data */
|
---|
112 | ULONG *pcbdataret /* returned size of data actually saved */
|
---|
113 | );
|
---|
114 |
|
---|
115 | void WIN32API RasQueryObjectUserData (
|
---|
116 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
117 | ULONG objident, /* unique object ident returned */
|
---|
118 | void *pdata, /* data buffer for queried data */
|
---|
119 | ULONG cbdata, /* size of data buffer */
|
---|
120 | ULONG *pcbdataret /* returned size of data actually queried */
|
---|
121 | );
|
---|
122 |
|
---|
123 | /* RAS serialization */
|
---|
124 | void WIN32API RasEnterSerialize (
|
---|
125 | void
|
---|
126 | );
|
---|
127 |
|
---|
128 | void WIN32API RasExitSerialize (
|
---|
129 | void
|
---|
130 | );
|
---|
131 |
|
---|
132 | /* RAS logging channels */
|
---|
133 | typedef struct _RAS_LOG_CHANNEL *RAS_LOG_CHANNEL_H;
|
---|
134 |
|
---|
135 | int WIN32API RasOpenLogChannel ( /* returns system error code */
|
---|
136 | RAS_LOG_CHANNEL_H *phchannel, /* returned channel handle */
|
---|
137 | const char *env_loghandler, /* name of environment variable that is equal to name of external logging dll */
|
---|
138 | const char *filename /* file name to log to */
|
---|
139 | );
|
---|
140 |
|
---|
141 | void WIN32API RasWriteLogChannel (
|
---|
142 | RAS_LOG_CHANNEL_H hchannel, /* log channel handle returned by RasOpenLogChannel */
|
---|
143 | const char *msg, /* string to log */
|
---|
144 | ULONG length /* length of string */
|
---|
145 | );
|
---|
146 |
|
---|
147 | void WIN32API RasCloseLogChannel (
|
---|
148 | RAS_LOG_CHANNEL_H hchannel /* log channel handle returned by RasOpenLogChannel */
|
---|
149 | );
|
---|
150 |
|
---|
151 | /* RAS logging functions */
|
---|
152 | void WIN32API_VA RasLog (
|
---|
153 | const char *fmt, /* 'printf' style format string */
|
---|
154 | ...
|
---|
155 | );
|
---|
156 |
|
---|
157 | void WIN32API_VA RasLogNoEOL (
|
---|
158 | const char *fmt, /* 'printf' style format string */
|
---|
159 | ...
|
---|
160 | );
|
---|
161 |
|
---|
162 | void WIN32API RasLogMsg (
|
---|
163 | ULONG msg, /* RAS message number */
|
---|
164 | ULONG parm1, /* message parameter 1 */
|
---|
165 | ULONG parm2 /* message parameter 2 */
|
---|
166 | );
|
---|
167 |
|
---|
168 | #define RAS_FLAG_LOG_OBJECTS (0x1)
|
---|
169 |
|
---|
170 | void WIN32API RasLogObjects (
|
---|
171 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
172 | ULONG flags /* logging mode */
|
---|
173 | );
|
---|
174 |
|
---|
175 | void WIN32API_VA RasLog2 (
|
---|
176 | RAS_LOG_CHANNEL_H hchannel, /* log channel to log to */
|
---|
177 | char *fmt, /* 'printf' style format string */
|
---|
178 | ...
|
---|
179 | );
|
---|
180 |
|
---|
181 | void WIN32API_VA RasLogNoEOL2 (
|
---|
182 | RAS_LOG_CHANNEL_H hchannel, /* log channel to log to */
|
---|
183 | char *fmt, /* 'printf' style format string */
|
---|
184 | ...
|
---|
185 | );
|
---|
186 |
|
---|
187 | void WIN32API RasLogMsg2 (
|
---|
188 | RAS_LOG_CHANNEL_H hchannel, /* log channel to log to */
|
---|
189 | ULONG msg, /* RAS message number */
|
---|
190 | ULONG parm1, /* message parameter 1 */
|
---|
191 | ULONG parm2 /* message parameter 2 */
|
---|
192 | );
|
---|
193 |
|
---|
194 | /* RAS replacement for C runtime sprintf function */
|
---|
195 | #ifdef __GNUC__
|
---|
196 | int WIN32API_VA ras_snprintf (
|
---|
197 | #else
|
---|
198 | int WIN32API snprintf (
|
---|
199 | #endif
|
---|
200 | char *buf, /* memory buffer for formatted string */
|
---|
201 | int n, /* length of memeory buffer */
|
---|
202 | const char *fmt, /* 'printf' style format string */
|
---|
203 | ...
|
---|
204 | );
|
---|
205 |
|
---|
206 | /* Tracked object counting function */
|
---|
207 | void WIN32API RasCountObjects (
|
---|
208 | RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
|
---|
209 | ULONG *pcount, /* pointer to returned count of objects */
|
---|
210 | ULONG *pallocated /* pointer to returned number of bytes allocated for memory trackings */
|
---|
211 | );
|
---|
212 |
|
---|
213 | /* Obtain tracking handle for particular objects */
|
---|
214 | RAS_TRACK_HANDLE WIN32API RasGetTrackHandle (
|
---|
215 | const char *objname /* object name use in RasRegisterObjectTracking */
|
---|
216 | );
|
---|
217 |
|
---|
218 |
|
---|
219 |
|
---|
220 | /* Odin context save and restore functions.
|
---|
221 | * The context has to be saved before calling
|
---|
222 | * any external API (OS/2 and or C runtime functions).
|
---|
223 | */
|
---|
224 |
|
---|
225 | typedef struct _RASCONTEXT
|
---|
226 | {
|
---|
227 | ULONG data[8];
|
---|
228 | } RASCONTEXT;
|
---|
229 |
|
---|
230 | void WIN32API RasSaveContext (
|
---|
231 | RASCONTEXT *pcontext /* memory buffer for context to save */
|
---|
232 | );
|
---|
233 | void WIN32API RasRestoreContext (
|
---|
234 | RASCONTEXT *pcontext /* memory buffer for context to restore */
|
---|
235 | );
|
---|
236 |
|
---|
237 | FARPROC WIN32API RasSetProcAddr ( /* returns old procedure address */
|
---|
238 | ULONG hModule, /* Odin32 module handle */
|
---|
239 | LPCSTR lpszProc, /* name of procedure */
|
---|
240 | FARPROC pfnNewProc /* new procedure address */
|
---|
241 | );
|
---|
242 |
|
---|
243 | ULONG WIN32API RasGetModuleHandle (
|
---|
244 | LPCTSTR lpszModule
|
---|
245 | );
|
---|
246 |
|
---|
247 | #ifdef __cplusplus
|
---|
248 | } // extern "C"
|
---|
249 | #endif
|
---|
250 |
|
---|
251 | /* RAS entries that are passed to plugin to use
|
---|
252 | */
|
---|
253 | typedef struct _RasEntryTable
|
---|
254 | {
|
---|
255 | ULONG cb;
|
---|
256 |
|
---|
257 | void (* WIN32API RasRegisterObjectTracking) (RAS_TRACK_HANDLE *ph, const char *objname, ULONG cbuserdata, ULONG flags, FNLOC *pfnLogObjectContent, FNCOC *pfnCompareObjectContent);
|
---|
258 | void (* WIN32API RasDeregisterObjectTracking) (RAS_TRACK_HANDLE h);
|
---|
259 | ULONG (* WIN32API RasAddObject) (RAS_TRACK_HANDLE h, ULONG objhandle, void *objdata, ULONG cbobjdata);
|
---|
260 | void (* WIN32API RasRemoveObject) (RAS_TRACK_HANDLE h, ULONG objhandle);
|
---|
261 | void (* WIN32API RasSetObjectUserData) (RAS_TRACK_HANDLE h, ULONG objident, void *pdata, ULONG cbdata, ULONG *pcbdataret);
|
---|
262 | void (* WIN32API RasQueryObjectUserData) (RAS_TRACK_HANDLE h, ULONG objident, void *pdata, ULONG cbdata, ULONG *pcbdataret);
|
---|
263 | void (* WIN32API RasEnterSerialize) (void);
|
---|
264 | void (* WIN32API RasExitSerialize) (void);
|
---|
265 | int (* WIN32API RasOpenLogChannel) (RAS_LOG_CHANNEL_H *phchannel, const char *env_loghandler, const char *filename);
|
---|
266 | void (* WIN32API RasWriteLogChannel) (RAS_LOG_CHANNEL_H hchannel, const char *msg, ULONG length);
|
---|
267 | void (* WIN32API RasCloseLogChannel) (RAS_LOG_CHANNEL_H hchannel);
|
---|
268 | void (* WIN32API_VA RasLog) (RAS_LOG_CHANNEL_H hchannel, char *fmt, ...);
|
---|
269 | void (* WIN32API_VA RasLogNoEOL) (RAS_LOG_CHANNEL_H hchannel, char *fmt, ...);
|
---|
270 | void (* WIN32API RasLogMsg) (RAS_LOG_CHANNEL_H hchannel, ULONG msg, ULONG parm1, ULONG parm2);
|
---|
271 | int (* WIN32API_VA snprintf) (char *buf, int n, const char *fmt, ...);
|
---|
272 | void (* WIN32API RasSaveContext) (RASCONTEXT *pcontext);
|
---|
273 | void (* WIN32API RasRestoreContext) (RASCONTEXT *pcontext);
|
---|
274 | FARPROC (* WIN32API RasSetProcAddr) (HMODULE hModule, LPCSTR lpszProc, FARPROC pfnNewProc);
|
---|
275 | ULONG (* WIN32API RasGetModuleHandle) (LPCTSTR lpszModule);
|
---|
276 | void (* WIN32API RasCountObjects) (RAS_TRACK_HANDLE h, ULONG *pcount, ULONG *pallocated);
|
---|
277 | void (* WIN32API RasTrackMemAlloc) (RAS_TRACK_HANDLE h, ULONG size);
|
---|
278 | void (* WIN32API RasTrackMemRealloc) (RAS_TRACK_HANDLE h, ULONG oldsize,ULONG newsize);
|
---|
279 | void (* WIN32API RasTrackMemFree) (RAS_TRACK_HANDLE h, ULONG size);
|
---|
280 | RAS_TRACK_HANDLE (* WIN32API RasGetTrackHandle) (const char *objname);
|
---|
281 |
|
---|
282 | } RasEntryTable;
|
---|
283 |
|
---|
284 | /* RAS entries those can be replaced by plugin
|
---|
285 | */
|
---|
286 | typedef struct _RasPluginEntryTable
|
---|
287 | {
|
---|
288 | ULONG cb;
|
---|
289 |
|
---|
290 | void (* WIN32API RasEntry) (ULONG ulEvent, void *p, ULONG cb);
|
---|
291 | } RasPluginEntryTable;
|
---|
292 |
|
---|
293 | /* RAS plugin functions typedefs */
|
---|
294 | typedef void WIN32API FNPI (HMODULE hmod, RasEntryTable *pret, RasPluginEntryTable *ppet);
|
---|
295 | typedef void WIN32API FNPE (HMODULE hmod);
|
---|
296 |
|
---|
297 | /* RAS breakpoint support */
|
---|
298 | #if defined(__GNUC__)
|
---|
299 | #include <sys/builtin.h>
|
---|
300 | #else
|
---|
301 | #include <builtin.h>
|
---|
302 | #endif
|
---|
303 |
|
---|
304 | #ifdef __cplusplus
|
---|
305 | #define __INLINE inline
|
---|
306 | #else
|
---|
307 | #define __INLINE _Inline
|
---|
308 | #endif
|
---|
309 |
|
---|
310 | #if 0
|
---|
311 |
|
---|
312 | // Note: no need to generate int 3 in RAS build, just log the event.
|
---|
313 | // Note 2: disabled for now since RAS is always defined when this file is
|
---|
314 | // included which would unconditioanlly override the normal DebugInt3 behavior
|
---|
315 |
|
---|
316 | #define RasDebugInt3() RasBreakPoint(__FILE__, __FUNCTION__, __LINE__, 0, 0, 0)
|
---|
317 | #define RasDebugInt3_x(a, b, c) RasBreakPoint(__FILE__, __FUNCTION__, __LINE__, a, b, c)
|
---|
318 |
|
---|
319 | void __INLINE RasBreakPoint (const char *szFile, const char *szFunction, int iLine, ULONG msg, ULONG parm1, ULONG parm2)
|
---|
320 | {
|
---|
321 | RasLog ("BreakPoint at %s(%d)::%s", szFile, iLine, szFunction);
|
---|
322 | if (msg)
|
---|
323 | {
|
---|
324 | RasLogMsg (msg, parm1, parm2);
|
---|
325 | }
|
---|
326 | }
|
---|
327 |
|
---|
328 | /* Replace old DebugInt3 with RAS version */
|
---|
329 | #ifdef DebugInt3
|
---|
330 | #undef DebugInt3
|
---|
331 | #endif
|
---|
332 |
|
---|
333 | #define DebugInt3 RasDebugInt3
|
---|
334 |
|
---|
335 | #endif
|
---|
336 |
|
---|
337 | #else
|
---|
338 |
|
---|
339 | // non RAS version, that does nothing
|
---|
340 | #define RasRegisterObjectTracking(a, b, c, d, e, f)
|
---|
341 | #define RasDeregisterObjectTracking(a)
|
---|
342 | #define RasAddObject(a, b, c, d)
|
---|
343 | #define RasRemoveObject(a, b)
|
---|
344 | #define RasSetObjectUserData(a, b, c, d, e)
|
---|
345 | #define RasQueryObjectUserData(a, b, c, d, e)
|
---|
346 | #define RasInitialize()
|
---|
347 | #define RasUninitialize()
|
---|
348 | #define RasLogObjects(a, b)
|
---|
349 | #define RasEntry (a, b, c)
|
---|
350 | #define RasTrackMemAlloc(a, b)
|
---|
351 | #define RasTrackMemRealloc(a, b, c)
|
---|
352 | #define RasTrackMemFree(a, b)
|
---|
353 |
|
---|
354 |
|
---|
355 | #endif /* RAS */
|
---|
356 |
|
---|
357 | #endif /* __RAS__H */
|
---|