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)
34 SetErrorMode( UINT uMode )
36 UINT OldErrMode = GetErrorMode();
37 GlobalErrMode = uMode;
41 LPTOP_LEVEL_EXCEPTION_FILTER
43 SetUnhandledExceptionFilter(
44 LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
47 LPTOP_LEVEL_EXCEPTION_FILTER OldTopLevelExceptionFilter =
48 GlobalTopLevelExceptionFilter;
49 lpTopLevelExceptionFilter = GlobalTopLevelExceptionFilter;
50 return OldTopLevelExceptionFilter;
56 UnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo)
62 if(ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION) {
63 // might check read only resource
64 // Is there a debugger running ?
65 errCode = NtQueryInformationProcess(NtCurrentProcess(),ProcessDebugPort,&DebugPort,sizeof(HANDLE),NULL);
66 if ( !NT_SUCCESS(errCode) ) {
67 SetLastErrorByStatus(errCode);
68 return EXCEPTION_EXECUTE_HANDLER;
71 //return EXCEPTION_CONTINUE_SEARCH;
73 if(GlobalTopLevelExceptionFilter != NULL) {
74 dbgRet = GlobalTopLevelExceptionFilter(ExceptionInfo);
75 if(dbgRet == EXCEPTION_EXECUTE_HANDLER)
76 return EXCEPTION_EXECUTE_HANDLER;
77 else if(dbgRet == EXCEPTION_CONTINUE_EXECUTION)
78 return EXCEPTION_CONTINUE_EXECUTION;
83 //if ( GetErrorMode() & SEM_NOGPFAULTERRORBOX == SEM_NOGPFAULTERRORBOX ) {
84 // produce a stack trace or pop a message
85 //sprintf( message, "Unhandled exception 0x%08lx at address 0x%08lx.",
86 // ExceptionInfo->ExceptionRecord->ExceptionCode,
87 // (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress );
88 //MessageBoxA( 0, message, "Error", MB_OK | MB_ICONHAND );
91 // Returning EXCEPTION_EXECUTE_HANDLER means that the code in
92 // the __execept block will be executed. Normally this will end up in a
95 return EXCEPTION_EXECUTE_HANDLER;
102 DWORD dwExceptionCode,
103 DWORD dwExceptionFlags,
104 DWORD nNumberOfArguments,
105 CONST DWORD * lpArguments OPTIONAL
108 EXCEPTION_RECORD ExceptionRecord;
110 /* Do NOT normalize dwExceptionCode: it will be done in
111 * NTDLL.RtlRaiseException().
113 ExceptionRecord.ExceptionCode = dwExceptionCode;
114 ExceptionRecord.ExceptionRecord = NULL;
115 ExceptionRecord.ExceptionAddress = (PVOID) RaiseException;
117 * Normalize dwExceptionFlags.
119 ExceptionRecord.ExceptionFlags = (dwExceptionFlags & EXCEPTION_NONCONTINUABLE);
121 * Normalize nNumberOfArguments.
123 if (EXCEPTION_MAXIMUM_PARAMETERS < nNumberOfArguments)
125 nNumberOfArguments = EXCEPTION_MAXIMUM_PARAMETERS;
128 * If the exception has no argument,
129 * or it is a non-continuable exception,
130 * ignore nNumberOfArguments and lpArguments.
132 if ((NULL == lpArguments) || ExceptionRecord.ExceptionFlags)
134 ExceptionRecord.NumberParameters = 0;
138 ExceptionRecord.NumberParameters = nNumberOfArguments;
139 for ( nNumberOfArguments = 0;
140 (nNumberOfArguments < ExceptionRecord.NumberParameters);
141 nNumberOfArguments ++
144 ExceptionRecord.ExceptionInformation [nNumberOfArguments]
148 RtlRaiseException (& ExceptionRecord);