GuestProcessImpl.cpp revision 687794577e2e35c3cae67e692a7f2130d1262a82
/* $Id$ */
/** @file
* VirtualBox Main - XXX.
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* 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 (GPL) 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 *
*******************************************************************************/
#include "GuestProcessImpl.h"
#include "GuestSessionImpl.h"
#include "ConsoleImpl.h"
#include "Global.h"
#include "AutoCaller.h"
#include "Logging.h"
#include "VMMDev.h"
#include <memory> /* For auto_ptr. */
struct GuestProcessTask
{
~GuestProcessTask(void) { }
private:
int mRC;
};
struct GuestProcessStartTask : public GuestProcessTask
{
: GuestProcessTask(pProcess) { }
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
LogFlowThisFunc(("\n"));
mData.mNextContextID = 0;
mData.mProcessID = 0;
return BaseFinalConstruct();
}
void GuestProcess::FinalRelease(void)
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
int GuestProcess::init(Console *aConsole, GuestSession *aSession, ULONG aProcessID, const GuestProcessInfo &aProcInfo)
{
/* Enclose the state transition NotReady->InInit->Ready. */
AutoInitSpan autoInitSpan(this);
/* Everything else will be set by the actual starting routine. */
/* Asynchronously start the process on the guest by kicking off a
* worker thread. */
"gctlPrcStart");
if (RT_SUCCESS(rc))
{
/* task is now owned by startProcessThread(), so release it. */
/* Confirm a successful initialization when it's the case. */
}
return rc;
}
/**
* Uninitializes the instance.
* Called from FinalRelease().
*/
void GuestProcess::uninit(void)
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady. */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
}
/////////////////////////////////////////////////////////////////////////////
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
size_t s = 0;
it++, s++)
{
}
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
{
}
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
/*
SYNC TO ASK:
either can be called synchronously or asynchronously by running in a Main worker
thread.
Rules:
- Only one async operation per process a time can be around.
*/
{
ULONG uSessionID = 0;
/* Create a new context ID and assign it. */
int rc = VERR_NOT_FOUND;
ULONG uNewContextID = 0;
for (;;)
{
/* Create a new context ID ... */
if (uNewContextID == UINT32_MAX)
mData.mNextContextID = 0;
/* Is the context ID already used? Try next ID ... */
if (!callbackExists(uNewContextID))
{
/* Callback with context ID was not found. This means
* we can use this context ID for our new callback we want
* to add below. */
rc = VINF_SUCCESS;
break;
}
if (++uTries == UINT32_MAX)
break; /* Don't try too hard. */
}
if (RT_SUCCESS(rc))
{
/* Add callback with new context ID to our callback map. */
/* Report back new context ID. */
if (puContextID)
}
return rc;
}
int GuestProcess::callbackDispatcher(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData)
{
{
int rc;
switch (uFunction)
{
case GUEST_DISCONNECTED:
{
PCALLBACKDATACLIENTDISCONNECTED pCBData = reinterpret_cast<PCALLBACKDATACLIENTDISCONNECTED>(pvData);
AssertReturn(CALLBACKDATAMAGIC_CLIENT_DISCONNECTED == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
break;
}
case GUEST_EXEC_SEND_STATUS:
{
break;
}
case GUEST_EXEC_SEND_OUTPUT:
{
break;
}
{
break;
}
default:
/* Silently ignore not implemented functions. */
break;
}
return rc;
}
return VERR_NOT_FOUND;
}
{
AssertReturn(uContextID, false);
}
bool GuestProcess::isReady(void)
{
{
return true;
}
return false;
}
int GuestProcess::onGuestDisconnected(void)
{
return 0;
}
{
LogFlowFunc(("uPID=%RU32, uStatus=%RU32, uFlags=%RU32, cbDataProcessed=%RU32\n",
return 0;
}
{
LogFlowFunc(("uPID=%RU32, uStatus=%RU32, uFlags=%RU32\n",
return 0;
}
{
LogFlowFunc(("uPID=%RU32, uHandle=%RU32, uFlags=%RU32, pvData=%p, cbData=%RU32\n",
return 0;
}
int GuestProcess::readData(ULONG uHandle, ULONG uSize, ULONG uTimeoutMS, BYTE *pbData, size_t cbData)
{
LogFlowFunc(("uPID=%RU32, uHandle=%RU32, uSize=%RU32, uTimeoutMS=%RU32, pbData=%p, cbData=%z\n",
return 0;
}
int GuestProcess::startProcess(void)
{
LogFlowFunc(("aCmd=%s, aTimeoutMS=%RU32, fFlags=%x\n",
int rc;
if (!pCallbackStart)
return VERR_NO_MEMORY;
{
/* Wait until the caller function (if kicked off by a thread)
* has returned and continue operation. */
/* Create callback and add it to the map. */
if (RT_SUCCESS(rc))
}
if (RT_SUCCESS(rc))
{
/* Prepare arguments. */
if (cArgs)
{
if (RT_SUCCESS(rc))
}
/* Prepare environment. */
if (RT_SUCCESS(rc))
{
/* Prepare HGCM call. */
int i = 0;
paParms[i++].setPointer((void*)sessionCreds.mPassword.c_str(), (ULONG)sessionCreds.mPassword.length() + 1);
/*
* If the WaitForProcessStartOnly flag is set, we only want to define and wait for a timeout
* until the process was started - the process itself then gets an infinite timeout for execution.
* This is handy when we want to start a process inside a worker thread within a certain timeout
* but let the started process perform lengthly operations then.
*/
else
{
/* Make sure mParent is valid, so set the read lock while using.
* Do not keep this lock while doing the actual call, because in the meanwhile
* another thread could request a write lock which would be a bad idea ... */
/* Forward the information to the VMM device. */
}
i, paParms);
}
if (pszArgs)
if (RT_SUCCESS(rc))
{
/*
* Let's wait for the process being started.
*/
}
}
return rc;
}
{
return rc;
}
int GuestProcess::terminateProcess(void)
{
return 0;
}
{
LogFlowFunc(("fFlags=%x, uTimeoutMS=%RU32, penmReason=%p\n",
return 0;
}
int GuestProcess::writeData(ULONG uHandle, const BYTE *pbData, size_t cbData, ULONG uTimeoutMS, ULONG *puWritten)
{
LogFlowFunc(("uPID=%RU32, uHandle=%RU32, pbData=%p, cbData=%z, uTimeoutMS=%RU32, puWritten=%p\n",
/* Rest is optional. */
return 0;
}
// implementation of public methods
/////////////////////////////////////////////////////////////////////////////
STDMETHODIMP GuestProcess::Read(ULONG aHandle, ULONG aSize, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData))
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
if (aSize == 0)
AutoCaller autoCaller(this);
if (RT_SUCCESS(rc))
/** @todo Do setError() here. */
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
int rc = terminateProcess();
/** @todo Do setError() here. */
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestProcess::WaitFor(ComSafeArrayIn(ProcessWaitForFlag_T, aFlags), ULONG aTimeoutMS, ProcessWaitReason_T *aReason)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
/** @todo Do setError() here. */
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestProcess::Write(ULONG aHandle, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
/** @todo Do setError() here. */
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}