From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 580F0382D47B; Tue, 7 Jun 2022 16:00:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 580F0382D47B Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Introduce wrapper for CreateProcess X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 265aa48b392cda4355b5875fde46b59c271cc093 X-Git-Newrev: 8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008 Message-Id: <20220607160010.580F0382D47B@sourceware.org> Date: Tue, 7 Jun 2022 16:00:10 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2022 16:00:10 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8fea1a81c7d9= 279a6f91e49ebacfb61e0f8ce008 commit 8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008 Author: Tom Tromey Date: Tue Sep 7 14:41:52 2021 -0600 Introduce wrapper for CreateProcess =20 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. Diff: --- 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 ca6a529601e..8048344752b 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -741,6 +741,57 @@ wait_for_debug_event (DEBUG_EVENT *event, DWORD timeou= t) return result; } =20 +/* 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, flag= s, + 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, flag= s, + environment, cur_dir, + startup_info, process_info); +} + +#endif /* __CYGWIN__ */ + /* Define dummy functions which always return error for the rare cases whe= re these functions could not be found. */ template diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 450ba69c844..d8c498ef06e 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -294,6 +294,21 @@ extern BOOL continue_last_debug_event (DWORD continue_= status, =20 extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout); =20 +/* 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 8631a1b4569..262619d9cb7 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -78,12 +78,10 @@ using namespace windows_nat; static windows_process_info windows_process; =20 #undef STARTUPINFO -#undef CreateProcess =20 #ifndef __CYGWIN__ # define __PMAX (MAX_PATH + 1) # 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 @@ static windows_process_info windows_process; # define __USEWIDE typedef wchar_t cygwin_buf_t; # define STARTUPINFO STARTUPINFOW -# define CreateProcess CreateProcessW #endif =20 static int have_saved_context; /* True if we've saved context from a @@ -2494,17 +2491,9 @@ windows_nat_target::create_inferior (const char *exe= c_file, } =20 windows_init_thread_list (); - ret =3D CreateProcess (0, - args, /* command line */ - NULL, /* Security */ - NULL, /* thread */ - TRUE, /* inherit handles */ - flags, /* start flags */ - w32_env, /* environment */ - inferior_cwd !=3D NULL ? infcwd : NULL, /* current - directory */ - &si, - &pi); + ret =3D create_process (args, flags, w32_env, + inferior_cwd !=3D nullptr ? infcwd : nullptr, + &si, &pi); if (w32_env) /* Just free the Win32 environment, if it could be created. */ free (w32_env); @@ -2618,11 +2607,8 @@ windows_nat_target::create_inferior (const char *exe= c_file, *temp =3D 0; =20 windows_init_thread_list (); - ret =3D CreateProcessA (0, + ret =3D 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 f941e8d2903..00ce2a52feb 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -578,11 +578,8 @@ create_process (const char *program, char *args, strcpy (program_and_args, program); strcat (program_and_args, " "); strcat (program_and_args, args); - ret =3D CreateProcessA (program, /* image name */ + ret =3D create_process (program, /* image name */ program_and_args, /* command line */ - NULL, /* security */ - NULL, /* thread */ - TRUE, /* inherit handles */ flags, /* start flags */ NULL, /* environment */ /* current directory */