Added CreateProcessForLaunch, ResumeProcess and CloseResumeHandle that can
authorMike McLaughlin <mikem@microsoft.com>
Sat, 5 Mar 2016 01:19:20 +0000 (17:19 -0800)
committerMike McLaughlin <mikem@microsoft.com>
Wed, 9 Mar 2016 02:05:05 +0000 (18:05 -0800)
be better supported cross-plat.

Commit migrated from https://github.com/dotnet/coreclr/commit/86103a426ace432520c28b0f7ac19bcb88ce8343

src/coreclr/src/dlls/dbgshim/dbgshim.cpp
src/coreclr/src/dlls/dbgshim/dbgshim.h
src/coreclr/src/dlls/dbgshim/dbgshim.ntdef

index 7f683f3..1299bbd 100644 (file)
@@ -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
index 979a7ee..777c706 100644 (file)
 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);
-
index 4b726a9..6915bee 100644 (file)
@@ -3,6 +3,9 @@
 ; See the LICENSE file in the project root for more information.
 
 EXPORTS
+        CreateProcessForLaunch
+        ResumeProcess
+        CloseResumeHandle
         RegisterForRuntimeStartup
         UnregisterForRuntimeStartup
        GetStartupNotificationEvent