source: branches/gcc-kmk/include/_ras.h@ 21710

Last change on this file since 21710 was 21710, checked in by dmik, 14 years ago

_ras.h: Use <sys/binutil.h> under GCC and remove useless typedef.

  • Property svn:eol-style set to native
File size: 13.3 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 *RAS_LOG_CHANNEL_H;
130
131int WIN32API RasOpenLogChannel ( /* returns system error code */
132 RAS_LOG_CHANNEL_H *phchannel, /* returned channel handle */
133 const char *env_loghandler, /* name of environment variable that is equal to name of external logging dll */
134 const char *filename /* file name to log to */
135 );
136
137void WIN32API RasWriteLogChannel (
138 RAS_LOG_CHANNEL_H hchannel, /* log channel handle returned by RasOpenLogChannel */
139 const char *msg, /* string to log */
140 ULONG length /* length of string */
141 );
142
143void WIN32API RasCloseLogChannel (
144 RAS_LOG_CHANNEL_H hchannel /* log channel handle returned by RasOpenLogChannel */
145 );
146
147/* RAS logging functions */
148void WIN32API RasLog (
149 char *fmt, /* 'printf' style format string */
150 ...
151 );
152
153void WIN32API RasLogNoEOL (
154 char *fmt, /* 'printf' style format string */
155 ...
156 );
157
158void WIN32API RasLogMsg (
159 ULONG msg, /* RAS message number */
160 ULONG parm1, /* message parameter 1 */
161 ULONG parm2 /* message parameter 2 */
162 );
163
164#define RAS_FLAG_LOG_OBJECTS (0x1)
165
166void WIN32API RasLogObjects (
167 RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
168 ULONG flags /* logging mode */
169 );
170
171void WIN32API RasLog2 (
172 RAS_LOG_CHANNEL_H hchannel, /* log channel to log to */
173 char *fmt, /* 'printf' style format string */
174 ...
175 );
176
177void WIN32API RasLogNoEOL2 (
178 RAS_LOG_CHANNEL_H hchannel, /* log channel to log to */
179 char *fmt, /* 'printf' style format string */
180 ...
181 );
182
183void WIN32API RasLogMsg2 (
184 RAS_LOG_CHANNEL_H hchannel, /* log channel to log to */
185 ULONG msg, /* RAS message number */
186 ULONG parm1, /* message parameter 1 */
187 ULONG parm2 /* message parameter 2 */
188 );
189
190/* RAS replacement for C runtime sprintf function */
191int WIN32API snprintf (
192 char *buf, /* memory buffer for formatted string */
193 int n, /* length of memeory buffer */
194 const char *fmt, /* 'printf' style format string */
195 ...
196 );
197
198/* Tracked object counting function */
199void WIN32API RasCountObjects (
200 RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
201 ULONG *pcount, /* pointer to returned count of objects */
202 ULONG *pallocated /* pointer to returned number of bytes allocated for memory trackings */
203 );
204
205/* Obtain tracking handle for particular objects */
206RAS_TRACK_HANDLE WIN32API RasGetTrackHandle (
207 const char *objname /* object name use in RasRegisterObjectTracking */
208 );
209
210
211
212/* Odin context save and restore functions.
213 * The context has to be saved before calling
214 * any external API (OS/2 and or C runtime functions).
215 */
216
217typedef struct _RASCONTEXT
218{
219 ULONG data[8];
220} RASCONTEXT;
221
222void WIN32API RasSaveContext (
223 RASCONTEXT *pcontext /* memory buffer for context to save */
224 );
225void WIN32API RasRestoreContext (
226 RASCONTEXT *pcontext /* memory buffer for context to restore */
227 );
228
229FARPROC WIN32API RasSetProcAddr ( /* returns old procedure address */
230 ULONG hModule, /* Odin32 module handle */
231 LPCSTR lpszProc, /* name of procedure */
232 FARPROC pfnNewProc /* new procedure address */
233 );
234
235ULONG WIN32API RasGetModuleHandle (
236 LPCTSTR lpszModule
237 );
238
239
240/* RAS entries that are passed to plugin to use
241 */
242typedef struct _RasEntryTable
243{
244 ULONG cb;
245
246 void (* WIN32API RasRegisterObjectTracking) (RAS_TRACK_HANDLE *ph, char *objname, ULONG cbuserdata, ULONG flags, FNLOC *pfnLogObjectContent, FNCOC *pfnCompareObjectContent);
247 void (* WIN32API RasDeregisterObjectTracking) (RAS_TRACK_HANDLE h);
248 ULONG (* WIN32API RasAddObject) (RAS_TRACK_HANDLE h, ULONG objhandle, void *objdata, ULONG cbobjdata);
249 void (* WIN32API RasRemoveObject) (RAS_TRACK_HANDLE h, ULONG objhandle);
250 void (* WIN32API RasSetObjectUserData) (RAS_TRACK_HANDLE h, ULONG objident, void *pdata, ULONG cbdata, ULONG *pcbdataret);
251 void (* WIN32API RasQueryObjectUserData) (RAS_TRACK_HANDLE h, ULONG objident, void *pdata, ULONG cbdata, ULONG *pcbdataret);
252 void (* WIN32API RasEnterSerialize) (void);
253 void (* WIN32API RasExitSerialize) (void);
254 int (* WIN32API RasOpenLogChannel) (RAS_LOG_CHANNEL_H *phchannel, const char *env_loghandler, const char *filename);
255 void (* WIN32API RasWriteLogChannel) (RAS_LOG_CHANNEL_H hchannel, const char *msg, ULONG length);
256 void (* WIN32API RasCloseLogChannel) (RAS_LOG_CHANNEL_H hchannel);
257 void (* WIN32API RasLog) (RAS_LOG_CHANNEL_H hchannel, char *fmt, ...);
258 void (* WIN32API RasLogNoEOL) (RAS_LOG_CHANNEL_H hchannel, char *fmt, ...);
259 void (* WIN32API RasLogMsg) (RAS_LOG_CHANNEL_H hchannel, ULONG msg, ULONG parm1, ULONG parm2);
260 int (* WIN32API snprintf) (char *buf, int n, const char *fmt, ...);
261 void (* WIN32API RasSaveContext) (RASCONTEXT *pcontext);
262 void (* WIN32API RasRestoreContext) (RASCONTEXT *pcontext);
263 FARPROC (* WIN32API RasSetProcAddr) (HMODULE hModule, LPCSTR lpszProc, FARPROC pfnNewProc);
264 ULONG (* WIN32API RasGetModuleHandle) (LPCTSTR lpszModule);
265 void (* WIN32API RasCountObjects) (RAS_TRACK_HANDLE h, ULONG *pcount, ULONG *pallocated);
266 void (* WIN32API RasTrackMemAlloc) (RAS_TRACK_HANDLE h, ULONG size);
267 void (* WIN32API RasTrackMemRealloc) (RAS_TRACK_HANDLE h, ULONG oldsize,ULONG newsize);
268 void (* WIN32API RasTrackMemFree) (RAS_TRACK_HANDLE h, ULONG size);
269 RAS_TRACK_HANDLE (* WIN32API RasGetTrackHandle) (const char *objname);
270
271} RasEntryTable;
272
273/* RAS entries those can be replaced by plugin
274 */
275typedef struct _RasPluginEntryTable
276{
277 ULONG cb;
278
279 void (* WIN32API RasEntry) (ULONG ulEvent, void *p, ULONG cb);
280} RasPluginEntryTable;
281
282/* RAS plugin functions typedefs */
283typedef void WIN32API FNPI (HMODULE hmod, RasEntryTable *pret, RasPluginEntryTable *ppet);
284typedef void WIN32API FNPE (HMODULE hmod);
285
286/* RAS breakpoint support */
287#if defined(__GNUC__)
288#include <sys/builtin.h>
289#else
290#include <builtin.h>
291#endif
292
293#ifdef __cplusplus
294#define __INLINE inline
295#else
296#define __INLINE _Inline
297#endif
298
299// Note: no need to generate int 3 in RAS build, just log the event.
300
301#define RasDebugInt3() RasBreakPoint(__FILE__, __FUNCTION__, __LINE__, 0, 0, 0)
302#define RasDebugInt3_x(a, b, c) RasBreakPoint(__FILE__, __FUNCTION__, __LINE__, a, b, c)
303
304void __INLINE RasBreakPoint (char *szFile, char *szFunction, int iLine, ULONG msg, ULONG parm1, ULONG parm2)
305{
306 RasLog ("BreakPoint at %s(%d)::%s", szFile, iLine, szFunction);
307 if (msg)
308 {
309 RasLogMsg (msg, parm1, parm2);
310 }
311}
312
313/* Replace old DebugInt3 with RAS version */
314#ifdef DebugInt3
315#undef DebugInt3
316#endif
317
318#define DebugInt3 RasDebugInt3
319
320#else
321
322// non RAS version, that does nothing
323#define RasRegisterObjectTracking(a, b, c, d, e, f)
324#define RasDeregisterObjectTracking(a)
325#define RasAddObject(a, b, c, d)
326#define RasRemoveObject(a, b)
327#define RasSetObjectUserData(a, b, c, d, e)
328#define RasQueryObjectUserData(a, b, c, d, e)
329#define RasInitialize()
330#define RasUninitialize()
331#define RasLogObjects(a, b)
332#define RasEntry (a, b, c)
333#define RasTrackMemAlloc(a, b)
334#define RasTrackMemRealloc(a, b, c)
335#define RasTrackMemFree(a, b)
336
337
338#endif /* RAS */
339
340#endif /* __RAS__H */
Note: See TracBrowser for help on using the repository browser.