blob: fba7762f5205c643cbd03064e32058241863030f [file] [log] [blame]
Alexandre Julliard23946ad1997-06-16 17:43:53 +00001/*
2 * Log internal errors
3 *
4 * Copyright 1997 Andrew Taylor
5 */
6
Alexandre Julliard23946ad1997-06-16 17:43:53 +00007#include <stdlib.h>
Alexandre Julliard383da682000-02-10 22:15:21 +00008#include <stdio.h>
Alexandre Julliard23946ad1997-06-16 17:43:53 +00009#include <string.h>
10
Patrik Stridvall6cc47d42000-03-08 18:26:56 +000011#include "winbase.h"
Jim Aston2e1cafa1999-03-14 16:35:05 +000012#include "windef.h"
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000013#include "stackframe.h"
Alexandre Julliard61fece01999-06-26 19:09:08 +000014#include "debugtools.h"
Alexandre Julliard23946ad1997-06-16 17:43:53 +000015
Alexandre Julliard23946ad1997-06-16 17:43:53 +000016#define ErrorString(manifest) { manifest, # manifest }
17
Alexandre Julliarda11d7b11998-03-01 20:05:02 +000018static const struct {
Alexandre Julliard23946ad1997-06-16 17:43:53 +000019 int constant;
20 const char *name;
21} ErrorStrings[] = {
22
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)
47};
48
Alexandre Julliarda11d7b11998-03-01 20:05:02 +000049static const struct {
Alexandre Julliard23946ad1997-06-16 17:43:53 +000050 int constant;
51 const char *name;
52} ParamErrorStrings[] = {
53
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)
88};
89
Alexandre Julliarda11d7b11998-03-01 20:05:02 +000090#undef ErrorString
91#define ErrorStringCount (sizeof(ErrorStrings) / sizeof(ErrorStrings[0]))
Alexandre Julliard23946ad1997-06-16 17:43:53 +000092#define ParamErrorStringCount (sizeof(ParamErrorStrings) / sizeof(ParamErrorStrings[0]))
93
Alexandre Julliard23946ad1997-06-16 17:43:53 +000094/***********************************************************************
95* GetErrorString (internal)
96*/
Alexandre Julliarda11d7b11998-03-01 20:05:02 +000097static const char *GetErrorString(UINT16 uErr)
98{
99 static char buffer[80];
Alexandre Julliard908464d2000-11-01 03:11:12 +0000100 unsigned int n;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000101
Alexandre Julliard908464d2000-11-01 03:11:12 +0000102 for (n = 0; n < ErrorStringCount; n++) {
103 if (uErr == ErrorStrings[n].constant)
104 return ErrorStrings[n].name;
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000105 }
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000106
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000107 sprintf(buffer, "%x", uErr);
108 return buffer;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000109}
110
111
112/***********************************************************************
113* GetParamErrorString (internal)
114*/
115static const char *GetParamErrorString(UINT16 uErr) {
116 static char buffer[80];
117
118 if (uErr & ERR_WARNING) {
119 strcpy(buffer, "ERR_WARNING | ");
120 uErr &= ~ERR_WARNING;
121 } else
122 buffer[0] = '\0';
123
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000124 {
Alexandre Julliard908464d2000-11-01 03:11:12 +0000125 unsigned int n;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000126
Alexandre Julliard908464d2000-11-01 03:11:12 +0000127 for (n = 0; n < ParamErrorStringCount; n++) {
128 if (uErr == ParamErrorStrings[n].constant) {
129 strcat(buffer, ParamErrorStrings[n].name);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000130 return buffer;
131 }
132 }
133 }
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000134
135 sprintf(buffer + strlen(buffer), "%x", uErr);
136 return buffer;
137}
138
139
140/***********************************************************************
141* LogError (KERNEL.324)
142*/
Alexandre Julliarda3960291999-02-26 11:11:13 +0000143VOID WINAPI LogError16(UINT16 uErr, LPVOID lpvInfo)
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000144{
Alexandre Julliard61fece01999-06-26 19:09:08 +0000145 MESSAGE("(%s, %p)\n", GetErrorString(uErr), lpvInfo);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000146}
147
148
149/***********************************************************************
150* LogParamError (KERNEL.325)
151*/
Alexandre Julliarda3960291999-02-26 11:11:13 +0000152void WINAPI LogParamError16(UINT16 uErr, FARPROC16 lpfn, LPVOID lpvParam)
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000153{
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000154 /* FIXME: is it possible to get the module name/function
155 * from the lpfn param?
156 */
Alexandre Julliard61fece01999-06-26 19:09:08 +0000157 MESSAGE("(%s, %p, %p)\n", GetParamErrorString(uErr), lpfn, lpvParam);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000158}
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000159
160/***********************************************************************
Ulrich Weigand82944511998-12-01 16:23:19 +0000161* HandleParamError (KERNEL.327)
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000162*/
Alexandre Julliard617955d1999-06-26 18:40:24 +0000163void WINAPI HandleParamError( CONTEXT86 *context )
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000164{
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000165 UINT16 uErr = LOWORD(context->Ebx);
Alexandre Julliard982a2232000-12-13 20:20:09 +0000166 FARPROC16 lpfn = (FARPROC16)MAKESEGPTR( context->SegCs, context->Eip );
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000167 LPVOID lpvParam = (LPVOID)MAKELONG( LOWORD(context->Eax), LOWORD(context->Ecx) );
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000168
Alexandre Julliarda3960291999-02-26 11:11:13 +0000169 LogParamError16( uErr, lpfn, lpvParam );
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000170
171 if (!(uErr & ERR_WARNING))
172 {
173 /* Abort current procedure: Unwind stack frame and jump
174 to error handler (location at [bp-2]) */
175
Alexandre Julliard982a2232000-12-13 20:20:09 +0000176 WORD *stack = MapSL( MAKESEGPTR( context->SegSs, LOWORD(context->Ebp) ));
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000177 context->Esp = LOWORD(context->Ebp) - 2;
178 context->Ebp = stack[0] & 0xfffe;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000179
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000180 context->Eip = stack[-1];
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000181
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000182 context->Eax = context->Ecx = context->Edx = 0;
183 context->SegEs = 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000184 }
185}
186