Jacek Caban : kernelbase: Lock console critical section when changing current console.

Alexandre Julliard julliard at winehq.org
Thu Jul 30 15:31:26 CDT 2020


Module: wine
Branch: master
Commit: e7550069ded02c1f8503a15e155127e1e2c26f6a
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=e7550069ded02c1f8503a15e155127e1e2c26f6a

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Jul 30 17:15:45 2020 +0200

kernelbase: Lock console critical section when changing current console.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernelbase/console.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/dlls/kernelbase/console.c b/dlls/kernelbase/console.c
index 10b52df4e9..c3634c792f 100644
--- a/dlls/kernelbase/console.c
+++ b/dlls/kernelbase/console.c
@@ -178,6 +178,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH AttachConsole( DWORD pid )
 
     TRACE( "(%x)\n", pid );
 
+    RtlEnterCriticalSection( &console_section );
+
     SERVER_START_REQ( attach_console )
     {
         req->pid = pid;
@@ -189,6 +191,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH AttachConsole( DWORD pid )
         }
     }
     SERVER_END_REQ;
+
+    RtlLeaveCriticalSection( &console_section );
     return ret;
 }
 
@@ -211,11 +215,14 @@ BOOL WINAPI AllocConsole(void)
 
     TRACE("()\n");
 
+    RtlEnterCriticalSection( &console_section );
+
     std_in = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 0, NULL, OPEN_EXISTING, 0, 0 );
     if (GetConsoleMode( std_in, &mode ))
     {
         /* we already have a console opened on this process, don't create a new one */
         CloseHandle( std_in );
+        RtlLeaveCriticalSection( &console_section );
         return FALSE;
     }
 
@@ -248,7 +255,7 @@ BOOL WINAPI AllocConsole(void)
         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 );
     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_OUTPUT_HANDLE, std_out );
     SetStdHandle( STD_ERROR_HANDLE,  std_err );
+    RtlLeaveCriticalSection( &console_section );
     SetLastError( ERROR_SUCCESS );
     return TRUE;
 
@@ -295,6 +303,7 @@ error:
     if (std_out != INVALID_HANDLE_VALUE) CloseHandle(std_out);
     if (std_err != INVALID_HANDLE_VALUE) CloseHandle(std_err);
     FreeConsole();
+    RtlLeaveCriticalSection( &console_section );
     return FALSE;
 }
 
@@ -468,12 +477,16 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeConsole(void)
     HANDLE event;
     BOOL ret;
 
+    RtlEnterCriticalSection( &console_section );
+
     SERVER_START_REQ( free_console )
     {
         ret = !wine_server_call_err( req );
     }
     SERVER_END_REQ;
     if ((event = InterlockedExchangePointer( &console_wait_event, NULL ))) NtClose( event );
+
+    RtlLeaveCriticalSection( &console_section );
     return ret;
 }
 




More information about the wine-cvs mailing list