source: trunk/src/kernel32/exceptutil.asm@ 9442

Last change on this file since 9442 was 9442, checked in by sandervl, 23 years ago

update

File size: 7.7 KB
Line 
1; $Id: exceptutil.asm,v 1.21 2002-11-29 09:30:55 sandervl Exp $
2
3;/*
4; * Project Odin Software License can be found in LICENSE.TXT
5; * Win32 Exception handling + misc functions for OS/2
6; *
7; * Copyright 1998 Sander van Leeuwen
8; *
9; */
10.386p
11 NAME except
12
13DATA32 segment dword use32 public 'DATA'
14DATA32 ends
15CONST32_RO segment dword use32 public 'CONST'
16CONST32_RO ends
17BSS32 segment dword use32 public 'BSS'
18BSS32 ends
19DGROUP group BSS32, DATA32
20 assume cs:FLAT, ds:FLAT, ss:FLAT, es:FLAT
21
22DATA32 segment dword use32 public 'DATA'
23
24CONST32_RO segment
25 align 04h
26@CBE8 db "KERNEL32: Calling handle"
27db "r at %p code=%lx flags=%"
28db "lx",0ah,0h
29@CBE9 db "KERNEL32: Handler return"
30db "ed %lx",0ah,0h
31CONST32_RO ends
32DATA32 ends
33
34CODE32 SEGMENT DWORD PUBLIC USE32 'CODE'
35 public _RaiseException@16
36 extrn OS2RAISEEXCEPTION : near
37
38_RaiseException@16 proc near
39 push dword ptr [esp+4] ;DWORD dwExceptionCode
40 push dword ptr [esp+12] ;DWORD dwExceptionFlags
41 push dword ptr [esp+20] ;DWORD cArguments
42 push dword ptr [esp+28] ;DWORD *lpArguments
43 push dword ptr [esp+16] ;return address
44 push esp
45 add dword ptr [esp], 20
46 push ebp
47 pushfd
48 push eax
49 push ebx
50 push ecx
51 push edx
52 push edi
53 push esi
54 xor eax, eax
55 mov eax, cs
56 push eax
57 mov eax, ds
58 push eax
59 mov eax, es
60 push eax
61 mov eax, fs
62 push eax
63 mov eax, gs
64 push eax
65 mov eax, ss
66 push eax
67 call OS2RAISEEXCEPTION
68
69 ret 16 ;__stdcall
70_RaiseException@16 endp
71
72 public _RtlUnwind@16
73 extrn OS2RTLUNWIND : near
74
75_RtlUnwind@16 proc near
76 push dword ptr [esp+4] ;PWINEXCEPTION_FRAME pEndFrame
77 push dword ptr [esp+12] ;LPVOID unusedEip
78 push dword ptr [esp+20] ;PWINEXCEPTION_RECORD pRecord
79 push dword ptr [esp+28] ;DWORD returnEax
80 push dword ptr [esp+16] ;return address
81 push esp
82 add dword ptr [esp], 20
83 push ebp
84 pushfd
85 push eax
86 push ebx
87 push ecx
88 push edx
89 push edi
90 push esi
91 xor eax, eax
92 mov eax, cs
93 push eax
94 mov eax, ds
95 push eax
96 mov eax, es
97 push eax
98 mov eax, fs
99 push eax
100 mov eax, gs
101 push eax
102 mov eax, ss
103 push eax
104 call OS2RTLUNWIND
105
106 ret 16 ;__stdcall
107_RtlUnwind@16 endp
108
109
110 PUBLIC QueryExceptionChain
111
112QueryExceptionChain proc near
113 mov eax, fs:[0]
114 ret
115QueryExceptionChain endp
116
117 PUBLIC GetExceptionRecord
118GetExceptionRecord proc near
119 push ebp
120 mov ebp, esp
121 push fs
122 push ebx
123
124 mov eax, [ebp+8]
125 mov fs, eax
126 mov ebx, [ebp+12]
127 mov eax, fs:[ebx]
128
129 pop ebx
130 pop fs
131 pop ebp
132 ret
133GetExceptionRecord endp
134
135 PUBLIC ChangeTIBStack
136ChangeTIBStack proc near
137; xor eax, eax
138 push ebx
139 mov eax, fs:[4]
140 mov ebx, fs:[8]
141 add ebx, 8
142 mov fs:[4], ebx
143 mov fs:[8], eax
144 pop ebx
145 ret
146ChangeTIBStack endp
147
148 PUBLIC _SetExceptionChain
149
150_SetExceptionChain proc near
151 mov eax, dword ptr [esp+4]
152 mov fs:[0], eax
153 ret
154_SetExceptionChain endp
155
156
157 PUBLIC _AsmCallThreadHandler
158_AsmCallThreadHandler proc near
159 push ebp
160 mov ebp, esp
161
162 push dword ptr [ebp+12]
163 mov eax, dword ptr [ebp+8]
164 call eax
165
166 mov esp, ebp
167 pop ebp
168 ret
169_AsmCallThreadHandler endp
170
171 PUBLIC _CallEntryPoint
172_CallEntryPoint proc near
173 push ebp
174 mov ebp, esp
175
176;We're asking for problems if our stack start near a 64kb boundary
177;Some OS/2 thunking procedures can choke on misaligned stack addresses
178 mov eax, esp
179 and eax, 0FFFFh
180 cmp eax, 0E000h
181 jge @goodstack
182
183 add eax, 1000h
184 sub esp, eax
185@goodstack:
186
187 mov eax, esp
188 sub eax, 16
189 and eax, 0FFFFFFF0h
190 add eax, 4
191 mov esp, eax
192
193 push dword ptr [ebp+12]
194 mov eax, dword ptr [ebp+8]
195 call eax
196
197 mov esp, ebp
198 pop ebp
199 ret
200_CallEntryPoint endp
201
202
203; 281 static DWORD EXC_CallHandler( WINEXCEPTION_RECORD *record, WINEXCEPTION_FRAME *frame,
204 EXTRN WriteLog:PROC
205 EXTRN _GetThreadTEB@0:PROC
206IFDEF DEBUG
207 EXTRN DbgEnabledKERNEL32:DWORD
208ENDIF
209
210EXC_push_frame__FP19_WINEXCEPTION_FRAME proc
211 push ebp
212 mov ebp,esp
213 sub esp,04h
214 mov [ebp+08h],eax; frame
215
216; 132 TEB *teb = GetThreadTEB();
217 call _GetThreadTEB@0
218 mov [ebp-04h],eax; teb
219
220; 133 frame->Prev = (PWINEXCEPTION_FRAME)teb->except;
221 mov ecx,[ebp-04h]; teb
222 mov ecx,[ecx]
223 mov eax,[ebp+08h]; frame
224 mov [eax],ecx
225
226; 134 teb->except = frame;
227 mov eax,[ebp-04h]; teb
228 mov ecx,[ebp+08h]; frame
229 mov [eax],ecx
230
231; 135 return frame->Prev;
232 mov eax,[ebp+08h]; frame
233 mov eax,[eax]
234 leave
235 ret
236EXC_push_frame__FP19_WINEXCEPTION_FRAME endp
237
238; 138 static inline WINEXCEPTION_FRAME * EXC_pop_frame( WINEXCEPTION_FRAME *frame )
239 align 04h
240
241EXC_pop_frame__FP19_WINEXCEPTION_FRAME proc
242 push ebp
243 mov ebp,esp
244 sub esp,04h
245 mov [ebp+08h],eax; frame
246
247; 141 TEB *teb = GetThreadTEB();
248 call _GetThreadTEB@0
249 mov [ebp-04h],eax; teb
250
251; 142 teb->except = frame->Prev;
252 mov ecx,[ebp+08h]; frame
253 mov ecx,[ecx]
254 mov eax,[ebp-04h]; teb
255 mov [eax],ecx
256
257; 143 return frame->Prev;
258 mov eax,[ebp+08h]; frame
259 mov eax,[eax]
260 leave
261 ret
262EXC_pop_frame__FP19_WINEXCEPTION_FRAME endp
263
264 align 04h
265 PUBLIC EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5
266
267EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 proc
268 push ebp
269 mov ebp,esp
270 sub esp,010h
271 sub esp,04h
272 mov [ebp+08h],eax; record
273 mov [ebp+0ch],edx; frame
274 mov [ebp+010h],ecx; context
275
276; 296 newframe.frame.Handler = nested_handler;
277 mov eax,[ebp+01ch]; nested_handler
278 mov [ebp-08h],eax; newframe
279
280; 297 newframe.prevFrame = frame;
281 mov eax,[ebp+0ch]; frame
282 mov [ebp-04h],eax; newframe
283
284; 298 EXC_push_frame( &newframe.frame );
285 lea eax,[ebp-0ch]; newframe
286 call EXC_push_frame__FP19_WINEXCEPTION_FRAME
287
288; 299 dprintf(("KERNEL32: Calling handler at %p code=%lx flags=%lx\n",
289IFDEF DEBUG
290 cmp word ptr DbgEnabledKERNEL32+020h,01h
291 jne @BLBL20
292 mov eax,[ebp+08h]; record
293 push dword ptr [eax+04h]
294 mov eax,[ebp+08h]; record
295 push dword ptr [eax]
296 push dword ptr [ebp+018h]; handler
297 push offset FLAT:@CBE8
298 call WriteLog
299 add esp,010h
300ENDIF
301
302; 300 handler, record->ExceptionCode, record->ExceptionFlags));
303@BLBL20:
304
305; 301 ret = handler( record, frame, context, dispatcher );
306 push dword ptr [ebp+014h]; dispatcher
307 push dword ptr [ebp+010h]; context
308 push dword ptr [ebp+0ch]; frame
309 push dword ptr [ebp+08h]; record
310 call dword ptr [ebp+018h]; handler
311 mov [ebp-010h],eax; ret
312
313IFDEF DEBUG
314; 302 dprintf(("KERNEL32: Handler returned %lx\n", ret));
315 cmp word ptr DbgEnabledKERNEL32+020h,01h
316 jne @BLBL21
317 push dword ptr [ebp-010h]; ret
318 push offset FLAT:@CBE9
319 call WriteLog
320 add esp,08h
321@BLBL21:
322ENDIF
323
324; 303 EXC_pop_frame( &newframe.frame );
325 lea eax,[ebp-0ch]; newframe
326 call EXC_pop_frame__FP19_WINEXCEPTION_FRAME
327
328; 304 return ret;
329 mov eax,[ebp-010h]; ret
330 add esp,04h
331 leave
332 ret
333EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 endp
334
335CODE32 ENDS
336
337 END
Note: See TracBrowser for help on using the repository browser.