source: trunk/include/_ras.h@ 21380

Last change on this file since 21380 was 21301, checked in by ydario, 16 years ago

Header updates.

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