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

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

Touch all stack pages we skip in the out of stack workaround for 16 bits code. Jumping over the guard page causes a protection violation exception

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