kernel32: Use a vectored exception handler to catch Ctrl-C.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-06-06 16:43:48 +02:00
parent 20c91c5e80
commit 173644b08f
3 changed files with 8 additions and 13 deletions

View File

@ -894,14 +894,15 @@ BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
*
* Check whether the shall manipulate CtrlC events
*/
int CONSOLE_HandleCtrlC(unsigned sig)
LONG CALLBACK CONSOLE_HandleCtrlC( EXCEPTION_POINTERS *eptr )
{
extern DWORD WINAPI CtrlRoutine( void *arg );
HANDLE thread;
if (eptr->ExceptionRecord->ExceptionCode != CONTROL_C_EXIT) return EXCEPTION_CONTINUE_SEARCH;
/* FIXME: better test whether a console is attached to this process ??? */
extern unsigned CONSOLE_GetNumHistoryEntries(void);
if (CONSOLE_GetNumHistoryEntries() == (unsigned)-1) return 0;
if (CONSOLE_GetNumHistoryEntries() == (unsigned)-1) return EXCEPTION_CONTINUE_SEARCH;
/* check if we have to ignore ctrl-C events */
if (!(NtCurrentTeb()->Peb->ProcessParameters->ConsoleFlags & 1))
@ -916,12 +917,9 @@ int CONSOLE_HandleCtrlC(unsigned sig)
* we can wait on this critical section
*/
thread = CreateThread(NULL, 0, CtrlRoutine, (void*)CTRL_C_EVENT, 0, NULL);
if (thread == NULL)
return 0;
CloseHandle(thread);
if (thread) CloseHandle(thread);
}
return 1;
return EXCEPTION_CONTINUE_EXECUTION;
}
/******************************************************************

View File

@ -22,8 +22,7 @@
#define __WINE_CONSOLE_PRIVATE_H
/* console.c */
extern int CONSOLE_HandleCtrlC(unsigned) DECLSPEC_HIDDEN;
/* console.c */
extern LONG CALLBACK CONSOLE_HandleCtrlC( EXCEPTION_POINTERS *eptr ) DECLSPEC_HIDDEN;
extern int CONSOLE_GetHistory(int idx, WCHAR* buf, int buf_len) DECLSPEC_HIDDEN;
extern BOOL CONSOLE_AppendHistory(const WCHAR *p) DECLSPEC_HIDDEN;
extern unsigned CONSOLE_GetNumHistoryEntries(void) DECLSPEC_HIDDEN;

View File

@ -39,8 +39,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(process);
extern int CDECL __wine_set_signal_handler(unsigned, int (*)(unsigned));
static STARTUPINFOA startup_infoA;
/***********************************************************************
@ -150,7 +148,7 @@ static BOOL process_attach( HMODULE module )
}
/* finish the process initialisation for console bits, if needed */
__wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC);
RtlAddVectoredExceptionHandler( FALSE, CONSOLE_HandleCtrlC );
if (params->ConsoleHandle == KERNEL32_CONSOLE_ALLOC)
{