diff options
author | Mike McLaughlin <mikem@microsoft.com> | 2016-03-04 17:19:20 -0800 |
---|---|---|
committer | Mike McLaughlin <mikem@microsoft.com> | 2016-03-08 18:05:05 -0800 |
commit | 86103a426ace432520c28b0f7ac19bcb88ce8343 (patch) | |
tree | 714b948fbf1a3a8168cd8cccd2f9a4e1fca5b7cb | |
parent | d2ab1fbd40343e01fcb71fb9793ee7c681eeb1de (diff) | |
download | coreclr-86103a426ace432520c28b0f7ac19bcb88ce8343.tar.gz coreclr-86103a426ace432520c28b0f7ac19bcb88ce8343.tar.bz2 coreclr-86103a426ace432520c28b0f7ac19bcb88ce8343.zip |
Added CreateProcessForLaunch, ResumeProcess and CloseResumeHandle that can
be better supported cross-plat.
-rw-r--r-- | src/dlls/dbgshim/dbgshim.cpp | 98 | ||||
-rw-r--r-- | src/dlls/dbgshim/dbgshim.h | 18 | ||||
-rw-r--r-- | src/dlls/dbgshim/dbgshim.ntdef | 3 |
3 files changed, 118 insertions, 1 deletions
diff --git a/src/dlls/dbgshim/dbgshim.cpp b/src/dlls/dbgshim/dbgshim.cpp index 7f683f35e9..1299bbdc95 100644 --- a/src/dlls/dbgshim/dbgshim.cpp +++ b/src/dlls/dbgshim/dbgshim.cpp @@ -62,6 +62,104 @@ Notes: } \ CONTRACTL_END; \ + +//----------------------------------------------------------------------------- +// Public API. +// +// CreateProcessForLaunch - a stripped down version of the Windows CreateProcess +// that can be supported cross-platform. +// +//----------------------------------------------------------------------------- +HRESULT +CreateProcessForLaunch( + __in LPWSTR lpCommandLine, + __in BOOL bSuspendProcess, + __in LPVOID lpEnvironment, + __in LPCWSTR lpCurrentDirectory, + __out PDWORD pProcessId, + __out HANDLE *pResumeHandle) +{ + PUBLIC_CONTRACT; + + PROCESS_INFORMATION processInfo; + STARTUPINFOW startupInfo; + DWORD dwCreationFlags = 0; + + ZeroMemory(&processInfo, sizeof(processInfo)); + ZeroMemory(&startupInfo, sizeof(startupInfo)); + + startupInfo.cb = sizeof(startupInfo); + + if (bSuspendProcess) + { + dwCreationFlags = CREATE_SUSPENDED; + } + + BOOL result = CreateProcessW( + NULL, + lpCommandLine, + NULL, + NULL, + FALSE, + dwCreationFlags, + lpEnvironment, + lpCurrentDirectory, + &startupInfo, + &processInfo); + + if (!result) { + *pProcessId = 0; + *pResumeHandle = NULL; + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (processInfo.hProcess != NULL) + { + CloseHandle(processInfo.hProcess); + } + + *pProcessId = processInfo.dwProcessId; + *pResumeHandle = processInfo.hThread; + + return S_OK; +} + +//----------------------------------------------------------------------------- +// Public API. +// +// ResumeProcess - to be used with the CreateProcessForLaunch resume handle +// +//----------------------------------------------------------------------------- +HRESULT +ResumeProcess( + __in HANDLE hResumeHandle) +{ + PUBLIC_CONTRACT; + if (ResumeThread(hResumeHandle) == (DWORD)-1) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + return S_OK; +} + +//----------------------------------------------------------------------------- +// Public API. +// +// CloseResumeHandle - to be used with the CreateProcessForLaunch resume handle +// +//----------------------------------------------------------------------------- +HRESULT +CloseResumeHandle( + __in HANDLE hResumeHandle) +{ + PUBLIC_CONTRACT; + if (!CloseHandle(hResumeHandle)) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + return S_OK; +} + #ifdef FEATURE_PAL static diff --git a/src/dlls/dbgshim/dbgshim.h b/src/dlls/dbgshim/dbgshim.h index 979a7ee6da..777c706ade 100644 --- a/src/dlls/dbgshim/dbgshim.h +++ b/src/dlls/dbgshim/dbgshim.h @@ -11,6 +11,23 @@ typedef VOID (*PSTARTUP_CALLBACK)(IUnknown *pCordb, PVOID parameter, HRESULT hr); EXTERN_C HRESULT +CreateProcessForLaunch( + __in LPWSTR lpCommandLine, + __in BOOL bSuspendProcess, + __in LPVOID lpEnvironment, + __in LPCWSTR lpCurrentDirectory, + __out PDWORD pProcessId, + __out HANDLE *pResumeHandle); + +EXTERN_C HRESULT +ResumeProcess( + __in HANDLE hResumeHandle); + +EXTERN_C HRESULT +CloseResumeHandle( + __in HANDLE hResumeHandle); + +EXTERN_C HRESULT RegisterForRuntimeStartup( __in DWORD dwProcessId, __in PSTARTUP_CALLBACK pfnCallback, @@ -56,4 +73,3 @@ EXTERN_C HRESULT CreateDebuggingInterfaceFromVersion( __in LPCWSTR szDebuggeeVersion, __out IUnknown ** ppCordb); - diff --git a/src/dlls/dbgshim/dbgshim.ntdef b/src/dlls/dbgshim/dbgshim.ntdef index 4b726a9da5..6915beebf9 100644 --- a/src/dlls/dbgshim/dbgshim.ntdef +++ b/src/dlls/dbgshim/dbgshim.ntdef @@ -3,6 +3,9 @@ ; See the LICENSE file in the project root for more information. EXPORTS + CreateProcessForLaunch + ResumeProcess + CloseResumeHandle RegisterForRuntimeStartup UnregisterForRuntimeStartup GetStartupNotificationEvent |