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

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

Exception handling changes

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