Created
April 2, 2022 03:42
-
-
Save openglfreak/f9d545d53b99407b766c1c1f970e5bb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 43389f82e96cc6b238602a9a2a351e392bbef800 Mon Sep 17 00:00:00 2001 | |
From: Torge Matthies <openglfreak@googlemail.com> | |
Date: Sat, 2 Apr 2022 02:15:55 +0200 | |
Subject: [PATCH] [Split] Implement CREATE_NO_WINDOW process creation flag. | |
--- | |
dlls/kernelbase/console.c | 2 ++ | |
dlls/kernelbase/process.c | 9 +++++---- | |
dlls/ntdll/unix/loader.c | 2 ++ | |
dlls/ntdll/unix/process.c | 4 ++-- | |
programs/conhost/conhost.c | 9 +++++++-- | |
server/process.c | 9 ++++++++- | |
6 files changed, 26 insertions(+), 9 deletions(-) | |
diff --git a/dlls/kernelbase/console.c b/dlls/kernelbase/console.c | |
index b2bb6c53fd9..f562ebaa5fc 100644 | |
--- a/dlls/kernelbase/console.c | |
+++ b/dlls/kernelbase/console.c | |
@@ -419,6 +419,8 @@ BOOL WINAPI AllocConsole(void) | |
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 )); | |
+ if (NtCurrentTeb()->Peb->ProcessParameters->ConsoleFlags & 2) | |
+ wcsncat( cmd, L" --no-window", ARRAY_SIZE(cmd) ); | |
Wow64DisableWow64FsRedirection( &redir ); | |
ret = CreateProcessW( conhost_path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &console_si, &pi ); | |
Wow64RevertWow64FsRedirection( redir ); | |
diff --git a/dlls/kernelbase/process.c b/dlls/kernelbase/process.c | |
index 1cecbce9321..2ce6a4be9ef 100644 | |
--- a/dlls/kernelbase/process.c | |
+++ b/dlls/kernelbase/process.c | |
@@ -189,8 +189,9 @@ static RTL_USER_PROCESS_PARAMETERS *create_process_params( const WCHAR *filename | |
} | |
RtlFreeUnicodeString( &newdirW ); | |
- if (flags & CREATE_NEW_PROCESS_GROUP) params->ConsoleFlags = 1; | |
- if (flags & CREATE_NEW_CONSOLE) params->ConsoleHandle = CONSOLE_HANDLE_ALLOC; | |
+ if (flags & CREATE_NEW_PROCESS_GROUP) params->ConsoleFlags |= 1; | |
+ if (flags & CREATE_NO_WINDOW) params->ConsoleFlags |= 2; | |
+ if (flags & (CREATE_NEW_CONSOLE | CREATE_NO_WINDOW)) params->ConsoleHandle = CONSOLE_HANDLE_ALLOC; | |
else if (!(flags & DETACHED_PROCESS)) | |
{ | |
params->ConsoleHandle = NtCurrentTeb()->Peb->ProcessParameters->ConsoleHandle; | |
@@ -532,8 +533,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessInternalW( HANDLE token, const WCHAR | |
/* Warn if unsupported features are used */ | |
if (flags & (IDLE_PRIORITY_CLASS | HIGH_PRIORITY_CLASS | REALTIME_PRIORITY_CLASS | | |
- CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW | | |
- PROFILE_USER | PROFILE_KERNEL | PROFILE_SERVER)) | |
+ CREATE_DEFAULT_ERROR_MODE | PROFILE_USER | PROFILE_KERNEL | | |
+ PROFILE_SERVER)) | |
WARN( "(%s,...): ignoring some flags in %lx\n", debugstr_w(app_name), flags ); | |
if (cur_dir) | |
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c | |
index d1c42ddc0f3..f6ebc77ad12 100644 | |
--- a/dlls/ntdll/unix/loader.c | |
+++ b/dlls/ntdll/unix/loader.c | |
@@ -2170,6 +2170,8 @@ static void start_main_thread(void) | |
NtCreateKeyedEvent( &keyed_event, GENERIC_READ | GENERIC_WRITE, NULL, 0 ); | |
load_ntdll(); | |
if (main_image_info.Machine != current_machine) load_wow64_ntdll( main_image_info.Machine ); | |
+ if (main_image_info.SubSystemType != IMAGE_SUBSYSTEM_WINDOWS_CUI) | |
+ peb->ProcessParameters->ConsoleFlags &= ~2; | |
load_apiset_dll(); | |
ntdll_init_syscalls( 0, &syscall_table, p__wine_syscall_dispatcher ); | |
status = p__wine_set_unix_funcs( NTDLL_UNIXLIB_VERSION, &unix_funcs ); | |
diff --git a/dlls/ntdll/unix/process.c b/dlls/ntdll/unix/process.c | |
index 99c8e37053c..e8a7ada8f2f 100644 | |
--- a/dlls/ntdll/unix/process.c | |
+++ b/dlls/ntdll/unix/process.c | |
@@ -443,7 +443,7 @@ static NTSTATUS spawn_process( const RTL_USER_PROCESS_PARAMETERS *params, int so | |
{ | |
if (!(pid = fork())) /* grandchild */ | |
{ | |
- if (params->ConsoleFlags || | |
+ if ((params->ConsoleFlags & 1) || | |
params->ConsoleHandle == CONSOLE_HANDLE_ALLOC || | |
(params->hStdInput == INVALID_HANDLE_VALUE && params->hStdOutput == INVALID_HANDLE_VALUE)) | |
{ | |
@@ -583,7 +583,7 @@ static NTSTATUS fork_and_exec( OBJECT_ATTRIBUTES *attr, int unixdir, | |
{ | |
close( fd[0] ); | |
- if (params->ConsoleFlags || | |
+ if ((params->ConsoleFlags & 1) || | |
params->ConsoleHandle == CONSOLE_HANDLE_ALLOC || | |
(params->hStdInput == INVALID_HANDLE_VALUE && params->hStdOutput == INVALID_HANDLE_VALUE)) | |
{ | |
diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c | |
index d494e3f53a5..a9d439c49bc 100644 | |
--- a/programs/conhost/conhost.c | |
+++ b/programs/conhost/conhost.c | |
@@ -2853,7 +2853,7 @@ static int main_loop( struct console *console, HANDLE signal ) | |
int __cdecl wmain(int argc, WCHAR *argv[]) | |
{ | |
- int headless = 0, i, width = 0, height = 0; | |
+ int headless = 0, no_window = 0, i, width = 0, height = 0; | |
HANDLE signal = NULL; | |
WCHAR *end; | |
@@ -2897,6 +2897,11 @@ int __cdecl wmain(int argc, WCHAR *argv[]) | |
if ((!height && !console.is_unix) || height > 0xffff || *end) return 1; | |
continue; | |
} | |
+ if (!wcscmp( argv[i], L"--no-window")) | |
+ { | |
+ no_window = 1; | |
+ continue; | |
+ } | |
if (!wcscmp( argv[i], L"--signal" )) | |
{ | |
if (++i == argc) return 1; | |
@@ -2932,7 +2937,7 @@ int __cdecl wmain(int argc, WCHAR *argv[]) | |
init_tty_output( &console ); | |
if (!console.is_unix && !ensure_tty_input_thread( &console )) return 1; | |
} | |
- else | |
+ else if (!no_window) | |
{ | |
STARTUPINFOW si; | |
if (!init_window( &console )) return 1; | |
diff --git a/server/process.c b/server/process.c | |
index 65e2aa70de2..96cdf4bc3f6 100644 | |
--- a/server/process.c | |
+++ b/server/process.c | |
@@ -1298,6 +1298,9 @@ DECL_HANDLER(new_process) | |
goto done; | |
} | |
+ if (parent && parent->startup_info && parent->startup_info->data->console_flags & 2) | |
+ info->data->console_flags |= 2; | |
+ | |
if (!(process = create_process( socket_fd, parent, req->flags, info->data, sd, | |
handles, req->handles_size / sizeof(*handles), token ))) | |
goto done; | |
@@ -1363,7 +1366,7 @@ DECL_HANDLER(new_process) | |
/* debug_children is set to 1 by default */ | |
} | |
- if (!info->data->console_flags) process->group_id = parent->group_id; | |
+ if (!(info->data->console_flags & 1)) process->group_id = parent->group_id; | |
info->process = (struct process *)grab_object( process ); | |
reply->info = alloc_handle( current->process, info, SYNCHRONIZE, 0 ); | |
@@ -1414,6 +1417,7 @@ DECL_HANDLER(get_startup_info) | |
DECL_HANDLER(init_process_done) | |
{ | |
struct process *process = current->process; | |
+ struct startup_info *info = process->startup_info; | |
struct memory_view *view; | |
client_ptr_t base; | |
const pe_image_info_t *image_info; | |
@@ -1437,6 +1441,9 @@ DECL_HANDLER(init_process_done) | |
process->start_time = current_time; | |
current->entry_point = base + image_info->entry_point; | |
+ if (info && info->data && image_info->subsystem != IMAGE_SUBSYSTEM_WINDOWS_CUI) | |
+ info->data->console_flags &= ~2; | |
+ | |
init_process_tracing( process ); | |
generate_startup_debug_events( process ); | |
set_process_startup_state( process, STARTUP_DONE ); | |
-- | |
2.35.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment