本文整理汇总了C++中RTMemTmpAlloc函数的典型用法代码示例。如果您正苦于以下问题:C++ RTMemTmpAlloc函数的具体用法?C++ RTMemTmpAlloc怎么用?C++ RTMemTmpAlloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTMemTmpAlloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DECLINLINE
DECLINLINE(void *) rtTarMemTmpAlloc(size_t *pcbSize)
{
*pcbSize = 0;
/* Allocate a reasonably large buffer, fall back on a tiny one.
* Note: has to be 512 byte aligned and >= 512 byte. */
size_t cbTmp = _1M;
void *pvTmp = RTMemTmpAlloc(cbTmp);
if (!pvTmp)
{
cbTmp = sizeof(RTTARRECORD);
pvTmp = RTMemTmpAlloc(cbTmp);
}
*pcbSize = cbTmp;
return pvTmp;
}
示例2: RTDECL
RTDECL(int) RTEnvUnsetUtf8(const char *pszVar)
{
AssertReturn(strchr(pszVar, '=') == NULL, VERR_ENV_INVALID_VAR_NAME);
size_t cwcVar;
int rc = RTStrCalcUtf16LenEx(pszVar, RTSTR_MAX, &cwcVar);
if (RT_SUCCESS(rc))
{
PRTUTF16 pwszTmp = (PRTUTF16)RTMemTmpAlloc((cwcVar + 1 + 1) * sizeof(RTUTF16));
if (pwszTmp)
{
rc = RTStrToUtf16Ex(pszVar, RTSTR_MAX, &pwszTmp, cwcVar + 1, NULL);
if (RT_SUCCESS(rc))
{
pwszTmp[cwcVar] = '=';
pwszTmp[cwcVar + 1] = '\0';
if (!_wputenv(pwszTmp))
rc = VINF_SUCCESS;
else
rc = RTErrConvertFromErrno(errno);
}
RTMemTmpFree(pwszTmp);
}
}
return rc;
}
示例3: alock
HRESULT MachineDebugger::logStringProps(PRTLOGGER pLogger, PFNLOGGETSTR pfnLogGetStr,
const char *pszLogGetStr, BSTR *a_pbstrSettings)
{
/* Make sure the VM is powered up. */
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
Console::SafeVMPtr ptrVM(mParent);
HRESULT hrc = ptrVM.rc();
if (FAILED(hrc))
return hrc;
/* Make sure we've got a logger. */
if (!pLogger)
{
Bstr bstrEmpty;
bstrEmpty.cloneTo(a_pbstrSettings);
return S_OK;
}
/* Do the job. */
size_t cbBuf = _1K;
for (;;)
{
char *pszBuf = (char *)RTMemTmpAlloc(cbBuf);
AssertReturn(pszBuf, E_OUTOFMEMORY);
int rc = pfnLogGetStr(pLogger, pszBuf, cbBuf);
if (RT_SUCCESS(rc))
{
try
{
Bstr bstrRet(pszBuf);
bstrRet.detachTo(a_pbstrSettings);
hrc = S_OK;
}
catch (std::bad_alloc)
{
hrc = E_OUTOFMEMORY;
}
RTMemTmpFree(pszBuf);
return hrc;
}
RTMemTmpFree(pszBuf);
AssertReturn(rc == VERR_BUFFER_OVERFLOW, setError(VBOX_E_IPRT_ERROR, tr("%s returned %Rrc"), pszLogGetStr, rc));
/* try again with a bigger buffer. */
cbBuf *= 2;
AssertReturn(cbBuf <= _256K, setError(E_FAIL, tr("%s returns too much data"), pszLogGetStr));
}
}
示例4: RTDECL
RTDECL(int) RTErrInfoAllocEx(size_t cbMsg, PRTERRINFO *ppErrInfo)
{
if (cbMsg == 0)
cbMsg = _4K;
else
cbMsg = RT_ALIGN_Z(cbMsg, 256);
PRTERRINFO pErrInfo;
*ppErrInfo = pErrInfo = (PRTERRINFO)RTMemTmpAlloc(sizeof(*pErrInfo) + cbMsg);
if (RT_UNLIKELY(!pErrInfo))
return VERR_NO_TMP_MEMORY;
RTErrInfoInit(pErrInfo, (char *)(pErrInfo + 1), cbMsg);
pErrInfo->fFlags = RTERRINFO_FLAGS_T_ALLOC | RTERRINFO_FLAGS_MAGIC;
return VINF_SUCCESS;
}
示例5: alock
HRESULT MachineDebugger::i_logStringProps(PRTLOGGER pLogger, PFNLOGGETSTR pfnLogGetStr,
const char *pszLogGetStr, Utf8Str *pstrSettings)
{
/* Make sure the VM is powered up. */
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
Console::SafeVMPtr ptrVM(mParent);
HRESULT hrc = ptrVM.rc();
if (FAILED(hrc))
return hrc;
/* Make sure we've got a logger. */
if (!pLogger)
{
*pstrSettings = "";
return S_OK;
}
/* Do the job. */
size_t cbBuf = _1K;
for (;;)
{
char *pszBuf = (char *)RTMemTmpAlloc(cbBuf);
AssertReturn(pszBuf, E_OUTOFMEMORY);
int vrc = pstrSettings->reserveNoThrow(cbBuf);
if (RT_SUCCESS(vrc))
{
vrc = pfnLogGetStr(pLogger, pstrSettings->mutableRaw(), cbBuf);
if (RT_SUCCESS(vrc))
{
pstrSettings->jolt();
return S_OK;
}
*pstrSettings = "";
AssertReturn(vrc == VERR_BUFFER_OVERFLOW, setError(VBOX_E_IPRT_ERROR, tr("%s returned %Rrc"), pszLogGetStr, vrc));
}
else
return E_OUTOFMEMORY;
/* try again with a bigger buffer. */
cbBuf *= 2;
AssertReturn(cbBuf <= _256K, setError(E_FAIL, tr("%s returns too much data"), pszLogGetStr));
}
}
示例6: vboxNetFltFreeBSDoutput
/**
* Output processing task, handles outgoing frames
*/
static void vboxNetFltFreeBSDoutput(void *arg, int pending)
{
PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)arg;
struct mbuf *m, *m0;
struct ifnet *ifp = pThis->u.s.ifp;
unsigned int cSegs = 0;
bool fDropIt = false, fActive;
PINTNETSG pSG;
VBOXCURVNET_SET(ifp->if_vnet);
vboxNetFltRetain(pThis, true /* fBusy */);
for (;;)
{
mtx_lock_spin(&pThis->u.s.outq.ifq_mtx);
_IF_DEQUEUE(&pThis->u.s.outq, m);
mtx_unlock_spin(&pThis->u.s.outq.ifq_mtx);
if (m == NULL)
break;
for (m0 = m; m0 != NULL; m0 = m0->m_next)
if (m0->m_len > 0)
cSegs++;
#ifdef PADD_RUNT_FRAMES_FROM_HOST
if (m_length(m, NULL) < 60)
cSegs++;
#endif
/* Create a copy and deliver to the virtual switch */
pSG = RTMemTmpAlloc(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
vboxNetFltFreeBSDMBufToSG(pThis, m, pSG, cSegs, 0);
fDropIt = pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL /* pvIf */, pSG, INTNETTRUNKDIR_HOST);
RTMemTmpFree(pSG);
if (fDropIt)
m_freem(m);
else
ether_output_frame(ifp, m);
}
vboxNetFltRelease(pThis, true /* fBusy */);
VBOXCURVNET_RESTORE();
}
示例7: rtManifestGetEntry
/**
* Gets an entry.
*
* @returns IPRT status code.
* @param pThis The manifest to work with.
* @param pszEntry The entry name.
* @param fNeedNormalization Whether rtManifestValidateNameEntry said it
* needed normalization.
* @param cchEntry The length of the name.
* @param ppEntry Where to return the entry pointer on success.
*/
static int rtManifestGetEntry(RTMANIFESTINT *pThis, const char *pszEntry, bool fNeedNormalization, size_t cchEntry,
PRTMANIFESTENTRY *ppEntry)
{
PRTMANIFESTENTRY pEntry;
AssertCompileMemberOffset(RTMANIFESTATTR, StrCore, 0);
if (!fNeedNormalization)
pEntry = (PRTMANIFESTENTRY)RTStrSpaceGet(&pThis->Entries, pszEntry);
else
{
char *pszCopy = (char *)RTMemTmpAlloc(cchEntry + 1);
if (RT_UNLIKELY(!pszCopy))
return VERR_NO_TMP_MEMORY;
memcpy(pszCopy, pszEntry, cchEntry + 1);
rtManifestNormalizeEntry(pszCopy);
pEntry = (PRTMANIFESTENTRY)RTStrSpaceGet(&pThis->Entries, pszCopy);
RTMemTmpFree(pszCopy);
}
*ppEntry = pEntry;
return pEntry ? VINF_SUCCESS : VERR_NOT_FOUND;
}
示例8: vbglR3GRAlloc
int vbglR3GRAlloc(VMMDevRequestHeader **ppReq, uint32_t cb, VMMDevRequestType enmReqType)
{
VMMDevRequestHeader *pReq;
AssertPtrReturn(ppReq, VERR_INVALID_PARAMETER);
AssertMsgReturn(cb >= sizeof(VMMDevRequestHeader), ("%#x vs %#zx\n", cb, sizeof(VMMDevRequestHeader)),
VERR_INVALID_PARAMETER);
pReq = (VMMDevRequestHeader *)RTMemTmpAlloc(cb);
if (RT_UNLIKELY(!pReq))
return VERR_NO_MEMORY;
pReq->size = cb;
pReq->version = VMMDEV_REQUEST_HEADER_VERSION;
pReq->requestType = enmReqType;
pReq->rc = VERR_GENERAL_FAILURE;
pReq->reserved1 = 0;
pReq->reserved2 = 0;
*ppReq = pReq;
return VINF_SUCCESS;
}
示例9: RTDECL
RTDECL(int) RTFileCopyByHandlesEx(RTFILE FileSrc, RTFILE FileDst, PFNRTPROGRESS pfnProgress, void *pvUser)
{
/*
* Validate input.
*/
AssertMsgReturn(RTFileIsValid(FileSrc), ("FileSrc=%RTfile\n", FileSrc), VERR_INVALID_PARAMETER);
AssertMsgReturn(RTFileIsValid(FileDst), ("FileDst=%RTfile\n", FileDst), VERR_INVALID_PARAMETER);
AssertMsgReturn(!pfnProgress || VALID_PTR(pfnProgress), ("pfnProgress=%p\n", pfnProgress), VERR_INVALID_PARAMETER);
/*
* Save file offset.
*/
RTFOFF offSrcSaved;
int rc = RTFileSeek(FileSrc, 0, RTFILE_SEEK_CURRENT, (uint64_t *)&offSrcSaved);
if (RT_FAILURE(rc))
return rc;
/*
* Get the file size.
*/
RTFOFF cbSrc;
rc = RTFileSeek(FileSrc, 0, RTFILE_SEEK_END, (uint64_t *)&cbSrc);
if (RT_FAILURE(rc))
return rc;
/*
* Allocate buffer.
*/
size_t cbBuf;
uint8_t *pbBufFree = NULL;
uint8_t *pbBuf;
if (cbSrc < _512K)
{
cbBuf = 8*_1K;
pbBuf = (uint8_t *)alloca(cbBuf);
}
else
{
cbBuf = _128K;
pbBuf = pbBufFree = (uint8_t *)RTMemTmpAlloc(cbBuf);
}
if (pbBuf)
{
/*
* Seek to the start of each file
* and set the size of the destination file.
*/
rc = RTFileSeek(FileSrc, 0, RTFILE_SEEK_BEGIN, NULL);
if (RT_SUCCESS(rc))
{
rc = RTFileSeek(FileDst, 0, RTFILE_SEEK_BEGIN, NULL);
if (RT_SUCCESS(rc))
rc = RTFileSetSize(FileDst, cbSrc);
if (RT_SUCCESS(rc) && pfnProgress)
rc = pfnProgress(0, pvUser);
if (RT_SUCCESS(rc))
{
/*
* Copy loop.
*/
unsigned uPercentage = 0;
RTFOFF off = 0;
RTFOFF cbPercent = cbSrc / 100;
RTFOFF offNextPercent = cbPercent;
while (off < cbSrc)
{
/* copy block */
RTFOFF cbLeft = cbSrc - off;
size_t cbBlock = cbLeft >= (RTFOFF)cbBuf ? cbBuf : (size_t)cbLeft;
rc = RTFileRead(FileSrc, pbBuf, cbBlock, NULL);
if (RT_FAILURE(rc))
break;
rc = RTFileWrite(FileDst, pbBuf, cbBlock, NULL);
if (RT_FAILURE(rc))
break;
/* advance */
off += cbBlock;
if (pfnProgress && offNextPercent < off)
{
while (offNextPercent < off)
{
uPercentage++;
offNextPercent += cbPercent;
}
rc = pfnProgress(uPercentage, pvUser);
if (RT_FAILURE(rc))
break;
}
}
#if 0
/*
* Copy OS specific data (EAs and stuff).
*/
rtFileCopyOSStuff(FileSrc, FileDst);
#endif
/* 100% */
if (pfnProgress && uPercentage < 100 && RT_SUCCESS(rc))
//.........这里部分代码省略.........
示例10: vboxguestLinuxIOCtl
static int vboxguestLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg)
#endif
{
PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pFilp->private_data;
uint32_t cbData = _IOC_SIZE(uCmd);
void *pvBufFree;
void *pvBuf;
int rc;
uint64_t au64Buf[32/sizeof(uint64_t)];
Log6(("vboxguestLinuxIOCtl: pFilp=%p uCmd=%#x ulArg=%p pid=%d/%d\n", pFilp, uCmd, (void *)ulArg, RTProcSelf(), current->pid));
/*
* Buffer the request.
*/
if (cbData <= sizeof(au64Buf))
{
pvBufFree = NULL;
pvBuf = &au64Buf[0];
}
else
{
pvBufFree = pvBuf = RTMemTmpAlloc(cbData);
if (RT_UNLIKELY(!pvBuf))
{
LogRel((DEVICE_NAME "::IOCtl: RTMemTmpAlloc failed to alloc %u bytes.\n", cbData));
return -ENOMEM;
}
}
if (RT_LIKELY(copy_from_user(pvBuf, (void *)ulArg, cbData) == 0))
{
/*
* Process the IOCtl.
*/
size_t cbDataReturned;
rc = VbgdCommonIoCtl(uCmd, &g_DevExt, pSession, pvBuf, cbData, &cbDataReturned);
/*
* Copy ioctl data and output buffer back to user space.
*/
if (RT_SUCCESS(rc))
{
rc = 0;
if (RT_UNLIKELY(cbDataReturned > cbData))
{
LogRel((DEVICE_NAME "::IOCtl: too much output data %u expected %u\n", cbDataReturned, cbData));
cbDataReturned = cbData;
}
if (cbDataReturned > 0)
{
if (RT_UNLIKELY(copy_to_user((void *)ulArg, pvBuf, cbDataReturned) != 0))
{
LogRel((DEVICE_NAME "::IOCtl: copy_to_user failed; pvBuf=%p ulArg=%p cbDataReturned=%u uCmd=%d\n",
pvBuf, (void *)ulArg, cbDataReturned, uCmd, rc));
rc = -EFAULT;
}
}
}
else
{
Log(("vboxguestLinuxIOCtl: pFilp=%p uCmd=%#x ulArg=%p failed, rc=%d\n", pFilp, uCmd, (void *)ulArg, rc));
rc = -rc; Assert(rc > 0); /* Positive returns == negated VBox error status codes. */
}
}
else
{
Log((DEVICE_NAME "::IOCtl: copy_from_user(,%#lx, %#x) failed; uCmd=%#x.\n", ulArg, cbData, uCmd));
rc = -EFAULT;
}
if (pvBufFree)
RTMemFree(pvBufFree);
Log6(("vboxguestLinuxIOCtl: returns %d (pid=%d/%d)\n", rc, RTProcSelf(), current->pid));
return rc;
}
示例11: vboxExtPackClearDesc
/**
* Reads the extension pack descriptor.
*
* @returns NULL on success, pointer to an error message on failure (caller
* deletes it).
* @param a_pszDir The directory containing the description file.
* @param a_pExtPackDesc Where to store the extension pack descriptor.
* @param a_pObjInfo Where to store the object info for the file (unix
* attribs). Optional.
*/
RTCString *VBoxExtPackLoadDescFromVfsFile(RTVFSFILE hVfsFile, PVBOXEXTPACKDESC a_pExtPackDesc, PRTFSOBJINFO a_pObjInfo)
{
vboxExtPackClearDesc(a_pExtPackDesc);
/*
* Query the object info.
*/
RTFSOBJINFO ObjInfo;
int rc = RTVfsFileQueryInfo(hVfsFile, &ObjInfo, RTFSOBJATTRADD_UNIX);
if (RT_FAILURE(rc))
return &(new RTCString)->printf("RTVfsFileQueryInfo failed: %Rrc", rc);
if (a_pObjInfo)
*a_pObjInfo = ObjInfo;
/*
* The simple approach, read the whole thing into memory and pass this to
* the XML parser.
*/
/* Check the file size. */
if (ObjInfo.cbObject > _1M || ObjInfo.cbObject < 0)
return &(new RTCString)->printf("The XML file is too large (%'RU64 bytes)", ObjInfo.cbObject);
size_t const cbFile = (size_t)ObjInfo.cbObject;
/* Rewind to the start of the file. */
rc = RTVfsFileSeek(hVfsFile, 0, RTFILE_SEEK_BEGIN, NULL);
if (RT_FAILURE(rc))
return &(new RTCString)->printf("RTVfsFileSeek(,0,BEGIN) failed: %Rrc", rc);
/* Allocate memory and read the file content into it. */
void *pvFile = RTMemTmpAlloc(cbFile);
if (!pvFile)
return &(new RTCString)->printf("RTMemTmpAlloc(%zu) failed", cbFile);
RTCString *pstrErr = NULL;
rc = RTVfsFileRead(hVfsFile, pvFile, cbFile, NULL);
if (RT_FAILURE(rc))
pstrErr = &(new RTCString)->printf("RTVfsFileRead failed: %Rrc", rc);
/*
* Parse the file.
*/
xml::Document Doc;
if (RT_SUCCESS(rc))
{
xml::XmlMemParser Parser;
RTCString strFileName = VBOX_EXTPACK_DESCRIPTION_NAME;
try
{
Parser.read(pvFile, cbFile, strFileName, Doc);
}
catch (xml::XmlError Err)
{
pstrErr = new RTCString(Err.what());
rc = VERR_PARSE_ERROR;
}
}
RTMemTmpFree(pvFile);
/*
* Hand the xml doc over to the common code.
*/
if (RT_SUCCESS(rc))
pstrErr = vboxExtPackLoadDescFromDoc(&Doc, a_pExtPackDesc);
return pstrErr;
}
示例12: vmmR3SwitcherInit
/**
* VMMR3Init worker that initiates the switcher code (aka core code).
*
* This is core per VM code which might need fixups and/or for ease of use are
* put on linear contiguous backing.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
*/
int vmmR3SwitcherInit(PVM pVM)
{
#ifndef VBOX_WITH_RAW_MODE
return VINF_SUCCESS;
#else
/*
* Calc the size.
*/
unsigned cbCoreCode = 0;
for (unsigned iSwitcher = 0; iSwitcher < RT_ELEMENTS(s_apSwitchers); iSwitcher++)
{
pVM->vmm.s.aoffSwitchers[iSwitcher] = cbCoreCode;
PVMMSWITCHERDEF pSwitcher = s_apSwitchers[iSwitcher];
if (pSwitcher)
{
AssertRelease((unsigned)pSwitcher->enmType == iSwitcher);
cbCoreCode += RT_ALIGN_32(pSwitcher->cbCode + 1, 32);
}
}
/*
* Allocate contiguous pages for switchers and deal with
* conflicts in the intermediate mapping of the code.
*/
pVM->vmm.s.cbCoreCode = RT_ALIGN_32(cbCoreCode, PAGE_SIZE);
pVM->vmm.s.pvCoreCodeR3 = SUPR3ContAlloc(pVM->vmm.s.cbCoreCode >> PAGE_SHIFT, &pVM->vmm.s.pvCoreCodeR0, &pVM->vmm.s.HCPhysCoreCode);
int rc = VERR_NO_MEMORY;
if (pVM->vmm.s.pvCoreCodeR3)
{
rc = PGMR3MapIntermediate(pVM, pVM->vmm.s.pvCoreCodeR0, pVM->vmm.s.HCPhysCoreCode, cbCoreCode);
if (rc == VERR_PGM_INTERMEDIATE_PAGING_CONFLICT)
{
/* try more allocations - Solaris, Linux. */
const unsigned cTries = 8234;
struct VMMInitBadTry
{
RTR0PTR pvR0;
void *pvR3;
RTHCPHYS HCPhys;
RTUINT cb;
} *paBadTries = (struct VMMInitBadTry *)RTMemTmpAlloc(sizeof(*paBadTries) * cTries);
AssertReturn(paBadTries, VERR_NO_TMP_MEMORY);
unsigned i = 0;
do
{
paBadTries[i].pvR3 = pVM->vmm.s.pvCoreCodeR3;
paBadTries[i].pvR0 = pVM->vmm.s.pvCoreCodeR0;
paBadTries[i].HCPhys = pVM->vmm.s.HCPhysCoreCode;
i++;
pVM->vmm.s.pvCoreCodeR0 = NIL_RTR0PTR;
pVM->vmm.s.HCPhysCoreCode = NIL_RTHCPHYS;
pVM->vmm.s.pvCoreCodeR3 = SUPR3ContAlloc(pVM->vmm.s.cbCoreCode >> PAGE_SHIFT, &pVM->vmm.s.pvCoreCodeR0, &pVM->vmm.s.HCPhysCoreCode);
if (!pVM->vmm.s.pvCoreCodeR3)
break;
rc = PGMR3MapIntermediate(pVM, pVM->vmm.s.pvCoreCodeR0, pVM->vmm.s.HCPhysCoreCode, cbCoreCode);
} while ( rc == VERR_PGM_INTERMEDIATE_PAGING_CONFLICT
&& i < cTries - 1);
/* cleanup */
if (RT_FAILURE(rc))
{
paBadTries[i].pvR3 = pVM->vmm.s.pvCoreCodeR3;
paBadTries[i].pvR0 = pVM->vmm.s.pvCoreCodeR0;
paBadTries[i].HCPhys = pVM->vmm.s.HCPhysCoreCode;
paBadTries[i].cb = pVM->vmm.s.cbCoreCode;
i++;
LogRel(("Failed to allocated and map core code: rc=%Rrc\n", rc));
}
while (i-- > 0)
{
LogRel(("Core code alloc attempt #%d: pvR3=%p pvR0=%p HCPhys=%RHp\n",
i, paBadTries[i].pvR3, paBadTries[i].pvR0, paBadTries[i].HCPhys));
SUPR3ContFree(paBadTries[i].pvR3, paBadTries[i].cb >> PAGE_SHIFT);
}
RTMemTmpFree(paBadTries);
}
}
示例13: VBoxGuestSolarisIOCtl
/**
* Driver ioctl, an alternate entry point for this character driver.
*
* @param Dev Device number
* @param Cmd Operation identifier
* @param pArg Arguments from user to driver
* @param Mode Information bitfield (read/write, address space etc.)
* @param pCred User credentials
* @param pVal Return value for calling process.
*
* @return corresponding solaris error code.
*/
static int VBoxGuestSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg, int Mode, cred_t *pCred, int *pVal)
{
LogFlow((DEVICE_NAME ":VBoxGuestSolarisIOCtl\n"));
/*
* Get the session from the soft state item.
*/
vboxguest_state_t *pState = ddi_get_soft_state(g_pVBoxGuestSolarisState, getminor(Dev));
if (!pState)
{
LogRel((DEVICE_NAME "::IOCtl: no state data for %d\n", getminor(Dev)));
return EINVAL;
}
PVBOXGUESTSESSION pSession = pState->pSession;
if (!pSession)
{
LogRel((DEVICE_NAME "::IOCtl: no session data for %d\n", getminor(Dev)));
return EINVAL;
}
/*
* Read and validate the request wrapper.
*/
VBGLBIGREQ ReqWrap;
if (IOCPARM_LEN(Cmd) != sizeof(ReqWrap))
{
LogRel((DEVICE_NAME "::IOCtl: bad request %#x size=%d expected=%d\n", Cmd, IOCPARM_LEN(Cmd), sizeof(ReqWrap)));
return ENOTTY;
}
int rc = ddi_copyin((void *)pArg, &ReqWrap, sizeof(ReqWrap), Mode);
if (RT_UNLIKELY(rc))
{
LogRel((DEVICE_NAME "::IOCtl: ddi_copyin failed to read header pArg=%p Cmd=%d. rc=%#x.\n", pArg, Cmd, rc));
return EINVAL;
}
if (ReqWrap.u32Magic != VBGLBIGREQ_MAGIC)
{
LogRel((DEVICE_NAME "::IOCtl: bad magic %#x; pArg=%p Cmd=%#x.\n", ReqWrap.u32Magic, pArg, Cmd));
return EINVAL;
}
if (RT_UNLIKELY(ReqWrap.cbData > _1M*16))
{
LogRel((DEVICE_NAME "::IOCtl: bad size %#x; pArg=%p Cmd=%#x.\n", ReqWrap.cbData, pArg, Cmd));
return EINVAL;
}
/*
* Read the request payload if any; requests like VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS have no data payload.
*/
void *pvBuf = NULL;
if (RT_LIKELY(ReqWrap.cbData > 0))
{
pvBuf = RTMemTmpAlloc(ReqWrap.cbData);
if (RT_UNLIKELY(!pvBuf))
{
LogRel((DEVICE_NAME "::IOCtl: RTMemTmpAlloc failed to alloc %d bytes.\n", ReqWrap.cbData));
return ENOMEM;
}
rc = ddi_copyin((void *)(uintptr_t)ReqWrap.pvDataR3, pvBuf, ReqWrap.cbData, Mode);
if (RT_UNLIKELY(rc))
{
RTMemTmpFree(pvBuf);
LogRel((DEVICE_NAME "::IOCtl: ddi_copyin failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd, rc));
return EFAULT;
}
if (RT_UNLIKELY(!VALID_PTR(pvBuf)))
{
RTMemTmpFree(pvBuf);
LogRel((DEVICE_NAME "::IOCtl: pvBuf invalid pointer %p\n", pvBuf));
return EINVAL;
}
}
Log((DEVICE_NAME "::IOCtl: pSession=%p pid=%d.\n", pSession, (int)RTProcSelf()));
/*
* Process the IOCtl.
*/
size_t cbDataReturned = 0;
rc = VBoxGuestCommonIOCtl(Cmd, &g_DevExt, pSession, pvBuf, ReqWrap.cbData, &cbDataReturned);
if (RT_SUCCESS(rc))
{
rc = 0;
if (RT_UNLIKELY(cbDataReturned > ReqWrap.cbData))
{
//.........这里部分代码省略.........
示例14: rtStrParseAddrStr6
/**
* Parses any string and tests if it is an IPv6 Address
*
* This function should NOT be used directly. If you do, note
* that no security checks are done at the moment. This can change.
*
* @returns iprt sstatus code.
* @param pszAddress The strin that holds the IPv6 address
* @param addressLength The length of pszAddress
* @param pszAddressOut Returns a plain, full blown IPv6 address
* as a char array
* @param addressOutSize The size of pszAddressOut (length)
* @param pPortOut 32 bit unsigned integer, holding the port
* If pszAddress doesn't contain a port, it's 0
* @param pszScopeOut Returns the scope of the address, if none it's 0
* @param scopeOutSize sizeof(pszScopeOut)
* @param pBrackets returns true if the address was enclosed in brackets
* @param pEmbeddedV4 returns true if the address is an embedded IPv4 address
* @param followRfc if set to true, the function follows RFC (default)
*/
static int rtStrParseAddrStr6(const char *pszAddress, size_t addressLength, char *pszAddressOut, size_t addressOutSize, uint32_t *pPortOut, char *pszIfIdOut, size_t ifIdOutSize, bool *pBrackets, bool *pEmbeddedV4, bool followRfc)
{
/************************\
* Pointer Hell Ahead *
\************************/
const char szIpV6AddressChars[] = "ABCDEF01234567890abcdef.:[]%"; // order IMPORTANT
const char szIpV4AddressChars[] = "01234567890.:[]"; // order IMPORTANT
const char szLinkLocalPrefix[] = "FfEe8800"; //
const char *pszIpV6AddressChars = NULL, *pszIpV4AddressChars = NULL, *pszLinkLocalPrefix = NULL;
char *pszSourceAddress = NULL, *pszSourceAddressStart = NULL;
char *pszResultAddress = NULL, *pszResultAddressStart = NULL;
char *pszResultAddress4 = NULL, *pszResultAddress4Start = NULL;
char *pszResultPort = NULL, *pszResultPortStart = NULL;
char *pszInternalAddress = NULL, *pszInternalAddressStart = NULL;
char *pszInternalPort = NULL, *pszInternalPortStart = NULL;
char *pStart = NULL, *pNow = NULL, *pNext = NULL, *pNowChar = NULL, *pIfId = NULL, *pIfIdEnd = NULL;
char *pNowDigit = NULL, *pFrom = NULL, *pTo = NULL, *pLast = NULL;
char *pGap = NULL, *pMisc = NULL, *pDotStart = NULL, *pFieldStart = NULL, *pFieldEnd = NULL;
char *pFieldStartLongest = NULL, *pBracketOpen = NULL, *pBracketClose = NULL;
char *pszRc = NULL;
bool isLinkLocal = false;
char szDummy[4];
uint8_t *pByte = NULL;
uint32_t byteOut = 0;
uint16_t returnValue = 0;
uint32_t colons = 0;
uint32_t colonsOverAll = 0;
uint32_t fieldLength = 0;
uint32_t dots = 0;
size_t gapSize = 0;
uint32_t intPortOut = 0;
pszIpV4AddressChars = &szIpV4AddressChars[0];
pszIpV6AddressChars = &szIpV6AddressChars[6];
pszLinkLocalPrefix = &szLinkLocalPrefix[6];
if (!followRfc)
pszIpV6AddressChars = &szIpV6AddressChars[0];
if (addressLength<2)
returnValue = 711;
pszResultAddressStart = (char *)RTMemTmpAlloc(34);
pszInternalAddressStart = (char *)RTMemTmpAlloc(34);
pszInternalPortStart = (char * )RTMemTmpAlloc(10);
if (! (pszResultAddressStart && pszInternalAddressStart && pszInternalPortStart))
{
if (pszResultAddressStart)
RTMemTmpFree(pszResultAddressStart);
if (pszInternalAddressStart)
RTMemTmpFree(pszInternalAddressStart);
if (pszInternalPortStart)
RTMemTmpFree(pszInternalPortStart);
return -701;
}
memset(szDummy, '\0', 4);
pszResultAddress = pszResultAddressStart;
memset(pszResultAddressStart, '\0', 34);
pszInternalAddress = pszInternalAddressStart;
memset(pszInternalAddressStart, '\0' , 34);
pszInternalPort = pszInternalPortStart;
memset(pszInternalPortStart, '\0', 10);
pszSourceAddress = pszSourceAddressStart = (char *)pszAddress;
pFrom = pTo = pStart = pLast = pszSourceAddressStart;
//.........这里部分代码省略.........
示例15: supdrvOSLdrOpen
int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
{
pImage->pvNtSectionObj = NULL;
pImage->hMemLock = NIL_RTR0MEMOBJ;
#ifdef VBOX_WITHOUT_NATIVE_R0_LOADER
# ifndef RT_ARCH_X86
# error "VBOX_WITHOUT_NATIVE_R0_LOADER is only safe on x86."
# endif
NOREF(pDevExt); NOREF(pszFilename); NOREF(pImage);
return VERR_NOT_SUPPORTED;
#else
/*
* Convert the filename from DOS UTF-8 to NT UTF-16.
*/
size_t cwcFilename;
int rc = RTStrCalcUtf16LenEx(pszFilename, RTSTR_MAX, &cwcFilename);
if (RT_FAILURE(rc))
return rc;
PRTUTF16 pwcsFilename = (PRTUTF16)RTMemTmpAlloc((4 + cwcFilename + 1) * sizeof(RTUTF16));
if (!pwcsFilename)
return VERR_NO_TMP_MEMORY;
pwcsFilename[0] = '\\';
pwcsFilename[1] = '?';
pwcsFilename[2] = '?';
pwcsFilename[3] = '\\';
PRTUTF16 pwcsTmp = &pwcsFilename[4];
rc = RTStrToUtf16Ex(pszFilename, RTSTR_MAX, &pwcsTmp, cwcFilename + 1, NULL);
if (RT_SUCCESS(rc))
{
/*
* Try load it.
*/
MYSYSTEMGDIDRIVERINFO Info;
RtlInitUnicodeString(&Info.Name, pwcsFilename);
Info.ImageAddress = NULL;
Info.SectionPointer = NULL;
Info.EntryPointer = NULL;
Info.ExportSectionPointer = NULL;
Info.ImageLength = 0;
NTSTATUS rcNt = ZwSetSystemInformation(MY_SystemLoadGdiDriverInSystemSpaceInformation, &Info, sizeof(Info));
if (NT_SUCCESS(rcNt))
{
pImage->pvImage = Info.ImageAddress;
pImage->pvNtSectionObj = Info.SectionPointer;
Log(("ImageAddress=%p SectionPointer=%p ImageLength=%#x cbImageBits=%#x rcNt=%#x '%ls'\n",
Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rcNt, Info.Name.Buffer));
# ifdef DEBUG_bird
SUPR0Printf("ImageAddress=%p SectionPointer=%p ImageLength=%#x cbImageBits=%#x rcNt=%#x '%ws'\n",
Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rcNt, Info.Name.Buffer);
# endif
if (pImage->cbImageBits == Info.ImageLength)
{
/*
* Lock down the entire image, just to be on the safe side.
*/
rc = RTR0MemObjLockKernel(&pImage->hMemLock, pImage->pvImage, pImage->cbImageBits, RTMEM_PROT_READ);
if (RT_FAILURE(rc))
{
pImage->hMemLock = NIL_RTR0MEMOBJ;
supdrvOSLdrUnload(pDevExt, pImage);
}
}
else
{
supdrvOSLdrUnload(pDevExt, pImage);
rc = VERR_LDR_MISMATCH_NATIVE;
}
}
else
{
Log(("rcNt=%#x '%ls'\n", rcNt, pwcsFilename));
SUPR0Printf("VBoxDrv: rcNt=%x '%ws'\n", rcNt, pwcsFilename);
switch (rcNt)
{
case /* 0xc0000003 */ STATUS_INVALID_INFO_CLASS:
# ifdef RT_ARCH_AMD64
/* Unwind will crash and BSOD, so no fallback here! */
rc = VERR_NOT_IMPLEMENTED;
# else
/*
* Use the old way of loading the modules.
*
* Note! We do *NOT* try class 26 because it will probably
* not work correctly on terminal servers and such.
*/
rc = VERR_NOT_SUPPORTED;
# endif
break;
case /* 0xc0000034 */ STATUS_OBJECT_NAME_NOT_FOUND:
rc = VERR_MODULE_NOT_FOUND;
break;
case /* 0xC0000263 */ STATUS_DRIVER_ENTRYPOINT_NOT_FOUND:
rc = VERR_LDR_IMPORTED_SYMBOL_NOT_FOUND;
break;
case 0xC0000428 /* STATUS_INVALID_IMAGE_HASH */ :
//.........这里部分代码省略.........