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

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

Workaround stdcall bug in GCC related to vararg functions.

This can be easily removed once GCC gets fixed.

  • 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#ifdef __cplusplus
18extern "C" {
19#endif
20
21/* The RAS subsystem initialization/deinitialization */
22
23int WIN32API RasInitialize (
24 HMODULE hmod /* the custom dll handle */
25 );
26
27void WIN32API RasUninitialize (
28 void
29 );
30
31
32/* Generic RAS entry to be called from various places in Odin code.
33 */
34void 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 */
46typedef int WIN32API FNOLF (ULONG *ph, const char *logfilename);
47typedef void WIN32API FNCLF (ULONG h);
48typedef void WIN32API FNWL (ULONG h, char *buf, ULONG buflen);
49
50/* Tracked objects logging functions typedefs */
51typedef void WIN32API_VA FNRASLOG_EXTERNAL (const char *fmt, ...);
52
53typedef ULONG WIN32API FNLOC (ULONG objident, ULONG objhandle, void *objdata, ULONG cbobjdata, FNRASLOG_EXTERNAL *pRasLog);
54typedef ULONG WIN32API FNCOC (ULONG objhandle, void *objdata1, ULONG cbobjdata1, void *objdata2, ULONG cbobjdata);
55
56/* Object tracking handle */
57typedef struct _RAS_TRACK RAS_TRACK;
58typedef 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
66void 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
75void WIN32API RasDeregisterObjectTracking (
76 RAS_TRACK_HANDLE h /* handle previously returned by RasRegisterObjectTracking */
77 );
78
79ULONG 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
86void WIN32API RasTrackMemAlloc (
87 RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
88 ULONG size
89 );
90
91void WIN32API RasTrackMemRealloc (
92 RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
93 ULONG oldsize,
94 ULONG newsize
95 );
96
97void WIN32API RasTrackMemFree (
98 RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
99 ULONG size
100 );
101
102void WIN32API RasRemoveObject (
103 RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
104 ULONG objhandle /* distinctive handle of the object */
105 );
106
107void 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
115void 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 */
124void WIN32API RasEnterSerialize (
125 void
126 );
127
128void WIN32API RasExitSerialize (
129 void
130 );
131
132/* RAS logging channels */
133typedef struct _RAS_LOG_CHANNEL *RAS_LOG_CHANNEL_H;
134
135int 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
141void 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
147void WIN32API RasCloseLogChannel (
148 RAS_LOG_CHANNEL_H hchannel /* log channel handle returned by RasOpenLogChannel */
149 );
150
151/* RAS logging functions */
152void WIN32API_VA RasLog (
153 const char *fmt, /* 'printf' style format string */
154 ...
155 );
156
157void WIN32API_VA RasLogNoEOL (
158 const char *fmt, /* 'printf' style format string */
159 ...
160 );
161
162void 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
170void WIN32API RasLogObjects (
171 RAS_TRACK_HANDLE h, /* handle previously returned by RasRegisterObjectTracking */
172 ULONG flags /* logging mode */
173 );
174
175void WIN32API_VA RasLog2 (
176 RAS_LOG_CHANNEL_H hchannel, /* log channel to log to */
177 char *fmt, /* 'printf' style format string */
178 ...
179 );
180
181void WIN32API_VA RasLogNoEOL2 (
182 RAS_LOG_CHANNEL_H hchannel, /* log channel to log to */
183 char *fmt, /* 'printf' style format string */
184 ...
185 );
186
187void 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__
196int WIN32API_VA ras_snprintf (
197#else
198int 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 */
207void 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 */
214RAS_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
225typedef struct _RASCONTEXT
226{
227 ULONG data[8];
228} RASCONTEXT;
229
230void WIN32API RasSaveContext (
231 RASCONTEXT *pcontext /* memory buffer for context to save */
232 );
233void WIN32API RasRestoreContext (
234 RASCONTEXT *pcontext /* memory buffer for context to restore */
235 );
236
237FARPROC 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
243ULONG 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 */
253typedef 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 */
286typedef 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 */
294typedef void WIN32API FNPI (HMODULE hmod, RasEntryTable *pret, RasPluginEntryTable *ppet);
295typedef 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// Note: no need to generate int 3 in RAS build, just log the event.
311
312#define RasDebugInt3() RasBreakPoint(__FILE__, __FUNCTION__, __LINE__, 0, 0, 0)
313#define RasDebugInt3_x(a, b, c) RasBreakPoint(__FILE__, __FUNCTION__, __LINE__, a, b, c)
314
315void __INLINE RasBreakPoint (const char *szFile, const char *szFunction, int iLine, ULONG msg, ULONG parm1, ULONG parm2)
316{
317 RasLog ("BreakPoint at %s(%d)::%s", szFile, iLine, szFunction);
318 if (msg)
319 {
320 RasLogMsg (msg, parm1, parm2);
321 }
322}
323
324/* Replace old DebugInt3 with RAS version */
325#ifdef DebugInt3
326#undef DebugInt3
327#endif
328
329#define DebugInt3 RasDebugInt3
330
331#else
332
333// non RAS version, that does nothing
334#define RasRegisterObjectTracking(a, b, c, d, e, f)
335#define RasDeregisterObjectTracking(a)
336#define RasAddObject(a, b, c, d)
337#define RasRemoveObject(a, b)
338#define RasSetObjectUserData(a, b, c, d, e)
339#define RasQueryObjectUserData(a, b, c, d, e)
340#define RasInitialize()
341#define RasUninitialize()
342#define RasLogObjects(a, b)
343#define RasEntry (a, b, c)
344#define RasTrackMemAlloc(a, b)
345#define RasTrackMemRealloc(a, b, c)
346#define RasTrackMemFree(a, b)
347
348
349#endif /* RAS */
350
351#endif /* __RAS__H */
Note: See TracBrowser for help on using the repository browser.