4 * Copyright 1997 Andrew Taylor
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "stackframe.h"
29 #include "wine/debug.h"
32 /* LogParamError and LogError values */
34 /* Error modifier bits */
35 #define ERR_WARNING 0x8000
36 #define ERR_PARAM 0x4000
38 #define ERR_SIZE_MASK 0x3000
39 #define ERR_BYTE 0x1000
40 #define ERR_WORD 0x2000
41 #define ERR_DWORD 0x3000
44 /* LogParamError() values */
46 /* Generic parameter values */
47 #define ERR_BAD_VALUE 0x6001
48 #define ERR_BAD_FLAGS 0x6002
49 #define ERR_BAD_INDEX 0x6003
50 #define ERR_BAD_DVALUE 0x7004
51 #define ERR_BAD_DFLAGS 0x7005
52 #define ERR_BAD_DINDEX 0x7006
53 #define ERR_BAD_PTR 0x7007
54 #define ERR_BAD_FUNC_PTR 0x7008
55 #define ERR_BAD_SELECTOR 0x6009
56 #define ERR_BAD_STRING_PTR 0x700a
57 #define ERR_BAD_HANDLE 0x600b
59 /* KERNEL parameter errors */
60 #define ERR_BAD_HINSTANCE 0x6020
61 #define ERR_BAD_HMODULE 0x6021
62 #define ERR_BAD_GLOBAL_HANDLE 0x6022
63 #define ERR_BAD_LOCAL_HANDLE 0x6023
64 #define ERR_BAD_ATOM 0x6024
65 #define ERR_BAD_HFILE 0x6025
67 /* USER parameter errors */
68 #define ERR_BAD_HWND 0x6040
69 #define ERR_BAD_HMENU 0x6041
70 #define ERR_BAD_HCURSOR 0x6042
71 #define ERR_BAD_HICON 0x6043
72 #define ERR_BAD_HDWP 0x6044
73 #define ERR_BAD_CID 0x6045
74 #define ERR_BAD_HDRVR 0x6046
76 /* GDI parameter errors */
77 #define ERR_BAD_COORDS 0x7060
78 #define ERR_BAD_GDI_OBJECT 0x6061
79 #define ERR_BAD_HDC 0x6062
80 #define ERR_BAD_HPEN 0x6063
81 #define ERR_BAD_HFONT 0x6064
82 #define ERR_BAD_HBRUSH 0x6065
83 #define ERR_BAD_HBITMAP 0x6066
84 #define ERR_BAD_HRGN 0x6067
85 #define ERR_BAD_HPALETTE 0x6068
86 #define ERR_BAD_HMETAFILE 0x6069
89 /* LogError() values */
92 #define ERR_GALLOC 0x0001
93 #define ERR_GREALLOC 0x0002
94 #define ERR_GLOCK 0x0003
95 #define ERR_LALLOC 0x0004
96 #define ERR_LREALLOC 0x0005
97 #define ERR_LLOCK 0x0006
98 #define ERR_ALLOCRES 0x0007
99 #define ERR_LOCKRES 0x0008
100 #define ERR_LOADMODULE 0x0009
103 #define ERR_CREATEDLG 0x0040
104 #define ERR_CREATEDLG2 0x0041
105 #define ERR_REGISTERCLASS 0x0042
106 #define ERR_DCBUSY 0x0043
107 #define ERR_CREATEWND 0x0044
108 #define ERR_STRUCEXTRA 0x0045
109 #define ERR_LOADSTR 0x0046
110 #define ERR_LOADMENU 0x0047
111 #define ERR_NESTEDBEGINPAINT 0x0048
112 #define ERR_BADINDEX 0x0049
113 #define ERR_CREATEMENU 0x004a
116 #define ERR_CREATEDC 0x0080
117 #define ERR_CREATEMETA 0x0081
118 #define ERR_DELOBJSELECTED 0x0082
119 #define ERR_SELBITMAP 0x0083
122 #define ErrorString(manifest) { manifest, # manifest }
124 static const struct {
129 ErrorString(ERR_GALLOC),
130 ErrorString(ERR_GREALLOC),
131 ErrorString(ERR_GLOCK),
132 ErrorString(ERR_LALLOC),
133 ErrorString(ERR_LREALLOC),
134 ErrorString(ERR_LLOCK),
135 ErrorString(ERR_ALLOCRES),
136 ErrorString(ERR_LOCKRES),
137 ErrorString(ERR_LOADMODULE),
138 ErrorString(ERR_CREATEDLG),
139 ErrorString(ERR_CREATEDLG2),
140 ErrorString(ERR_REGISTERCLASS),
141 ErrorString(ERR_DCBUSY),
142 ErrorString(ERR_CREATEWND),
143 ErrorString(ERR_STRUCEXTRA),
144 ErrorString(ERR_LOADSTR),
145 ErrorString(ERR_LOADMENU),
146 ErrorString(ERR_NESTEDBEGINPAINT),
147 ErrorString(ERR_BADINDEX),
148 ErrorString(ERR_CREATEMENU),
149 ErrorString(ERR_CREATEDC),
150 ErrorString(ERR_CREATEMETA),
151 ErrorString(ERR_DELOBJSELECTED),
152 ErrorString(ERR_SELBITMAP)
155 static const struct {
158 } ParamErrorStrings[] = {
160 ErrorString(ERR_BAD_VALUE),
161 ErrorString(ERR_BAD_FLAGS),
162 ErrorString(ERR_BAD_INDEX),
163 ErrorString(ERR_BAD_DVALUE),
164 ErrorString(ERR_BAD_DFLAGS),
165 ErrorString(ERR_BAD_DINDEX),
166 ErrorString(ERR_BAD_PTR),
167 ErrorString(ERR_BAD_FUNC_PTR),
168 ErrorString(ERR_BAD_SELECTOR),
169 ErrorString(ERR_BAD_STRING_PTR),
170 ErrorString(ERR_BAD_HANDLE),
171 ErrorString(ERR_BAD_HINSTANCE),
172 ErrorString(ERR_BAD_HMODULE),
173 ErrorString(ERR_BAD_GLOBAL_HANDLE),
174 ErrorString(ERR_BAD_LOCAL_HANDLE),
175 ErrorString(ERR_BAD_ATOM),
176 ErrorString(ERR_BAD_HFILE),
177 ErrorString(ERR_BAD_HWND),
178 ErrorString(ERR_BAD_HMENU),
179 ErrorString(ERR_BAD_HCURSOR),
180 ErrorString(ERR_BAD_HICON),
181 ErrorString(ERR_BAD_HDWP),
182 ErrorString(ERR_BAD_CID),
183 ErrorString(ERR_BAD_HDRVR),
184 ErrorString(ERR_BAD_COORDS),
185 ErrorString(ERR_BAD_GDI_OBJECT),
186 ErrorString(ERR_BAD_HDC),
187 ErrorString(ERR_BAD_HPEN),
188 ErrorString(ERR_BAD_HFONT),
189 ErrorString(ERR_BAD_HBRUSH),
190 ErrorString(ERR_BAD_HBITMAP),
191 ErrorString(ERR_BAD_HRGN),
192 ErrorString(ERR_BAD_HPALETTE),
193 ErrorString(ERR_BAD_HMETAFILE)
197 #define ErrorStringCount (sizeof(ErrorStrings) / sizeof(ErrorStrings[0]))
198 #define ParamErrorStringCount (sizeof(ParamErrorStrings) / sizeof(ParamErrorStrings[0]))
200 /***********************************************************************
201 * GetErrorString (internal)
203 static const char *GetErrorString(UINT16 uErr)
205 static char buffer[80];
208 for (n = 0; n < ErrorStringCount; n++) {
209 if (uErr == ErrorStrings[n].constant)
210 return ErrorStrings[n].name;
213 sprintf(buffer, "%x", uErr);
218 /***********************************************************************
219 * GetParamErrorString (internal)
221 static const char *GetParamErrorString(UINT16 uErr) {
222 static char buffer[80];
224 if (uErr & ERR_WARNING) {
225 strcpy(buffer, "ERR_WARNING | ");
226 uErr &= ~ERR_WARNING;
233 for (n = 0; n < ParamErrorStringCount; n++) {
234 if (uErr == ParamErrorStrings[n].constant) {
235 strcat(buffer, ParamErrorStrings[n].name);
241 sprintf(buffer + strlen(buffer), "%x", uErr);
246 /***********************************************************************
247 * LogError (KERNEL.324)
249 VOID WINAPI LogError16(UINT16 uErr, LPVOID lpvInfo)
251 MESSAGE("(%s, %p)\n", GetErrorString(uErr), lpvInfo);
255 /***********************************************************************
256 * LogParamError (KERNEL.325)
258 void WINAPI LogParamError16(UINT16 uErr, FARPROC16 lpfn, LPVOID lpvParam)
260 /* FIXME: is it possible to get the module name/function
261 * from the lpfn param?
263 MESSAGE("(%s, %p, %p)\n", GetParamErrorString(uErr), lpfn, lpvParam);
266 /***********************************************************************
269 void WINAPI HandleParamError( CONTEXT86 *context )
271 UINT16 uErr = LOWORD(context->Ebx);
272 FARPROC16 lpfn = (FARPROC16)MAKESEGPTR( context->SegCs, context->Eip );
273 LPVOID lpvParam = (LPVOID)MAKELONG( LOWORD(context->Eax), LOWORD(context->Ecx) );
275 LogParamError16( uErr, lpfn, lpvParam );
277 if (!(uErr & ERR_WARNING))
279 /* Abort current procedure: Unwind stack frame and jump
280 to error handler (location at [bp-2]) */
282 WORD *stack = MapSL( MAKESEGPTR( context->SegSs, LOWORD(context->Ebp) ));
283 context->Esp = LOWORD(context->Ebp) - 2;
284 context->Ebp = stack[0] & 0xfffe;
286 context->Eip = stack[-1];
288 context->Eax = context->Ecx = context->Edx = 0;