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 (n
= 0; n
< ErrorStringCount
; n
++) {
103 if (uErr
== ErrorStrings
[n
].constant
)
104 return ErrorStrings
[n
].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 (n
= 0; n
< ParamErrorStringCount
; n
++) {
128 if (uErr
== ParamErrorStrings
[n
].constant
) {
129 strcat(buffer
, ParamErrorStrings
[n
].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 /***********************************************************************
163 void WINAPI
HandleParamError( CONTEXT86
*context
)
165 UINT16 uErr
= LOWORD(context
->Ebx
);
166 FARPROC16 lpfn
= (FARPROC16
)MAKESEGPTR( context
->SegCs
, context
->Eip
);
167 LPVOID lpvParam
= (LPVOID
)MAKELONG( LOWORD(context
->Eax
), LOWORD(context
->Ecx
) );
169 LogParamError16( 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
= MapSL( MAKESEGPTR( context
->SegSs
, LOWORD(context
->Ebp
) ));
177 context
->Esp
= LOWORD(context
->Ebp
) - 2;
178 context
->Ebp
= stack
[0] & 0xfffe;
180 context
->Eip
= stack
[-1];
182 context
->Eax
= context
->Ecx
= context
->Edx
= 0;