wine/win32/except.c
Alexandre Julliard 8cc3a5e4d4 Release 960811
Sun Aug 11 13:00:20 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [configure.in] [include/acconfig.h] [tools/build.c]
	Added check for underscore on external symbols.

	* [memory/selector.c] [memory/global.c]
	Fixed FreeSelector() to free only one selector.
	Added SELECTOR_FreeBlock() to free an array of selectors.

	* [objects/color.c]
	Fixed a bug in COLOR_ToLogical() that caused GetPixel() to fail on
	hi-color displays.

	* [tools/build.c] [if1632/crtdll.spec]
	Added 'extern' type, used for external variables or functions.

	* [windows/winpos.c]
	Allow de-activating a window in WINPOS_ChangeActiveWindow().

	* [windows/winproc.c]
	Added 32-to-16 translation for button messages.
	Fixed WINPROC_GetPtr() to avoid crashes on 32-bit procedures that
	happen to be valid SEGPTRs.

Sat Aug 10 18:22:25 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [windows/message.c]
	Removed a FIXME in MSG_PeekHardwareMsg(): produces correct 
	data for the JOURNALRECORD-hook (using EVENTMSG16 structure).

	* [if1632/gdi.spec] [include/windows.h] [objects/metafile.c]
	Introduced undocumented API function IsValidMetaFile(), plus a
 	minor fix in last patch of CopyMetaFile().

	* [objects/gdiobj.c]
	Removed a FIXME in IsGDIObject(): added magic word check.

Sun Aug 10 18:10:10 1996  Bruce Milner <Bruce.Milner@genetics.utah.edu>

	* [controls/statuswin.c]
	First pass at implementing the StatusWindow class.

	* [include/commctrl.h]
	Header file for common controls.

	* [controls/widgets.c]
	Added InitCommonControls().

	* [if1632/comctl32.spec]
	Add DrawStatusTextA, CreateStatusWindowA, InitCommonControls.

	* [win32/findfile.c] [if1632/kernel32.spec]
	Add FindNextFile32A, FindClose.
	Modified FindFirstFile32A so it works with FindNextFile32A.

	* [include/winbase.h]
	Fixed WIN32_FIND_DATA structure member names.

Sat Aug 10 09:00:00 1996  Alex Korobka <alex@phm30.pharm.sunysb.edu>

	* [windows/scroll.c]
	Changed scrolling routines to benefit from DCE code update.

Thu Aug  8 18:05:09 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [files/file.c]
	SearchPath* could get NULL for lastpart argument.

	* [if1632/build-spec.txt] [documentation/debugging]
	Varargs documentation added, debugging hints updated.

	* [if1632/crtdll.spec][misc/crtdll.c][misc/Makefile.in]
	Started to implement CRTDLL.

	* [if1632/wsock32.spec]
	Some thunks to standard libc functions (structures have the same
 	elements, but perhaps wrong offset due to packing).

	* [include/kernel32.h][include/windows.h][win32/*.c][loader/main.c]
	Merged kernel32.h into windows.h.

	* [misc/lstr.c]
	Enhanced FormatMessage().

	* [misc/main.c] [if1632/kernel.spec] [include/windows.h]
	GetVersion() updated to new naming standard.
	Changed language handling to support language ids.

	* [misc/shell.c]
	Enhanced FindExecutable, so it finds files in the search path too.

	* [win32/environment.c]
	GetCommandLine* updated.

	* [loader/resource.c] [loader/pe_resource.c]
	FindResourceEx32* added.
	Loading of messagetables added.
	Language handling now uses Wine default language id.
1996-08-11 15:49:51 +00:00

216 lines
6.6 KiB
C

/*
* Win32 exception functions
*
* Copyright (c) 1996 Onno Hovers, (onno@stack.urc.tue.nl)
*
* Notes:
* What really happens behind the scenes of those new
* __try{...}__except(..){....} and
* __try{...}__finally{...}
* statements is simply not documented by Microsoft. There could be different
* reasons for this:
* One reason could be that they try to hide the fact that exception
* handling in Win32 looks almost the same as in OS/2 2.x.
* Another reason could be that Microsoft does not want others to write
* binary compatible implementations of the Win32 API (like us).
*
* Whatever the reason, THIS SUCKS!! Ensuring portabilty or future
* compatability may be valid reasons to keep some things undocumented.
* But exception handling is so basic to Win32 that it should be
* documented!
*
* Fixmes:
* -Most functions need better parameter checking.
* -I do not know how to handle exceptions within an exception handler.
* or what is done when ExceptionNestedException is returned from an
* exception handler
* -Real exceptions are not yet implemented. only the exception functions
* are implemented. A real implementation needs some new code in
* loader/signal.c. There would also be a need for showing debugging
* information in UnhandledExceptionFilter.
*
*/
#ifndef WINELIB
#include <stdio.h>
#include "windows.h"
#include "winerror.h"
#include "stddebug.h"
#include "debug.h"
#include "except.h"
LPTOP_LEVEL_EXCEPTION_FILTER pTopExcHandler = NULL;
void EXC_Init(void)
{
pTopExcHandler = (LPTOP_LEVEL_EXCEPTION_FILTER)GetProcAddress32(
GetModuleHandle("KERNEL32"),
"UnhandledExceptionFilter" );
}
/*
* EXC_RtlUnwind
*
* This function is undocumented. This is the general idea of
* RtlUnwind, though. Note that error handling is not yet implemented
*
*/
void EXC_RtlUnwind(PEXCEPTION_FRAME pEndFrame,LPVOID unusedEip,
PEXCEPTION_RECORD pRecord, DWORD returnEax,
PCONTEXT pcontext)
{
EXCEPTION_RECORD record;
DWORD dispatch;
int retval;
pcontext->Eax=returnEax;
/* build an exception record, if we do not have one */
if(!pRecord)
{
record.ExceptionCode= 0xC0000026; /* invalid disposition */
record.ExceptionFlags= 0;
record.ExceptionRecord= NULL;
record.ExceptionAddress=(LPVOID) pcontext->Eip;
record.NumberParameters= 0;
pRecord=&record;
}
if(pEndFrame)
pRecord->ExceptionFlags|=EH_UNWINDING;
else
pRecord->ExceptionFlags|=EH_UNWINDING | EH_EXIT_UNWIND;
/* get chain of exception frames */
while((TebExceptionFrame!=NULL)&&
(TebExceptionFrame!=((void *)-1)) &&
(TebExceptionFrame!=pEndFrame))
{
dprintf_win32(stddeb,"calling exception handler at 0x%x\n",
(int) TebExceptionFrame->Handler);
dispatch=0;
retval=TebExceptionFrame->Handler(pRecord, TebExceptionFrame,
pcontext, &dispatch);
dprintf_win32(stddeb,"exception handler returns 0x%x, dispatch=0x%x\n",
retval, (int) dispatch);
if(retval==ExceptionCollidedUnwind)
TebExceptionFrame=(LPVOID) dispatch;
else if(TebExceptionFrame!=pEndFrame)
TebExceptionFrame=TebExceptionFrame->Prev;
else
break;
}
}
/*
* EXC_RaiseException
*
*/
VOID EXC_RaiseException(DWORD dwExceptionCode,
DWORD dwExceptionFlags,
DWORD cArguments,
const LPDWORD lpArguments,
PCONTEXT pcontext)
{
PEXCEPTION_FRAME pframe;
EXCEPTION_RECORD record;
DWORD dispatch; /* is this used in raising exceptions ?? */
int retval;
int i;
/* compose an exception record */
record.ExceptionCode = dwExceptionCode;
record.ExceptionFlags = dwExceptionFlags;
record.ExceptionRecord = NULL;
record.NumberParameters = cArguments;
record.ExceptionAddress = (LPVOID) pcontext->Eip;
for(i=0;i<cArguments;i++)
record.ExceptionInformation[i]=lpArguments[i];
/* get chain of exception frames */
retval=ExceptionContinueSearch;
pframe=TebExceptionFrame;
while((pframe!=NULL)&&(pframe!=((void *)0xFFFFFFFF)))
{
dprintf_win32(stddeb,"calling exception handler at 0x%x\n",
(int) pframe->Handler);
dispatch=0;
retval=pframe->Handler(&record,pframe,pcontext,&dispatch);
dprintf_win32(stddeb,"exception handler returns 0x%x, dispatch=0x%x\n",
retval, (int) dispatch);
if(retval==ExceptionContinueExecution)
break;
pframe=pframe->Prev;
}
if(retval!=ExceptionContinueExecution)
{
retval=EXC_CallUnhandledExceptionFilter(&record,pcontext);
if(retval!=EXCEPTION_CONTINUE_EXECUTION)
{
dprintf_win32(stddeb,"no handler wanted to handle "
"the exception, exiting\n" );
ExitProcess(dwExceptionCode); /* what status should be used here ? */
}
}
}
/*******************************************************************
* UnhandledExceptionFilter (KERNEL32.537)
*
* This is the unhandled exception code.
* Actually, this should show up a dialog box, with all kinds of
* fancy debugging information. It does nothing now!
*/
DWORD UnhandledExceptionFilter(PEXCEPTION_POINTERS epointers)
{
PEXCEPTION_RECORD pRecord;
PCONTEXT pContext;
pRecord=epointers->ExceptionRecord;
pContext=epointers->ContextRecord;
if(pRecord->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND) )
{
dprintf_win32(stddeb,"UnhandledExceptionFilter: exiting\n");
ExitProcess(pRecord->ExceptionCode);
}
else
{
RtlUnwind(0,pRecord,0,-1 );
}
/*
* This is just to avoid a warning, code should not get here
* if it does, EXC_RaiseException will terminate it.
*/
return EXCEPTION_CONTINUE_SEARCH;
}
/*************************************************************
* SetUnhandledExceptionFilter (KERNEL32.516)
*
*
*/
LPTOP_LEVEL_EXCEPTION_FILTER
SetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER efilter)
{
pTopExcHandler=efilter;
return efilter;
}
#endif /* WINELIB */