From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 1C6A63858D3C for ; Fri, 11 Mar 2022 18:57:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C6A63858D3C Received: by mail-io1-xd2a.google.com with SMTP id k25so11103143iok.8 for ; Fri, 11 Mar 2022 10:57:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o7FTTuzsgIphFt6Aqiba+eM6RVM/JL27q58ypgxWar0=; b=uWBae5+/t8nC1s8UTH19nKo1ocNPZZLtj6qeQpv4cLZtMgeU0AUaqKDBEQx5laGB2a XNl41ab6tbq4oElc+/KtWWX2yBfYyhf7lc8/s/bE8meroRHIiEUcbFrDPycNVN42JChR BDvdkydpC8D5JC8ni2cxHz5VAFQmSL4RkGroIGPm07k/HB2MaOoZDNFJZa/FBhN434tj 23PHODW9Y5w51/RCuQb6GoQfLiCt8QqiZJZ8NbnnKO+3Pmai7GwFjC4U2W+M9rfp8CIK n9pRN4/adL2h4rv36lOi//LwwaUhOwnGCkI9R0+exEWA1bMUK/sZ7EMQU5FCoBTa4DkD 6zEg== X-Gm-Message-State: AOAM532noaC+ev4tI0BrLDTrxme6xzz7ImF1wjj28EGZPc0wJB/0mYfS 1IW70h0uvRqloqLpPWd4bUsJpvaIm+Jjug== X-Google-Smtp-Source: ABdhPJwXBqsqzmziBOIyfO1QofCIRH/yyeZg5OBFZiotSzXk5Fi82UTIQXOU4sxXk47Uv65ltlg+xA== X-Received: by 2002:a05:6638:2116:b0:30f:cdfc:41a4 with SMTP id n22-20020a056638211600b0030fcdfc41a4mr9799515jaj.170.1647025027283; Fri, 11 Mar 2022 10:57:07 -0800 (PST) Received: from murgatroyd.Home (75-166-141-253.hlrn.qwest.net. [75.166.141.253]) by smtp.gmail.com with ESMTPSA id o6-20020a056e02188600b002c61b4fef99sm5129268ilu.1.2022.03.11.10.57.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 10:57:07 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 1/2] Introduce wrapper for CreateProcess Date: Fri, 11 Mar 2022 11:57:04 -0700 Message-Id: <20220311185705.774197-2-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220311185705.774197-1-tromey@adacore.com> References: <20220311185705.774197-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Mar 2022 18:57:09 -0000 This is a small refactoring that introduces a wrapper for the Windows CreateProcess function. This is done to make the next patch a bit simpler. --- gdb/nat/windows-nat.c | 51 ++++++++++++++++++++++++++++++++++++++++++ gdb/nat/windows-nat.h | 15 +++++++++++++ gdb/windows-nat.c | 22 ++++-------------- gdbserver/win32-low.cc | 5 +---- 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 21445f3f859..fdfc8e702f8 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -579,6 +579,57 @@ wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout) return result; } +/* Helper template for the CreateProcess wrappers. */ +template +BOOL +create_process_wrapper (FUNC *do_create_process, const CHAR *image, + CHAR *command_line, DWORD flags, + void *environment, const CHAR *cur_dir, + INFO *startup_info, + PROCESS_INFORMATION *process_info) +{ + return do_create_process (image, + command_line, /* command line */ + nullptr, /* Security */ + nullptr, /* thread */ + TRUE, /* inherit handles */ + flags, /* start flags */ + environment, /* environment */ + cur_dir, /* current directory */ + startup_info, + process_info); +} + +/* See nat/windows-nat.h. */ + +BOOL +create_process (const char *image, char *command_line, DWORD flags, + void *environment, const char *cur_dir, + STARTUPINFOA *startup_info, + PROCESS_INFORMATION *process_info) +{ + return create_process_wrapper (CreateProcessA, image, command_line, flags, + environment, cur_dir, + startup_info, process_info); +} + +#ifdef __CYGWIN__ + +/* See nat/windows-nat.h. */ + +BOOL +create_process (const wchar_t *image, wchar_t *command_line, DWORD flags, + void *environment, const wchar_t *cur_dir, + STARTUPINFOW *startup_info, + PROCESS_INFORMATION *process_info); +{ + return create_process_wrapper (CreateProcessW, image, command_line, flags, + environment, cur_dir, + startup_info, process_info); +} + +#endif /* __CYGWIN__ */ + /* Define dummy functions which always return error for the rare cases where these functions could not be found. */ template diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index f0abd7d795c..a0267cd96ba 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -263,6 +263,21 @@ extern BOOL continue_last_debug_event (DWORD continue_status, extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout); +/* Wrappers for CreateProcess. */ + +extern BOOL create_process (const char *image, char *command_line, + DWORD flags, void *environment, + const char *cur_dir, + STARTUPINFOA *startup_info, + PROCESS_INFORMATION *process_info); +#ifdef __CYGWIN__ +extern BOOL create_process (const wchar_t *image, wchar_t *command_line, + DWORD flags, void *environment, + const wchar_t *cur_dir, + STARTUPINFOW *startup_info, + PROCESS_INFORMATION *process_info); +#endif /* __CYGWIN__ */ + #define AdjustTokenPrivileges dyn_AdjustTokenPrivileges #define DebugActiveProcessStop dyn_DebugActiveProcessStop #define DebugBreakProcess dyn_DebugBreakProcess diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 81e26fe4759..251876c7022 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -75,14 +75,12 @@ using namespace windows_nat; #undef STARTUPINFO -#undef CreateProcess #undef GetModuleFileNameEx #ifndef __CYGWIN__ # define __PMAX (MAX_PATH + 1) # define GetModuleFileNameEx GetModuleFileNameExA # define STARTUPINFO STARTUPINFOA -# define CreateProcess CreateProcessA #else # define __PMAX PATH_MAX /* The starting and ending address of the cygwin1.dll text segment. */ @@ -92,7 +90,6 @@ using namespace windows_nat; typedef wchar_t cygwin_buf_t; # define GetModuleFileNameEx GetModuleFileNameExW # define STARTUPINFO STARTUPINFOW -# define CreateProcess CreateProcessW #endif static int have_saved_context; /* True if we've saved context from a @@ -2616,17 +2613,9 @@ windows_nat_target::create_inferior (const char *exec_file, } windows_init_thread_list (); - ret = CreateProcess (0, - args, /* command line */ - NULL, /* Security */ - NULL, /* thread */ - TRUE, /* inherit handles */ - flags, /* start flags */ - w32_env, /* environment */ - inferior_cwd != NULL ? infcwd : NULL, /* current - directory */ - &si, - &pi); + ret = create_process (args, flags, w32_env, + inferior_cwd != nullptr ? infcwd : nullptr, + &si, &pi); if (w32_env) /* Just free the Win32 environment, if it could be created. */ free (w32_env); @@ -2740,11 +2729,8 @@ windows_nat_target::create_inferior (const char *exec_file, *temp = 0; windows_init_thread_list (); - ret = CreateProcessA (0, + ret = create_process (nullptr, /* image */ args, /* command line */ - NULL, /* Security */ - NULL, /* thread */ - TRUE, /* inherit handles */ flags, /* start flags */ w32env, /* environment */ inferior_cwd, /* current directory */ diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index e19bc2bd6e8..5164da59a21 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -572,11 +572,8 @@ create_process (const char *program, char *args, strcpy (program_and_args, program); strcat (program_and_args, " "); strcat (program_and_args, args); - ret = CreateProcessA (program, /* image name */ + ret = create_process (program, /* image name */ program_and_args, /* command line */ - NULL, /* security */ - NULL, /* thread */ - TRUE, /* inherit handles */ flags, /* start flags */ NULL, /* environment */ /* current directory */ -- 2.34.1