mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2025-01-28 22:04:43 -08:00
Added kernel32-AttachConsole patchset
This commit is contained in:
parent
8b65c06f30
commit
2e982e862f
@ -0,0 +1,289 @@
|
||||
From 6a63336af94902ddc0d71d23d8e1e84260a71716 Mon Sep 17 00:00:00 2001
|
||||
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
|
||||
Date: Sat, 28 Jul 2018 10:49:59 +1000
|
||||
Subject: [PATCH] kernel32: Add AttachConsole implementation
|
||||
|
||||
---
|
||||
dlls/kernel32/console.c | 19 ++++-
|
||||
dlls/kernel32/tests/console.c | 131 +++++++++++++++++++++++++++++++---
|
||||
server/console.c | 43 +++++++++++
|
||||
server/protocol.def | 10 +++
|
||||
4 files changed, 193 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
|
||||
index 51061de922..1637a879dc 100644
|
||||
--- a/dlls/kernel32/console.c
|
||||
+++ b/dlls/kernel32/console.c
|
||||
@@ -2909,8 +2909,23 @@ BOOL WINAPI ScrollConsoleScreenBufferW(HANDLE hConsoleOutput, LPSMALL_RECT lpScr
|
||||
*/
|
||||
BOOL WINAPI AttachConsole(DWORD dwProcessId)
|
||||
{
|
||||
- FIXME("stub %x\n",dwProcessId);
|
||||
- return TRUE;
|
||||
+ BOOL ret;
|
||||
+
|
||||
+ TRACE("(%x)\n", dwProcessId);
|
||||
+
|
||||
+ SERVER_START_REQ( attach_console )
|
||||
+ {
|
||||
+ req->pid = dwProcessId;
|
||||
+ ret = !wine_server_call_err( req );
|
||||
+ if (ret)
|
||||
+ {
|
||||
+ SetStdHandle(STD_INPUT_HANDLE, wine_server_ptr_handle(reply->std_in));
|
||||
+ SetStdHandle(STD_OUTPUT_HANDLE, wine_server_ptr_handle(reply->std_out));
|
||||
+ SetStdHandle(STD_ERROR_HANDLE, wine_server_ptr_handle(reply->std_err));
|
||||
+ }
|
||||
+ }
|
||||
+ SERVER_END_REQ;
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
|
||||
index ac77ab76b0..acd61d078b 100644
|
||||
--- a/dlls/kernel32/tests/console.c
|
||||
+++ b/dlls/kernel32/tests/console.c
|
||||
@@ -208,19 +208,29 @@ static void testEmptyWrite(HANDLE hCon)
|
||||
okCURSOR(hCon, c);
|
||||
}
|
||||
|
||||
-static void testWriteSimple(HANDLE hCon)
|
||||
+static void simple_write_console(HANDLE console, const char *text)
|
||||
{
|
||||
- COORD c;
|
||||
- DWORD len;
|
||||
- const char* mytest = "abcdefg";
|
||||
- const int mylen = strlen(mytest);
|
||||
+ DWORD len;
|
||||
+ COORD c = {0, 0};
|
||||
+ BOOL ret;
|
||||
|
||||
/* single line write */
|
||||
c.X = c.Y = 0;
|
||||
- ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
|
||||
+ ok(SetConsoleCursorPosition(console, c) != 0, "Cursor in upper-left\n");
|
||||
+
|
||||
+ ret = WriteConsoleA(console, text, strlen(text), &len, NULL);
|
||||
+ ok(ret, "WriteConsoleA failed: %u\n", GetLastError());
|
||||
+ ok(len == strlen(text), "unexpected len %u\n", len);
|
||||
+}
|
||||
+
|
||||
+static void testWriteSimple(HANDLE hCon)
|
||||
+{
|
||||
+ const char* mytest = "abcdefg";
|
||||
+ int mylen = strlen(mytest);
|
||||
+ COORD c = {0, 0};
|
||||
+
|
||||
+ simple_write_console(hCon, mytest);
|
||||
|
||||
- ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
|
||||
- c.Y = 0;
|
||||
for (c.X = 0; c.X < mylen; c.X++)
|
||||
{
|
||||
okCHAR(hCon, c, mytest[c.X], TEST_ATTRIB);
|
||||
@@ -3019,6 +3029,98 @@ static void test_GetConsoleScreenBufferInfoEx(HANDLE std_output)
|
||||
ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
|
||||
}
|
||||
|
||||
+static void test_AttachConsole_child(DWORD console_pid)
|
||||
+{
|
||||
+ HANDLE pipe_in, pipe_out;
|
||||
+ COORD c = {0,0};
|
||||
+ HANDLE console;
|
||||
+ char buf[32];
|
||||
+ DWORD len;
|
||||
+ BOOL res;
|
||||
+
|
||||
+ res = CreatePipe(&pipe_in, &pipe_out, NULL, 0);
|
||||
+ ok(res, "CreatePipe failed: %u\n", GetLastError());
|
||||
+
|
||||
+ res = AttachConsole(console_pid);
|
||||
+ ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
|
||||
+ "AttachConsole returned: %x(%u)\n", res, GetLastError());
|
||||
+
|
||||
+ res = FreeConsole();
|
||||
+ ok(res, "FreeConsole failed: %u\n", GetLastError());
|
||||
+
|
||||
+ SetStdHandle(STD_ERROR_HANDLE, pipe_out);
|
||||
+
|
||||
+ res = AttachConsole(console_pid);
|
||||
+ ok(res, "AttachConsole failed: %u\n", GetLastError());
|
||||
+
|
||||
+ ok(pipe_out != GetStdHandle(STD_ERROR_HANDLE), "std handle not set to console\n");
|
||||
+
|
||||
+ console = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
||||
+ ok(console != INVALID_HANDLE_VALUE, "Could not open console\n");
|
||||
+
|
||||
+ res = ReadConsoleOutputCharacterA(console, buf, 6, c, &len);
|
||||
+ ok(res, "ReadConsoleOutputCharacterA failed: %u\n", GetLastError());
|
||||
+ ok(len == 6, "len = %u\n", len);
|
||||
+ ok(!memcmp(buf, "Parent", 6), "Unexpected console output\n");
|
||||
+
|
||||
+ res = FreeConsole();
|
||||
+ ok(res, "FreeConsole failed: %u\n", GetLastError());
|
||||
+
|
||||
+ SetStdHandle(STD_INPUT_HANDLE, pipe_in);
|
||||
+ SetStdHandle(STD_OUTPUT_HANDLE, pipe_out);
|
||||
+
|
||||
+ res = AttachConsole(ATTACH_PARENT_PROCESS);
|
||||
+ ok(res, "AttachConsole failed: %u\n", GetLastError());
|
||||
+
|
||||
+ ok(pipe_in != GetStdHandle(STD_INPUT_HANDLE), "std handle not set to console\n");
|
||||
+ ok(pipe_out != GetStdHandle(STD_OUTPUT_HANDLE), "std handle not set to console\n");
|
||||
+
|
||||
+ console = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
||||
+ ok(console != INVALID_HANDLE_VALUE, "Could not open console\n");
|
||||
+
|
||||
+ res = ReadConsoleOutputCharacterA(console, buf, 6, c, &len);
|
||||
+ ok(res, "ReadConsoleOutputCharacterA failed: %u\n", GetLastError());
|
||||
+ ok(len == 6, "len = %u\n", len);
|
||||
+ ok(!memcmp(buf, "Parent", 6), "Unexpected console output\n");
|
||||
+
|
||||
+ simple_write_console(console, "Child");
|
||||
+ CloseHandle(console);
|
||||
+
|
||||
+ res = FreeConsole();
|
||||
+ ok(res, "FreeConsole failed: %u\n", GetLastError());
|
||||
+
|
||||
+ res = CloseHandle(pipe_in);
|
||||
+ ok(res, "pipe_in is no longer valid\n");
|
||||
+ res = CloseHandle(pipe_out);
|
||||
+ ok(res, "pipe_out is no longer valid\n");
|
||||
+}
|
||||
+
|
||||
+static void test_AttachConsole(HANDLE console)
|
||||
+{
|
||||
+ STARTUPINFOA si = { sizeof(si) };
|
||||
+ PROCESS_INFORMATION info;
|
||||
+ char **argv, buf[MAX_PATH];
|
||||
+ COORD c = {0,0};
|
||||
+ DWORD len;
|
||||
+ BOOL res;
|
||||
+
|
||||
+ simple_write_console(console, "Parent console");
|
||||
+
|
||||
+ winetest_get_mainargs(&argv);
|
||||
+ sprintf(buf, "\"%s\" console attach_console %x", argv[0], GetCurrentProcessId());
|
||||
+ res = CreateProcessA(NULL, buf, NULL, NULL, TRUE, 0, NULL, NULL, &si, &info);
|
||||
+ ok(res, "CreateProcess failed: %u\n", GetLastError());
|
||||
+ CloseHandle(info.hThread);
|
||||
+
|
||||
+ winetest_wait_child_process(info.hProcess);
|
||||
+ CloseHandle(info.hProcess);
|
||||
+
|
||||
+ res = ReadConsoleOutputCharacterA(console, buf, 5, c, &len);
|
||||
+ ok(res, "ReadConsoleOutputCharacterA failed: %u\n", GetLastError());
|
||||
+ ok(len == 5, "len = %u\n", len);
|
||||
+ ok(!memcmp(buf, "Child", 5), "Unexpected console output\n");
|
||||
+}
|
||||
+
|
||||
START_TEST(console)
|
||||
{
|
||||
static const char font_name[] = "Lucida Console";
|
||||
@@ -3030,9 +3132,21 @@ START_TEST(console)
|
||||
char old_font[LF_FACESIZE];
|
||||
BOOL delete = FALSE;
|
||||
DWORD size;
|
||||
+ char **argv;
|
||||
+ int argc;
|
||||
|
||||
init_function_pointers();
|
||||
|
||||
+ argc = winetest_get_mainargs(&argv);
|
||||
+
|
||||
+ if (argc > 3 && !strcmp(argv[2], "attach_console"))
|
||||
+ {
|
||||
+ DWORD parent_pid;
|
||||
+ sscanf(argv[3], "%x", &parent_pid);
|
||||
+ test_AttachConsole_child(parent_pid);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
/* be sure we have a clean console (and that's our own)
|
||||
* FIXME: this will make the test fail (currently) if we don't run
|
||||
* under X11
|
||||
@@ -3170,4 +3284,5 @@ START_TEST(console)
|
||||
test_GetConsoleFontInfo(hConOut);
|
||||
test_SetConsoleFont(hConOut);
|
||||
test_GetConsoleScreenBufferInfoEx(hConOut);
|
||||
+ test_AttachConsole(hConOut);
|
||||
}
|
||||
diff --git a/server/console.c b/server/console.c
|
||||
index 51252e973c..a46310bb28 100644
|
||||
--- a/server/console.c
|
||||
+++ b/server/console.c
|
||||
@@ -1549,6 +1549,49 @@ DECL_HANDLER(open_console)
|
||||
else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
|
||||
}
|
||||
|
||||
+/* attach to a other process's console */
|
||||
+DECL_HANDLER(attach_console)
|
||||
+{
|
||||
+ struct process *process;
|
||||
+
|
||||
+ if (current->process->console)
|
||||
+ {
|
||||
+ set_error( STATUS_ACCESS_DENIED );
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ process = get_process_from_id( req->pid == ATTACH_PARENT_PROCESS
|
||||
+ ? current->process->parent_id : req->pid );
|
||||
+ if (!process) return;
|
||||
+
|
||||
+ if (process->console && process->console->active )
|
||||
+ {
|
||||
+ reply->std_in = alloc_handle( current->process, process->console, GENERIC_READ, 0 );
|
||||
+ if (!reply->std_in) goto error;
|
||||
+
|
||||
+ reply->std_out = alloc_handle( current->process, process->console->active, GENERIC_WRITE, 0 );
|
||||
+ if (!reply->std_out) goto error;
|
||||
+
|
||||
+ reply->std_err = alloc_handle( current->process, process->console->active, GENERIC_WRITE, 0 );
|
||||
+ if (!reply->std_err) goto error;
|
||||
+
|
||||
+ current->process->console = (struct console_input*)grab_object( process->console );
|
||||
+ current->process->console->num_proc++;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ set_error( STATUS_INVALID_HANDLE );
|
||||
+ }
|
||||
+
|
||||
+ release_object( process );
|
||||
+ return;
|
||||
+
|
||||
+error:
|
||||
+ if (reply->std_in) close_handle( current->process, reply->std_in);
|
||||
+ if (reply->std_out) close_handle( current->process, reply->std_out);
|
||||
+ release_object( process );
|
||||
+}
|
||||
+
|
||||
/* set info about a console input */
|
||||
DECL_HANDLER(set_console_input_info)
|
||||
{
|
||||
diff --git a/server/protocol.def b/server/protocol.def
|
||||
index f31557a57c..4cedeb66b4 100644
|
||||
--- a/server/protocol.def
|
||||
+++ b/server/protocol.def
|
||||
@@ -1501,6 +1501,16 @@ struct console_renderer_event
|
||||
@END
|
||||
|
||||
|
||||
+/* Attach to a other process's console */
|
||||
+@REQ(attach_console)
|
||||
+ process_id_t pid; /* pid of attached console process */
|
||||
+@REPLY
|
||||
+ obj_handle_t std_in; /* attached stdin */
|
||||
+ obj_handle_t std_out; /* attached stdout */
|
||||
+ obj_handle_t std_err; /* attached stderr */
|
||||
+@END
|
||||
+
|
||||
+
|
||||
/* Get the input queue wait event */
|
||||
@REQ(get_console_wait_event)
|
||||
@REPLY
|
||||
--
|
||||
2.18.0
|
||||
|
2
patches/kernel32-AttachConsole/definition
Normal file
2
patches/kernel32-AttachConsole/definition
Normal file
@ -0,0 +1,2 @@
|
||||
Fixes: [41573] AttachConsole implementation.
|
||||
Fixes: [43910] "Battle.net helper.exe" [NOT BLIZZARD APP!] crashes with Win 7 or higher
|
@ -163,6 +163,7 @@ patch_enable_all ()
|
||||
enable_inseng_Implementation="$1"
|
||||
enable_iphlpapi_System_Ping="$1"
|
||||
enable_iphlpapi_TCP_Table="$1"
|
||||
enable_kernel32_AttachConsole="$1"
|
||||
enable_kernel32_COMSPEC="$1"
|
||||
enable_kernel32_CopyFileEx="$1"
|
||||
enable_kernel32_Cwd_Startup_Info="$1"
|
||||
@ -661,6 +662,9 @@ patch_enable ()
|
||||
iphlpapi-TCP_Table)
|
||||
enable_iphlpapi_TCP_Table="$2"
|
||||
;;
|
||||
kernel32-AttachConsole)
|
||||
enable_kernel32_AttachConsole="$2"
|
||||
;;
|
||||
kernel32-COMSPEC)
|
||||
enable_kernel32_COMSPEC="$2"
|
||||
;;
|
||||
@ -3966,6 +3970,22 @@ if test "$enable_iphlpapi_TCP_Table" -eq 1; then
|
||||
) >> "$patchlist"
|
||||
fi
|
||||
|
||||
# Patchset kernel32-AttachConsole
|
||||
# |
|
||||
# | This patchset fixes the following Wine bugs:
|
||||
# | * [#41573] AttachConsole implementation.
|
||||
# | * [#43910] "Battle.net helper.exe" [NOT BLIZZARD APP!] crashes with Win 7 or higher
|
||||
# |
|
||||
# | Modified files:
|
||||
# | * dlls/kernel32/console.c, dlls/kernel32/tests/console.c, server/console.c, server/protocol.def
|
||||
# |
|
||||
if test "$enable_kernel32_AttachConsole" -eq 1; then
|
||||
patch_apply kernel32-AttachConsole/0001-kernel32-Add-AttachConsole-implementation.patch
|
||||
(
|
||||
printf '%s\n' '+ { "Alistair Leslie-Hughes", "kernel32: Add AttachConsole implementation.", 1 },';
|
||||
) >> "$patchlist"
|
||||
fi
|
||||
|
||||
# Patchset server-File_Permissions
|
||||
# |
|
||||
# | This patchset fixes the following Wine bugs:
|
||||
|
Loading…
x
Reference in New Issue
Block a user