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

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

Make sure the stack is properly aligned

File size: 7.8 KB
Line 
1; $Id: exceptutil.asm,v 1.20 2002-11-28 19:49:02 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
176IFDEF DEBUG
177;We're asking for problems if our stack start near a 64kb boundary
178;Some OS/2 thunking procedures can choke on misaligned stack addresses
179 mov eax, esp
180 and eax, 0FFFFh
181 cmp eax, 0E000h
182 jge @goodstack
183
184 add eax, 1000h
185 sub esp, eax
186@goodstack:
187ENDIF
188
189 mov eax, esp
190 sub eax, 16
191 and eax, 0FFFFFFF0h
192 add eax, 4
193 mov esp, eax
194
195 push dword ptr [ebp+12]
196 mov eax, dword ptr [ebp+8]
197 call eax
198
199 mov esp, ebp
200 pop ebp
201 ret
202_CallEntryPoint endp
203
204
205; 281 static DWORD EXC_CallHandler( WINEXCEPTION_RECORD *record, WINEXCEPTION_FRAME *frame,
206 EXTRN WriteLog:PROC
207 EXTRN _GetThreadTEB@0:PROC
208IFDEF DEBUG
209 EXTRN DbgEnabledKERNEL32:DWORD
210ENDIF
211
212EXC_push_frame__FP19_WINEXCEPTION_FRAME proc
213 push ebp
214 mov ebp,esp
215 sub esp,04h
216 mov [ebp+08h],eax; frame
217
218; 132 TEB *teb = GetThreadTEB();
219 call _GetThreadTEB@0
220 mov [ebp-04h],eax; teb
221
222; 133 frame->Prev = (PWINEXCEPTION_FRAME)teb->except;
223 mov ecx,[ebp-04h]; teb
224 mov ecx,[ecx]
225 mov eax,[ebp+08h]; frame
226 mov [eax],ecx
227
228; 134 teb->except = frame;
229 mov eax,[ebp-04h]; teb
230 mov ecx,[ebp+08h]; frame
231 mov [eax],ecx
232
233; 135 return frame->Prev;
234 mov eax,[ebp+08h]; frame
235 mov eax,[eax]
236 leave
237 ret
238EXC_push_frame__FP19_WINEXCEPTION_FRAME endp
239
240; 138 static inline WINEXCEPTION_FRAME * EXC_pop_frame( WINEXCEPTION_FRAME *frame )
241 align 04h
242
243EXC_pop_frame__FP19_WINEXCEPTION_FRAME proc
244 push ebp
245 mov ebp,esp
246 sub esp,04h
247 mov [ebp+08h],eax; frame
248
249; 141 TEB *teb = GetThreadTEB();
250 call _GetThreadTEB@0
251 mov [ebp-04h],eax; teb
252
253; 142 teb->except = frame->Prev;
254 mov ecx,[ebp+08h]; frame
255 mov ecx,[ecx]
256 mov eax,[ebp-04h]; teb
257 mov [eax],ecx
258
259; 143 return frame->Prev;
260 mov eax,[ebp+08h]; frame
261 mov eax,[eax]
262 leave
263 ret
264EXC_pop_frame__FP19_WINEXCEPTION_FRAME endp
265
266 align 04h
267 PUBLIC EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5
268
269EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 proc
270 push ebp
271 mov ebp,esp
272 sub esp,010h
273 sub esp,04h
274 mov [ebp+08h],eax; record
275 mov [ebp+0ch],edx; frame
276 mov [ebp+010h],ecx; context
277
278; 296 newframe.frame.Handler = nested_handler;
279 mov eax,[ebp+01ch]; nested_handler
280 mov [ebp-08h],eax; newframe
281
282; 297 newframe.prevFrame = frame;
283 mov eax,[ebp+0ch]; frame
284 mov [ebp-04h],eax; newframe
285
286; 298 EXC_push_frame( &newframe.frame );
287 lea eax,[ebp-0ch]; newframe
288 call EXC_push_frame__FP19_WINEXCEPTION_FRAME
289
290; 299 dprintf(("KERNEL32: Calling handler at %p code=%lx flags=%lx\n",
291IFDEF DEBUG
292 cmp word ptr DbgEnabledKERNEL32+020h,01h
293 jne @BLBL20
294 mov eax,[ebp+08h]; record
295 push dword ptr [eax+04h]
296 mov eax,[ebp+08h]; record
297 push dword ptr [eax]
298 push dword ptr [ebp+018h]; handler
299 push offset FLAT:@CBE8
300 call WriteLog
301 add esp,010h
302ENDIF
303
304; 300 handler, record->ExceptionCode, record->ExceptionFlags));
305@BLBL20:
306
307; 301 ret = handler( record, frame, context, dispatcher );
308 push dword ptr [ebp+014h]; dispatcher
309 push dword ptr [ebp+010h]; context
310 push dword ptr [ebp+0ch]; frame
311 push dword ptr [ebp+08h]; record
312 call dword ptr [ebp+018h]; handler
313 mov [ebp-010h],eax; ret
314
315IFDEF DEBUG
316; 302 dprintf(("KERNEL32: Handler returned %lx\n", ret));
317 cmp word ptr DbgEnabledKERNEL32+020h,01h
318 jne @BLBL21
319 push dword ptr [ebp-010h]; ret
320 push offset FLAT:@CBE9
321 call WriteLog
322 add esp,08h
323@BLBL21:
324ENDIF
325
326; 303 EXC_pop_frame( &newframe.frame );
327 lea eax,[ebp-0ch]; newframe
328 call EXC_pop_frame__FP19_WINEXCEPTION_FRAME
329
330; 304 return ret;
331 mov eax,[ebp-010h]; ret
332 add esp,04h
333 leave
334 ret
335EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 endp
336
337CODE32 ENDS
338
339 END
Note: See TracBrowser for help on using the repository browser.