4 * Copyright 1997 Andrew Taylor
11 #include "stackframe.h"
14 #define ErrorString(manifest) { manifest, # manifest }
21 ErrorString(ERR_GALLOC
),
22 ErrorString(ERR_GREALLOC
),
23 ErrorString(ERR_GLOCK
),
24 ErrorString(ERR_LALLOC
),
25 ErrorString(ERR_LREALLOC
),
26 ErrorString(ERR_LLOCK
),
27 ErrorString(ERR_ALLOCRES
),
28 ErrorString(ERR_LOCKRES
),
29 ErrorString(ERR_LOADMODULE
),
30 ErrorString(ERR_CREATEDLG
),
31 ErrorString(ERR_CREATEDLG2
),
32 ErrorString(ERR_REGISTERCLASS
),
33 ErrorString(ERR_DCBUSY
),
34 ErrorString(ERR_CREATEWND
),
35 ErrorString(ERR_STRUCEXTRA
),
36 ErrorString(ERR_LOADSTR
),
37 ErrorString(ERR_LOADMENU
),
38 ErrorString(ERR_NESTEDBEGINPAINT
),
39 ErrorString(ERR_BADINDEX
),
40 ErrorString(ERR_CREATEMENU
),
41 ErrorString(ERR_CREATEDC
),
42 ErrorString(ERR_CREATEMETA
),
43 ErrorString(ERR_DELOBJSELECTED
),
44 ErrorString(ERR_SELBITMAP
)
50 } ParamErrorStrings
[] = {
52 ErrorString(ERR_BAD_VALUE
),
53 ErrorString(ERR_BAD_FLAGS
),
54 ErrorString(ERR_BAD_INDEX
),
55 ErrorString(ERR_BAD_DVALUE
),
56 ErrorString(ERR_BAD_DFLAGS
),
57 ErrorString(ERR_BAD_DINDEX
),
58 ErrorString(ERR_BAD_PTR
),
59 ErrorString(ERR_BAD_FUNC_PTR
),
60 ErrorString(ERR_BAD_SELECTOR
),
61 ErrorString(ERR_BAD_STRING_PTR
),
62 ErrorString(ERR_BAD_HANDLE
),
63 ErrorString(ERR_BAD_HINSTANCE
),
64 ErrorString(ERR_BAD_HMODULE
),
65 ErrorString(ERR_BAD_GLOBAL_HANDLE
),
66 ErrorString(ERR_BAD_LOCAL_HANDLE
),
67 ErrorString(ERR_BAD_ATOM
),
68 ErrorString(ERR_BAD_HFILE
),
69 ErrorString(ERR_BAD_HWND
),
70 ErrorString(ERR_BAD_HMENU
),
71 ErrorString(ERR_BAD_HCURSOR
),
72 ErrorString(ERR_BAD_HICON
),
73 ErrorString(ERR_BAD_HDWP
),
74 ErrorString(ERR_BAD_CID
),
75 ErrorString(ERR_BAD_HDRVR
),
76 ErrorString(ERR_BAD_COORDS
),
77 ErrorString(ERR_BAD_GDI_OBJECT
),
78 ErrorString(ERR_BAD_HDC
),
79 ErrorString(ERR_BAD_HPEN
),
80 ErrorString(ERR_BAD_HFONT
),
81 ErrorString(ERR_BAD_HBRUSH
),
82 ErrorString(ERR_BAD_HBITMAP
),
83 ErrorString(ERR_BAD_HRGN
),
84 ErrorString(ERR_BAD_HPALETTE
),
85 ErrorString(ERR_BAD_HMETAFILE
)
89 #define ErrorStringCount (sizeof(ErrorStrings) / sizeof(ErrorStrings[0]))
90 #define ParamErrorStringCount (sizeof(ParamErrorStrings) / sizeof(ParamErrorStrings[0]))
92 /***********************************************************************
93 * GetErrorString (internal)
95 static const char *GetErrorString(UINT16 uErr
)
97 static char buffer
[80];
100 for (i
= 0; i
< ErrorStringCount
; i
++) {
101 if (uErr
== ErrorStrings
[i
].constant
)
102 return ErrorStrings
[i
].name
;
105 sprintf(buffer
, "%x", uErr
);
110 /***********************************************************************
111 * GetParamErrorString (internal)
113 static const char *GetParamErrorString(UINT16 uErr
) {
114 static char buffer
[80];
116 if (uErr
& ERR_WARNING
) {
117 strcpy(buffer
, "ERR_WARNING | ");
118 uErr
&= ~ERR_WARNING
;
125 for (i
= 0; i
< ParamErrorStringCount
; i
++) {
126 if (uErr
== ParamErrorStrings
[i
].constant
) {
127 strcat(buffer
, ParamErrorStrings
[i
].name
);
133 sprintf(buffer
+ strlen(buffer
), "%x", uErr
);
138 /***********************************************************************
139 * LogError (KERNEL.324)
141 VOID WINAPI
LogError(UINT16 uErr
, LPVOID lpvInfo
)
143 MSG("(%s, %p)\n", GetErrorString(uErr
), lpvInfo
);
147 /***********************************************************************
148 * LogParamError (KERNEL.325)
150 void WINAPI
LogParamError(UINT16 uErr
, FARPROC16 lpfn
, LPVOID lpvParam
)
152 /* FIXME: is it possible to get the module name/function
153 * from the lpfn param?
155 MSG("(%s, %p, %p)\n", GetParamErrorString(uErr
), lpfn
, lpvParam
);
158 /***********************************************************************
159 * LogParamErrorRegs (KERNEL.327)
161 void WINAPI
LogParamErrorRegs( CONTEXT
*context
)
163 UINT16 uErr
= BX_reg( context
);
164 FARPROC16 lpfn
= (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( CS_reg(context
),
166 LPVOID lpvParam
= (LPVOID
)MAKELONG( AX_reg( context
),
169 LogParamError( uErr
, lpfn
, lpvParam
);
171 if (!(uErr
& ERR_WARNING
))
173 /* Abort current procedure: Unwind stack frame and jump
174 to error handler (location at [bp-2]) */
176 WORD
*stack
= PTR_SEG_OFF_TO_LIN( SS_reg( context
),
178 SP_reg( context
) = BP_reg( context
) - 2;
179 BP_reg( context
) = stack
[0] & 0xfffe;
181 IP_reg( context
) = stack
[-1];
183 EAX_reg( context
) = ECX_reg( context
) = EDX_reg( context
) = 0;
184 ES_reg( context
) = 0;