4 * Copyright 1997 Andrew Taylor
13 #include "stackframe.h"
14 #include "debugtools.h"
16 #define ErrorString(manifest) { manifest, # manifest }
23 ErrorString(ERR_GALLOC),
24 ErrorString(ERR_GREALLOC),
25 ErrorString(ERR_GLOCK),
26 ErrorString(ERR_LALLOC),
27 ErrorString(ERR_LREALLOC),
28 ErrorString(ERR_LLOCK),
29 ErrorString(ERR_ALLOCRES),
30 ErrorString(ERR_LOCKRES),
31 ErrorString(ERR_LOADMODULE),
32 ErrorString(ERR_CREATEDLG),
33 ErrorString(ERR_CREATEDLG2),
34 ErrorString(ERR_REGISTERCLASS),
35 ErrorString(ERR_DCBUSY),
36 ErrorString(ERR_CREATEWND),
37 ErrorString(ERR_STRUCEXTRA),
38 ErrorString(ERR_LOADSTR),
39 ErrorString(ERR_LOADMENU),
40 ErrorString(ERR_NESTEDBEGINPAINT),
41 ErrorString(ERR_BADINDEX),
42 ErrorString(ERR_CREATEMENU),
43 ErrorString(ERR_CREATEDC),
44 ErrorString(ERR_CREATEMETA),
45 ErrorString(ERR_DELOBJSELECTED),
46 ErrorString(ERR_SELBITMAP)
52 } ParamErrorStrings[] = {
54 ErrorString(ERR_BAD_VALUE),
55 ErrorString(ERR_BAD_FLAGS),
56 ErrorString(ERR_BAD_INDEX),
57 ErrorString(ERR_BAD_DVALUE),
58 ErrorString(ERR_BAD_DFLAGS),
59 ErrorString(ERR_BAD_DINDEX),
60 ErrorString(ERR_BAD_PTR),
61 ErrorString(ERR_BAD_FUNC_PTR),
62 ErrorString(ERR_BAD_SELECTOR),
63 ErrorString(ERR_BAD_STRING_PTR),
64 ErrorString(ERR_BAD_HANDLE),
65 ErrorString(ERR_BAD_HINSTANCE),
66 ErrorString(ERR_BAD_HMODULE),
67 ErrorString(ERR_BAD_GLOBAL_HANDLE),
68 ErrorString(ERR_BAD_LOCAL_HANDLE),
69 ErrorString(ERR_BAD_ATOM),
70 ErrorString(ERR_BAD_HFILE),
71 ErrorString(ERR_BAD_HWND),
72 ErrorString(ERR_BAD_HMENU),
73 ErrorString(ERR_BAD_HCURSOR),
74 ErrorString(ERR_BAD_HICON),
75 ErrorString(ERR_BAD_HDWP),
76 ErrorString(ERR_BAD_CID),
77 ErrorString(ERR_BAD_HDRVR),
78 ErrorString(ERR_BAD_COORDS),
79 ErrorString(ERR_BAD_GDI_OBJECT),
80 ErrorString(ERR_BAD_HDC),
81 ErrorString(ERR_BAD_HPEN),
82 ErrorString(ERR_BAD_HFONT),
83 ErrorString(ERR_BAD_HBRUSH),
84 ErrorString(ERR_BAD_HBITMAP),
85 ErrorString(ERR_BAD_HRGN),
86 ErrorString(ERR_BAD_HPALETTE),
87 ErrorString(ERR_BAD_HMETAFILE)
91 #define ErrorStringCount (sizeof(ErrorStrings) / sizeof(ErrorStrings[0]))
92 #define ParamErrorStringCount (sizeof(ParamErrorStrings) / sizeof(ParamErrorStrings[0]))
94 /***********************************************************************
95 * GetErrorString (internal)
97 static const char *GetErrorString(UINT16 uErr)
99 static char buffer[80];
102 for (i = 0; i < ErrorStringCount; i++) {
103 if (uErr == ErrorStrings[i].constant)
104 return ErrorStrings[i].name;
107 sprintf(buffer, "%x", uErr);
112 /***********************************************************************
113 * GetParamErrorString (internal)
115 static const char *GetParamErrorString(UINT16 uErr) {
116 static char buffer[80];
118 if (uErr & ERR_WARNING) {
119 strcpy(buffer, "ERR_WARNING | ");
120 uErr &= ~ERR_WARNING;
127 for (i = 0; i < ParamErrorStringCount; i++) {
128 if (uErr == ParamErrorStrings[i].constant) {
129 strcat(buffer, ParamErrorStrings[i].name);
135 sprintf(buffer + strlen(buffer), "%x", uErr);
140 /***********************************************************************
141 * LogError (KERNEL.324)
143 VOID WINAPI LogError16(UINT16 uErr, LPVOID lpvInfo)
145 MESSAGE("(%s, %p)\n", GetErrorString(uErr), lpvInfo);
149 /***********************************************************************
150 * LogParamError (KERNEL.325)
152 void WINAPI LogParamError16(UINT16 uErr, FARPROC16 lpfn, LPVOID lpvParam)
154 /* FIXME: is it possible to get the module name/function
155 * from the lpfn param?
157 MESSAGE("(%s, %p, %p)\n", GetParamErrorString(uErr), lpfn, lpvParam);
160 /***********************************************************************
161 * HandleParamError (KERNEL.327)
163 void WINAPI HandleParamError( CONTEXT86 *context )
165 UINT16 uErr = BX_reg( context );
166 FARPROC16 lpfn = (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( CS_reg(context),
168 LPVOID lpvParam = (LPVOID)MAKELONG( AX_reg( context ),
171 LogParamError16( uErr, lpfn, lpvParam );
173 if (!(uErr & ERR_WARNING))
175 /* Abort current procedure: Unwind stack frame and jump
176 to error handler (location at [bp-2]) */
178 WORD *stack = PTR_SEG_OFF_TO_LIN( SS_reg( context ),
179 LOWORD(EBP_reg( context )) );
180 ESP_reg( context ) = LOWORD(EBP_reg( context )) - 2;
181 EBP_reg( context ) = stack[0] & 0xfffe;
183 EIP_reg( context ) = stack[-1];
185 EAX_reg( context ) = ECX_reg( context ) = EDX_reg( context ) = 0;
186 ES_reg( context) = 0;