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

Last change on this file since 5557 was 5557, checked in by sandervl, 24 years ago

rewrote EXC_CallHandler in assembly + workaround for high addresses in stdout WriteFile

File size: 9.0 KB
Line 
1; $Id: exceptutil.asm,v 1.15 2001-04-21 09:10:14 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
19EH_CODE segment dword use32 public 'CODE'
20EH_CODE ends
21CTOR_DTOR1 segment dword use32 public 'DATA'
22CTOR_DTOR1 ends
23CTOR_DTOR2 segment dword use32 public 'DATA'
24CTOR_DTOR2 ends
25CTOR_DTOR3 segment dword use32 public 'DATA'
26CTOR_DTOR3 ends
27EH_DATA segment para use32 public 'DATA'
28EH_DATA ends
29_VFT segment para use32 public 'DATA'
30_VFT ends
31DGROUP group BSS32, DATA32
32 assume cs:FLAT, ds:FLAT, ss:FLAT, es:FLAT
33
34DATA32 segment dword use32 public 'DATA'
35
36CONST32_RO segment
37 align 04h
38@CBE8 db "KERNEL32: Calling handle"
39db "r at %p code=%lx flags=%"
40db "lx",0ah,0h
41@CBE9 db "KERNEL32: Handler return"
42db "ed %lx",0ah,0h
43CONST32_RO ends
44DATA32 ends
45
46CODE32 SEGMENT DWORD PUBLIC USE32 'CODE'
47 public _RaiseException@16
48 extrn OS2RAISEEXCEPTION : near
49
50_RaiseException@16 proc near
51 push dword ptr [esp+4] ;DWORD dwExceptionCode
52 push dword ptr [esp+12] ;DWORD dwExceptionFlags
53 push dword ptr [esp+20] ;DWORD cArguments
54 push dword ptr [esp+28] ;DWORD *lpArguments
55 push dword ptr [esp+16] ;return address
56 push esp
57 add dword ptr [esp], 20
58 push ebp
59 pushfd
60 push eax
61 push ebx
62 push ecx
63 push edx
64 push edi
65 push esi
66 xor eax, eax
67 mov eax, cs
68 push eax
69 mov eax, ds
70 push eax
71 mov eax, es
72 push eax
73 mov eax, fs
74 push eax
75 mov eax, gs
76 push eax
77 mov eax, ss
78 push eax
79 call OS2RAISEEXCEPTION
80
81 ret 16 ;__stdcall
82_RaiseException@16 endp
83
84 public _RtlUnwind@16
85 extrn OS2RTLUNWIND : near
86
87_RtlUnwind@16 proc near
88 push dword ptr [esp+4] ;PWINEXCEPTION_FRAME pEndFrame
89 push dword ptr [esp+12] ;LPVOID unusedEip
90 push dword ptr [esp+20] ;PWINEXCEPTION_RECORD pRecord
91 push dword ptr [esp+28] ;DWORD returnEax
92 push dword ptr [esp+16] ;return address
93 push esp
94 add dword ptr [esp], 20
95 push ebp
96 pushfd
97 push eax
98 push ebx
99 push ecx
100 push edx
101 push edi
102 push esi
103 xor eax, eax
104 mov eax, cs
105 push eax
106 mov eax, ds
107 push eax
108 mov eax, es
109 push eax
110 mov eax, fs
111 push eax
112 mov eax, gs
113 push eax
114 mov eax, ss
115 push eax
116 call OS2RTLUNWIND
117
118 ret 16 ;__stdcall
119_RtlUnwind@16 endp
120
121
122 PUBLIC QueryExceptionChain
123
124QueryExceptionChain proc near
125 mov eax, fs:[0]
126 ret
127QueryExceptionChain endp
128
129 PUBLIC GetExceptionRecord
130GetExceptionRecord proc near
131 push ebp
132 mov ebp, esp
133 push fs
134 push ebx
135
136 mov eax, [ebp+8]
137 mov fs, eax
138 mov ebx, [ebp+12]
139 mov eax, fs:[ebx]
140
141 pop ebx
142 pop fs
143 pop ebp
144 ret
145GetExceptionRecord endp
146
147 PUBLIC ChangeTIBStack
148ChangeTIBStack proc near
149; xor eax, eax
150 push ebx
151 mov eax, fs:[4]
152 mov ebx, fs:[8]
153 add ebx, 8
154 mov fs:[4], ebx
155 mov fs:[8], eax
156 pop ebx
157 ret
158ChangeTIBStack endp
159
160 PUBLIC _SetExceptionChain
161
162_SetExceptionChain proc near
163 mov eax, dword ptr [esp+4]
164 mov fs:[0], eax
165 ret
166_SetExceptionChain endp
167
168 PUBLIC getEAX
169 PUBLIC getEBX
170getEAX proc near
171 ret
172getEAX endp
173
174getEBX proc near
175 mov eax, ebx
176 ret
177getEBX endp
178
179 PUBLIC GetFS
180GetFS proc near
181 mov eax, fs
182 ret
183GetFS endp
184
185 PUBLIC SetFS
186SetFS proc near
187 mov eax, [esp+4]
188 mov fs, eax
189 ret
190SetFS endp
191
192 PUBLIC getCS
193getCS proc near
194 mov eax, cs
195 ret
196getCS endp
197
198 PUBLIC getDS
199getDS proc near
200 mov eax, ds
201 ret
202getDS endp
203
204 PUBLIC SetReturnFS
205SetReturnFS proc near
206 push fs
207 mov eax, [esp+8]
208 mov fs, eax
209 pop eax
210 ret
211SetReturnFS endp
212
213 PUBLIC getSS
214getSS proc near
215 mov ax, ss
216 ret
217getSS endp
218
219 PUBLIC getES
220getES proc near
221 mov eax, es
222 ret
223getES endp
224
225 PUBLIC getGS
226getGS proc near
227 mov eax, gs
228 ret
229getGS endp
230
231 PUBLIC getESP
232getESP proc near
233 mov eax, esp
234 ret
235getESP endp
236
237 PUBLIC RestoreOS2FS
238RestoreOS2FS proc near
239 push 150bh
240 mov ax, fs
241 pop fs
242 ret
243RestoreOS2FS endp
244
245 PUBLIC _Mul32x32to64
246_Mul32x32to64 proc near
247 push ebp
248 mov ebp, esp
249 push eax
250 push edx
251 push edi
252
253 mov edi, [ebp+8] ;64 bits result
254 mov eax, [ebp+12] ;op1
255 mov edx, [ebp+16] ;op2
256 mul edx
257 mov [edi], eax
258 mov [edi+4], edx
259
260 pop edi
261 pop edx
262 pop eax
263 pop ebp
264 ret
265_Mul32x32to64 endp
266
267 PUBLIC _AsmCallThreadHandler
268_AsmCallThreadHandler proc near
269 push ebp
270 mov ebp, esp
271
272 push dword ptr [ebp+12]
273 mov eax, dword ptr [ebp+8]
274 call eax
275
276 mov esp, ebp
277 pop ebp
278 ret
279_AsmCallThreadHandler endp
280
281; 281 static DWORD EXC_CallHandler( WINEXCEPTION_RECORD *record, WINEXCEPTION_FRAME *frame,
282 EXTRN WriteLog:PROC
283 EXTRN _GetThreadTEB@0:PROC
284IFDEF DEBUG
285 EXTRN DbgEnabled:DWORD
286ENDIF
287
288EXC_push_frame__FP19_WINEXCEPTION_FRAME proc
289 push ebp
290 mov ebp,esp
291 sub esp,04h
292 mov [ebp+08h],eax; frame
293
294; 132 TEB *teb = GetThreadTEB();
295 call _GetThreadTEB@0
296 mov [ebp-04h],eax; teb
297
298; 133 frame->Prev = (PWINEXCEPTION_FRAME)teb->except;
299 mov ecx,[ebp-04h]; teb
300 mov ecx,[ecx]
301 mov eax,[ebp+08h]; frame
302 mov [eax],ecx
303
304; 134 teb->except = frame;
305 mov eax,[ebp-04h]; teb
306 mov ecx,[ebp+08h]; frame
307 mov [eax],ecx
308
309; 135 return frame->Prev;
310 mov eax,[ebp+08h]; frame
311 mov eax,[eax]
312 leave
313 ret
314EXC_push_frame__FP19_WINEXCEPTION_FRAME endp
315
316; 138 static inline WINEXCEPTION_FRAME * EXC_pop_frame( WINEXCEPTION_FRAME *frame )
317 align 04h
318
319EXC_pop_frame__FP19_WINEXCEPTION_FRAME proc
320 push ebp
321 mov ebp,esp
322 sub esp,04h
323 mov [ebp+08h],eax; frame
324
325; 141 TEB *teb = GetThreadTEB();
326 call _GetThreadTEB@0
327 mov [ebp-04h],eax; teb
328
329; 142 teb->except = frame->Prev;
330 mov ecx,[ebp+08h]; frame
331 mov ecx,[ecx]
332 mov eax,[ebp-04h]; teb
333 mov [eax],ecx
334
335; 143 return frame->Prev;
336 mov eax,[ebp+08h]; frame
337 mov eax,[eax]
338 leave
339 ret
340EXC_pop_frame__FP19_WINEXCEPTION_FRAME endp
341
342 align 04h
343 PUBLIC EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5
344
345EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 proc
346 push ebp
347 mov ebp,esp
348 sub esp,010h
349 sub esp,04h
350 mov [ebp+08h],eax; record
351 mov [ebp+0ch],edx; frame
352 mov [ebp+010h],ecx; context
353
354; 296 newframe.frame.Handler = nested_handler;
355 mov eax,[ebp+01ch]; nested_handler
356 mov [ebp-08h],eax; newframe
357
358; 297 newframe.prevFrame = frame;
359 mov eax,[ebp+0ch]; frame
360 mov [ebp-04h],eax; newframe
361
362; 298 EXC_push_frame( &newframe.frame );
363 lea eax,[ebp-0ch]; newframe
364 call EXC_push_frame__FP19_WINEXCEPTION_FRAME
365
366; 299 dprintf(("KERNEL32: Calling handler at %p code=%lx flags=%lx\n",
367IFDEF DEBUG
368 cmp word ptr DbgEnabled+020h,01h
369 jne @BLBL20
370 mov eax,[ebp+08h]; record
371 push dword ptr [eax+04h]
372 mov eax,[ebp+08h]; record
373 push dword ptr [eax]
374 push dword ptr [ebp+018h]; handler
375 push offset FLAT:@CBE8
376 call WriteLog
377 add esp,010h
378ENDIF
379
380; 300 handler, record->ExceptionCode, record->ExceptionFlags));
381@BLBL20:
382
383; 301 ret = handler( record, frame, context, dispatcher );
384 push dword ptr [ebp+014h]; dispatcher
385 push dword ptr [ebp+010h]; context
386 push dword ptr [ebp+0ch]; frame
387 push dword ptr [ebp+08h]; record
388 call dword ptr [ebp+018h]; handler
389 mov [ebp-010h],eax; ret
390
391IFDEF DEBUG
392; 302 dprintf(("KERNEL32: Handler returned %lx\n", ret));
393 cmp word ptr DbgEnabled+020h,01h
394 jne @BLBL21
395 push dword ptr [ebp-010h]; ret
396 push offset FLAT:@CBE9
397 call WriteLog
398 add esp,08h
399@BLBL21:
400ENDIF
401
402; 303 EXC_pop_frame( &newframe.frame );
403 lea eax,[ebp-0ch]; newframe
404 call EXC_pop_frame__FP19_WINEXCEPTION_FRAME
405
406; 304 return ret;
407 mov eax,[ebp-010h]; ret
408 add esp,04h
409 leave
410 ret
411EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 endp
412
413CODE32 ENDS
414
415 END
Note: See TracBrowser for help on using the repository browser.