process-win.cpp revision 7c3df511b65c587226c53ce0d72c3644bc803ef9
/* $Id$ */
/** @file
* innotek Portable Runtime - Process, Win32.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_PROCESS
#include <Windows.h>
#include <process.h>
#include <errno.h>
/*
* This is from Winternl.h. It has been copied here
* because the header does not define a calling convention for
* its prototypes and just assumes that _stdcall is the standard
* calling convention.
*/
typedef struct _PEB {
typedef struct _PROCESS_BASIC_INFORMATION {
typedef enum _PROCESSINFOCLASS {
);
/** @todo r=michael This function currently does not work correctly if the arguments
contain spaces. */
RTR3DECL(int) RTProcCreate(const char *pszExec, const char * const *papszArgs, RTENV Env, unsigned fFlags, PRTPROCESS pProcess)
{
/*
* Validate input.
*/
/* later: path searching. */
/*
* Spawn the child.
*/
/** @todo utf-8 considerations! */
{
if (pProcess)
{
/*
* GetProcessId requires XP SP1 or later
*/
#if defined(RT_ARCH_AMD64)
#else /* !RT_ARCH_AMD64 */
static bool fInitialized = false;
if (!fInitialized)
{
if (hmodKernel32)
fInitialized = true;
}
if (pfnGetProcessId)
{
if (!*pProcess)
{
return rc;
}
}
else
{
/*
* Fall back to the NT api for older versions.
*/
if (Status != 0)
{
int rc = ERROR_INTERNAL_ERROR; /* (we don't have a valid conversion here, but this shouldn't happen anyway.) */
AssertMsgFailed(("failed to get pid from hProcess=%#x rc=%Vrc Status=%#x\n", hProcess, rc, Status));
return rc;
}
}
#endif /* !RT_ARCH_AMD64 */
}
return VINF_SUCCESS;
}
return rc;
}
{
AssertReturn(!(fFlags & ~(RTPROCWAIT_FLAGS_BLOCK | RTPROCWAIT_FLAGS_NOBLOCK)), VERR_INVALID_PARAMETER);
/*
* Open the process.
*/
{
/*
* Wait for it to terminate.
*/
while (WaitRc == WAIT_IO_COMPLETION)
switch (WaitRc)
{
/*
* It has terminated.
*/
case WAIT_OBJECT_0:
{
{
if (pProcStatus)
{
}
return VINF_SUCCESS;
}
break;
}
/*
* It hasn't terminated just yet.
*/
case WAIT_TIMEOUT:
return VERR_PROCESS_RUNNING;
/*
* Something went wrong...
*/
case WAIT_FAILED:
break;
case WAIT_ABANDONED:
AssertFailed();
return VERR_GENERAL_FAILURE;
default:
return VERR_GENERAL_FAILURE;
}
}
return RTErrConvertFromWin32(dwErr);
}
{
{
if (fRc)
return VINF_SUCCESS;
}
return RTErrConvertFromWin32(dwErr);
}
{
BOOL fRc = GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask);
return dwProcessAffinityMask;
}
{
return pszExecName;
return NULL;
}