kernelbase: Lock console critical section when changing current console.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
fa2b372ec0
commit
e7550069de
|
@ -178,6 +178,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH AttachConsole( DWORD pid )
|
||||||
|
|
||||||
TRACE( "(%x)\n", pid );
|
TRACE( "(%x)\n", pid );
|
||||||
|
|
||||||
|
RtlEnterCriticalSection( &console_section );
|
||||||
|
|
||||||
SERVER_START_REQ( attach_console )
|
SERVER_START_REQ( attach_console )
|
||||||
{
|
{
|
||||||
req->pid = pid;
|
req->pid = pid;
|
||||||
|
@ -189,6 +191,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH AttachConsole( DWORD pid )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SERVER_END_REQ;
|
SERVER_END_REQ;
|
||||||
|
|
||||||
|
RtlLeaveCriticalSection( &console_section );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,11 +215,14 @@ BOOL WINAPI AllocConsole(void)
|
||||||
|
|
||||||
TRACE("()\n");
|
TRACE("()\n");
|
||||||
|
|
||||||
|
RtlEnterCriticalSection( &console_section );
|
||||||
|
|
||||||
std_in = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 0, NULL, OPEN_EXISTING, 0, 0 );
|
std_in = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 0, NULL, OPEN_EXISTING, 0, 0 );
|
||||||
if (GetConsoleMode( std_in, &mode ))
|
if (GetConsoleMode( std_in, &mode ))
|
||||||
{
|
{
|
||||||
/* we already have a console opened on this process, don't create a new one */
|
/* we already have a console opened on this process, don't create a new one */
|
||||||
CloseHandle( std_in );
|
CloseHandle( std_in );
|
||||||
|
RtlLeaveCriticalSection( &console_section );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +255,7 @@ BOOL WINAPI AllocConsole(void)
|
||||||
console_si.lpTitle = buffer;
|
console_si.lpTitle = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(event = CreateEventW( &inheritable_attr, TRUE, FALSE, NULL ))) return FALSE;
|
if (!(event = CreateEventW( &inheritable_attr, TRUE, FALSE, NULL ))) goto error;
|
||||||
|
|
||||||
swprintf( cmd, ARRAY_SIZE(cmd), L"wineconsole --use-event=%ld", (DWORD_PTR)event );
|
swprintf( cmd, ARRAY_SIZE(cmd), L"wineconsole --use-event=%ld", (DWORD_PTR)event );
|
||||||
if ((ret = CreateProcessW( NULL, cmd, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &console_si, &pi )))
|
if ((ret = CreateProcessW( NULL, cmd, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &console_si, &pi )))
|
||||||
|
@ -286,6 +293,7 @@ BOOL WINAPI AllocConsole(void)
|
||||||
SetStdHandle( STD_INPUT_HANDLE, std_in );
|
SetStdHandle( STD_INPUT_HANDLE, std_in );
|
||||||
SetStdHandle( STD_OUTPUT_HANDLE, std_out );
|
SetStdHandle( STD_OUTPUT_HANDLE, std_out );
|
||||||
SetStdHandle( STD_ERROR_HANDLE, std_err );
|
SetStdHandle( STD_ERROR_HANDLE, std_err );
|
||||||
|
RtlLeaveCriticalSection( &console_section );
|
||||||
SetLastError( ERROR_SUCCESS );
|
SetLastError( ERROR_SUCCESS );
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -295,6 +303,7 @@ error:
|
||||||
if (std_out != INVALID_HANDLE_VALUE) CloseHandle(std_out);
|
if (std_out != INVALID_HANDLE_VALUE) CloseHandle(std_out);
|
||||||
if (std_err != INVALID_HANDLE_VALUE) CloseHandle(std_err);
|
if (std_err != INVALID_HANDLE_VALUE) CloseHandle(std_err);
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
|
RtlLeaveCriticalSection( &console_section );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,12 +477,16 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeConsole(void)
|
||||||
HANDLE event;
|
HANDLE event;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
|
RtlEnterCriticalSection( &console_section );
|
||||||
|
|
||||||
SERVER_START_REQ( free_console )
|
SERVER_START_REQ( free_console )
|
||||||
{
|
{
|
||||||
ret = !wine_server_call_err( req );
|
ret = !wine_server_call_err( req );
|
||||||
}
|
}
|
||||||
SERVER_END_REQ;
|
SERVER_END_REQ;
|
||||||
if ((event = InterlockedExchangePointer( &console_wait_event, NULL ))) NtClose( event );
|
if ((event = InterlockedExchangePointer( &console_wait_event, NULL ))) NtClose( event );
|
||||||
|
|
||||||
|
RtlLeaveCriticalSection( &console_section );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue