mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-31 12:54:13 +00:00
Implemented guard pages and stack overflow exceptions.
This commit is contained in:
parent
3ef9322915
commit
51f6aeb462
3 changed files with 28 additions and 7 deletions
|
@ -475,13 +475,14 @@ static HANDLER_DEF(segv_handler)
|
||||||
{
|
{
|
||||||
EXCEPTION_RECORD rec;
|
EXCEPTION_RECORD rec;
|
||||||
CONTEXT context;
|
CONTEXT context;
|
||||||
|
DWORD page_fault_code = EXCEPTION_ACCESS_VIOLATION;
|
||||||
|
|
||||||
handler_init( &context, HANDLER_CONTEXT );
|
handler_init( &context, HANDLER_CONTEXT );
|
||||||
|
|
||||||
#ifdef CR2_sig
|
#ifdef CR2_sig
|
||||||
/* we want the page-fault case to be fast */
|
/* we want the page-fault case to be fast */
|
||||||
if (get_trap_code(HANDLER_CONTEXT) == T_PAGEFLT)
|
if (get_trap_code(HANDLER_CONTEXT) == T_PAGEFLT)
|
||||||
if (VIRTUAL_HandleFault( (LPVOID)CR2_sig(HANDLER_CONTEXT) )) return;
|
if (!(page_fault_code = VIRTUAL_HandleFault( (LPVOID)CR2_sig(HANDLER_CONTEXT) ))) return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
save_context( &context, HANDLER_CONTEXT );
|
save_context( &context, HANDLER_CONTEXT );
|
||||||
|
@ -520,7 +521,7 @@ static HANDLER_DEF(segv_handler)
|
||||||
#endif /* ERROR_sig */
|
#endif /* ERROR_sig */
|
||||||
rec.ExceptionInformation[1] = CR2_sig(HANDLER_CONTEXT);
|
rec.ExceptionInformation[1] = CR2_sig(HANDLER_CONTEXT);
|
||||||
#endif /* CR2_sig */
|
#endif /* CR2_sig */
|
||||||
rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
|
rec.ExceptionCode = page_fault_code;
|
||||||
break;
|
break;
|
||||||
case T_ALIGNFLT: /* Alignment check exception */
|
case T_ALIGNFLT: /* Alignment check exception */
|
||||||
/* FIXME: pass through exception handler first? */
|
/* FIXME: pass through exception handler first? */
|
||||||
|
|
|
@ -37,7 +37,7 @@ extern LPVOID VIRTUAL_MapFileW( LPCWSTR name );
|
||||||
|
|
||||||
typedef BOOL (*HANDLERPROC)(LPVOID, LPCVOID);
|
typedef BOOL (*HANDLERPROC)(LPVOID, LPCVOID);
|
||||||
extern BOOL VIRTUAL_SetFaultHandler(LPCVOID addr, HANDLERPROC proc, LPVOID arg);
|
extern BOOL VIRTUAL_SetFaultHandler(LPCVOID addr, HANDLERPROC proc, LPVOID arg);
|
||||||
extern BOOL VIRTUAL_HandleFault(LPCVOID addr);
|
extern DWORD VIRTUAL_HandleFault(LPCVOID addr);
|
||||||
|
|
||||||
/* memory/atom.c */
|
/* memory/atom.c */
|
||||||
extern BOOL ATOM_Init( WORD globalTableSel );
|
extern BOOL ATOM_Init( WORD globalTableSel );
|
||||||
|
|
|
@ -510,13 +510,33 @@ BOOL VIRTUAL_SetFaultHandler( LPCVOID addr, HANDLERPROC proc, LPVOID arg )
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* VIRTUAL_HandleFault
|
* VIRTUAL_HandleFault
|
||||||
*/
|
*/
|
||||||
BOOL VIRTUAL_HandleFault( LPCVOID addr )
|
DWORD VIRTUAL_HandleFault( LPCVOID addr )
|
||||||
{
|
{
|
||||||
FILE_VIEW *view = VIRTUAL_FindView((UINT)addr);
|
FILE_VIEW *view = VIRTUAL_FindView((UINT)addr);
|
||||||
|
DWORD ret = EXCEPTION_ACCESS_VIOLATION;
|
||||||
|
|
||||||
if (view && view->handlerProc)
|
if (view)
|
||||||
return view->handlerProc(view->handlerArg, addr);
|
{
|
||||||
return FALSE;
|
if (view->handlerProc)
|
||||||
|
{
|
||||||
|
if (view->handlerProc(view->handlerArg, addr)) ret = 0; /* handled */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BYTE vprot = view->prot[((UINT)addr - view->base) >> page_shift];
|
||||||
|
UINT page = (UINT)addr & ~page_mask;
|
||||||
|
char *stack = (char *)NtCurrentTeb()->stack_base + SIGNAL_STACK_SIZE + page_mask + 1;
|
||||||
|
if (vprot & VPROT_GUARD)
|
||||||
|
{
|
||||||
|
VIRTUAL_SetProt( view, page, page_mask + 1, vprot & ~VPROT_GUARD );
|
||||||
|
ret = STATUS_GUARD_PAGE_VIOLATION;
|
||||||
|
}
|
||||||
|
/* is it inside the stack guard pages? */
|
||||||
|
if (((char *)addr >= stack) && ((char *)addr < stack + 2*(page_mask+1)))
|
||||||
|
ret = STATUS_STACK_OVERFLOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue