include: Add transact.idl to oledb.idl.
[wine.git] / dlls / ntdll / signal_i386.c
blob14971032ce6d7b8445772543d064595f16943f47
1 /*
2 * i386 signal handling routines
4 * Copyright 1999 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifdef __i386__
23 #include <errno.h>
24 #include <signal.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <sys/types.h>
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "ntdll_misc.h"
34 #include "wine/exception.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(seh);
39 struct x86_thread_data
41 DWORD fs; /* 1d4 TEB selector */
42 DWORD gs; /* 1d8 libc selector; update winebuild if you move this! */
43 DWORD dr0; /* 1dc debug registers */
44 DWORD dr1; /* 1e0 */
45 DWORD dr2; /* 1e4 */
46 DWORD dr3; /* 1e8 */
47 DWORD dr6; /* 1ec */
48 DWORD dr7; /* 1f0 */
49 void *exit_frame; /* 1f4 exit frame pointer */
52 C_ASSERT( sizeof(struct x86_thread_data) <= 16 * sizeof(void *) );
53 C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct x86_thread_data, gs ) == 0x1d8 );
54 C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct x86_thread_data, exit_frame ) == 0x1f4 );
56 static inline struct x86_thread_data *x86_thread_data(void)
58 return (struct x86_thread_data *)&NtCurrentTeb()->GdiTebBatch;
61 struct ldt_copy *__wine_ldt_copy = NULL;
63 /* Exception record for handling exceptions happening inside exception handlers */
64 typedef struct
66 EXCEPTION_REGISTRATION_RECORD frame;
67 EXCEPTION_REGISTRATION_RECORD *prevFrame;
68 } EXC_NESTED_FRAME;
70 extern DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
71 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher,
72 PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler );
74 /*******************************************************************
75 * is_valid_frame
77 static inline BOOL is_valid_frame( void *frame )
79 if ((ULONG_PTR)frame & 3) return FALSE;
80 return (frame >= NtCurrentTeb()->Tib.StackLimit &&
81 (void **)frame < (void **)NtCurrentTeb()->Tib.StackBase - 1);
84 /*******************************************************************
85 * raise_handler
87 * Handler for exceptions happening inside a handler.
89 static DWORD raise_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
90 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
92 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
93 return ExceptionContinueSearch;
94 /* We shouldn't get here so we store faulty frame in dispatcher */
95 *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
96 return ExceptionNestedException;
100 /*******************************************************************
101 * unwind_handler
103 * Handler for exceptions happening inside an unwind handler.
105 static DWORD unwind_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
106 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
108 if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
109 return ExceptionContinueSearch;
110 /* We shouldn't get here so we store faulty frame in dispatcher */
111 *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
112 return ExceptionCollidedUnwind;
116 /**********************************************************************
117 * call_stack_handlers
119 * Call the stack handlers chain.
121 static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
123 EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame;
124 DWORD res;
126 frame = NtCurrentTeb()->Tib.ExceptionList;
127 nested_frame = NULL;
128 while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL)
130 /* Check frame address */
131 if (!is_valid_frame( frame ))
133 rec->ExceptionFlags |= EH_STACK_INVALID;
134 break;
137 /* Call handler */
138 TRACE( "calling handler at %p code=%x flags=%x\n",
139 frame->Handler, rec->ExceptionCode, rec->ExceptionFlags );
140 res = EXC_CallHandler( rec, frame, context, &dispatch, frame->Handler, raise_handler );
141 TRACE( "handler at %p returned %x\n", frame->Handler, res );
143 if (frame == nested_frame)
145 /* no longer nested */
146 nested_frame = NULL;
147 rec->ExceptionFlags &= ~EH_NESTED_CALL;
150 switch(res)
152 case ExceptionContinueExecution:
153 if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return STATUS_SUCCESS;
154 return STATUS_NONCONTINUABLE_EXCEPTION;
155 case ExceptionContinueSearch:
156 break;
157 case ExceptionNestedException:
158 if (nested_frame < dispatch) nested_frame = dispatch;
159 rec->ExceptionFlags |= EH_NESTED_CALL;
160 break;
161 default:
162 return STATUS_INVALID_DISPOSITION;
164 frame = frame->Prev;
166 return STATUS_UNHANDLED_EXCEPTION;
170 /*******************************************************************
171 * KiUserExceptionDispatcher (NTDLL.@)
173 NTSTATUS WINAPI dispatch_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
175 NTSTATUS status;
176 DWORD c;
178 TRACE( "code=%x flags=%x addr=%p ip=%08x tid=%04x\n",
179 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
180 context->Eip, GetCurrentThreadId() );
181 for (c = 0; c < rec->NumberParameters; c++)
182 TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] );
184 if (rec->ExceptionCode == EXCEPTION_WINE_STUB)
186 if (rec->ExceptionInformation[1] >> 16)
187 MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
188 rec->ExceptionAddress,
189 (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] );
190 else
191 MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
192 rec->ExceptionAddress,
193 (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
195 else if (rec->ExceptionCode == EXCEPTION_WINE_NAME_THREAD && rec->ExceptionInformation[0] == 0x1000)
197 WARN( "Thread %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], debugstr_a((char *)rec->ExceptionInformation[1]) );
199 else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C)
201 WARN( "%s\n", debugstr_an((char *)rec->ExceptionInformation[1], rec->ExceptionInformation[0] - 1) );
203 else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_WIDE_C)
205 WARN( "%s\n", debugstr_wn((WCHAR *)rec->ExceptionInformation[1], rec->ExceptionInformation[0] - 1) );
207 else
209 if (rec->ExceptionCode == STATUS_ASSERTION_FAILURE)
210 ERR( "%s exception (code=%x) raised\n", debugstr_exception_code(rec->ExceptionCode), rec->ExceptionCode );
211 else
212 WARN( "%s exception (code=%x) raised\n", debugstr_exception_code(rec->ExceptionCode), rec->ExceptionCode );
214 TRACE(" eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n",
215 context->Eax, context->Ebx, context->Ecx,
216 context->Edx, context->Esi, context->Edi );
217 TRACE(" ebp=%08x esp=%08x cs=%04x ss=%04x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n",
218 context->Ebp, context->Esp, context->SegCs, context->SegSs, context->SegDs,
219 context->SegEs, context->SegFs, context->SegGs, context->EFlags );
222 if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
223 NtContinue( context, FALSE );
225 if ((status = call_stack_handlers( rec, context )) == STATUS_SUCCESS)
226 NtContinue( context, FALSE );
228 if (status != STATUS_UNHANDLED_EXCEPTION) RtlRaiseStatus( status );
229 return NtRaiseException( rec, context, FALSE );
232 __ASM_STDCALL_FUNC( KiUserExceptionDispatcher, 8,
233 "pushl 4(%esp)\n\t"
234 "pushl 4(%esp)\n\t"
235 "call " __ASM_STDCALL("dispatch_exception", 8) "\n\t"
236 "int3" )
239 /*******************************************************************
240 * KiUserApcDispatcher (NTDLL.@)
242 void WINAPI KiUserApcDispatcher( CONTEXT *context, ULONG_PTR ctx, ULONG_PTR arg1, ULONG_PTR arg2,
243 PNTAPCFUNC func )
245 func( ctx, arg1, arg2 );
246 NtContinue( context, TRUE );
250 /*******************************************************************
251 * KiUserCallbackDispatcher (NTDLL.@)
253 void WINAPI KiUserCallbackDispatcher( ULONG id, void *args, ULONG len )
255 NTSTATUS (WINAPI *func)(void *, ULONG) = ((void **)NtCurrentTeb()->Peb->KernelCallbackTable)[id];
257 RtlRaiseStatus( NtCallbackReturn( NULL, 0, func( args, len )));
261 /***********************************************************************
262 * save_fpu
264 * Save the thread FPU context.
266 static inline void save_fpu( CONTEXT *context )
268 #ifdef __GNUC__
269 struct
271 DWORD ControlWord;
272 DWORD StatusWord;
273 DWORD TagWord;
274 DWORD ErrorOffset;
275 DWORD ErrorSelector;
276 DWORD DataOffset;
277 DWORD DataSelector;
279 float_status;
281 context->ContextFlags |= CONTEXT_FLOATING_POINT;
282 __asm__ __volatile__( "fnsave %0; fwait" : "=m" (context->FloatSave) );
284 /* Reset unmasked exceptions status to avoid firing an exception. */
285 memcpy(&float_status, &context->FloatSave, sizeof(float_status));
286 float_status.StatusWord &= float_status.ControlWord | 0xffffff80;
288 __asm__ __volatile__( "fldenv %0" : : "m" (float_status) );
289 #endif
293 /***********************************************************************
294 * save_fpux
296 * Save the thread FPU extended context.
298 static inline void save_fpux( CONTEXT *context )
300 #ifdef __GNUC__
301 /* we have to enforce alignment by hand */
302 char buffer[sizeof(XSAVE_FORMAT) + 16];
303 XSAVE_FORMAT *state = (XSAVE_FORMAT *)(((ULONG_PTR)buffer + 15) & ~15);
305 context->ContextFlags |= CONTEXT_EXTENDED_REGISTERS;
306 __asm__ __volatile__( "fxsave %0" : "=m" (*state) );
307 memcpy( context->ExtendedRegisters, state, sizeof(*state) );
308 #endif
312 /***********************************************************************
313 * RtlCaptureContext (NTDLL.@)
315 __ASM_STDCALL_FUNC( RtlCaptureContext, 4,
316 "pushl %eax\n\t"
317 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
318 "movl 8(%esp),%eax\n\t" /* context */
319 "movl $0x10007,(%eax)\n\t" /* context->ContextFlags */
320 "movw %gs,0x8c(%eax)\n\t" /* context->SegGs */
321 "movw %fs,0x90(%eax)\n\t" /* context->SegFs */
322 "movw %es,0x94(%eax)\n\t" /* context->SegEs */
323 "movw %ds,0x98(%eax)\n\t" /* context->SegDs */
324 "movl %edi,0x9c(%eax)\n\t" /* context->Edi */
325 "movl %esi,0xa0(%eax)\n\t" /* context->Esi */
326 "movl %ebx,0xa4(%eax)\n\t" /* context->Ebx */
327 "movl %edx,0xa8(%eax)\n\t" /* context->Edx */
328 "movl %ecx,0xac(%eax)\n\t" /* context->Ecx */
329 "movl 0(%ebp),%edx\n\t"
330 "movl %edx,0xb4(%eax)\n\t" /* context->Ebp */
331 "movl 4(%ebp),%edx\n\t"
332 "movl %edx,0xb8(%eax)\n\t" /* context->Eip */
333 "movw %cs,0xbc(%eax)\n\t" /* context->SegCs */
334 "pushfl\n\t"
335 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
336 "popl 0xc0(%eax)\n\t" /* context->EFlags */
337 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
338 "leal 8(%ebp),%edx\n\t"
339 "movl %edx,0xc4(%eax)\n\t" /* context->Esp */
340 "movw %ss,0xc8(%eax)\n\t" /* context->SegSs */
341 "popl 0xb0(%eax)\n\t" /* context->Eax */
342 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
343 "ret $4" )
346 /*******************************************************************
347 * RtlUnwind (NTDLL.@)
349 void WINAPI DECLSPEC_HIDDEN __regs_RtlUnwind( EXCEPTION_REGISTRATION_RECORD* pEndFrame, PVOID targetIp,
350 PEXCEPTION_RECORD pRecord, PVOID retval, CONTEXT *context )
352 EXCEPTION_RECORD record;
353 EXCEPTION_REGISTRATION_RECORD *frame, *dispatch;
354 DWORD res;
356 context->Eax = (DWORD)retval;
358 /* build an exception record, if we do not have one */
359 if (!pRecord)
361 record.ExceptionCode = STATUS_UNWIND;
362 record.ExceptionFlags = 0;
363 record.ExceptionRecord = NULL;
364 record.ExceptionAddress = (void *)context->Eip;
365 record.NumberParameters = 0;
366 pRecord = &record;
369 pRecord->ExceptionFlags |= EH_UNWINDING | (pEndFrame ? 0 : EH_EXIT_UNWIND);
371 TRACE( "code=%x flags=%x\n", pRecord->ExceptionCode, pRecord->ExceptionFlags );
372 TRACE( "eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n",
373 context->Eax, context->Ebx, context->Ecx, context->Edx, context->Esi, context->Edi );
374 TRACE( "ebp=%08x esp=%08x eip=%08x cs=%04x ds=%04x fs=%04x gs=%04x flags=%08x\n",
375 context->Ebp, context->Esp, context->Eip, LOWORD(context->SegCs), LOWORD(context->SegDs),
376 LOWORD(context->SegFs), LOWORD(context->SegGs), context->EFlags );
378 /* get chain of exception frames */
379 frame = NtCurrentTeb()->Tib.ExceptionList;
380 while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != pEndFrame))
382 /* Check frame address */
383 if (pEndFrame && (frame > pEndFrame))
384 raise_status( STATUS_INVALID_UNWIND_TARGET, pRecord );
386 if (!is_valid_frame( frame )) raise_status( STATUS_BAD_STACK, pRecord );
388 /* Call handler */
389 TRACE( "calling handler at %p code=%x flags=%x\n",
390 frame->Handler, pRecord->ExceptionCode, pRecord->ExceptionFlags );
391 res = EXC_CallHandler( pRecord, frame, context, &dispatch, frame->Handler, unwind_handler );
392 TRACE( "handler at %p returned %x\n", frame->Handler, res );
394 switch(res)
396 case ExceptionContinueSearch:
397 break;
398 case ExceptionCollidedUnwind:
399 frame = dispatch;
400 break;
401 default:
402 raise_status( STATUS_INVALID_DISPOSITION, pRecord );
403 break;
405 frame = __wine_pop_frame( frame );
407 NtContinue( context, FALSE );
409 __ASM_STDCALL_FUNC( RtlUnwind, 16,
410 "pushl %ebp\n\t"
411 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
412 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
413 "movl %esp,%ebp\n\t"
414 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
415 "leal -(0x2cc+8)(%esp),%esp\n\t" /* sizeof(CONTEXT) + alignment */
416 "pushl %eax\n\t"
417 "leal 4(%esp),%eax\n\t" /* context */
418 "xchgl %eax,(%esp)\n\t"
419 "call " __ASM_STDCALL("RtlCaptureContext",4) "\n\t"
420 "leal 24(%ebp),%eax\n\t"
421 "movl %eax,0xc4(%esp)\n\t" /* context->Esp */
422 "pushl %esp\n\t"
423 "pushl 20(%ebp)\n\t"
424 "pushl 16(%ebp)\n\t"
425 "pushl 12(%ebp)\n\t"
426 "pushl 8(%ebp)\n\t"
427 "call " __ASM_STDCALL("__regs_RtlUnwind",20) "\n\t"
428 "leave\n\t"
429 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
430 __ASM_CFI(".cfi_same_value %ebp\n\t")
431 "ret $16" ) /* actually never returns */
434 /*******************************************************************
435 * raise_exception_full_context
437 * Raise an exception with the full CPU context.
439 void raise_exception_full_context( EXCEPTION_RECORD *rec, CONTEXT *context )
441 save_fpu( context );
442 save_fpux( context );
443 /* FIXME: xstate */
444 context->Dr0 = x86_thread_data()->dr0;
445 context->Dr1 = x86_thread_data()->dr1;
446 context->Dr2 = x86_thread_data()->dr2;
447 context->Dr3 = x86_thread_data()->dr3;
448 context->Dr6 = x86_thread_data()->dr6;
449 context->Dr7 = x86_thread_data()->dr7;
450 context->ContextFlags |= CONTEXT_DEBUG_REGISTERS;
452 RtlRaiseStatus( NtRaiseException( rec, context, TRUE ));
456 /***********************************************************************
457 * RtlRaiseException (NTDLL.@)
459 __ASM_STDCALL_FUNC( RtlRaiseException, 4,
460 "pushl %ebp\n\t"
461 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
462 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
463 "movl %esp,%ebp\n\t"
464 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
465 "leal -0x2cc(%esp),%esp\n\t" /* sizeof(CONTEXT) */
466 "pushl %esp\n\t" /* context */
467 "call " __ASM_STDCALL("RtlCaptureContext",4) "\n\t"
468 "movl 4(%ebp),%eax\n\t" /* return address */
469 "movl 8(%ebp),%ecx\n\t" /* rec */
470 "movl %eax,12(%ecx)\n\t" /* rec->ExceptionAddress */
471 "leal 12(%ebp),%eax\n\t"
472 "movl %eax,0xc4(%esp)\n\t" /* context->Esp */
473 "movl %esp,%eax\n\t"
474 "pushl %eax\n\t"
475 "pushl %ecx\n\t"
476 "call " __ASM_NAME("raise_exception_full_context") "\n\t"
477 "leave\n\t"
478 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
479 __ASM_CFI(".cfi_same_value %ebp\n\t")
480 "ret $4" ) /* actually never returns */
483 /*************************************************************************
484 * RtlCaptureStackBackTrace (NTDLL.@)
486 USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
488 CONTEXT context;
489 ULONG i;
490 ULONG *frame;
492 RtlCaptureContext( &context );
493 if (hash) *hash = 0;
494 frame = (ULONG *)context.Ebp;
496 while (skip--)
498 if (!is_valid_frame( frame )) return 0;
499 frame = (ULONG *)*frame;
502 for (i = 0; i < count; i++)
504 if (!is_valid_frame( frame )) break;
505 buffer[i] = (void *)frame[1];
506 if (hash) *hash += frame[1];
507 frame = (ULONG *)*frame;
509 return i;
513 /***********************************************************************
514 * signal_start_thread
516 __ASM_GLOBAL_FUNC( signal_start_thread,
517 "movl 4(%esp),%esi\n\t" /* context */
518 "leal -12(%esi),%edi\n\t"
519 /* clear the thread stack */
520 "andl $~0xfff,%edi\n\t" /* round down to page size */
521 "movl $0xf0000,%ecx\n\t"
522 "subl %ecx,%edi\n\t"
523 "movl %edi,%esp\n\t"
524 "xorl %eax,%eax\n\t"
525 "shrl $2,%ecx\n\t"
526 "rep; stosl\n\t"
527 /* switch to the initial context */
528 "leal -12(%esi),%esp\n\t"
529 "movl $1,4(%esp)\n\t"
530 "movl %esi,(%esp)\n\t"
531 "call " __ASM_STDCALL("NtContinue", 8) )
533 /**********************************************************************
534 * DbgBreakPoint (NTDLL.@)
536 __ASM_STDCALL_FUNC( DbgBreakPoint, 0, "int $3; ret"
537 "\n\tnop; nop; nop; nop; nop; nop; nop; nop"
538 "\n\tnop; nop; nop; nop; nop; nop" );
540 /**********************************************************************
541 * DbgUserBreakPoint (NTDLL.@)
543 __ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "int $3; ret"
544 "\n\tnop; nop; nop; nop; nop; nop; nop; nop"
545 "\n\tnop; nop; nop; nop; nop; nop" );
547 /**********************************************************************
548 * NtCurrentTeb (NTDLL.@)
550 __ASM_STDCALL_FUNC( NtCurrentTeb, 0, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" )
553 /**************************************************************************
554 * _chkstk (NTDLL.@)
556 __ASM_GLOBAL_FUNC( _chkstk,
557 "negl %eax\n\t"
558 "addl %esp,%eax\n\t"
559 "xchgl %esp,%eax\n\t"
560 "movl 0(%eax),%eax\n\t" /* copy return address from old location */
561 "movl %eax,0(%esp)\n\t"
562 "ret" )
564 /**************************************************************************
565 * _alloca_probe (NTDLL.@)
567 __ASM_GLOBAL_FUNC( _alloca_probe,
568 "negl %eax\n\t"
569 "addl %esp,%eax\n\t"
570 "xchgl %esp,%eax\n\t"
571 "movl 0(%eax),%eax\n\t" /* copy return address from old location */
572 "movl %eax,0(%esp)\n\t"
573 "ret" )
576 /**********************************************************************
577 * EXC_CallHandler (internal)
579 * Some exception handlers depend on EBP to have a fixed position relative to
580 * the exception frame.
581 * Shrinker depends on (*1) doing what it does,
582 * (*2) being the exact instruction it is and (*3) beginning with 0x64
583 * (i.e. the %fs prefix to the movl instruction). It also depends on the
584 * function calling the handler having only 5 parameters (*4).
586 __ASM_GLOBAL_FUNC( EXC_CallHandler,
587 "pushl %ebp\n\t"
588 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
589 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
590 "movl %esp,%ebp\n\t"
591 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
592 "pushl %ebx\n\t"
593 __ASM_CFI(".cfi_rel_offset %ebx,-4\n\t")
594 "movl 28(%ebp), %edx\n\t" /* ugly hack to pass the 6th param needed because of Shrinker */
595 "pushl 24(%ebp)\n\t"
596 "pushl 20(%ebp)\n\t"
597 "pushl 16(%ebp)\n\t"
598 "pushl 12(%ebp)\n\t"
599 "pushl 8(%ebp)\n\t"
600 "call " __ASM_NAME("call_exception_handler") "\n\t"
601 "popl %ebx\n\t"
602 __ASM_CFI(".cfi_same_value %ebx\n\t")
603 "leave\n"
604 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
605 __ASM_CFI(".cfi_same_value %ebp\n\t")
606 "ret" )
607 __ASM_GLOBAL_FUNC(call_exception_handler,
608 "pushl %ebp\n\t"
609 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
610 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
611 "movl %esp,%ebp\n\t"
612 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
613 "subl $12,%esp\n\t"
614 "pushl 12(%ebp)\n\t" /* make any exceptions in this... */
615 "pushl %edx\n\t" /* handler be handled by... */
616 ".byte 0x64\n\t"
617 "pushl (0)\n\t" /* nested_handler (passed in edx). */
618 ".byte 0x64\n\t"
619 "movl %esp,(0)\n\t" /* push the new exception frame onto the exception stack. */
620 "pushl 20(%ebp)\n\t"
621 "pushl 16(%ebp)\n\t"
622 "pushl 12(%ebp)\n\t"
623 "pushl 8(%ebp)\n\t"
624 "movl 24(%ebp), %ecx\n\t" /* (*1) */
625 "call *%ecx\n\t" /* call handler. (*2) */
626 ".byte 0x64\n\t"
627 "movl (0), %esp\n\t" /* restore previous... (*3) */
628 ".byte 0x64\n\t"
629 "popl (0)\n\t" /* exception frame. */
630 "movl %ebp, %esp\n\t" /* restore saved stack, in case it was corrupted */
631 "popl %ebp\n\t"
632 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
633 __ASM_CFI(".cfi_same_value %ebp\n\t")
634 "ret $20" ) /* (*4) */
636 #endif /* __i386__ */