1 /* $Id: except.c,v 1.11 2003/07/10 18:50:51 chorns Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/misc/except.c
6 * PURPOSE: Exception functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * modified from WINE [ Onno Hovers, (onno@stack.urc.tue.nl) ]
16 typedef LONG (STDCALL
*LPTOP_LEVEL_EXCEPTION_FILTER
)(
17 struct _EXCEPTION_POINTERS
*ExceptionInfo
21 LPTOP_LEVEL_EXCEPTION_FILTER GlobalTopLevelExceptionFilter
;
23 UINT
GetErrorMode(void);
27 UINT
GetErrorMode(void)
38 SetErrorMode( UINT uMode
)
40 UINT OldErrMode
= GetErrorMode();
41 GlobalErrMode
= uMode
;
49 LPTOP_LEVEL_EXCEPTION_FILTER
51 SetUnhandledExceptionFilter(
52 LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
55 LPTOP_LEVEL_EXCEPTION_FILTER OldTopLevelExceptionFilter
=
56 GlobalTopLevelExceptionFilter
;
57 lpTopLevelExceptionFilter
= GlobalTopLevelExceptionFilter
;
58 return OldTopLevelExceptionFilter
;
67 UnhandledExceptionFilter(struct _EXCEPTION_POINTERS
*ExceptionInfo
)
73 if(ExceptionInfo
->ExceptionRecord
->ExceptionCode
== STATUS_ACCESS_VIOLATION
) {
74 // might check read only resource
75 // Is there a debugger running ?
76 errCode
= NtQueryInformationProcess(NtCurrentProcess(),ProcessDebugPort
,&DebugPort
,sizeof(HANDLE
),NULL
);
77 if ( !NT_SUCCESS(errCode
) ) {
78 SetLastErrorByStatus(errCode
);
79 return EXCEPTION_EXECUTE_HANDLER
;
82 //return EXCEPTION_CONTINUE_SEARCH;
84 if(GlobalTopLevelExceptionFilter
!= NULL
) {
85 dbgRet
= GlobalTopLevelExceptionFilter(ExceptionInfo
);
86 if(dbgRet
== EXCEPTION_EXECUTE_HANDLER
)
87 return EXCEPTION_EXECUTE_HANDLER
;
88 else if(dbgRet
== EXCEPTION_CONTINUE_EXECUTION
)
89 return EXCEPTION_CONTINUE_EXECUTION
;
94 //if ( GetErrorMode() & SEM_NOGPFAULTERRORBOX == SEM_NOGPFAULTERRORBOX ) {
95 // produce a stack trace or pop a message
96 //sprintf( message, "Unhandled exception 0x%08lx at address 0x%08lx.",
97 // ExceptionInfo->ExceptionRecord->ExceptionCode,
98 // (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress );
99 //MessageBoxA( 0, message, "Error", MB_OK | MB_ICONHAND );
102 // Returning EXCEPTION_EXECUTE_HANDLER means that the code in
103 // the __execept block will be executed. Normally this will end up in a
104 // Terminate process.
106 return EXCEPTION_EXECUTE_HANDLER
;
117 DWORD dwExceptionCode
,
118 DWORD dwExceptionFlags
,
119 DWORD nNumberOfArguments
,
120 CONST DWORD
* lpArguments OPTIONAL
123 EXCEPTION_RECORD ExceptionRecord
;
125 /* Do NOT normalize dwExceptionCode: it will be done in
126 * NTDLL.RtlRaiseException().
128 ExceptionRecord
.ExceptionCode
= dwExceptionCode
;
129 ExceptionRecord
.ExceptionRecord
= NULL
;
130 ExceptionRecord
.ExceptionAddress
= (PVOID
) RaiseException
;
132 * Normalize dwExceptionFlags.
134 ExceptionRecord
.ExceptionFlags
= (dwExceptionFlags
& EXCEPTION_NONCONTINUABLE
);
136 * Normalize nNumberOfArguments.
138 if (EXCEPTION_MAXIMUM_PARAMETERS
< nNumberOfArguments
)
140 nNumberOfArguments
= EXCEPTION_MAXIMUM_PARAMETERS
;
143 * If the exception has no argument,
144 * or it is a non-continuable exception,
145 * ignore nNumberOfArguments and lpArguments.
147 if ((NULL
== lpArguments
) || ExceptionRecord
.ExceptionFlags
)
149 ExceptionRecord
.NumberParameters
= 0;
153 ExceptionRecord
.NumberParameters
= nNumberOfArguments
;
154 for ( nNumberOfArguments
= 0;
155 (nNumberOfArguments
< ExceptionRecord
.NumberParameters
);
156 nNumberOfArguments
++
159 ExceptionRecord
.ExceptionInformation
[nNumberOfArguments
]
163 RtlRaiseException (& ExceptionRecord
);