dinput: Delete the action mapping registry key on SetActionMap.
[wine.git] / dlls / krnl386.exe16 / error.c
blob5508d7c0e8caf0d87e1c607635aef44ba5798d3a
1 /*
2 * Log internal errors
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "windef.h"
27 #include "wine/winbase16.h"
28 #include "wine/debug.h"
31 /* LogParamError and LogError values */
33 /* Error modifier bits */
34 #define ERR_WARNING 0x8000
35 #define ERR_PARAM 0x4000
37 #define ERR_SIZE_MASK 0x3000
38 #define ERR_BYTE 0x1000
39 #define ERR_WORD 0x2000
40 #define ERR_DWORD 0x3000
43 /* LogParamError() values */
45 /* Generic parameter values */
46 #define ERR_BAD_VALUE 0x6001
47 #define ERR_BAD_FLAGS 0x6002
48 #define ERR_BAD_INDEX 0x6003
49 #define ERR_BAD_DVALUE 0x7004
50 #define ERR_BAD_DFLAGS 0x7005
51 #define ERR_BAD_DINDEX 0x7006
52 #define ERR_BAD_PTR 0x7007
53 #define ERR_BAD_FUNC_PTR 0x7008
54 #define ERR_BAD_SELECTOR 0x6009
55 #define ERR_BAD_STRING_PTR 0x700a
56 #define ERR_BAD_HANDLE 0x600b
58 /* KERNEL parameter errors */
59 #define ERR_BAD_HINSTANCE 0x6020
60 #define ERR_BAD_HMODULE 0x6021
61 #define ERR_BAD_GLOBAL_HANDLE 0x6022
62 #define ERR_BAD_LOCAL_HANDLE 0x6023
63 #define ERR_BAD_ATOM 0x6024
64 #define ERR_BAD_HFILE 0x6025
66 /* USER parameter errors */
67 #define ERR_BAD_HWND 0x6040
68 #define ERR_BAD_HMENU 0x6041
69 #define ERR_BAD_HCURSOR 0x6042
70 #define ERR_BAD_HICON 0x6043
71 #define ERR_BAD_HDWP 0x6044
72 #define ERR_BAD_CID 0x6045
73 #define ERR_BAD_HDRVR 0x6046
75 /* GDI parameter errors */
76 #define ERR_BAD_COORDS 0x7060
77 #define ERR_BAD_GDI_OBJECT 0x6061
78 #define ERR_BAD_HDC 0x6062
79 #define ERR_BAD_HPEN 0x6063
80 #define ERR_BAD_HFONT 0x6064
81 #define ERR_BAD_HBRUSH 0x6065
82 #define ERR_BAD_HBITMAP 0x6066
83 #define ERR_BAD_HRGN 0x6067
84 #define ERR_BAD_HPALETTE 0x6068
85 #define ERR_BAD_HMETAFILE 0x6069
88 /* LogError() values */
90 /* KERNEL errors */
91 #define ERR_GALLOC 0x0001
92 #define ERR_GREALLOC 0x0002
93 #define ERR_GLOCK 0x0003
94 #define ERR_LALLOC 0x0004
95 #define ERR_LREALLOC 0x0005
96 #define ERR_LLOCK 0x0006
97 #define ERR_ALLOCRES 0x0007
98 #define ERR_LOCKRES 0x0008
99 #define ERR_LOADMODULE 0x0009
101 /* USER errors */
102 #define ERR_CREATEDLG 0x0040
103 #define ERR_CREATEDLG2 0x0041
104 #define ERR_REGISTERCLASS 0x0042
105 #define ERR_DCBUSY 0x0043
106 #define ERR_CREATEWND 0x0044
107 #define ERR_STRUCEXTRA 0x0045
108 #define ERR_LOADSTR 0x0046
109 #define ERR_LOADMENU 0x0047
110 #define ERR_NESTEDBEGINPAINT 0x0048
111 #define ERR_BADINDEX 0x0049
112 #define ERR_CREATEMENU 0x004a
114 /* GDI errors */
115 #define ERR_CREATEDC 0x0080
116 #define ERR_CREATEMETA 0x0081
117 #define ERR_DELOBJSELECTED 0x0082
118 #define ERR_SELBITMAP 0x0083
121 #define ErrorString(manifest) { manifest, # manifest }
123 static const struct {
124 int constant;
125 const char *name;
126 } ErrorStrings[] = {
128 ErrorString(ERR_GALLOC),
129 ErrorString(ERR_GREALLOC),
130 ErrorString(ERR_GLOCK),
131 ErrorString(ERR_LALLOC),
132 ErrorString(ERR_LREALLOC),
133 ErrorString(ERR_LLOCK),
134 ErrorString(ERR_ALLOCRES),
135 ErrorString(ERR_LOCKRES),
136 ErrorString(ERR_LOADMODULE),
137 ErrorString(ERR_CREATEDLG),
138 ErrorString(ERR_CREATEDLG2),
139 ErrorString(ERR_REGISTERCLASS),
140 ErrorString(ERR_DCBUSY),
141 ErrorString(ERR_CREATEWND),
142 ErrorString(ERR_STRUCEXTRA),
143 ErrorString(ERR_LOADSTR),
144 ErrorString(ERR_LOADMENU),
145 ErrorString(ERR_NESTEDBEGINPAINT),
146 ErrorString(ERR_BADINDEX),
147 ErrorString(ERR_CREATEMENU),
148 ErrorString(ERR_CREATEDC),
149 ErrorString(ERR_CREATEMETA),
150 ErrorString(ERR_DELOBJSELECTED),
151 ErrorString(ERR_SELBITMAP)
154 static const struct {
155 int constant;
156 const char *name;
157 } ParamErrorStrings[] = {
159 ErrorString(ERR_BAD_VALUE),
160 ErrorString(ERR_BAD_FLAGS),
161 ErrorString(ERR_BAD_INDEX),
162 ErrorString(ERR_BAD_DVALUE),
163 ErrorString(ERR_BAD_DFLAGS),
164 ErrorString(ERR_BAD_DINDEX),
165 ErrorString(ERR_BAD_PTR),
166 ErrorString(ERR_BAD_FUNC_PTR),
167 ErrorString(ERR_BAD_SELECTOR),
168 ErrorString(ERR_BAD_STRING_PTR),
169 ErrorString(ERR_BAD_HANDLE),
170 ErrorString(ERR_BAD_HINSTANCE),
171 ErrorString(ERR_BAD_HMODULE),
172 ErrorString(ERR_BAD_GLOBAL_HANDLE),
173 ErrorString(ERR_BAD_LOCAL_HANDLE),
174 ErrorString(ERR_BAD_ATOM),
175 ErrorString(ERR_BAD_HFILE),
176 ErrorString(ERR_BAD_HWND),
177 ErrorString(ERR_BAD_HMENU),
178 ErrorString(ERR_BAD_HCURSOR),
179 ErrorString(ERR_BAD_HICON),
180 ErrorString(ERR_BAD_HDWP),
181 ErrorString(ERR_BAD_CID),
182 ErrorString(ERR_BAD_HDRVR),
183 ErrorString(ERR_BAD_COORDS),
184 ErrorString(ERR_BAD_GDI_OBJECT),
185 ErrorString(ERR_BAD_HDC),
186 ErrorString(ERR_BAD_HPEN),
187 ErrorString(ERR_BAD_HFONT),
188 ErrorString(ERR_BAD_HBRUSH),
189 ErrorString(ERR_BAD_HBITMAP),
190 ErrorString(ERR_BAD_HRGN),
191 ErrorString(ERR_BAD_HPALETTE),
192 ErrorString(ERR_BAD_HMETAFILE)
195 #undef ErrorString
197 /***********************************************************************
198 * GetErrorString (internal)
200 static const char *GetErrorString(UINT16 uErr)
202 static char buffer[80];
203 unsigned int n;
205 for (n = 0; n < ARRAY_SIZE(ErrorStrings); n++) {
206 if (uErr == ErrorStrings[n].constant)
207 return ErrorStrings[n].name;
210 sprintf(buffer, "%x", uErr);
211 return buffer;
215 /***********************************************************************
216 * GetParamErrorString (internal)
218 static const char *GetParamErrorString(UINT16 uErr) {
219 static char buffer[80];
221 if (uErr & ERR_WARNING) {
222 strcpy(buffer, "ERR_WARNING | ");
223 uErr &= ~ERR_WARNING;
224 } else
225 buffer[0] = '\0';
228 unsigned int n;
230 for (n = 0; n < ARRAY_SIZE(ParamErrorStrings); n++) {
231 if (uErr == ParamErrorStrings[n].constant) {
232 strcat(buffer, ParamErrorStrings[n].name);
233 return buffer;
238 sprintf(buffer + strlen(buffer), "%x", uErr);
239 return buffer;
243 /***********************************************************************
244 * SetLastError (KERNEL.147)
246 void WINAPI SetLastError16( DWORD error )
248 SetLastError( error );
252 /***********************************************************************
253 * GetLastError (KERNEL.148)
255 DWORD WINAPI GetLastError16(void)
257 return GetLastError();
261 /***********************************************************************
262 * LogError (KERNEL.324)
264 VOID WINAPI LogError16(UINT16 uErr, LPVOID lpvInfo)
266 MESSAGE("(%s, %p)\n", GetErrorString(uErr), lpvInfo);
270 /***********************************************************************
271 * LogParamError (KERNEL.325)
273 void WINAPI LogParamError16(UINT16 uErr, FARPROC16 lpfn, LPVOID lpvParam)
275 /* FIXME: is it possible to get the module name/function
276 * from the lpfn param?
278 MESSAGE("(%s, %p, %p)\n", GetParamErrorString(uErr), lpfn, lpvParam);
281 /***********************************************************************
282 * K327 (KERNEL.327)
284 void WINAPI HandleParamError( CONTEXT *context )
286 UINT16 uErr = LOWORD(context->Ebx);
287 FARPROC16 lpfn = (FARPROC16)MAKESEGPTR( context->SegCs, context->Eip );
288 LPVOID lpvParam = (LPVOID)MAKELONG( LOWORD(context->Eax), LOWORD(context->Ecx) );
290 LogParamError16( uErr, lpfn, lpvParam );
292 if (!(uErr & ERR_WARNING))
294 /* Abort current procedure: Unwind stack frame and jump
295 to error handler (location at [bp-2]) */
297 WORD *stack = MapSL( MAKESEGPTR( context->SegSs, LOWORD(context->Ebp) ));
298 context->Esp = LOWORD(context->Ebp) - 2;
299 context->Ebp = stack[0] & 0xfffe;
301 context->Eip = stack[-1];
303 context->Eax = context->Ecx = context->Edx = 0;
304 context->SegEs = 0;