Jacek Caban : kernelbase: Use conhost in AllocConsole.
Alexandre Julliard
julliard at winehq.org
Mon Oct 12 15:20:51 CDT 2020
Module: wine
Branch: master
Commit: 859b526c81a2af841b5b7b28d06f3d782bccdab5
URL: https://source.winehq.org/git/wine.git/?a=commit;h=859b526c81a2af841b5b7b28d06f3d782bccdab5
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Oct 12 18:27:18 2020 +0200
kernelbase: Use conhost in AllocConsole.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/kernelbase/console.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/dlls/kernelbase/console.c b/dlls/kernelbase/console.c
index 502fbcddaf..0fd832d378 100644
--- a/dlls/kernelbase/console.c
+++ b/dlls/kernelbase/console.c
@@ -326,9 +326,10 @@ BOOL WINAPI AllocConsole(void)
{
SECURITY_ATTRIBUTES inheritable_attr = { sizeof(inheritable_attr), NULL, TRUE };
STARTUPINFOW app_si, console_si;
- WCHAR buffer[1024], cmd[256];
+ HANDLE server, console = NULL;
+ WCHAR buffer[1024], cmd[256], conhost_path[MAX_PATH];
PROCESS_INFORMATION pi;
- HANDLE event, console;
+ void *redir;
BOOL ret;
TRACE("()\n");
@@ -343,6 +344,8 @@ BOOL WINAPI AllocConsole(void)
return FALSE;
}
+ if (!(server = create_console_server()) || !(console = create_console_reference( server ))) goto error;
+
GetStartupInfoW(&app_si);
memset(&console_si, 0, sizeof(console_si));
@@ -372,30 +375,27 @@ BOOL WINAPI AllocConsole(void)
console_si.lpTitle = buffer;
}
- if (!(event = CreateEventW( &inheritable_attr, TRUE, FALSE, NULL ))) goto error;
+ swprintf( conhost_path, ARRAY_SIZE(conhost_path), L"%s\\conhost.exe", system_dir );
+ swprintf( cmd, ARRAY_SIZE(cmd), L"\"%s\" --server 0x%x", conhost_path, condrv_handle( server ));
+ Wow64DisableWow64FsRedirection( &redir );
+ ret = CreateProcessW( conhost_path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &console_si, &pi );
+ Wow64RevertWow64FsRedirection( redir );
+
+ if (!ret || !create_console_connection( console)) goto error;
+ if (!init_console_std_handles( !(app_si.dwFlags & STARTF_USESTDHANDLES) )) 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 )))
- {
- HANDLE wait_handles[2] = { event, pi.hProcess };
- ret = WaitForMultipleObjects( ARRAY_SIZE(wait_handles), wait_handles, FALSE, INFINITE ) == WAIT_OBJECT_0;
- CloseHandle( pi.hThread );
- CloseHandle( pi.hProcess );
- }
- CloseHandle( event );
- if (!ret || !init_console_std_handles( !(app_si.dwFlags & STARTF_USESTDHANDLES) )) goto error;
- console = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 0, NULL, OPEN_EXISTING, 0, 0 );
- if (console == INVALID_HANDLE_VALUE) goto error;
RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle = console;
-
TRACE( "Started wineconsole pid=%08x tid=%08x\n", pi.dwProcessId, pi.dwThreadId );
+ CloseHandle( server );
RtlLeaveCriticalSection( &console_section );
SetLastError( ERROR_SUCCESS );
return TRUE;
error:
ERR("Can't allocate console\n");
+ NtClose( console );
+ NtClose( server );
FreeConsole();
RtlLeaveCriticalSection( &console_section );
return FALSE;
More information about the wine-cvs
mailing list