2002-09-08 10:23:54 +00:00
|
|
|
/* $Id: except.c,v 1.9 2002/09/08 10:22:41 chorns Exp $
|
2000-06-03 14:47:33 +00:00
|
|
|
*
|
1998-12-04 18:28:13 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/kernel32/misc/except.c
|
|
|
|
* PURPOSE: Exception functions
|
|
|
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
1999-10-07 23:46:27 +00:00
|
|
|
* modified from WINE [ Onno Hovers, (onno@stack.urc.tue.nl) ]
|
1998-12-04 18:28:13 +00:00
|
|
|
* UPDATE HISTORY:
|
|
|
|
* Created 01/11/98
|
|
|
|
*/
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
#include <ddk/ntddk.h>
|
1999-10-07 23:46:27 +00:00
|
|
|
#include <windows.h>
|
2002-09-08 10:23:54 +00:00
|
|
|
|
2000-06-03 14:47:33 +00:00
|
|
|
#include <kernel32/error.h>
|
1998-12-04 18:28:13 +00:00
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
typedef LONG (STDCALL *LPTOP_LEVEL_EXCEPTION_FILTER)(
|
|
|
|
struct _EXCEPTION_POINTERS *ExceptionInfo
|
|
|
|
);
|
|
|
|
|
1998-12-04 18:28:13 +00:00
|
|
|
UINT GlobalErrMode;
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER GlobalTopLevelExceptionFilter;
|
|
|
|
|
|
|
|
UINT GetErrorMode(void);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UINT GetErrorMode(void)
|
|
|
|
{
|
|
|
|
return GlobalErrMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT
|
|
|
|
STDCALL
|
|
|
|
SetErrorMode( UINT uMode )
|
|
|
|
{
|
|
|
|
UINT OldErrMode = GetErrorMode();
|
|
|
|
GlobalErrMode = uMode;
|
|
|
|
return OldErrMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER
|
|
|
|
STDCALL
|
|
|
|
SetUnhandledExceptionFilter(
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER OldTopLevelExceptionFilter =
|
|
|
|
GlobalTopLevelExceptionFilter;
|
|
|
|
lpTopLevelExceptionFilter = GlobalTopLevelExceptionFilter;
|
|
|
|
return OldTopLevelExceptionFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-07 23:46:27 +00:00
|
|
|
LONG
|
1998-12-04 18:28:13 +00:00
|
|
|
STDCALL
|
|
|
|
UnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo)
|
|
|
|
{
|
|
|
|
DWORD dbgRet;
|
|
|
|
HANDLE DebugPort;
|
|
|
|
NTSTATUS errCode;
|
|
|
|
|
|
|
|
if(ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION) {
|
|
|
|
// might check read only resource
|
|
|
|
// Is there a debugger running ?
|
|
|
|
errCode = NtQueryInformationProcess(NtCurrentProcess(),ProcessDebugPort,&DebugPort,sizeof(HANDLE),NULL);
|
1999-10-07 23:46:27 +00:00
|
|
|
if ( !NT_SUCCESS(errCode) ) {
|
2000-06-03 14:47:33 +00:00
|
|
|
SetLastErrorByStatus(errCode);
|
1998-12-04 18:28:13 +00:00
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
|
|
|
if ( DebugPort ) {
|
|
|
|
//return EXCEPTION_CONTINUE_SEARCH;
|
1999-10-07 23:46:27 +00:00
|
|
|
}
|
|
|
|
if(GlobalTopLevelExceptionFilter != NULL) {
|
1998-12-04 18:28:13 +00:00
|
|
|
dbgRet = GlobalTopLevelExceptionFilter(ExceptionInfo);
|
|
|
|
if(dbgRet == EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
else if(dbgRet == EXCEPTION_CONTINUE_EXECUTION)
|
|
|
|
return EXCEPTION_CONTINUE_EXECUTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
1999-10-07 23:46:27 +00:00
|
|
|
|
1998-12-04 18:28:13 +00:00
|
|
|
//if ( GetErrorMode() & SEM_NOGPFAULTERRORBOX == SEM_NOGPFAULTERRORBOX ) {
|
|
|
|
// produce a stack trace or pop a message
|
|
|
|
//sprintf( message, "Unhandled exception 0x%08lx at address 0x%08lx.",
|
|
|
|
// ExceptionInfo->ExceptionRecord->ExceptionCode,
|
|
|
|
// (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress );
|
|
|
|
//MessageBoxA( 0, message, "Error", MB_OK | MB_ICONHAND );
|
|
|
|
|
|
|
|
//}
|
|
|
|
// Returning EXCEPTION_EXECUTE_HANDLER means that the code in
|
|
|
|
// the __execept block will be executed. Normally this will end up in a
|
|
|
|
// Terminate process.
|
|
|
|
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
|
|
|
|
}
|
2000-06-03 14:47:33 +00:00
|
|
|
|
2001-03-31 01:17:30 +00:00
|
|
|
VOID
|
|
|
|
STDCALL
|
|
|
|
RaiseException (
|
|
|
|
DWORD dwExceptionCode,
|
|
|
|
DWORD dwExceptionFlags,
|
|
|
|
DWORD nNumberOfArguments,
|
2001-08-03 17:39:09 +00:00
|
|
|
CONST DWORD * lpArguments OPTIONAL
|
2001-03-31 01:17:30 +00:00
|
|
|
)
|
|
|
|
{
|
2001-08-03 17:39:09 +00:00
|
|
|
EXCEPTION_RECORD ExceptionRecord;
|
|
|
|
|
|
|
|
/* Do NOT normalize dwExceptionCode: it will be done in
|
|
|
|
* NTDLL.RtlRaiseException().
|
|
|
|
*/
|
|
|
|
ExceptionRecord.ExceptionCode = dwExceptionCode;
|
|
|
|
ExceptionRecord.ExceptionRecord = NULL;
|
|
|
|
ExceptionRecord.ExceptionAddress = (PVOID) RaiseException;
|
|
|
|
/*
|
|
|
|
* Normalize dwExceptionFlags.
|
|
|
|
*/
|
|
|
|
ExceptionRecord.ExceptionFlags = (dwExceptionFlags & EXCEPTION_NONCONTINUABLE);
|
|
|
|
/*
|
|
|
|
* Normalize nNumberOfArguments.
|
|
|
|
*/
|
|
|
|
if (EXCEPTION_MAXIMUM_PARAMETERS < nNumberOfArguments)
|
|
|
|
{
|
|
|
|
nNumberOfArguments = EXCEPTION_MAXIMUM_PARAMETERS;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the exception has no argument,
|
|
|
|
* or it is a non-continuable exception,
|
|
|
|
* ignore nNumberOfArguments and lpArguments.
|
|
|
|
*/
|
|
|
|
if ((NULL == lpArguments) || ExceptionRecord.ExceptionFlags)
|
|
|
|
{
|
|
|
|
ExceptionRecord.NumberParameters = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ExceptionRecord.NumberParameters = nNumberOfArguments;
|
|
|
|
for ( nNumberOfArguments = 0;
|
|
|
|
(nNumberOfArguments < ExceptionRecord.NumberParameters);
|
|
|
|
nNumberOfArguments ++
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ExceptionRecord.ExceptionInformation [nNumberOfArguments]
|
|
|
|
= *lpArguments ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RtlRaiseException (& ExceptionRecord);
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2000-06-03 14:47:33 +00:00
|
|
|
/* EOF */
|