source: trunk/src/kernel32/oslibexcept.cpp@ 2803

Last change on this file since 2803 was 2803, checked in by sandervl, 26 years ago

Added new logging feature

File size: 9.6 KB
Line 
1/* $Id: oslibexcept.cpp,v 1.2 2000-02-16 14:25:45 sandervl Exp $ */
2/*
3 * Exception handler util. procedures
4 *
5 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 *
7 */
8#define INCL_BASE
9#define INCL_DOSEXCEPTIONS
10#define INCL_DOSMEMMGR
11#define INCL_DOSPROCESS
12#include <os2wrap.h> //Odin32 OS/2 api wrappers
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <win32type.h>
17#include <misc.h>
18#include "oslibexcept.h"
19#include <exceptions.h>
20
21#define DBG_LOCALLOG DBG_oslibexcept
22#include "dbglocal.h"
23
24//******************************************************************************
25//Dispatches OS/2 exception to win32 handler
26//Returns: TRUE, win32 exception handler returned continue execution
27// FALSE, otherwise
28//******************************************************************************
29BOOL OSLibDispatchException(PEXCEPTIONREPORTRECORD pReportRec,
30 PEXCEPTIONREGISTRATIONRECORD pRegistrationRec,
31 PCONTEXTRECORD pContextRec, PVOID p)
32{
33 WINEXCEPTION_RECORD winreportrec;
34 WINCONTEXT wincontextrec;
35 ULONG rc;
36
37 memset(&winreportrec, 0, sizeof(winreportrec));
38 memcpy(&winreportrec, pReportRec, sizeof(*pReportRec));
39
40 switch(pReportRec->ExceptionNum) {
41 case XCPT_FLOAT_DENORMAL_OPERAND:
42 winreportrec.ExceptionCode = EXCEPTION_FLT_DENORMAL_OPERAND;
43 break;
44 case XCPT_FLOAT_DIVIDE_BY_ZERO:
45 winreportrec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
46 break;
47 case XCPT_FLOAT_INEXACT_RESULT:
48 winreportrec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
49 break;
50 case XCPT_FLOAT_INVALID_OPERATION:
51 winreportrec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
52 break;
53 case XCPT_FLOAT_OVERFLOW:
54 winreportrec.ExceptionCode = EXCEPTION_FLT_OVERFLOW;
55 break;
56 case XCPT_FLOAT_STACK_CHECK:
57 winreportrec.ExceptionCode = EXCEPTION_FLT_STACK_CHECK;
58 break;
59 case XCPT_FLOAT_UNDERFLOW:
60 winreportrec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
61 break;
62 case XCPT_INTEGER_DIVIDE_BY_ZERO:
63 winreportrec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
64 break;
65 case XCPT_INTEGER_OVERFLOW:
66 winreportrec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
67 break;
68 case XCPT_PRIVILEGED_INSTRUCTION:
69 winreportrec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
70 break;
71 case XCPT_BREAKPOINT:
72 winreportrec.ExceptionCode = EXCEPTION_BREAKPOINT;
73 break;
74 case XCPT_SINGLE_STEP:
75 winreportrec.ExceptionCode = EXCEPTION_SINGLE_STEP;
76 break;
77 case XCPT_ARRAY_BOUNDS_EXCEEDED:
78 winreportrec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
79 break;
80 case XCPT_DATATYPE_MISALIGNMENT:
81 winreportrec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
82 break;
83 case XCPT_ILLEGAL_INSTRUCTION:
84 winreportrec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
85 break;
86 case XCPT_INVALID_LOCK_SEQUENCE:
87 winreportrec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
88 break;
89 case XCPT_GUARD_PAGE_VIOLATION:
90 winreportrec.ExceptionCode = EXCEPTION_GUARD_PAGE;
91 break;
92 case XCPT_UNABLE_TO_GROW_STACK:
93 winreportrec.ExceptionCode = EXCEPTION_STACK_OVERFLOW;
94 break;
95 case XCPT_IN_PAGE_ERROR:
96 winreportrec.ExceptionCode = EXCEPTION_IN_PAGE_ERROR;
97 break;
98 case XCPT_ACCESS_VIOLATION:
99 winreportrec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
100 break;
101 default: //no other exceptions should be dispatched to win32 apps
102 return FALSE;
103 }
104 //TODO:
105 //According to the Wine folks the flags are the same in OS/2 and win32
106 //Let's assume for now the rest is identical as well
107
108 //copy context record info
109 memset(&wincontextrec, 0, sizeof(wincontextrec));
110 if(pContextRec->ContextFlags & CONTEXT_CONTROL) {
111 wincontextrec.ContextFlags |= WINCONTEXT_CONTROL;
112 wincontextrec.Ebp = pContextRec->ctx_RegEbp;
113 wincontextrec.Eip = pContextRec->ctx_RegEip;
114 wincontextrec.SegCs = pContextRec->ctx_SegCs;
115 wincontextrec.EFlags = pContextRec->ctx_EFlags;
116 wincontextrec.Esp = pContextRec->ctx_RegEsp;
117 wincontextrec.SegSs = pContextRec->ctx_SegSs;
118 }
119 if(pContextRec->ContextFlags & CONTEXT_INTEGER) {
120 wincontextrec.ContextFlags |= WINCONTEXT_INTEGER;
121 wincontextrec.Edi = pContextRec->ctx_RegEdi;
122 wincontextrec.Esi = pContextRec->ctx_RegEsi;
123 wincontextrec.Ebx = pContextRec->ctx_RegEbx;
124 wincontextrec.Edx = pContextRec->ctx_RegEdx;
125 wincontextrec.Ecx = pContextRec->ctx_RegEcx;
126 wincontextrec.Eax = pContextRec->ctx_RegEax;
127 }
128 if(pContextRec->ContextFlags & CONTEXT_SEGMENTS) {
129 wincontextrec.ContextFlags |= WINCONTEXT_SEGMENTS;
130 wincontextrec.SegGs = pContextRec->ctx_SegGs;
131 wincontextrec.SegFs = pContextRec->ctx_SegFs;
132 wincontextrec.SegEs = pContextRec->ctx_SegEs;
133 wincontextrec.SegDs = pContextRec->ctx_SegDs;
134 }
135 if(pContextRec->ContextFlags & CONTEXT_FLOATING_POINT) {
136 wincontextrec.ContextFlags |= WINCONTEXT_FLOATING_POINT;
137 //TODO: First 7 dwords the same?
138 memcpy(&wincontextrec.FloatSave, pContextRec->ctx_env, sizeof(pContextRec->ctx_env));
139 memcpy(&wincontextrec.FloatSave.RegisterArea, pContextRec->ctx_stack, sizeof(pContextRec->ctx_stack));
140 }
141 //It doesn't seem correct if we dispatch real exceptions to win32 apps
142 //Some just call RtlUnwind and continue as if they were processing an
143 //exception thrown by C++ code. (instead of real OS exception)
144#if 0
145 switch(pReportRec->ExceptionNum) {
146 case XCPT_FLOAT_DENORMAL_OPERAND:
147 case XCPT_FLOAT_DIVIDE_BY_ZERO:
148 case XCPT_FLOAT_INEXACT_RESULT:
149 case XCPT_FLOAT_INVALID_OPERATION:
150 case XCPT_FLOAT_OVERFLOW:
151 case XCPT_FLOAT_STACK_CHECK:
152 case XCPT_FLOAT_UNDERFLOW:
153 rc = RtlDispatchException(&winreportrec, &wincontextrec);
154 break;
155
156 case XCPT_ACCESS_VIOLATION:
157 rc = RtlDispatchException(&winreportrec, &wincontextrec);
158 break;
159
160 case XCPT_INTEGER_DIVIDE_BY_ZERO:
161 case XCPT_INTEGER_OVERFLOW:
162 case XCPT_PRIVILEGED_INSTRUCTION:
163 case XCPT_BREAKPOINT:
164 case XCPT_SINGLE_STEP:
165 case XCPT_ARRAY_BOUNDS_EXCEEDED:
166 case XCPT_DATATYPE_MISALIGNMENT:
167 case XCPT_ILLEGAL_INSTRUCTION:
168 case XCPT_INVALID_LOCK_SEQUENCE:
169 case XCPT_GUARD_PAGE_VIOLATION:
170 case XCPT_UNABLE_TO_GROW_STACK:
171 case XCPT_IN_PAGE_ERROR:
172 return FALSE; //let's no dispatch those for now
173 }
174
175 if(rc == ExceptionContinueExecution) {
176 dprintf(("Win32 exception handler returned ExceptionContinueExecution"));
177 if(wincontextrec.ContextFlags & WINCONTEXT_CONTROL) {
178 pContextRec->ctx_RegEbp = wincontextrec.Ebp;
179 pContextRec->ctx_RegEip = wincontextrec.Eip;
180 pContextRec->ctx_SegCs = wincontextrec.SegCs;
181 pContextRec->ctx_EFlags = wincontextrec.EFlags;
182 pContextRec->ctx_RegEsp = wincontextrec.Esp;
183 pContextRec->ctx_SegSs = wincontextrec.SegSs;
184 }
185 if(wincontextrec.ContextFlags & WINCONTEXT_INTEGER) {
186 pContextRec->ctx_RegEdi = wincontextrec.Edi;
187 pContextRec->ctx_RegEsi = wincontextrec.Esi;
188 pContextRec->ctx_RegEbx = wincontextrec.Ebx;
189 pContextRec->ctx_RegEdx = wincontextrec.Edx;
190 pContextRec->ctx_RegEcx = wincontextrec.Ecx;
191 pContextRec->ctx_RegEax = wincontextrec.Eax;
192 }
193#if 0
194 //This is not a good idea
195 if(wincontextrec.ContextFlags & WINCONTEXT_SEGMENTS) {
196 pContextRec->ctx_SegGs = wincontextrec.SegGs;
197 pContextRec->ctx_SegFs = wincontextrec.SegFs;
198 pContextRec->ctx_SegEs = wincontextrec.SegEs;
199 pContextRec->ctx_SegDs = wincontextrec.SegDs;
200 }
201#endif
202 if(wincontextrec.ContextFlags & WINCONTEXT_FLOATING_POINT) {
203 //TODO: First 7 dwords the same?
204 memcpy(pContextRec->ctx_env, &wincontextrec.FloatSave, sizeof(pContextRec->ctx_env));
205 memcpy(pContextRec->ctx_stack, &wincontextrec.FloatSave.RegisterArea, sizeof(pContextRec->ctx_stack));
206 }
207 if (pContextRec->ContextFlags & CONTEXT_CONTROL) /* check flags */
208 dprintf((" SS:ESP=%04x:%08x EFLAGS=%08x\n"
209 " CS:EIP=%04x:%08x EBP =%08x\n",
210 pContextRec->ctx_SegSs,
211 pContextRec->ctx_RegEsp,
212 pContextRec->ctx_EFlags,
213 pContextRec->ctx_SegCs,
214 pContextRec->ctx_RegEip,
215 pContextRec->ctx_RegEbp));
216
217 if (pContextRec->ContextFlags & CONTEXT_INTEGER) /* check flags */
218 dprintf((" EAX=%08x EBX=%08x ESI=%08x\n"
219 " ECX=%08x EDX=%08x EDI=%08x\n",
220 pContextRec->ctx_RegEax,
221 pContextRec->ctx_RegEbx,
222 pContextRec->ctx_RegEsi,
223 pContextRec->ctx_RegEcx,
224 pContextRec->ctx_RegEdx,
225 pContextRec->ctx_RegEdi));
226
227 if (pContextRec->ContextFlags & CONTEXT_SEGMENTS) /* check flags */
228 dprintf((" DS=%04x ES=%08x"
229 " FS=%04x GS=%04x\n",
230 pContextRec->ctx_SegDs,
231 pContextRec->ctx_SegEs,
232 pContextRec->ctx_SegFs,
233 pContextRec->ctx_SegGs));
234
235 if (pContextRec->ContextFlags & CONTEXT_FLOATING_POINT) /* check flags */
236 {
237 ULONG ulCounter; /* temporary local counter for fp stack */
238
239 dprintf((" Env[0]=%08x Env[1]=%08x Env[2]=%08x Env[3]=%08x\n",
240 pContextRec->ctx_env[0],
241 pContextRec->ctx_env[1],
242 pContextRec->ctx_env[2],
243 pContextRec->ctx_env[3]));
244
245 dprintf((" Env[4]=%08x Env[5]=%08x Env[6]=%08x\n",
246 pContextRec->ctx_env[4],
247 pContextRec->ctx_env[5],
248 pContextRec->ctx_env[6]));
249
250 for (ulCounter = 0;
251 ulCounter < 8; /* see TOOLKIT\INCLUDE\BSEEXPT.H, _CONTEXT structure */
252 ulCounter ++)
253 dprintf((" FP-Stack[%u] losig=%08x hisig=%08x signexp=%04x\n",
254 ulCounter,
255 pContextRec->ctx_stack[0].losig,
256 pContextRec->ctx_stack[0].hisig,
257 pContextRec->ctx_stack[0].signexp));
258 }
259
260 return TRUE;
261 }
262 dprintf(("Win32 exception handler returned %x", rc));
263#endif
264 return FALSE;
265}
266//******************************************************************************
267//******************************************************************************
Note: See TracBrowser for help on using the repository browser.