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

Last change on this file since 10010 was 9913, checked in by sandervl, 22 years ago

Don't change the stack alignment if the thread has less than 128 kb stack.

File size: 9.3 KB
Line 
1; $Id: exceptutil.asm,v 1.25 2003-03-06 12:49:08 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;;ULONG CDECL AsmCallThreadHandler(BOOL fAlignStack, ULONG handler, LPVOID parameter);
158 PUBLIC _AsmCallThreadHandler
159_AsmCallThreadHandler proc near
160 push ebp
161 mov ebp, esp
162
163;first check if we have 128kb stack or more; if not, then skip the stack alignment code
164 mov eax, [ebp+8]
165 cmp eax, 0
166 je @goodthreadstack
167
168;We're asking for problems if our stack start near a 64kb boundary
169;Some OS/2 thunking procedures can choke if there's not enough stack left
170 mov eax, esp
171 and eax, 0FFFFh
172 cmp eax, 0E000h
173 jge @goodthreadstack
174
175 ;set ESP to the top of the next 64kb block and touch each
176 ;page to make sure the guard page exception handler commits
177 ;those pages
178 mov edx, esp
179 sub edx, eax
180
181 and esp, 0FFFFF000h
182 dec esp
183
184@touchthreadstackpages:
185 mov al, byte ptr [esp]
186
187 sub esp, 1000h
188
189 cmp esp, edx
190 jg @touchthreadstackpages
191
192 mov esp, edx
193 sub esp, 16
194
195 ;also touch this page
196 mov eax, dword ptr [esp]
197
198@goodthreadstack:
199
200 push dword ptr [ebp+16]
201 mov eax, dword ptr [ebp+12]
202 call eax
203
204 mov esp, ebp
205 pop ebp
206 ret
207_AsmCallThreadHandler endp
208
209 PUBLIC _CallEntryPoint
210_CallEntryPoint proc near
211 push ebp
212 mov ebp, esp
213
214;We're asking for problems if our stack start near a 64kb boundary
215;Some OS/2 thunking procedures can choke if there's not enough stack left
216 mov eax, esp
217 and eax, 0FFFFh
218 cmp eax, 0E000h
219 jge @goodmainstack
220
221 ;set ESP to the top of the next 64kb block and touch each
222 ;page to make sure the guard page exception handler commits
223 ;those pages
224 mov edx, esp
225 sub edx, eax
226
227 and esp, 0FFFFF000h
228 dec esp
229
230@touchmainstackpages:
231 mov al, byte ptr [esp]
232
233 sub esp, 1000h
234
235 cmp esp, edx
236 jg @touchmainstackpages
237
238 mov esp, edx
239 sub esp, 16
240
241 ;also touch this page
242 mov eax, dword ptr [esp]
243
244@goodmainstack:
245
246 mov eax, esp
247 sub eax, 16
248 and eax, 0FFFFFFF0h
249 add eax, 4
250 mov esp, eax
251
252 push dword ptr [ebp+12]
253 mov eax, dword ptr [ebp+8]
254 call eax
255
256 mov esp, ebp
257 pop ebp
258 ret
259_CallEntryPoint endp
260
261
262; 281 static DWORD EXC_CallHandler( WINEXCEPTION_RECORD *record, WINEXCEPTION_FRAME *frame,
263 EXTRN WriteLog:PROC
264 EXTRN _GetThreadTEB@0:PROC
265IFDEF DEBUG
266 EXTRN DbgEnabledKERNEL32:DWORD
267ENDIF
268
269EXC_push_frame__FP19_WINEXCEPTION_FRAME proc
270 push ebp
271 mov ebp,esp
272 sub esp,04h
273 mov [ebp+08h],eax; frame
274
275; 132 TEB *teb = GetThreadTEB();
276 call _GetThreadTEB@0
277 mov [ebp-04h],eax; teb
278
279; 133 frame->Prev = (PWINEXCEPTION_FRAME)teb->except;
280 mov ecx,[ebp-04h]; teb
281 mov ecx,[ecx]
282 mov eax,[ebp+08h]; frame
283 mov [eax],ecx
284
285; 134 teb->except = frame;
286 mov eax,[ebp-04h]; teb
287 mov ecx,[ebp+08h]; frame
288 mov [eax],ecx
289
290; 135 return frame->Prev;
291 mov eax,[ebp+08h]; frame
292 mov eax,[eax]
293 leave
294 ret
295EXC_push_frame__FP19_WINEXCEPTION_FRAME endp
296
297; 138 static inline WINEXCEPTION_FRAME * EXC_pop_frame( WINEXCEPTION_FRAME *frame )
298 align 04h
299
300EXC_pop_frame__FP19_WINEXCEPTION_FRAME proc
301 push ebp
302 mov ebp,esp
303 sub esp,04h
304 mov [ebp+08h],eax; frame
305
306; 141 TEB *teb = GetThreadTEB();
307 call _GetThreadTEB@0
308 mov [ebp-04h],eax; teb
309
310; 142 teb->except = frame->Prev;
311 mov ecx,[ebp+08h]; frame
312 mov ecx,[ecx]
313 mov eax,[ebp-04h]; teb
314 mov [eax],ecx
315
316; 143 return frame->Prev;
317 mov eax,[ebp+08h]; frame
318 mov eax,[eax]
319 leave
320 ret
321EXC_pop_frame__FP19_WINEXCEPTION_FRAME endp
322
323 align 04h
324 PUBLIC EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5
325
326EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 proc
327 push ebp
328 mov ebp,esp
329 sub esp,010h
330 sub esp,04h
331 mov [ebp+08h],eax; record
332 mov [ebp+0ch],edx; frame
333 mov [ebp+010h],ecx; context
334
335; 296 newframe.frame.Handler = nested_handler;
336 mov eax,[ebp+01ch]; nested_handler
337 mov [ebp-08h],eax; newframe
338
339; 297 newframe.prevFrame = frame;
340 mov eax,[ebp+0ch]; frame
341 mov [ebp-04h],eax; newframe
342
343; 298 EXC_push_frame( &newframe.frame );
344 lea eax,[ebp-0ch]; newframe
345 call EXC_push_frame__FP19_WINEXCEPTION_FRAME
346
347; 299 dprintf(("KERNEL32: Calling handler at %p code=%lx flags=%lx\n",
348IFDEF DEBUG
349 cmp word ptr DbgEnabledKERNEL32+020h,01h
350 jne @BLBL20
351 mov eax,[ebp+08h]; record
352 push dword ptr [eax+04h]
353 mov eax,[ebp+08h]; record
354 push dword ptr [eax]
355 push dword ptr [ebp+018h]; handler
356 push offset FLAT:@CBE8
357 call WriteLog
358 add esp,010h
359ENDIF
360
361; 300 handler, record->ExceptionCode, record->ExceptionFlags));
362@BLBL20:
363
364; 301 ret = handler( record, frame, context, dispatcher );
365 push dword ptr [ebp+014h]; dispatcher
366 push dword ptr [ebp+010h]; context
367 push dword ptr [ebp+0ch]; frame
368 push dword ptr [ebp+08h]; record
369 call dword ptr [ebp+018h]; handler
370 mov [ebp-010h],eax; ret
371
372IFDEF DEBUG
373; 302 dprintf(("KERNEL32: Handler returned %lx\n", ret));
374 cmp word ptr DbgEnabledKERNEL32+020h,01h
375 jne @BLBL21
376 push dword ptr [ebp-010h]; ret
377 push offset FLAT:@CBE9
378 call WriteLog
379 add esp,08h
380@BLBL21:
381ENDIF
382
383; 303 EXC_pop_frame( &newframe.frame );
384 lea eax,[ebp-0ch]; newframe
385 call EXC_pop_frame__FP19_WINEXCEPTION_FRAME
386
387; 304 return ret;
388 mov eax,[ebp-010h]; ret
389 add esp,04h
390 leave
391 ret
392EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 endp
393
394CODE32 ENDS
395
396 END
Note: See TracBrowser for help on using the repository browser.