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

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

Touch last stack page using ESP. (just in case)

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