Introduce wrapper for CreateProcess
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.
This commit is contained in:
parent
265aa48b39
commit
8fea1a81c7
4 changed files with 71 additions and 22 deletions
|
@ -741,6 +741,57 @@ wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper template for the CreateProcess wrappers. */
|
||||||
|
template<typename FUNC, typename CHAR, typename INFO>
|
||||||
|
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
|
/* Define dummy functions which always return error for the rare cases where
|
||||||
these functions could not be found. */
|
these functions could not be found. */
|
||||||
template<typename... T>
|
template<typename... T>
|
||||||
|
|
|
@ -294,6 +294,21 @@ extern BOOL continue_last_debug_event (DWORD continue_status,
|
||||||
|
|
||||||
extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout);
|
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 AdjustTokenPrivileges dyn_AdjustTokenPrivileges
|
||||||
#define DebugActiveProcessStop dyn_DebugActiveProcessStop
|
#define DebugActiveProcessStop dyn_DebugActiveProcessStop
|
||||||
#define DebugBreakProcess dyn_DebugBreakProcess
|
#define DebugBreakProcess dyn_DebugBreakProcess
|
||||||
|
|
|
@ -78,12 +78,10 @@ using namespace windows_nat;
|
||||||
static windows_process_info windows_process;
|
static windows_process_info windows_process;
|
||||||
|
|
||||||
#undef STARTUPINFO
|
#undef STARTUPINFO
|
||||||
#undef CreateProcess
|
|
||||||
|
|
||||||
#ifndef __CYGWIN__
|
#ifndef __CYGWIN__
|
||||||
# define __PMAX (MAX_PATH + 1)
|
# define __PMAX (MAX_PATH + 1)
|
||||||
# define STARTUPINFO STARTUPINFOA
|
# define STARTUPINFO STARTUPINFOA
|
||||||
# define CreateProcess CreateProcessA
|
|
||||||
#else
|
#else
|
||||||
# define __PMAX PATH_MAX
|
# define __PMAX PATH_MAX
|
||||||
/* The starting and ending address of the cygwin1.dll text segment. */
|
/* The starting and ending address of the cygwin1.dll text segment. */
|
||||||
|
@ -92,7 +90,6 @@ static windows_process_info windows_process;
|
||||||
# define __USEWIDE
|
# define __USEWIDE
|
||||||
typedef wchar_t cygwin_buf_t;
|
typedef wchar_t cygwin_buf_t;
|
||||||
# define STARTUPINFO STARTUPINFOW
|
# define STARTUPINFO STARTUPINFOW
|
||||||
# define CreateProcess CreateProcessW
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int have_saved_context; /* True if we've saved context from a
|
static int have_saved_context; /* True if we've saved context from a
|
||||||
|
@ -2494,17 +2491,9 @@ windows_nat_target::create_inferior (const char *exec_file,
|
||||||
}
|
}
|
||||||
|
|
||||||
windows_init_thread_list ();
|
windows_init_thread_list ();
|
||||||
ret = CreateProcess (0,
|
ret = create_process (args, flags, w32_env,
|
||||||
args, /* command line */
|
inferior_cwd != nullptr ? infcwd : nullptr,
|
||||||
NULL, /* Security */
|
&si, &pi);
|
||||||
NULL, /* thread */
|
|
||||||
TRUE, /* inherit handles */
|
|
||||||
flags, /* start flags */
|
|
||||||
w32_env, /* environment */
|
|
||||||
inferior_cwd != NULL ? infcwd : NULL, /* current
|
|
||||||
directory */
|
|
||||||
&si,
|
|
||||||
&pi);
|
|
||||||
if (w32_env)
|
if (w32_env)
|
||||||
/* Just free the Win32 environment, if it could be created. */
|
/* Just free the Win32 environment, if it could be created. */
|
||||||
free (w32_env);
|
free (w32_env);
|
||||||
|
@ -2618,11 +2607,8 @@ windows_nat_target::create_inferior (const char *exec_file,
|
||||||
*temp = 0;
|
*temp = 0;
|
||||||
|
|
||||||
windows_init_thread_list ();
|
windows_init_thread_list ();
|
||||||
ret = CreateProcessA (0,
|
ret = create_process (nullptr, /* image */
|
||||||
args, /* command line */
|
args, /* command line */
|
||||||
NULL, /* Security */
|
|
||||||
NULL, /* thread */
|
|
||||||
TRUE, /* inherit handles */
|
|
||||||
flags, /* start flags */
|
flags, /* start flags */
|
||||||
w32env, /* environment */
|
w32env, /* environment */
|
||||||
inferior_cwd, /* current directory */
|
inferior_cwd, /* current directory */
|
||||||
|
|
|
@ -578,11 +578,8 @@ create_process (const char *program, char *args,
|
||||||
strcpy (program_and_args, program);
|
strcpy (program_and_args, program);
|
||||||
strcat (program_and_args, " ");
|
strcat (program_and_args, " ");
|
||||||
strcat (program_and_args, args);
|
strcat (program_and_args, args);
|
||||||
ret = CreateProcessA (program, /* image name */
|
ret = create_process (program, /* image name */
|
||||||
program_and_args, /* command line */
|
program_and_args, /* command line */
|
||||||
NULL, /* security */
|
|
||||||
NULL, /* thread */
|
|
||||||
TRUE, /* inherit handles */
|
|
||||||
flags, /* start flags */
|
flags, /* start flags */
|
||||||
NULL, /* environment */
|
NULL, /* environment */
|
||||||
/* current directory */
|
/* current directory */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue