Create a branch for header work.

svn path=/branches/header-work/; revision=45691
This commit is contained in:
Timo Kreuzer 2010-02-26 22:57:55 +00:00
parent 14fe274b1c
commit 9ea495ba33
19538 changed files with 0 additions and 1063950 deletions

View file

@ -0,0 +1 @@
#include <precomp.h>

View file

@ -0,0 +1,31 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* PURPOSE: Implementation of _chkstk and _alloca_probe
* FILE: lib/sdk/crt/math/amd64/chkstk_asm.s
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include <ndk/amd64/asm.h>
#include <ndk/amd64/asmmacro.S>
.intel_syntax noprefix
.global _MsgUnimplemented
_MsgUnimplemented:
.asciz "WARNING: %s at %s:%d is UNIMPLEMENTED!\n"
.proc _chkstk
UNIMPLEMENTED chkstk
ret
.endproc
.proc _alloca_probe
UNIMPLEMENTED alloca_probe
ret
.endproc
/* EOF */

View file

@ -0,0 +1,56 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CRT
* FILE: lib/crt/misc/i386/seh.S
* PURPOSE: SEH Support for the CRT
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include <ndk/asm.h>
.intel_syntax noprefix
#define DISPOSITION_DISMISS 0
#define DISPOSITION_CONTINUE_SEARCH 1
#define DISPOSITION_COLLIDED_UNWIND 3
/* GLOBALS *******************************************************************/
.globl __global_unwind2
.globl __local_unwind2
.globl __abnormal_termination
.globl __except_handler2
.globl __except_handler3
/* FUNCTIONS *****************************************************************/
.func unwind_handler
_unwind_handler:
ret
.endfunc
.func _global_unwind2
__global_unwind2:
ret
.endfunc
.func _abnormal_termination
__abnormal_termination:
ret
.endfunc
.func _local_unwind2
__local_unwind2:
ret
.endfunc
.func _except_handler2
__except_handler2:
ret
.endfunc
.func _except_handler3
__except_handler3:
ret
.endfunc

View file

@ -0,0 +1,35 @@
/*********************************************************************
* _chkesp (MSVCRT.@)
*
* Trap to a debugger if the value of the stack pointer has changed.
*
* PARAMS
* None.
*
* RETURNS
* Does not return.
*
* NOTES
* This function is available for iX86 only.
*
* When VC++ generates debug code, it stores the value of the stack pointer
* before calling any external function, and checks the value following
* the call. It then calls this function, which will trap if the values are
* not the same. Usually this means that the prototype used to call
* the function is incorrect. It can also mean that the .spec entry has
* the wrong calling convention or parameters.
*/
#ifdef __i386__
void _chkesp(void)
{
}
#else
void _chkesp(void)
{
}
#endif /* __i386__ */

1184
lib/sdk/crt/except/cpp.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,480 @@
/*
* msvcrt C++ exception handling
*
* Copyright 2002 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* NOTES
* A good reference is the article "How a C++ compiler implements
* exception handling" by Vishal Kochhar, available on
* www.thecodeproject.com.
*/
#define __WINE_DEBUG_CHANNEL__
#include <precomp.h>
#include <stdarg.h>
#include <internal/wine/msvcrt.h>
#include <internal/wine/cppexcept.h>
#ifdef __i386__ /* CxxFrameHandler is not supported on non-i386 */
WINE_DEFAULT_DEBUG_CHANNEL(seh);
DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
const cxx_function_descr *descr,
EXCEPTION_REGISTRATION_RECORD* nested_frame, int nested_trylevel );
/* call a function with a given ebp */
static inline void *call_ebp_func( void *func, void *ebp )
{
void *ret;
int dummy;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"pushl %%ebp\n\t"
"movl %4,%%ebp\n\t"
"call *%%eax\n\t"
"popl %%ebp\n\t"
"popl %%ebx"
: "=a" (ret), "=S" (dummy), "=D" (dummy)
: "0" (func), "1" (ebp) : "ecx", "edx", "memory" );
return ret;
}
/* call a copy constructor */
static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase )
{
TRACE( "calling copy ctor %p object %p src %p\n", func, this, src );
if (has_vbase)
/* in that case copy ctor takes an extra bool indicating whether to copy the base class */
__asm__ __volatile__("pushl $1; pushl %2; call *%0"
: : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" );
else
__asm__ __volatile__("pushl %2; call *%0"
: : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" );
}
/* call the destructor of the exception object */
static inline void call_dtor( void *func, void *object )
{
__asm__ __volatile__("call *%0" : : "r" (func), "c" (object) : "eax", "edx", "memory" );
}
/* continue execution to the specified address after exception is caught */
static inline void DECLSPEC_NORETURN continue_after_catch( cxx_exception_frame* frame, void *addr )
{
__asm__ __volatile__("movl -4(%0),%%esp; leal 12(%0),%%ebp; jmp *%1"
: : "r" (frame), "a" (addr) );
for (;;) ; /* unreached */
}
static inline void dump_type( const cxx_type_info *type )
{
TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n",
type->flags, type->type_info, dbgstr_type_info(type->type_info),
type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset,
type->size, type->copy_ctor );
}
static void dump_exception_type( const cxx_exception_type *type )
{
UINT i;
TRACE( "flags %x destr %p handler %p type info %p\n",
type->flags, type->destructor, type->custom_handler, type->type_info_table );
for (i = 0; i < type->type_info_table->count; i++)
{
TRACE( " %d: ", i );
dump_type( type->type_info_table->info[i] );
}
}
static void dump_function_descr( const cxx_function_descr *descr )
{
#ifndef WINE_NO_TRACE_MSGS
UINT i;
int j;
TRACE( "magic %x\n", descr->magic );
TRACE( "unwind table: %p %d\n", descr->unwind_table, descr->unwind_count );
for (i = 0; i < descr->unwind_count; i++)
{
TRACE( " %d: prev %d func %p\n", i,
descr->unwind_table[i].prev, descr->unwind_table[i].handler );
}
TRACE( "try table: %p %d\n", descr->tryblock, descr->tryblock_count );
for (i = 0; i < descr->tryblock_count; i++)
{
TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i,
descr->tryblock[i].start_level, descr->tryblock[i].end_level,
descr->tryblock[i].catch_level, descr->tryblock[i].catchblock,
descr->tryblock[i].catchblock_count );
for (j = 0; j < descr->tryblock[i].catchblock_count; j++)
{
const catchblock_info *ptr = &descr->tryblock[i].catchblock[j];
TRACE( " %d: flags %x offset %d handler %p type %p %s\n",
j, ptr->flags, ptr->offset, ptr->handler,
ptr->type_info, dbgstr_type_info( ptr->type_info ) );
}
}
#endif
}
/* check if the exception type is caught by a given catch block, and return the type that matched */
static const cxx_type_info *find_caught_type( cxx_exception_type *exc_type,
const catchblock_info *catchblock )
{
UINT i;
for (i = 0; i < exc_type->type_info_table->count; i++)
{
const cxx_type_info *type = exc_type->type_info_table->info[i];
if (!catchblock->type_info) return type; /* catch(...) matches any type */
if (catchblock->type_info != type->type_info)
{
if (strcmp( catchblock->type_info->mangled, type->type_info->mangled )) continue;
}
/* type is the same, now check the flags */
if ((exc_type->flags & TYPE_FLAG_CONST) &&
!(catchblock->flags & TYPE_FLAG_CONST)) continue;
if ((exc_type->flags & TYPE_FLAG_VOLATILE) &&
!(catchblock->flags & TYPE_FLAG_VOLATILE)) continue;
return type; /* it matched */
}
return NULL;
}
/* copy the exception object where the catch block wants it */
static void copy_exception( void *object, cxx_exception_frame *frame,
const catchblock_info *catchblock, const cxx_type_info *type )
{
void **dest_ptr;
if (!catchblock->type_info || !catchblock->type_info->mangled[0]) return;
if (!catchblock->offset) return;
dest_ptr = (void **)((char *)&frame->ebp + catchblock->offset);
if (catchblock->flags & TYPE_FLAG_REFERENCE)
{
*dest_ptr = get_this_pointer( &type->offsets, object );
}
else if (type->flags & CLASS_IS_SIMPLE_TYPE)
{
memmove( dest_ptr, object, type->size );
/* if it is a pointer, adjust it */
if (type->size == sizeof(void *)) *dest_ptr = get_this_pointer( &type->offsets, *dest_ptr );
}
else /* copy the object */
{
if (type->copy_ctor)
call_copy_ctor( type->copy_ctor, dest_ptr, get_this_pointer(&type->offsets,object),
(type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) );
else
memmove( dest_ptr, get_this_pointer(&type->offsets,object), type->size );
}
}
/* unwind the local function up to a given trylevel */
static void cxx_local_unwind( cxx_exception_frame* frame, const cxx_function_descr *descr, int last_level)
{
void (*handler)();
int trylevel = frame->trylevel;
while (trylevel != last_level)
{
if (trylevel < 0 || trylevel >= descr->unwind_count)
{
ERR( "invalid trylevel %d\n", trylevel );
MSVCRT_terminate();
}
handler = descr->unwind_table[trylevel].handler;
if (handler)
{
TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n",
handler, trylevel, last_level, &frame->ebp );
call_ebp_func( handler, &frame->ebp );
}
trylevel = descr->unwind_table[trylevel].prev;
}
frame->trylevel = last_level;
}
/* exception frame for nested exceptions in catch block */
struct catch_func_nested_frame
{
EXCEPTION_REGISTRATION_RECORD frame; /* standard exception frame */
EXCEPTION_RECORD *prev_rec; /* previous record to restore in thread data */
cxx_exception_frame *cxx_frame; /* frame of parent exception */
const cxx_function_descr *descr; /* descriptor of parent exception */
int trylevel; /* current try level */
EXCEPTION_RECORD *rec; /* rec associated with frame */
};
/* handler for exceptions happening while calling a catch function */
static DWORD catch_function_nested_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
{
struct catch_func_nested_frame *nested_frame = (struct catch_func_nested_frame *)frame;
if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
{
msvcrt_get_thread_data()->exc_record = nested_frame->prev_rec;
return ExceptionContinueSearch;
}
TRACE( "got nested exception in catch function\n" );
if(rec->ExceptionCode == CXX_EXCEPTION)
{
PEXCEPTION_RECORD prev_rec = nested_frame->rec;
if(rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
{
/* exception was rethrown */
rec->ExceptionInformation[1] = prev_rec->ExceptionInformation[1];
rec->ExceptionInformation[2] = prev_rec->ExceptionInformation[2];
TRACE("detect rethrow: re-propagate: obj: %lx, type: %lx\n",
rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
}
else {
/* new exception in exception handler, destroy old */
void *object = (void*)prev_rec->ExceptionInformation[1];
cxx_exception_type *info = (cxx_exception_type*) prev_rec->ExceptionInformation[2];
TRACE("detect threw new exception in catch block - destroy old(obj: %p type: %p)\n",
object, info);
if(info && info->destructor)
call_dtor( info->destructor, object );
}
}
return cxx_frame_handler( rec, nested_frame->cxx_frame, context,
NULL, nested_frame->descr, &nested_frame->frame,
nested_frame->trylevel );
}
/* find and call the appropriate catch block for an exception */
/* returns the address to continue execution to after the catch block was called */
static inline void call_catch_block( PEXCEPTION_RECORD rec, cxx_exception_frame *frame,
const cxx_function_descr *descr, int nested_trylevel,
cxx_exception_type *info )
{
UINT i;
int j;
void *addr, *object = (void *)rec->ExceptionInformation[1];
struct catch_func_nested_frame nested_frame;
int trylevel = frame->trylevel;
MSVCRT_thread_data *thread_data = msvcrt_get_thread_data();
DWORD save_esp = ((DWORD*)frame)[-1];
for (i = 0; i < descr->tryblock_count; i++)
{
const tryblock_info *tryblock = &descr->tryblock[i];
if (trylevel < tryblock->start_level) continue;
if (trylevel > tryblock->end_level) continue;
/* got a try block */
for (j = 0; j < tryblock->catchblock_count; j++)
{
const catchblock_info *catchblock = &tryblock->catchblock[j];
if(info)
{
const cxx_type_info *type = find_caught_type( info, catchblock );
if (!type) continue;
TRACE( "matched type %p in tryblock %d catchblock %d\n", type, i, j );
/* copy the exception to its destination on the stack */
copy_exception( object, frame, catchblock, type );
}
else
{
/* no CXX_EXCEPTION only proceed with a catch(...) block*/
if(catchblock->type_info)
continue;
TRACE("found catch(...) block\n");
}
/* unwind the stack */
RtlUnwind( frame, 0, rec, 0 );
cxx_local_unwind( frame, descr, tryblock->start_level );
frame->trylevel = tryblock->end_level + 1;
/* call the catch block */
TRACE( "calling catch block %p addr %p ebp %p\n",
catchblock, catchblock->handler, &frame->ebp );
/* setup an exception block for nested exceptions */
nested_frame.frame.Handler = (PEXCEPTION_ROUTINE)catch_function_nested_handler;
nested_frame.prev_rec = thread_data->exc_record;
nested_frame.cxx_frame = frame;
nested_frame.descr = descr;
nested_frame.trylevel = nested_trylevel + 1;
nested_frame.rec = rec;
__wine_push_frame( &nested_frame.frame );
thread_data->exc_record = rec;
addr = call_ebp_func( catchblock->handler, &frame->ebp );
thread_data->exc_record = nested_frame.prev_rec;
__wine_pop_frame( &nested_frame.frame );
((DWORD*)frame)[-1] = save_esp;
if (info && info->destructor) call_dtor( info->destructor, object );
TRACE( "done, continuing at %p\n", addr );
continue_after_catch( frame, addr );
}
}
}
/*********************************************************************
* cxx_frame_handler
*
* Implementation of __CxxFrameHandler.
*/
DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
const cxx_function_descr *descr,
EXCEPTION_REGISTRATION_RECORD* nested_frame,
int nested_trylevel )
{
cxx_exception_type *exc_type;
if (descr->magic != CXX_FRAME_MAGIC)
{
ERR( "invalid frame magic %x\n", descr->magic );
return ExceptionContinueSearch;
}
if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND))
{
if (descr->unwind_count && !nested_trylevel) cxx_local_unwind( frame, descr, -1 );
return ExceptionContinueSearch;
}
if (!descr->tryblock_count) return ExceptionContinueSearch;
if(rec->ExceptionCode == CXX_EXCEPTION)
{
exc_type = (cxx_exception_type *)rec->ExceptionInformation[2];
if (rec->ExceptionInformation[0] > CXX_FRAME_MAGIC &&
exc_type->custom_handler)
{
return exc_type->custom_handler( rec, frame, context, dispatch,
descr, nested_trylevel, nested_frame, 0 );
}
if (TRACE_ON(seh))
{
TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n",
rec, frame, frame->trylevel, descr, nested_frame );
dump_exception_type( exc_type );
dump_function_descr( descr );
}
}
else
{
exc_type = NULL;
TRACE("handling C exception code %x rec %p frame %p trylevel %d descr %p nested_frame %p\n",
rec->ExceptionCode, rec, frame, frame->trylevel, descr, nested_frame );
}
call_catch_block( rec, frame, descr, frame->trylevel, exc_type );
return ExceptionContinueSearch;
}
/*********************************************************************
* __CxxFrameHandler (MSVCRT.@)
*/
extern DWORD CDECL __CxxFrameHandler( PEXCEPTION_RECORD rec, EXCEPTION_REGISTRATION_RECORD* frame,
PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch );
__ASM_GLOBAL_FUNC( __CxxFrameHandler,
"pushl $0\n\t" /* nested_trylevel */
"pushl $0\n\t" /* nested_frame */
"pushl %eax\n\t" /* descr */
"pushl 28(%esp)\n\t" /* dispatch */
"pushl 28(%esp)\n\t" /* context */
"pushl 28(%esp)\n\t" /* frame */
"pushl 28(%esp)\n\t" /* rec */
"call " __ASM_NAME("cxx_frame_handler") "\n\t"
"add $28,%esp\n\t"
"ret" )
/*********************************************************************
* __CxxLongjmpUnwind (MSVCRT.@)
*
* Callback meant to be used as UnwindFunc for setjmp/longjmp.
*/
void __stdcall __CxxLongjmpUnwind( const struct MSVCRT___JUMP_BUFFER *buf )
{
cxx_exception_frame *frame = (cxx_exception_frame *)buf->Registration;
const cxx_function_descr *descr = (const cxx_function_descr *)buf->UnwindData[0];
TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame, descr, buf->TryLevel );
cxx_local_unwind( frame, descr, buf->TryLevel );
}
#endif /* __i386__ */
/*********************************************************************
* _CxxThrowException (MSVCRT.@)
*/
void CDECL _CxxThrowException( exception *object, const cxx_exception_type *type )
{
ULONG_PTR args[3];
args[0] = CXX_FRAME_MAGIC;
args[1] = (ULONG_PTR)object;
args[2] = (ULONG_PTR)type;
RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 3, args );
}
/*********************************************************************
* __CxxDetectRethrow (MSVCRT.@)
*/
BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
{
PEXCEPTION_RECORD rec;
if (!ptrs)
return FALSE;
rec = ptrs->ExceptionRecord;
if (rec->ExceptionCode == CXX_EXCEPTION &&
rec->NumberParameters == 3 &&
rec->ExceptionInformation[0] == CXX_FRAME_MAGIC &&
rec->ExceptionInformation[2])
{
ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
return TRUE;
}
return (msvcrt_get_thread_data()->exc_record == rec);
}
/*********************************************************************
* __CxxQueryExceptionSize (MSVCRT.@)
*/
unsigned int CDECL __CxxQueryExceptionSize(void)
{
return sizeof(cxx_exception_type);
}

View file

@ -0,0 +1,66 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Stack checker
* FILE: lib/ntdll/rtl/i386/chkstk.s
* PROGRAMER: KJK::Hyperion <noog@libero.it>
*/
.globl __chkstk
.globl __alloca_probe
/*
_chkstk() is called by all stack allocations of more than 4 KB. It grows the
stack in areas of 4 KB each, trying to access each area. This ensures that the
guard page for the stack is hit, and the stack growing triggered
*/
__chkstk:
__alloca_probe:
/* EAX = size to be allocated */
/* save the ECX register */
pushl %ecx
/* ECX = top of the previous stack frame */
leal 8(%esp), %ecx
/* probe the desired memory, page by page */
cmpl $0x1000, %eax
jge .l_MoreThanAPage
jmp .l_LessThanAPage
.l_MoreThanAPage:
/* raise the top of the stack by a page and probe */
subl $0x1000, %ecx
testl %eax, 0(%ecx)
/* loop if still more than a page must be probed */
subl $0x1000, %eax
cmpl $0x1000, %eax
jge .l_MoreThanAPage
.l_LessThanAPage:
/* raise the top of the stack by EAX bytes (size % 4096) and probe */
subl %eax, %ecx
testl %eax, 0(%ecx)
/* EAX = top of the stack */
movl %esp, %eax
/* allocate the memory */
movl %ecx, %esp
/* restore ECX */
movl 0(%eax), %ecx
/* restore the return address */
movl 4(%eax), %eax
pushl %eax
/* return */
ret
/* EOF */

View file

@ -0,0 +1,27 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CRT
* FILE: lib/crt/misc/i386/prolog.s
* PURPOSE: SEH Support for the CRT
* PROGRAMMERS: Wine Development Team
*/
/* INCLUDES ******************************************************************/
#include <ndk/asm.h>
/* GLOBALS *******************************************************************/
.globl __EH_prolog
// Copied from Wine.
__EH_prolog:
pushl $-1
pushl %eax
pushl %fs:0
movl %esp, %fs:0
movl 12(%esp), %eax
movl %ebp, 12(%esp)
leal 12(%esp), %ebp
pushl %eax
ret

View file

@ -0,0 +1,440 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CRT
* FILE: lib/crt/misc/i386/seh.S
* PURPOSE: SEH Support for the CRT
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include <ndk/asm.h>
.intel_syntax noprefix
#define DISPOSITION_DISMISS 0
#define DISPOSITION_CONTINUE_SEARCH 1
#define DISPOSITION_COLLIDED_UNWIND 3
/* GLOBALS *******************************************************************/
.globl __global_unwind2
.globl __local_unwind2
.globl __abnormal_termination
.globl __except_handler2
.globl __except_handler3
/* FUNCTIONS *****************************************************************/
.func unwind_handler
_unwind_handler:
/* Check if we were unwinding and continue search if not */
mov ecx, [esp+4]
test dword ptr [ecx+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
mov eax, DISPOSITION_CONTINUE_SEARCH
jz unwind_handler_return
/* We have a collision, do a local unwind */
mov eax, [esp+20]
push ebp
mov ebp, [eax+16]
mov edx, [eax+40]
push edx
mov edx, [eax+36]
push edx
call __local_unwind2
add esp, 8
pop ebp
/* Set new try level */
mov eax, [esp+8]
mov edx, [esp+16]
mov [edx], eax
/* Return collided unwind */
mov eax, DISPOSITION_COLLIDED_UNWIND
unwind_handler_return:
ret
.endfunc
.func _global_unwind2
__global_unwind2:
/* Create stack and save all registers */
push ebp
mov ebp, esp
push ebx
push esi
push edi
push ebp
/* Call unwind */
push 0
push 0
push glu_return
push [ebp+8]
call _RtlUnwind@16
glu_return:
/* Restore registers and return */
pop ebp
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
.endfunc
.func _abnormal_termination
__abnormal_termination:
/* Assume false */
xor eax, eax
/* Check if the handler is the unwind handler */
mov ecx, fs:0
cmp dword ptr [ecx+4], offset _unwind_handler
jne short ab_return
/* Get the try level */
mov edx, [ecx+12]
mov edx, [edx+12]
/* Compare it */
cmp [ecx+8], edx
jne ab_return
/* Return true */
mov eax, 1
/* Return */
ab_return:
ret
.endfunc
.func _local_unwind2
__local_unwind2:
/* Save volatiles */
push ebx
push esi
push edi
/* Get the exception registration */
mov eax, [esp+16]
/* Setup SEH to protect the unwind */
push ebp
push eax
push -2
push offset _unwind_handler
push fs:0
mov fs:0, esp
unwind_loop:
/* Get the exception registration and try level */
mov eax, [esp+36]
mov ebx, [eax+8]
mov esi, [eax+12]
/* Validate the unwind */
cmp esi, -1
je unwind_return
cmp dword ptr [esp+40], -1
je unwind_ok
cmp esi, [esp+40]
jbe unwind_return
unwind_ok:
/* Get the new enclosing level and save it */
lea esi, [esi+esi*2]
mov ecx, [ebx+esi*4]
mov [esp+8], ecx
mov [eax+12], ecx
/* Check the filter type */
cmp dword ptr [ebx+esi*4+4], 0
jnz __NLG_Return2
/* FIXME: NLG Notification */
/* Call the handler */
call dword ptr [ebx+esi*4+8]
__NLG_Return2:
/* Unwind again */
jmp unwind_loop
unwind_return:
/* Cleanup SEH */
pop fs:0
add esp, 16
pop edi
pop esi
pop ebx
ret
.endfunc
.func _except_handler2
__except_handler2:
/* Setup stack and save volatiles */
push ebp
mov ebp, esp
sub esp, 8
push ebx
push esi
push edi
push ebp
/* Clear direction flag */
cld
/* Get exception registration and record */
mov ebx, [ebp+12]
mov eax, [ebp+8]
/* Check if this is an unwind */
test dword ptr [eax+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
jnz except_unwind2
/* Save exception pointers structure */
mov [ebp-8], eax
mov eax, [ebp+16]
mov [ebp-4], eax
lea eax, [ebp-8]
mov [ebx+20], eax
/* Get the try level and scope table */
mov esi, [ebx+12]
mov edi, [ebx+8]
except_loop2:
/* Validate try level */
cmp esi, -1
je except_search2
/* Check if this is the termination handler */
lea ecx, [esi+esi*2]
cmp dword ptr [edi+ecx*4+4], 0
jz except_continue2
/* Save registers and call filter, then restore them */
push esi
push ebp
mov ebp, [ebx+16]
call dword ptr [edi+ecx*4+4]
pop ebp
pop esi
/* Restore ebx and check the result */
mov ebx, [ebp+12]
or eax, eax
jz except_continue2
js except_dismiss2
/* So this is an accept, call the termination handlers */
mov edi, [ebx+8]
push ebx
call __global_unwind2
add esp, 4
/* Restore ebp */
mov ebp, [ebx+16]
/* Do local unwind */
push esi
push ebx
call __local_unwind2
add esp, 8
/* Set new try level */
lea ecx, [esi+esi*2]
mov eax, [edi+ecx*4]
mov [ebx+12], eax
/* Call except handler */
call [edi+ecx*4+8]
except_continue2:
/* Reload try level and except again */
mov edi, [ebx+8]
lea ecx, [esi+esi*2]
mov esi, [edi+ecx*4]
jmp except_loop2
except_dismiss2:
/* Dismiss it */
mov eax, DISPOSITION_DISMISS
jmp except_return2
except_search2:
/* Continue searching */
mov eax, DISPOSITION_CONTINUE_SEARCH
jmp except_return2
/* Do local unwind */
except_unwind2:
push ebp
mov ebp, [ebx+16]
push -1
push ebx
call __local_unwind2
add esp, 8
/* Retore EBP and set return disposition */
pop ebp
mov eax, DISPOSITION_CONTINUE_SEARCH
except_return2:
/* Restore registers and stack */
pop ebp
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
.endfunc
.func _except_handler3
__except_handler3:
/* Setup stack and save volatiles */
push ebp
mov ebp, esp
sub esp, 8
push ebx
push esi
push edi
push ebp
/* Clear direction flag */
cld
/* Get exception registration and record */
mov ebx, [ebp+12]
mov eax, [ebp+8]
/* Check if this is an unwind */
test dword ptr [eax+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
jnz except_unwind3
/* Save exception pointers structure */
mov [ebp-8], eax
mov eax, [ebp+16]
mov [ebp-4], eax
lea eax, [ebp-8]
mov [ebx-4], eax
/* Get the try level and scope table */
mov esi, [ebx+12]
mov edi, [ebx+8]
/* FIXME: Validate the SEH exception */
except_loop3:
/* Validate try level */
cmp esi, -1
je except_search3
/* Check if this is the termination handler */
lea ecx, [esi+esi*2]
mov eax, [edi+ecx*4+4]
or eax, eax
jz except_continue3
/* Save registers clear them all */
push esi
push ebp
lea ebp, [ebx+16]
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esi, esi
xor edi, edi
/* Call the filter and restore our registers */
call eax
pop ebp
pop esi
/* Restore ebx and check the result */
mov ebx, [ebp+12]
or eax, eax
jz except_continue3
js except_dismiss3
/* So this is an accept, call the termination handlers */
mov edi, [ebx+8]
push ebx
call __global_unwind2
add esp, 4
/* Restore ebp */
lea ebp, [ebx+16]
/* Do local unwind */
push esi
push ebx
call __local_unwind2
add esp, 8
/* FIXME: Do NLG Notification */
/* Set new try level */
lea ecx, [esi+esi*2]
mov eax, [edi+ecx*4]
mov [ebx+12], eax
/* Clear registers and call except handler */
mov eax, [edi+ecx*4+8]
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esi, esi
xor edi, edi
call eax
except_continue3:
/* Reload try level and except again */
mov edi, [ebx+8]
lea ecx, [esi+esi*2]
mov esi, [edi+ecx*4]
jmp except_loop3
except_dismiss3:
/* Dismiss it */
mov eax, DISPOSITION_DISMISS
jmp except_return3
except_search3:
/* Continue searching */
mov eax, DISPOSITION_CONTINUE_SEARCH
jmp except_return3
/* Do local unwind */
except_unwind3:
push ebp
mov ebp, [ebx+16]
push -1
push ebx
call __local_unwind2
add esp, 8
/* Retore EBP and set return disposition */
pop ebp
mov eax, DISPOSITION_CONTINUE_SEARCH
except_return3:
/* Restore registers and stack */
pop ebp
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
.endfunc

View file

@ -0,0 +1,56 @@
#define WIN32_NO_STATUS
#include <precomp.h>
#include <windows.h>
#define NTOS_MODE_USER
#include <ndk/umtypes.h>
#include <ndk/extypes.h>
#include <ndk/rtlfuncs.h>
/* VC++ extensions to Win32 SEH */
typedef struct _SCOPETABLE
{
int previousTryLevel;
int (*lpfnFilter)(PEXCEPTION_POINTERS);
int (*lpfnHandler)(void);
} SCOPETABLE, *PSCOPETABLE;
typedef struct _MSVCRT_EXCEPTION_FRAME
{
PEXCEPTION_REGISTRATION_RECORD *prev;
void (*handler)(PEXCEPTION_RECORD, PEXCEPTION_REGISTRATION_RECORD,
PCONTEXT, PEXCEPTION_RECORD);
PSCOPETABLE scopetable;
int trylevel;
int _ebp;
PEXCEPTION_POINTERS xpointers;
} MSVCRT_EXCEPTION_FRAME;
typedef struct __JUMP_BUFFER
{
unsigned long Ebp;
unsigned long Ebx;
unsigned long Edi;
unsigned long Esi;
unsigned long Esp;
unsigned long Eip;
unsigned long Registration;
unsigned long TryLevel;
/* Start of new struct members */
unsigned long Cookie;
unsigned long UnwindFunc;
unsigned long UnwindData[6];
} _JUMP_BUFFER;
void
_local_unwind2(MSVCRT_EXCEPTION_FRAME *RegistrationFrame,
LONG TryLevel);
/*
* @implemented
*/
void __stdcall _seh_longjmp_unwind(_JUMP_BUFFER *jmp)
{
_local_unwind2((MSVCRT_EXCEPTION_FRAME*) jmp->Registration, jmp->TryLevel);
}

View file

@ -0,0 +1,65 @@
#include <precomp.h>
#define __USE_ISOC9X 1
#define __USE_ISOC99 1
#include <math.h>
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
#ifndef HAVE_FINITE
#ifndef finite /* Could be a macro */
#ifdef isfinite
#define finite(x) isfinite(x)
#else
#define finite(x) (!isnan(x)) /* At least catch some cases */
#endif
#endif
#endif
#ifndef signbit
#define signbit(x) 0
#endif
typedef int (*MSVCRT_matherr_func)(struct _exception *);
static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
int CDECL _matherr(struct _exception *e)
{
if (e)
TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
e->retval);
else
TRACE("(null)\n");
if (MSVCRT_default_matherr_func)
return MSVCRT_default_matherr_func(e);
ERR(":Unhandled math error!\n");
return 0;
}
/*********************************************************************
* __setusermatherr (MSVCRT.@)
*/
void CDECL __setusermatherr(MSVCRT_matherr_func func)
{
MSVCRT_default_matherr_func = func;
TRACE(":new matherr handler %p\n", func);
}
#define _FPIEEE_RECORD void
/*
* @unimplemented
*/
int _fpieee_flt(
unsigned long exception_code,
struct _EXCEPTION_POINTERS* ExceptionPointer,
int (*handler)(_FPIEEE_RECORD*)
)
{
FIXME("Unimplemented!\n");
return 0;
}

View file

@ -0,0 +1,23 @@
/* $Id: chkstk_asm.s 26099 2007-03-14 20:30:32Z ion $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Stack checker
* FILE: lib/ntdll/rtl/i386/chkstk.s
* PROGRAMER: arty
*/
.globl _chkstk
.globl _alloca_probe
/*
_chkstk() is called by all stack allocations of more than 4 KB. It grows the
stack in areas of 4 KB each, trying to access each area. This ensures that the
guard page for the stack is hit, and the stack growing triggered
*/
_chkstk:
_alloca_probe:
/* return */
blr
/* EOF */

View file

@ -0,0 +1,75 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CRT
* FILE: lib/crt/misc/i386/seh.S
* PURPOSE: SEH Support for the CRT
* PROGRAMMERS: arty
*/
/* INCLUDES ******************************************************************/
#include <ndk/asm.h>
#define DISPOSITION_DISMISS 0
#define DISPOSITION_CONTINUE_SEARCH 1
#define DISPOSITION_COLLIDED_UNWIND 3
/* GLOBALS *******************************************************************/
.globl _global_unwind2
.globl _local_unwind2
.globl _abnormal_termination
.globl _except_handler2
.globl _except_handler3
/* FUNCTIONS *****************************************************************/
unwind_handler:
blr
_global_unwind2:
blr
_local_unwind2:
blr
_except_handler2:
blr
_except_handler3:
blr
//
//
// REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME
// sorry
//
//
.globl RtlpGetStackLimits
RtlpGetStackLimits:
stwu 1,16(1)
mflr 0
stw 0,4(1)
stw 3,8(1)
stw 4,12(1)
/* Get the current thread */
lwz 3,KPCR_CURRENT_THREAD(13)
/* Get the stack limits */
lwz 4,KTHREAD_STACK_LIMIT(3)
lwz 5,KTHREAD_INITIAL_STACK(3)
subi 5,5,SIZEOF_FX_SAVE_AREA
/* Return them */
lwz 3,8(1)
stw 4,0(3)
lwz 3,12(1)
stw 5,0(3)
addi 1,1,16
/* return */
blr

View file

@ -0,0 +1,107 @@
#include <precomp.h>
#include "internal/wine/msvcrt.h"
#include "internal/wine/cppexcept.h"
typedef void (*sighandler_t)(int);
static sighandler_t sighandlers[NSIG] = { SIG_DFL };
/* The exception codes are actually NTSTATUS values */
static const struct
{
NTSTATUS status;
int signal;
} float_exception_map[] = {
{ EXCEPTION_FLT_DENORMAL_OPERAND, _FPE_DENORMAL },
{ EXCEPTION_FLT_DIVIDE_BY_ZERO, _FPE_ZERODIVIDE },
{ EXCEPTION_FLT_INEXACT_RESULT, _FPE_INEXACT },
{ EXCEPTION_FLT_INVALID_OPERATION, _FPE_INVALID },
{ EXCEPTION_FLT_OVERFLOW, _FPE_OVERFLOW },
{ EXCEPTION_FLT_STACK_CHECK, _FPE_STACKOVERFLOW },
{ EXCEPTION_FLT_UNDERFLOW, _FPE_UNDERFLOW },
};
/*
* @implemented
*/
int
_XcptFilter(DWORD ExceptionCode,
struct _EXCEPTION_POINTERS * except)
{
LONG ret = EXCEPTION_CONTINUE_SEARCH;
sighandler_t handler;
if (!except || !except->ExceptionRecord)
return EXCEPTION_CONTINUE_SEARCH;
switch (except->ExceptionRecord->ExceptionCode)
{
case EXCEPTION_ACCESS_VIOLATION:
if ((handler = sighandlers[SIGSEGV]) != SIG_DFL)
{
if (handler != SIG_IGN)
{
sighandlers[SIGSEGV] = SIG_DFL;
handler(SIGSEGV);
}
ret = EXCEPTION_CONTINUE_EXECUTION;
}
break;
/* According to msdn,
* the FPE signal handler takes as a second argument the type of
* floating point exception.
*/
case EXCEPTION_FLT_DENORMAL_OPERAND:
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
case EXCEPTION_FLT_INEXACT_RESULT:
case EXCEPTION_FLT_INVALID_OPERATION:
case EXCEPTION_FLT_OVERFLOW:
case EXCEPTION_FLT_STACK_CHECK:
case EXCEPTION_FLT_UNDERFLOW:
if ((handler = sighandlers[SIGFPE]) != SIG_DFL)
{
if (handler != SIG_IGN)
{
int i, float_signal = _FPE_INVALID;
sighandlers[SIGFPE] = SIG_DFL;
for (i = 0; i < sizeof(float_exception_map) /
sizeof(float_exception_map[0]); i++)
{
if (float_exception_map[i].status ==
except->ExceptionRecord->ExceptionCode)
{
float_signal = float_exception_map[i].signal;
break;
}
}
((float_handler)handler)(SIGFPE, float_signal);
}
ret = EXCEPTION_CONTINUE_EXECUTION;
}
break;
case EXCEPTION_ILLEGAL_INSTRUCTION:
if ((handler = sighandlers[SIGILL]) != SIG_DFL)
{
if (handler != SIG_IGN)
{
sighandlers[SIGILL] = SIG_DFL;
handler(SIGILL);
}
ret = EXCEPTION_CONTINUE_EXECUTION;
}
break;
}
return ret;
}
int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
{
/* only filter c++ exceptions */
if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH;
return _XcptFilter( ex, ptr );
}