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

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

Check ESP when calling the entrypoint of a newly created thread.

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