2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
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
|
|
|
|
*/
|
|
|
|
|
2003-01-15 21:24:36 +00:00
|
|
|
#include <k32.h>
|
2002-09-08 10:23:54 +00:00
|
|
|
|
2004-07-07 16:32:02 +00:00
|
|
|
#define NDEBUG
|
2007-09-02 19:42:22 +00:00
|
|
|
#include <debug.h>
|
2004-07-07 16:32:02 +00:00
|
|
|
|
2007-12-20 15:41:24 +00:00
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER GlobalTopLevelExceptionFilter = NULL;
|
2011-07-20 15:54:21 +00:00
|
|
|
DWORD g_dwLastErrorToBreakOn;
|
1998-12-04 18:28:13 +00:00
|
|
|
|
2004-07-07 16:32:02 +00:00
|
|
|
/*
|
|
|
|
* Private helper function to lookup the module name from a given address.
|
|
|
|
* The address can point to anywhere within the module.
|
|
|
|
*/
|
|
|
|
static const char*
|
2005-05-09 01:46:57 +00:00
|
|
|
_module_name_from_addr(const void* addr, void **module_start_addr,
|
2005-03-07 16:37:49 +00:00
|
|
|
char* psz, size_t nChars)
|
2004-07-07 16:32:02 +00:00
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
if (VirtualQuery(addr, &mbi, sizeof(mbi)) != sizeof(mbi) ||
|
|
|
|
!GetModuleFileNameA((HMODULE)mbi.AllocationBase, psz, nChars))
|
|
|
|
{
|
|
|
|
psz[0] = '\0';
|
2005-03-07 16:37:49 +00:00
|
|
|
*module_start_addr = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*module_start_addr = (void *)mbi.AllocationBase;
|
2004-07-07 16:32:02 +00:00
|
|
|
}
|
|
|
|
return psz;
|
|
|
|
}
|
|
|
|
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
|
2004-09-26 16:54:53 +00:00
|
|
|
static VOID
|
|
|
|
_dump_context(PCONTEXT pc)
|
|
|
|
{
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
#ifdef _M_IX86
|
2004-09-26 16:54:53 +00:00
|
|
|
/*
|
|
|
|
* Print out the CPU registers
|
|
|
|
*/
|
|
|
|
DbgPrint("CS:EIP %x:%x\n", pc->SegCs&0xffff, pc->Eip );
|
|
|
|
DbgPrint("DS %x ES %x FS %x GS %x\n", pc->SegDs&0xffff, pc->SegEs&0xffff,
|
|
|
|
pc->SegFs&0xffff, pc->SegGs&0xfff);
|
|
|
|
DbgPrint("EAX: %.8x EBX: %.8x ECX: %.8x\n", pc->Eax, pc->Ebx, pc->Ecx);
|
|
|
|
DbgPrint("EDX: %.8x EBP: %.8x ESI: %.8x ESP: %.8x\n", pc->Edx,
|
|
|
|
pc->Ebp, pc->Esi, pc->Esp);
|
|
|
|
DbgPrint("EDI: %.8x EFLAGS: %.8x\n", pc->Edi, pc->EFlags);
|
2008-07-25 11:09:07 +00:00
|
|
|
#elif defined(_M_AMD64)
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
DbgPrint("CS:RIP %x:%I64x\n", pc->SegCs&0xffff, pc->Rip );
|
2008-07-25 11:09:07 +00:00
|
|
|
DbgPrint("DS %x ES %x FS %x GS %x\n", pc->SegDs&0xffff, pc->SegEs&0xffff,
|
|
|
|
pc->SegFs&0xffff, pc->SegGs&0xfff);
|
|
|
|
DbgPrint("RAX: %I64x RBX: %I64x RCX: %I64x RDI: %I64x\n", pc->Rax, pc->Rbx, pc->Rcx, pc->Rdi);
|
|
|
|
DbgPrint("RDX: %I64x RBP: %I64x RSI: %I64x RSP: %I64x\n", pc->Rdx, pc->Rbp, pc->Rsi, pc->Rsp);
|
|
|
|
DbgPrint("R8: %I64x R9: %I64x R10: %I64x R11: %I64x\n", pc->R8, pc->R9, pc->R10, pc->R11);
|
|
|
|
DbgPrint("R12: %I64x R13: %I64x R14: %I64x R15: %I64x\n", pc->R12, pc->R13, pc->R14, pc->R15);
|
|
|
|
DbgPrint("EFLAGS: %.8x\n", pc->EFlags);
|
2007-09-02 18:05:16 +00:00
|
|
|
#else
|
|
|
|
#warning Unknown architecture
|
|
|
|
#endif
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
}
|
2004-07-07 16:32:02 +00:00
|
|
|
|
2006-05-01 21:33:26 +00:00
|
|
|
static LONG
|
|
|
|
BasepCheckForReadOnlyResource(IN PVOID Ptr)
|
|
|
|
{
|
|
|
|
PVOID Data;
|
|
|
|
ULONG Size, OldProtect;
|
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
NTSTATUS Status;
|
|
|
|
LONG Ret = EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
|
|
|
/* Check if it was an attempt to write to a read-only image section! */
|
|
|
|
Status = NtQueryVirtualMemory(NtCurrentProcess(),
|
|
|
|
Ptr,
|
|
|
|
MemoryBasicInformation,
|
|
|
|
&mbi,
|
|
|
|
sizeof(mbi),
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS(Status) &&
|
|
|
|
mbi.Protect == PAGE_READONLY && mbi.Type == MEM_IMAGE)
|
|
|
|
{
|
|
|
|
/* Attempt to treat it as a resource section. We need to
|
|
|
|
use SEH here because we don't know if it's actually a
|
|
|
|
resource mapping */
|
|
|
|
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_TRY
|
2006-05-01 21:33:26 +00:00
|
|
|
{
|
|
|
|
Data = RtlImageDirectoryEntryToData(mbi.AllocationBase,
|
|
|
|
TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_RESOURCE,
|
|
|
|
&Size);
|
|
|
|
|
|
|
|
if (Data != NULL &&
|
|
|
|
(ULONG_PTR)Ptr >= (ULONG_PTR)Data &&
|
|
|
|
(ULONG_PTR)Ptr < (ULONG_PTR)Data + Size)
|
|
|
|
{
|
|
|
|
/* The user tried to write into the resources. Make the page
|
|
|
|
writable... */
|
|
|
|
Size = 1;
|
|
|
|
Status = NtProtectVirtualMemory(NtCurrentProcess(),
|
|
|
|
&Ptr,
|
|
|
|
&Size,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&OldProtect);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Ret = EXCEPTION_CONTINUE_EXECUTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-05-01 21:33:26 +00:00
|
|
|
{
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_END;
|
2006-05-01 21:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2010-03-02 18:16:21 +00:00
|
|
|
static VOID
|
|
|
|
PrintStackTrace(struct _EXCEPTION_POINTERS *ExceptionInfo)
|
|
|
|
{
|
|
|
|
PVOID StartAddr;
|
|
|
|
CHAR szMod[128] = "";
|
|
|
|
PEXCEPTION_RECORD ExceptionRecord = ExceptionInfo->ExceptionRecord;
|
|
|
|
PCONTEXT ContextRecord = ExceptionInfo->ContextRecord;
|
|
|
|
|
|
|
|
/* Print a stack trace. */
|
|
|
|
DbgPrint("Unhandled exception\n");
|
|
|
|
DbgPrint("ExceptionCode: %8x\n", ExceptionRecord->ExceptionCode);
|
|
|
|
|
|
|
|
if ((NTSTATUS)ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION &&
|
|
|
|
ExceptionRecord->NumberParameters == 2)
|
|
|
|
{
|
|
|
|
DbgPrint("Faulting Address: %8x\n", ExceptionRecord->ExceptionInformation[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
_dump_context (ContextRecord);
|
|
|
|
_module_name_from_addr(ExceptionRecord->ExceptionAddress, &StartAddr, szMod, sizeof(szMod));
|
|
|
|
DbgPrint("Address:\n %8x+%-8x %s\n",
|
|
|
|
(PVOID)StartAddr,
|
|
|
|
(ULONG_PTR)ExceptionRecord->ExceptionAddress - (ULONG_PTR)StartAddr,
|
|
|
|
szMod);
|
|
|
|
#ifdef _M_IX86
|
|
|
|
DbgPrint("Frames:\n");
|
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
PULONG Frame = (PULONG)ContextRecord->Ebp;
|
|
|
|
|
|
|
|
for (i = 0; Frame[1] != 0 && Frame[1] != 0xdeadbeef && i < 128; i++)
|
|
|
|
{
|
|
|
|
if (IsBadReadPtr((PVOID)Frame[1], 4))
|
|
|
|
{
|
|
|
|
DbgPrint(" %8x%9s %s\n", Frame[1], "<invalid address>"," ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_module_name_from_addr((const void*)Frame[1], &StartAddr,
|
|
|
|
szMod, sizeof(szMod));
|
|
|
|
DbgPrint(" %8x+%-8x %s\n",
|
|
|
|
(PVOID)StartAddr,
|
|
|
|
(ULONG_PTR)Frame[1] - (ULONG_PTR)StartAddr,
|
|
|
|
szMod);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsBadReadPtr((PVOID)Frame[0], sizeof(*Frame) * 2))
|
|
|
|
break;
|
|
|
|
|
|
|
|
Frame = (PULONG)Frame[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
DbgPrint("<error dumping stack trace: 0x%x>\n", _SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-07-20 15:54:21 +00:00
|
|
|
UINT
|
|
|
|
WINAPI
|
|
|
|
GetErrorMode(VOID)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
UINT ErrMode;
|
|
|
|
|
|
|
|
/* Query the current setting */
|
|
|
|
Status = NtQueryInformationProcess(NtCurrentProcess(),
|
|
|
|
ProcessDefaultHardErrorMode,
|
|
|
|
(PVOID)&ErrMode,
|
|
|
|
sizeof(ErrMode),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail if we couldn't query */
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if NOT failing critical errors was requested */
|
|
|
|
if (ErrMode & SEM_FAILCRITICALERRORS)
|
|
|
|
{
|
|
|
|
/* Mask it out, since the native API works differently */
|
|
|
|
ErrMode &= ~SEM_FAILCRITICALERRORS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* OR it if the caller didn't, due to different native semantics */
|
|
|
|
ErrMode |= SEM_FAILCRITICALERRORS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the mode */
|
|
|
|
return ErrMode;
|
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
2009-12-09 21:48:09 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2008-11-30 11:42:05 +00:00
|
|
|
LONG WINAPI
|
1998-12-04 18:28:13 +00:00
|
|
|
UnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo)
|
|
|
|
{
|
2006-05-01 21:33:26 +00:00
|
|
|
LONG RetValue;
|
2004-07-07 16:32:02 +00:00
|
|
|
HANDLE DebugPort = NULL;
|
|
|
|
NTSTATUS ErrCode;
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
ULONG_PTR ErrorParameters[4];
|
2007-12-20 15:41:24 +00:00
|
|
|
ULONG ErrorResponse;
|
2010-03-02 18:16:21 +00:00
|
|
|
PEXCEPTION_RECORD ExceptionRecord = ExceptionInfo->ExceptionRecord;
|
2004-07-07 16:32:02 +00:00
|
|
|
|
2010-03-02 18:16:21 +00:00
|
|
|
if ((NTSTATUS)ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION &&
|
|
|
|
ExceptionRecord->NumberParameters >= 2)
|
2004-07-07 16:32:02 +00:00
|
|
|
{
|
2010-03-02 18:16:21 +00:00
|
|
|
switch(ExceptionRecord->ExceptionInformation[0])
|
2007-11-28 13:27:42 +00:00
|
|
|
{
|
|
|
|
case EXCEPTION_WRITE_FAULT:
|
|
|
|
/* Change the protection on some write attempts, some InstallShield setups
|
|
|
|
have this bug */
|
|
|
|
RetValue = BasepCheckForReadOnlyResource(
|
2010-03-02 18:16:21 +00:00
|
|
|
(PVOID)ExceptionRecord->ExceptionInformation[1]);
|
2007-11-28 13:27:42 +00:00
|
|
|
if (RetValue == EXCEPTION_CONTINUE_EXECUTION)
|
|
|
|
return EXCEPTION_CONTINUE_EXECUTION;
|
|
|
|
break;
|
2007-12-20 15:41:24 +00:00
|
|
|
case EXCEPTION_EXECUTE_FAULT:
|
2007-11-28 13:27:42 +00:00
|
|
|
/* FIXME */
|
|
|
|
break;
|
|
|
|
}
|
2004-07-07 16:32:02 +00:00
|
|
|
}
|
|
|
|
|
2004-12-13 13:32:24 +00:00
|
|
|
/* Is there a debugger running ? */
|
|
|
|
ErrCode = NtQueryInformationProcess(NtCurrentProcess(), ProcessDebugPort,
|
|
|
|
&DebugPort, sizeof(HANDLE), NULL);
|
|
|
|
if (!NT_SUCCESS(ErrCode) && ErrCode != STATUS_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
SetLastErrorByStatus(ErrCode);
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DebugPort)
|
2004-07-07 16:32:02 +00:00
|
|
|
{
|
2004-12-13 13:32:24 +00:00
|
|
|
/* Pass the exception to debugger. */
|
|
|
|
DPRINT("Passing exception to debugger\n");
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
2004-07-07 16:32:02 +00:00
|
|
|
}
|
|
|
|
|
2007-11-28 13:27:42 +00:00
|
|
|
if (GlobalTopLevelExceptionFilter)
|
|
|
|
{
|
2010-03-02 18:16:21 +00:00
|
|
|
LONG ret = GlobalTopLevelExceptionFilter(ExceptionInfo);
|
2007-11-28 13:27:42 +00:00
|
|
|
if (ret != EXCEPTION_CONTINUE_SEARCH)
|
|
|
|
return ret;
|
|
|
|
}
|
2007-12-20 15:41:24 +00:00
|
|
|
|
2005-01-19 20:16:26 +00:00
|
|
|
if ((GetErrorMode() & SEM_NOGPFAULTERRORBOX) == 0)
|
2010-03-02 18:16:21 +00:00
|
|
|
PrintStackTrace(ExceptionInfo);
|
2004-07-07 16:32:02 +00:00
|
|
|
|
2007-12-20 15:41:24 +00:00
|
|
|
/* Save exception code and address */
|
2010-03-02 18:16:21 +00:00
|
|
|
ErrorParameters[0] = (ULONG)ExceptionRecord->ExceptionCode;
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
ErrorParameters[1] = (ULONG_PTR)ExceptionRecord->ExceptionAddress;
|
2007-12-20 15:41:24 +00:00
|
|
|
|
2010-03-02 18:16:21 +00:00
|
|
|
if ((NTSTATUS)ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION)
|
2007-12-20 15:41:24 +00:00
|
|
|
{
|
|
|
|
/* get the type of operation that caused the access violation */
|
2010-03-02 18:16:21 +00:00
|
|
|
ErrorParameters[2] = ExceptionRecord->ExceptionInformation[0];
|
2007-12-20 15:41:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-02 18:16:21 +00:00
|
|
|
ErrorParameters[2] = ExceptionRecord->ExceptionInformation[2];
|
2007-12-20 15:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save faulting address */
|
2010-03-02 18:16:21 +00:00
|
|
|
ErrorParameters[3] = ExceptionRecord->ExceptionInformation[1];
|
2007-12-20 15:41:24 +00:00
|
|
|
|
|
|
|
/* Raise the harderror */
|
|
|
|
ErrCode = NtRaiseHardError(STATUS_UNHANDLED_EXCEPTION | 0x10000000,
|
|
|
|
4, 0, ErrorParameters, OptionOkCancel, &ErrorResponse);
|
|
|
|
|
|
|
|
if (NT_SUCCESS(ErrCode) && (ErrorResponse == ResponseCancel))
|
|
|
|
{
|
|
|
|
/* FIXME: Check the result, if the "Cancel" button was
|
|
|
|
clicked run a debugger */
|
|
|
|
DPRINT1("Debugging is not implemented yet\n");
|
|
|
|
}
|
|
|
|
|
2004-07-07 16:32:02 +00:00
|
|
|
/*
|
2005-05-09 01:46:57 +00:00
|
|
|
* Returning EXCEPTION_EXECUTE_HANDLER means that the code in
|
2004-07-07 16:32:02 +00:00
|
|
|
* the __except block will be executed. Normally this will end up in a
|
|
|
|
* Terminate process.
|
|
|
|
*/
|
|
|
|
|
2005-05-09 01:46:57 +00:00
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
1998-12-04 18:28:13 +00:00
|
|
|
}
|
2000-06-03 14:47:33 +00:00
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2001-03-31 01:17:30 +00:00
|
|
|
VOID
|
2006-10-26 04:55:34 +00:00
|
|
|
WINAPI
|
|
|
|
RaiseException(IN DWORD dwExceptionCode,
|
|
|
|
IN DWORD dwExceptionFlags,
|
|
|
|
IN DWORD nNumberOfArguments,
|
|
|
|
IN CONST ULONG_PTR *lpArguments OPTIONAL)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2006-10-26 04:55:34 +00:00
|
|
|
EXCEPTION_RECORD ExceptionRecord;
|
|
|
|
|
|
|
|
/* Setup the exception record */
|
|
|
|
ExceptionRecord.ExceptionCode = dwExceptionCode;
|
|
|
|
ExceptionRecord.ExceptionRecord = NULL;
|
|
|
|
ExceptionRecord.ExceptionAddress = (PVOID)RaiseException;
|
|
|
|
ExceptionRecord.ExceptionFlags = dwExceptionFlags & EXCEPTION_NONCONTINUABLE;
|
|
|
|
|
|
|
|
/* Check if we have arguments */
|
|
|
|
if (!lpArguments)
|
|
|
|
{
|
|
|
|
/* We don't */
|
|
|
|
ExceptionRecord.NumberParameters = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We do, normalize the count */
|
|
|
|
if (nNumberOfArguments > EXCEPTION_MAXIMUM_PARAMETERS)
|
|
|
|
{
|
|
|
|
nNumberOfArguments = EXCEPTION_MAXIMUM_PARAMETERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the count of parameters */
|
|
|
|
ExceptionRecord.NumberParameters = nNumberOfArguments;
|
|
|
|
|
|
|
|
/* Loop each parameter */
|
|
|
|
for (nNumberOfArguments = 0;
|
|
|
|
(nNumberOfArguments < ExceptionRecord.NumberParameters);
|
|
|
|
nNumberOfArguments ++)
|
|
|
|
{
|
|
|
|
/* Copy the exception information */
|
|
|
|
ExceptionRecord.ExceptionInformation[nNumberOfArguments] =
|
|
|
|
*lpArguments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 10:16:14 +00:00
|
|
|
if (dwExceptionCode == 0xeedface || dwExceptionCode == 0xeedfade)
|
2008-01-21 11:02:14 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Delphi Exception at address: %p\n", ExceptionRecord.ExceptionInformation[0]);
|
|
|
|
DPRINT1("Exception-Object: %p\n", ExceptionRecord.ExceptionInformation[1]);
|
2009-10-19 21:42:27 +00:00
|
|
|
DPRINT1("Exception text: %s\n", ExceptionRecord.ExceptionInformation[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trace the wine special error and show the modulename and functionname */
|
|
|
|
if (dwExceptionCode == 0x80000100 /*EXCEPTION_WINE_STUB*/)
|
|
|
|
{
|
|
|
|
/* Numbers of parameter must be equal to two */
|
|
|
|
if (ExceptionRecord.NumberParameters == 2)
|
|
|
|
{
|
|
|
|
DPRINT1("Missing function in : %s\n", ExceptionRecord.ExceptionInformation[0]);
|
|
|
|
DPRINT1("with the functionname : %s\n", ExceptionRecord.ExceptionInformation[1]);
|
|
|
|
}
|
2008-01-21 11:02:14 +00:00
|
|
|
}
|
|
|
|
|
2006-10-26 04:55:34 +00:00
|
|
|
/* Raise the exception */
|
|
|
|
RtlRaiseException(&ExceptionRecord);
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 15:54:21 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
UINT
|
|
|
|
WINAPI
|
|
|
|
SetErrorMode(IN UINT uMode)
|
|
|
|
{
|
|
|
|
UINT PrevErrMode, NewMode;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Get the previous mode */
|
|
|
|
PrevErrMode = GetErrorMode();
|
|
|
|
NewMode = uMode;
|
|
|
|
|
|
|
|
/* Check if failing critical errors was requested */
|
|
|
|
if (NewMode & SEM_FAILCRITICALERRORS)
|
|
|
|
{
|
|
|
|
/* Mask it out, since the native API works differently */
|
|
|
|
NewMode &= ~SEM_FAILCRITICALERRORS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* OR it if the caller didn't, due to different native semantics */
|
|
|
|
NewMode |= SEM_FAILCRITICALERRORS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the new mode */
|
|
|
|
Status = NtSetInformationProcess(NtCurrentProcess(),
|
|
|
|
ProcessDefaultHardErrorMode,
|
|
|
|
(PVOID)&NewMode,
|
|
|
|
sizeof(NewMode));
|
|
|
|
if(!NT_SUCCESS(Status)) SetLastErrorByStatus(Status);
|
|
|
|
|
|
|
|
/* Return the previous mode */
|
|
|
|
return PrevErrMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER
|
|
|
|
WINAPI
|
|
|
|
SetUnhandledExceptionFilter(
|
|
|
|
IN LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
|
|
|
|
{
|
|
|
|
return InterlockedExchangePointer(&GlobalTopLevelExceptionFilter,
|
|
|
|
lpTopLevelExceptionFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
IsBadReadPtr(IN LPCVOID lp,
|
|
|
|
IN UINT_PTR ucb)
|
|
|
|
{
|
|
|
|
ULONG PageSize;
|
|
|
|
BOOLEAN Result = FALSE;
|
|
|
|
volatile CHAR *Current;
|
|
|
|
PCHAR Last;
|
|
|
|
|
|
|
|
/* Quick cases */
|
|
|
|
if (!ucb) return FALSE;
|
|
|
|
if (!lp) return TRUE;
|
|
|
|
|
|
|
|
/* Get the page size */
|
|
|
|
PageSize = BaseCachedSysInfo.PageSize;
|
|
|
|
|
|
|
|
/* Calculate the last page */
|
|
|
|
Last = (PCHAR)((ULONG_PTR)lp + ucb - 1);
|
|
|
|
|
|
|
|
/* Another quick failure case */
|
|
|
|
if ((ULONG_PTR)Last < (ULONG_PTR)lp) return TRUE;
|
|
|
|
|
|
|
|
/* Enter SEH */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Probe the entire range */
|
|
|
|
Current = (volatile CHAR*)lp;
|
|
|
|
Last = (PCHAR)(PAGE_ROUND_DOWN(Last));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*Current;
|
|
|
|
Current = (volatile CHAR*)(PAGE_ROUND_DOWN(Current) + PAGE_SIZE);
|
|
|
|
} while (Current <= Last);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* We hit an exception, so return true */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
|
|
|
_SEH2_END
|
|
|
|
|
|
|
|
/* Return exception status */
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
NTAPI
|
|
|
|
IsBadHugeReadPtr(LPCVOID lp,
|
|
|
|
UINT_PTR ucb)
|
|
|
|
{
|
|
|
|
/* Implementation is the same on 32-bit */
|
|
|
|
return IsBadReadPtr(lp, ucb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
NTAPI
|
|
|
|
IsBadCodePtr(FARPROC lpfn)
|
|
|
|
{
|
|
|
|
/* Executing has the same privileges as reading */
|
|
|
|
return IsBadReadPtr((LPVOID)lpfn, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
NTAPI
|
|
|
|
IsBadWritePtr(LPVOID lp,
|
|
|
|
UINT_PTR ucb)
|
|
|
|
{
|
|
|
|
ULONG PageSize;
|
|
|
|
BOOLEAN Result = FALSE;
|
|
|
|
volatile CHAR *Current;
|
|
|
|
PCHAR Last;
|
|
|
|
|
|
|
|
/* Quick cases */
|
|
|
|
if (!ucb) return FALSE;
|
|
|
|
if (!lp) return TRUE;
|
|
|
|
|
|
|
|
/* Get the page size */
|
|
|
|
PageSize = BaseCachedSysInfo.PageSize;
|
|
|
|
|
|
|
|
/* Calculate the last page */
|
|
|
|
Last = (PCHAR)((ULONG_PTR)lp + ucb - 1);
|
|
|
|
|
|
|
|
/* Another quick failure case */
|
|
|
|
if ((ULONG_PTR)Last < (ULONG_PTR)lp) return TRUE;
|
|
|
|
|
|
|
|
/* Enter SEH */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Probe the entire range */
|
|
|
|
Current = (volatile CHAR*)lp;
|
|
|
|
Last = (PCHAR)(PAGE_ROUND_DOWN(Last));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*Current = *Current;
|
|
|
|
Current = (volatile CHAR*)(PAGE_ROUND_DOWN(Current) + PAGE_SIZE);
|
|
|
|
} while (Current <= Last);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* We hit an exception, so return true */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
|
|
|
_SEH2_END
|
|
|
|
|
|
|
|
/* Return exception status */
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
NTAPI
|
|
|
|
IsBadHugeWritePtr(LPVOID lp,
|
|
|
|
UINT_PTR ucb)
|
|
|
|
{
|
|
|
|
/* Implementation is the same on 32-bit */
|
|
|
|
return IsBadWritePtr(lp, ucb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
NTAPI
|
|
|
|
IsBadStringPtrW(IN LPCWSTR lpsz,
|
|
|
|
UINT_PTR ucchMax)
|
|
|
|
{
|
|
|
|
BOOLEAN Result = FALSE;
|
|
|
|
volatile WCHAR *Current;
|
|
|
|
PWCHAR Last;
|
|
|
|
WCHAR Char;
|
|
|
|
|
|
|
|
/* Quick cases */
|
|
|
|
if (!ucchMax) return FALSE;
|
|
|
|
if (!lpsz) return TRUE;
|
|
|
|
|
|
|
|
/* Calculate the last page */
|
|
|
|
Last = (PWCHAR)((ULONG_PTR)lpsz + (ucchMax * 2) - 2);
|
|
|
|
|
|
|
|
/* Enter SEH */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Probe the entire range */
|
|
|
|
Current = (volatile WCHAR*)lpsz;
|
|
|
|
Last = (PWCHAR)(PAGE_ROUND_DOWN(Last));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Char = *Current;
|
|
|
|
Current++;
|
|
|
|
} while (Char && (Current != Last + 1));
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* We hit an exception, so return true */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
|
|
|
_SEH2_END
|
|
|
|
|
|
|
|
/* Return exception status */
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
NTAPI
|
|
|
|
IsBadStringPtrA(IN LPCSTR lpsz,
|
|
|
|
UINT_PTR ucchMax)
|
|
|
|
{
|
|
|
|
BOOLEAN Result = FALSE;
|
|
|
|
volatile CHAR *Current;
|
|
|
|
PCHAR Last;
|
|
|
|
CHAR Char;
|
|
|
|
|
|
|
|
/* Quick cases */
|
|
|
|
if (!ucchMax) return FALSE;
|
|
|
|
if (!lpsz) return TRUE;
|
|
|
|
|
|
|
|
/* Calculate the last page */
|
|
|
|
Last = (PCHAR)((ULONG_PTR)lpsz + ucchMax - 1);
|
|
|
|
|
|
|
|
/* Enter SEH */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Probe the entire range */
|
|
|
|
Current = (volatile CHAR*)lpsz;
|
|
|
|
Last = (PCHAR)(PAGE_ROUND_DOWN(Last));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Char = *Current;
|
|
|
|
Current++;
|
|
|
|
} while (Char && (Current != Last + 1));
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* We hit an exception, so return true */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
|
|
|
_SEH2_END
|
|
|
|
|
|
|
|
/* Return exception status */
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
WINAPI
|
2011-07-23 18:48:32 +00:00
|
|
|
SetLastError(IN DWORD dwErrCode)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 18:48:32 +00:00
|
|
|
/* Break if a debugger requested checking for this error code */
|
|
|
|
if ((g_dwLastErrorToBreakOn) && (g_dwLastErrorToBreakOn == dwErrCode)) DbgBreakPoint();
|
2011-07-20 15:54:21 +00:00
|
|
|
|
2011-07-23 18:48:32 +00:00
|
|
|
/* Set last error if it's a new error */
|
|
|
|
if (NtCurrentTeb()->LastErrorValue != dwErrCode) NtCurrentTeb()->LastErrorValue = dwErrCode;
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
WINAPI
|
2011-07-23 18:48:32 +00:00
|
|
|
BaseSetLastNTError(IN NTSTATUS Status)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 18:48:32 +00:00
|
|
|
/* Convert from NT to Win32, then set */
|
2011-07-20 15:54:21 +00:00
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2011-07-23 18:48:32 +00:00
|
|
|
GetLastError(VOID)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 18:48:32 +00:00
|
|
|
/* Return the current value */
|
2011-07-20 15:54:21 +00:00
|
|
|
return NtCurrentTeb()->LastErrorValue;
|
|
|
|
}
|
|
|
|
|
2000-06-03 14:47:33 +00:00
|
|
|
/* EOF */
|