예제 #1
0
HRESULT DbgTransportTarget::CreateProcess(LPCWSTR lpApplicationName,
                          LPCWSTR lpCommandLine,
                          LPSECURITY_ATTRIBUTES lpProcessAttributes,
                          LPSECURITY_ATTRIBUTES lpThreadAttributes,
                          BOOL bInheritHandles,
                          DWORD dwCreationFlags,
                          LPVOID lpEnvironment,
                          LPCWSTR lpCurrentDirectory,
                          LPSTARTUPINFOW lpStartupInfo,
                          LPPROCESS_INFORMATION lpProcessInformation)
{

    BOOL result = WszCreateProcess(lpApplicationName, 
                                   lpCommandLine,
                                   lpProcessAttributes,
                                   lpThreadAttributes,
                                   bInheritHandles,
                                   dwCreationFlags,
                                   lpEnvironment,
                                   lpCurrentDirectory,
                                   lpStartupInfo,
                                   lpProcessInformation);

    if (!result) 
    {
        return HRESULT_FROM_GetLastError();
    }

    return S_OK;
}
예제 #2
0
BOOL LaunchJITDebugger()
{
    STATIC_CONTRACT_NOTHROW;
    STATIC_CONTRACT_GC_NOTRIGGER;
    STATIC_CONTRACT_DEBUG_ONLY;

    BOOL fSuccess = FALSE;
#ifndef FEATURE_PAL    
    EX_TRY
    {
        SString debugger;
        GetDebuggerSettingInfo(debugger, NULL);

        SECURITY_ATTRIBUTES sa;
        sa.nLength = sizeof(sa);
        sa.lpSecurityDescriptor = NULL;
        sa.bInheritHandle = TRUE;

        // We can leave this event as it is since it is inherited by a child process.
        // We will block one scheduler, but the process is asking a user if they want to attach debugger.
        HandleHolder eventHandle = WszCreateEvent(&sa, TRUE, FALSE, NULL);
        if (eventHandle == NULL)
            ThrowOutOfMemory();
        
        SString cmdLine;
        cmdLine.Printf(debugger, GetCurrentProcessId(), eventHandle.GetValue());

        STARTUPINFO StartupInfo;
        memset(&StartupInfo, 0, sizeof(StartupInfo));
        StartupInfo.cb = sizeof(StartupInfo);
        StartupInfo.lpDesktop = W("Winsta0\\Default");

        PROCESS_INFORMATION ProcessInformation;
        if (WszCreateProcess(NULL, cmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &StartupInfo, &ProcessInformation))
        {
            WaitForSingleObject(eventHandle.GetValue(), INFINITE);
        }

        fSuccess = TRUE;
    }
    EX_CATCH
    {
    }
    EX_END_CATCH(SwallowAllExceptions);
#endif // !FEATURE_PAL
    return fSuccess;
}