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

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

Define ras_snprintf() which differs from GNU LIBC snprintf().

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