Added support for forwarded ordinals in built-in dlls.
[wine/multimedia.git] / win32 / except.c
blob8290a08aca9b771c3239b4a5851019afbb7bf48a
1 /*
2 * Win32 exception functions
4 * Copyright (c) 1996 Onno Hovers, (onno@stack.urc.tue.nl)
5 * Copyright (c) 1999 Alexandre Julliard
7 * Notes:
8 * What really happens behind the scenes of those new
9 * __try{...}__except(..){....} and
10 * __try{...}__finally{...}
11 * statements is simply not documented by Microsoft. There could be different
12 * reasons for this:
13 * One reason could be that they try to hide the fact that exception
14 * handling in Win32 looks almost the same as in OS/2 2.x.
15 * Another reason could be that Microsoft does not want others to write
16 * binary compatible implementations of the Win32 API (like us).
18 * Whatever the reason, THIS SUCKS!! Ensuring portabilty or future
19 * compatability may be valid reasons to keep some things undocumented.
20 * But exception handling is so basic to Win32 that it should be
21 * documented!
23 * Fixmes:
24 * -Most functions need better parameter checking.
25 * -I do not know how to handle exceptions within an exception handler.
26 * or what is done when ExceptionNestedException is returned from an
27 * exception handler
28 * -Real exceptions are not yet implemented. only the exception functions
29 * are implemented. A real implementation needs some new code in
30 * loader/signal.c. There would also be a need for showing debugging
31 * information in UnhandledExceptionFilter.
35 #include <assert.h>
36 #include "winuser.h"
37 #include "winerror.h"
38 #include "ldt.h"
39 #include "process.h"
40 #include "thread.h"
41 #include "debugtools.h"
42 #include "except.h"
43 #include "stackframe.h"
45 DEFAULT_DEBUG_CHANNEL(seh)
48 /*******************************************************************
49 * RaiseException (KERNEL32.418)
51 void WINAPI RaiseException( DWORD code, DWORD flags, DWORD nbargs, const LPDWORD args )
53 EXCEPTION_RECORD record;
55 /* Compose an exception record */
57 record.ExceptionCode = code;
58 record.ExceptionFlags = flags & EH_NONCONTINUABLE;
59 record.ExceptionRecord = NULL;
60 record.ExceptionAddress = RaiseException;
61 if (nbargs && args)
63 if (nbargs > EXCEPTION_MAXIMUM_PARAMETERS) nbargs = EXCEPTION_MAXIMUM_PARAMETERS;
64 record.NumberParameters = nbargs;
65 memcpy( record.ExceptionInformation, args, nbargs * sizeof(*args) );
67 else record.NumberParameters = 0;
69 RtlRaiseException( &record );
73 /*******************************************************************
74 * UnhandledExceptionFilter (KERNEL32.537)
76 DWORD WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS epointers)
78 char message[80];
79 PDB *pdb = PROCESS_Current();
81 /* FIXME: Should check if the process is being debugged */
83 if (pdb->top_filter)
85 DWORD ret = pdb->top_filter( epointers );
86 if (ret != EXCEPTION_CONTINUE_SEARCH) return ret;
89 /* FIXME: Should check the current error mode */
91 sprintf( message, "Unhandled exception 0x%08lx at address 0x%08lx.",
92 epointers->ExceptionRecord->ExceptionCode,
93 (DWORD)epointers->ExceptionRecord->ExceptionAddress );
94 MessageBoxA( 0, message, "Error", MB_OK | MB_ICONHAND );
95 return EXCEPTION_EXECUTE_HANDLER;
99 /*************************************************************
100 * SetUnhandledExceptionFilter (KERNEL32.516)
102 LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter(
103 LPTOP_LEVEL_EXCEPTION_FILTER filter )
105 PDB *pdb = PROCESS_Current();
106 LPTOP_LEVEL_EXCEPTION_FILTER old = pdb->top_filter;
107 pdb->top_filter = filter;
108 return old;