本文整理汇总了C++中RTMemFree函数的典型用法代码示例。如果您正苦于以下问题:C++ RTMemFree函数的具体用法?C++ RTMemFree怎么用?C++ RTMemFree使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTMemFree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vboxClipboardWndProc
//.........这里部分代码省略.........
/* Unsupported clipboard format is requested. */
Log(("WM_RENDERFORMAT unsupported format requested or client is not active.\n"));
EmptyClipboard ();
}
else
{
int vboxrc = vboxClipboardReadDataFromClient (pCtx, u32Format);
dprintf(("vboxClipboardReadDataFromClient vboxrc = %d\n", vboxrc));
if ( RT_SUCCESS (vboxrc)
&& pCtx->pClient->data.pv != NULL
&& pCtx->pClient->data.cb > 0
&& pCtx->pClient->data.u32Format == u32Format)
{
HANDLE hMem = GlobalAlloc (GMEM_DDESHARE | GMEM_MOVEABLE, pCtx->pClient->data.cb);
dprintf(("hMem %p\n", hMem));
if (hMem)
{
void *pMem = GlobalLock (hMem);
dprintf(("pMem %p, GlobalSize %d\n", pMem, GlobalSize (hMem)));
if (pMem)
{
Log(("WM_RENDERFORMAT setting data\n"));
if (pCtx->pClient->data.pv)
{
memcpy (pMem, pCtx->pClient->data.pv, pCtx->pClient->data.cb);
RTMemFree (pCtx->pClient->data.pv);
pCtx->pClient->data.pv = NULL;
}
pCtx->pClient->data.cb = 0;
pCtx->pClient->data.u32Format = 0;
/* The memory must be unlocked before inserting to the Clipboard. */
GlobalUnlock (hMem);
/* 'hMem' contains the host clipboard data.
* size is 'cb' and format is 'format'.
*/
HANDLE hClip = SetClipboardData (format, hMem);
dprintf(("vboxClipboardHostEvent hClip %p\n", hClip));
if (hClip)
{
/* The hMem ownership has gone to the system. Nothing to do. */
break;
}
}
GlobalFree (hMem);
}
}
RTMemFree (pCtx->pClient->data.pv);
pCtx->pClient->data.pv = NULL;
pCtx->pClient->data.cb = 0;
pCtx->pClient->data.u32Format = 0;
示例2: AssertPtrReturn
//.........这里部分代码省略.........
int rc2 = RTUtf16ToUtf8(pwszFile, &pszFile);
AssertRC(rc2);
}
else
rc = VERR_NO_MEMORY;
}
else /* ANSI */
{
/* Allocate enough space (including terminator). */
pszFile = (char *)RTMemAlloc((cch + 1) * sizeof(char));
if (pszFile)
{
cchFile = DragQueryFileA(hDrop, i /* File index */,
pszFile, cchFile + 1 /* Include terminator */);
AssertMsg(cchFile == cch, ("cchCopied (%RU16) does not match cchFile (%RU16)\n",
cchFile, cch));
}
else
rc = VERR_NO_MEMORY;
}
if (RT_SUCCESS(rc))
{
LogFlowFunc(("\tFile: %s (cchFile=%RU32)\n",
pszFile, cchFile));
rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */,
pszFile, cchFile);
if (RT_SUCCESS(rc))
cchFiles += cchFile;
}
if (pszFile)
RTMemFree(pszFile);
if (RT_FAILURE(rc))
break;
/* Add separation between filenames.
* Note: Also do this for the last element of the list. */
rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */,
"\r\n", 2 /* Bytes */);
if (RT_SUCCESS(rc))
cchFiles += 2; /* Include \r\n */
}
if (RT_SUCCESS(rc))
{
cchFiles += 1; /* Add string termination. */
uint32_t cbFiles = cchFiles * sizeof(char);
LogFlowFunc(("cFiles=%u, cchFiles=%RU32, cbFiles=%RU32, pszFiles=0x%p\n",
cFiles, cchFiles, cbFiles, pszFiles));
/* Translate the list into URI elements. */
DnDURIList lstURI;
rc = lstURI.AppendNativePathsFromList(pszFiles, cbFiles,
DNDURILIST_FLAGS_ABSOLUTE_PATHS);
if (RT_SUCCESS(rc))
{
RTCString strRoot = lstURI.RootToString();
size_t cbRoot = strRoot.length() + 1; /* Include termination */
mpvData = RTMemAlloc(cbRoot);
if (mpvData)
{
示例3: RTDECL
RTDECL(int) RTSemRWDestroy(RTSEMRW hRWSem)
{
struct RTSEMRWINTERNAL *pThis = hRWSem;
/*
* Validate handle.
*/
if (pThis == NIL_RTSEMRW)
return VINF_SUCCESS;
AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, VERR_INVALID_HANDLE);
/*
* Check if busy.
*/
int rc = RTCritSectTryEnter(&pThis->CritSect);
if (RT_SUCCESS(rc))
{
if (!pThis->cReads && !pThis->cWrites)
{
/*
* Make it invalid and unusable.
*/
ASMAtomicWriteU32(&pThis->u32Magic, ~RTSEMRW_MAGIC);
pThis->cReads = ~0;
/*
* Do actual cleanup. None of these can now fail.
*/
rc = RTSemEventMultiDestroy(pThis->ReadEvent);
AssertMsgRC(rc, ("RTSemEventMultiDestroy failed! rc=%Rrc\n", rc));
pThis->ReadEvent = NIL_RTSEMEVENTMULTI;
rc = RTSemEventDestroy(pThis->WriteEvent);
AssertMsgRC(rc, ("RTSemEventDestroy failed! rc=%Rrc\n", rc));
pThis->WriteEvent = NIL_RTSEMEVENT;
RTCritSectLeave(&pThis->CritSect);
rc = RTCritSectDelete(&pThis->CritSect);
AssertMsgRC(rc, ("RTCritSectDelete failed! rc=%Rrc\n", rc));
#ifdef RTSEMRW_STRICT
RTLockValidatorRecSharedDelete(&pThis->ValidatorRead);
RTLockValidatorRecExclDelete(&pThis->ValidatorWrite);
#endif
RTMemFree(pThis);
rc = VINF_SUCCESS;
}
else
{
rc = VERR_SEM_BUSY;
RTCritSectLeave(&pThis->CritSect);
}
}
else
{
AssertMsgRC(rc, ("RTCritSectTryEnter failed! rc=%Rrc\n", rc));
rc = VERR_SEM_BUSY;
}
return rc;
}
示例4: RTDECL
RTDECL(int) RTMemCacheCreate(PRTMEMCACHE phMemCache, size_t cbObject, size_t cbAlignment, uint32_t cMaxObjects,
PFNMEMCACHECTOR pfnCtor, PFNMEMCACHEDTOR pfnDtor, void *pvUser, uint32_t fFlags)
{
AssertPtr(phMemCache);
AssertPtrNull(pfnCtor);
AssertPtrNull(pfnDtor);
AssertReturn(!pfnDtor || pfnCtor, VERR_INVALID_PARAMETER);
AssertReturn(cbObject > 0, VERR_INVALID_PARAMETER);
AssertReturn(cbObject <= PAGE_SIZE / 8, VERR_INVALID_PARAMETER);
AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
if (cbAlignment == 0)
{
if (cbObject <= 2)
cbAlignment = cbObject;
else if (cbObject <= 4)
cbAlignment = 4;
else if (cbObject <= 8)
cbAlignment = 8;
else if (cbObject <= 16)
cbAlignment = 16;
else if (cbObject <= 32)
cbAlignment = 32;
else
cbAlignment = 64;
}
else
{
AssertReturn(!((cbAlignment - 1) & cbAlignment), VERR_NOT_POWER_OF_TWO);
AssertReturn(cbAlignment <= 64, VERR_OUT_OF_RANGE);
}
/*
* Allocate and initialize the instance memory.
*/
RTMEMCACHEINT *pThis = (RTMEMCACHEINT *)RTMemAlloc(sizeof(*pThis));
if (!pThis)
return VERR_NO_MEMORY;
int rc = RTCritSectInit(&pThis->CritSect);
if (RT_FAILURE(rc))
{
RTMemFree(pThis);
return rc;
}
pThis->u32Magic = RTMEMCACHE_MAGIC;
pThis->cbObject = (uint32_t)RT_ALIGN_Z(cbObject, cbAlignment);
pThis->cbAlignment = (uint32_t)cbAlignment;
pThis->cPerPage = (uint32_t)((PAGE_SIZE - RT_ALIGN_Z(sizeof(RTMEMCACHEPAGE), cbAlignment)) / pThis->cbObject);
while ( RT_ALIGN_Z(sizeof(RTMEMCACHEPAGE), 8)
+ pThis->cPerPage * pThis->cbObject
+ RT_ALIGN(pThis->cPerPage, 64) / 8 * 2
> PAGE_SIZE)
pThis->cPerPage--;
pThis->cBits = RT_ALIGN(pThis->cPerPage, 64);
pThis->cMax = cMaxObjects;
pThis->fUseFreeList = cbObject >= sizeof(RTMEMCACHEFREEOBJ)
&& !pfnCtor
&& !pfnDtor;
pThis->pPageHead = NULL;
pThis->pfnCtor = pfnCtor;
pThis->pfnDtor = pfnDtor;
pThis->pvUser = pvUser;
pThis->cTotal = 0;
pThis->cFree = 0;
pThis->pPageHint = NULL;
pThis->pFreeTop = NULL;
/** @todo
* Here is a puzzler (or maybe I'm just blind), the free list code breaks
* badly on my macbook pro (i7) (32-bit).
*
* I tried changing the reads from unordered to ordered to no avail. Then I
* tried optimizing the code with the ASMAtomicCmpXchgExPtr function to
* avoid some reads - no change. Inserting pause instructions did nothing
* (as expected). The only thing which seems to make a difference is
* reading the pFreeTop pointer twice in the the free code... This is weird
* or I'm overlooking something..
*
* No time to figure it out, so I'm disabling the broken code paths for
* now. */
pThis->fUseFreeList = false;
*phMemCache = pThis;
return VINF_SUCCESS;
}
示例5: vboxvfs_mount
static int vboxvfs_mount(struct mount *mp, struct thread *td)
{
int rc;
char *pszShare;
int cbShare, cbOption;
int uid = 0, gid = 0;
struct sf_glob_info *pShFlGlobalInfo;
SHFLSTRING *pShFlShareName = NULL;
int cbShFlShareName;
printf("%s: Enter\n", __FUNCTION__);
if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
return EOPNOTSUPP;
if (vfs_filteropt(mp->mnt_optnew, vboxvfs_opts))
{
vfs_mount_error(mp, "%s", "Invalid option");
return EINVAL;
}
rc = vfs_getopt(mp->mnt_optnew, "from", (void **)&pszShare, &cbShare);
if (rc || pszShare[cbShare-1] != '\0' || cbShare > 0xfffe)
return EINVAL;
rc = vfs_getopt(mp->mnt_optnew, "gid", (void **)&gid, &cbOption);
if ((rc != ENOENT) && (rc || cbOption != sizeof(gid)))
return EINVAL;
rc = vfs_getopt(mp->mnt_optnew, "uid", (void **)&uid, &cbOption);
if ((rc != ENOENT) && (rc || cbOption != sizeof(uid)))
return EINVAL;
pShFlGlobalInfo = RTMemAllocZ(sizeof(struct sf_glob_info));
if (!pShFlGlobalInfo)
return ENOMEM;
cbShFlShareName = offsetof (SHFLSTRING, String.utf8) + cbShare + 1;
pShFlShareName = RTMemAllocZ(cbShFlShareName);
if (!pShFlShareName)
return VERR_NO_MEMORY;
pShFlShareName->u16Length = cbShFlShareName;
pShFlShareName->u16Size = cbShFlShareName + 1;
memcpy (pShFlShareName->String.utf8, pszShare, cbShare + 1);
rc = vboxCallMapFolder (&g_vboxSFClient, pShFlShareName, &pShFlGlobalInfo->map);
RTMemFree(pShFlShareName);
if (RT_FAILURE (rc))
{
RTMemFree(pShFlGlobalInfo);
printf("vboxCallMapFolder failed rc=%d\n", rc);
return EPROTO;
}
pShFlGlobalInfo->uid = uid;
pShFlGlobalInfo->gid = gid;
mp->mnt_data = pShFlGlobalInfo;
/* @todo root vnode. */
vfs_getnewfsid(mp);
vfs_mountedfrom(mp, pszShare);
printf("%s: Leave rc=0\n", __FUNCTION__);
return 0;
}
示例6: RTDECL
/**
* Free a symbol structure previously allocated by a RTDbg method.
*
* @param pSymInfo The symbol info to free. NULL is ignored.
*/
RTDECL(void) RTDbgSymbolFree(PRTDBGSYMBOL pSymInfo)
{
RTMemFree(pSymInfo);
}
示例7: freeDeviceMembers
/**
* Free one USB device returned by getDevice().
*
* @param pDevice Pointer to the device.
*/
/*static*/ void
USBProxyService::freeDevice(PUSBDEVICE pDevice)
{
freeDeviceMembers(pDevice);
RTMemFree(pDevice);
}
示例8: VBoxDrvLinuxIOCtlSlow
/**
* Device I/O Control entry point.
*
* @param pFilp Associated file pointer.
* @param uCmd The function specified to ioctl().
* @param ulArg The argument specified to ioctl().
* @param pSession The session instance.
*/
static int VBoxDrvLinuxIOCtlSlow(struct file *pFilp, unsigned int uCmd, unsigned long ulArg, PSUPDRVSESSION pSession)
{
int rc;
SUPREQHDR Hdr;
PSUPREQHDR pHdr;
uint32_t cbBuf;
Log6(("VBoxDrvLinuxIOCtl: pFilp=%p uCmd=%#x ulArg=%p pid=%d/%d\n", pFilp, uCmd, (void *)ulArg, RTProcSelf(), current->pid));
/*
* Read the header.
*/
if (RT_FAILURE(RTR0MemUserCopyFrom(&Hdr, ulArg, sizeof(Hdr))))
{
Log(("VBoxDrvLinuxIOCtl: copy_from_user(,%#lx,) failed; uCmd=%#x\n", ulArg, uCmd));
return -EFAULT;
}
if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
{
Log(("VBoxDrvLinuxIOCtl: bad header magic %#x; uCmd=%#x\n", Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK, uCmd));
return -EINVAL;
}
/*
* Buffer the request.
*/
cbBuf = RT_MAX(Hdr.cbIn, Hdr.cbOut);
if (RT_UNLIKELY(cbBuf > _1M*16))
{
Log(("VBoxDrvLinuxIOCtl: too big cbBuf=%#x; uCmd=%#x\n", cbBuf, uCmd));
return -E2BIG;
}
if (RT_UNLIKELY(_IOC_SIZE(uCmd) ? cbBuf != _IOC_SIZE(uCmd) : Hdr.cbIn < sizeof(Hdr)))
{
Log(("VBoxDrvLinuxIOCtl: bad ioctl cbBuf=%#x _IOC_SIZE=%#x; uCmd=%#x\n", cbBuf, _IOC_SIZE(uCmd), uCmd));
return -EINVAL;
}
pHdr = RTMemAlloc(cbBuf);
if (RT_UNLIKELY(!pHdr))
{
OSDBGPRINT(("VBoxDrvLinuxIOCtl: failed to allocate buffer of %d bytes for uCmd=%#x\n", cbBuf, uCmd));
return -ENOMEM;
}
if (RT_FAILURE(RTR0MemUserCopyFrom(pHdr, ulArg, Hdr.cbIn)))
{
Log(("VBoxDrvLinuxIOCtl: copy_from_user(,%#lx, %#x) failed; uCmd=%#x\n", ulArg, Hdr.cbIn, uCmd));
RTMemFree(pHdr);
return -EFAULT;
}
if (Hdr.cbIn < cbBuf)
RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbBuf - Hdr.cbIn);
/*
* Process the IOCtl.
*/
rc = supdrvIOCtl(uCmd, &g_DevExt, pSession, pHdr, cbBuf);
/*
* Copy ioctl data and output buffer back to user space.
*/
if (RT_LIKELY(!rc))
{
uint32_t cbOut = pHdr->cbOut;
if (RT_UNLIKELY(cbOut > cbBuf))
{
OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n", cbOut, cbBuf, uCmd));
cbOut = cbBuf;
}
if (RT_FAILURE(RTR0MemUserCopyTo(ulArg, pHdr, cbOut)))
{
/* this is really bad! */
OSDBGPRINT(("VBoxDrvLinuxIOCtl: copy_to_user(%#lx,,%#x); uCmd=%#x!\n", ulArg, cbOut, uCmd));
rc = -EFAULT;
}
}
else
{
Log(("VBoxDrvLinuxIOCtl: pFilp=%p uCmd=%#x ulArg=%p failed, rc=%d\n", pFilp, uCmd, (void *)ulArg, rc));
rc = -EINVAL;
}
RTMemFree(pHdr);
Log6(("VBoxDrvLinuxIOCtl: returns %d (pid=%d/%d)\n", rc, RTProcSelf(), current->pid));
return rc;
}
示例9: VBoxDispD3DGlobal2DFormatsTerm
void VBoxDispD3DGlobal2DFormatsTerm(PVBOXWDDMDISP_ADAPTER pAdapter)
{
if (pAdapter->Formats.paFormstOps)
RTMemFree((void *)pAdapter->Formats.paFormstOps);
}
示例10: RTDECL
RTDECL(int) RTCrStoreCertExportAsPem(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename)
{
/*
* Validate input.
*/
AssertReturn(!fFlags, VERR_INVALID_FLAGS);
/*
* Start the enumeration first as this validates the store handle.
*/
RTCRSTORECERTSEARCH Search;
int rc = RTCrStoreCertFindAll(hStore, &Search);
if (RT_SUCCESS(rc))
{
/*
* Open the file for writing.
*
* Note! We must use text and no binary here, because the base-64 API
* below will use host specific EOL markers, not CRLF as PEM
* specifies.
*/
PRTSTREAM hStrm;
rc = RTStrmOpen(pszFilename, "w", &hStrm);
if (RT_SUCCESS(rc))
{
/*
* Enumerate the certificates in the store, writing them out one by one.
*/
size_t cbBase64 = 0;
char *pszBase64 = NULL;
PCRTCRCERTCTX pCertCtx;
while ((pCertCtx = RTCrStoreCertSearchNext(hStore, &Search)) != NULL)
{
const char *pszMarker;
switch (pCertCtx->fFlags & RTCRCERTCTX_F_ENC_MASK)
{
case RTCRCERTCTX_F_ENC_X509_DER: pszMarker = "CERTIFICATE"; break;
case RTCRCERTCTX_F_ENC_TAF_DER: pszMarker = "TRUST ANCHOR"; break;
default: pszMarker = NULL; break;
}
if (pszMarker && pCertCtx->cbEncoded > 0)
{
/*
* Do the base64 conversion first.
*/
size_t cchEncoded = RTBase64EncodedLength(pCertCtx->cbEncoded);
if (cchEncoded < cbBase64)
{ /* likely */ }
else
{
size_t cbNew = RT_ALIGN(cchEncoded + 64, 128);
void *pvNew = RTMemRealloc(pszBase64, cbNew);
if (!pvNew)
{
rc = VERR_NO_MEMORY;
break;
}
cbBase64 = cbNew;
pszBase64 = (char *)pvNew;
}
rc = RTBase64Encode(pCertCtx->pabEncoded, pCertCtx->cbEncoded, pszBase64, cbBase64, &cchEncoded);
if (RT_FAILURE(rc))
break;
RTStrmPrintf(hStrm, "-----BEGIN %s-----\n", pszMarker);
RTStrmWrite(hStrm, pszBase64, cchEncoded);
rc = RTStrmPrintf(hStrm, "\n-----END %s-----\n", pszMarker);
if (RT_FAILURE(rc))
break;
}
RTCrCertCtxRelease(pCertCtx);
}
if (pCertCtx)
RTCrCertCtxRelease(pCertCtx);
RTMemFree(pszBase64);
/*
* Flush the output file before closing.
*/
int rc2 = RTStrmFlush(hStrm);
if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
rc = rc2;
RTStrmClearError(hStrm); /** @todo fix RTStrmClose... */
rc2 = RTStrmClose(hStrm);
if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
rc = rc2;
}
int rc2 = RTCrStoreCertSearchDestroy(hStore, &Search); AssertRC(rc2);
}
return rc;
}
示例11: DECLCALLBACK
DECLCALLBACK(int) vboxUhgsmiD3DBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf,
VBOXUHGSMI_SYNCHOBJECT_TYPE enmSynchType, HVBOXUHGSMI_SYNCHOBJECT hSynch,
PVBOXUHGSMI_BUFFER* ppBuf)
{
bool bSynchCreated = false;
if (!cbBuf)
return VERR_INVALID_PARAMETER;
int rc = vboxUhgsmiBaseEventChkCreate(enmSynchType, &hSynch, &bSynchCreated);
AssertRC(rc);
if (RT_FAILURE(rc))
return rc;
cbBuf = VBOXWDDM_ROUNDBOUND(cbBuf, 0x1000);
Assert(cbBuf);
uint32_t cPages = cbBuf >> 12;
Assert(cPages);
PVBOXUHGSMI_PRIVATE_D3D pPrivate = VBOXUHGSMID3D_GET(pHgsmi);
PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuf = (PVBOXUHGSMI_BUFFER_PRIVATE_D3D)RTMemAllocZ(RT_OFFSETOF(VBOXUHGSMI_BUFFER_PRIVATE_D3D, aLockPageIndices[cPages]));
Assert(pBuf);
if (pBuf)
{
struct
{
D3DDDICB_ALLOCATE DdiAlloc;
D3DDDI_ALLOCATIONINFO DdiAllocInfo;
VBOXWDDM_ALLOCINFO AllocInfo;
} Buf;
memset(&Buf, 0, sizeof (Buf));
Buf.DdiAlloc.hResource = NULL;
Buf.DdiAlloc.hKMResource = NULL;
Buf.DdiAlloc.NumAllocations = 1;
Buf.DdiAlloc.pAllocationInfo = &Buf.DdiAllocInfo;
Buf.DdiAllocInfo.pPrivateDriverData = &Buf.AllocInfo;
Buf.DdiAllocInfo.PrivateDriverDataSize = sizeof (Buf.AllocInfo);
Buf.AllocInfo.enmType = VBOXWDDM_ALLOC_TYPE_UMD_HGSMI_BUFFER;
Buf.AllocInfo.cbBuffer = cbBuf;
Buf.AllocInfo.hSynch = hSynch;
Buf.AllocInfo.enmSynchType = enmSynchType;
HRESULT hr = pPrivate->pDevice->RtCallbacks.pfnAllocateCb(pPrivate->pDevice->hDevice, &Buf.DdiAlloc);
Assert(hr == S_OK);
if (hr == S_OK)
{
Assert(Buf.DdiAllocInfo.hAllocation);
pBuf->BasePrivate.Base.pfnLock = vboxUhgsmiD3DBufferLock;
pBuf->BasePrivate.Base.pfnUnlock = vboxUhgsmiD3DBufferUnlock;
// pBuf->Base.pfnAdjustValidDataRange = vboxUhgsmiD3DBufferAdjustValidDataRange;
pBuf->BasePrivate.Base.pfnDestroy = vboxUhgsmiD3DBufferDestroy;
pBuf->BasePrivate.Base.hSynch = hSynch;
pBuf->BasePrivate.Base.enmSynchType = enmSynchType;
pBuf->BasePrivate.Base.cbBuffer = cbBuf;
pBuf->BasePrivate.Base.bSynchCreated = bSynchCreated;
pBuf->pDevice = pPrivate->pDevice;
pBuf->BasePrivate.hAllocation = Buf.DdiAllocInfo.hAllocation;
*ppBuf = &pBuf->BasePrivate.Base;
return VINF_SUCCESS;
}
RTMemFree(pBuf);
}
else
rc = VERR_NO_MEMORY;
if (bSynchCreated)
CloseHandle(hSynch);
return rc;
}
示例12: tstVDBackendInfo
//.........这里部分代码省略.........
if (pa == aVDInfo[i].paFileExtensions)
RTPrintf("<EMPTY>");
}
else
RTPrintf("<NONE>");
RTPrintf(" config=");
if (aVDInfo[i].paConfigInfo)
{
PCVDCONFIGINFO pa = aVDInfo[i].paConfigInfo;
while (pa->pszKey != NULL)
{
if (pa != aVDInfo[i].paConfigInfo)
RTPrintf(",");
RTPrintf("(key=%s type=", pa->pszKey);
switch (pa->enmValueType)
{
case VDCFGVALUETYPE_INTEGER:
RTPrintf("integer");
break;
case VDCFGVALUETYPE_STRING:
RTPrintf("string");
break;
case VDCFGVALUETYPE_BYTES:
RTPrintf("bytes");
break;
default:
RTPrintf("INVALID!");
}
RTPrintf(" default=");
if (pa->pszDefaultValue)
RTPrintf("%s", pa->pszDefaultValue);
else
RTPrintf("<NONE>");
RTPrintf(" flags=");
if (!pa->uKeyFlags)
RTPrintf("none");
unsigned cFlags = 0;
if (pa->uKeyFlags & VD_CFGKEY_MANDATORY)
{
if (cFlags)
RTPrintf(",");
RTPrintf("mandatory");
cFlags++;
}
if (pa->uKeyFlags & VD_CFGKEY_EXPERT)
{
if (cFlags)
RTPrintf(",");
RTPrintf("expert");
cFlags++;
}
RTPrintf(")");
pa++;
}
if (pa == aVDInfo[i].paConfigInfo)
RTPrintf("<EMPTY>");
}
else
RTPrintf("<NONE>");
RTPrintf("\n");
PVDINTERFACE pVDIfs = NULL;
VDINTERFACECONFIG ic;
ic.pfnAreKeysValid = tstAreKeysValid;
ic.pfnQuerySize = tstQuerySize;
ic.pfnQuery = tstQuery;
rc = VDInterfaceAdd(&ic.Core, "tstVD-2_Config", VDINTERFACETYPE_CONFIG,
NULL, sizeof(VDINTERFACECONFIG), &pVDIfs);
AssertRC(rc);
char *pszLocation, *pszName;
rc = aVDInfo[i].pfnComposeLocation(pVDIfs, &pszLocation);
CHECK("pfnComposeLocation()");
if (pszLocation)
{
RTMemFree(pszLocation);
if (aVDInfo[i].uBackendCaps & VD_CAP_FILE)
{
RTPrintf("Non-NULL location returned for file-based backend!\n");
return VERR_INTERNAL_ERROR;
}
}
rc = aVDInfo[i].pfnComposeName(pVDIfs, &pszName);
CHECK("pfnComposeName()");
if (pszName)
{
RTMemFree(pszName);
if (aVDInfo[i].uBackendCaps & VD_CAP_FILE)
{
RTPrintf("Non-NULL name returned for file-based backend!\n");
return VERR_INTERNAL_ERROR;
}
}
}
#undef CHECK
return 0;
}
示例13: cpumR3DbGetCpuInfo
//.........这里部分代码省略.........
|| pEntry->uFamily != uFamily)
pEntry = pCur;
else if ( pCur->enmMicroarch >= enmMicroarch
? pCur->enmMicroarch < pEntry->enmMicroarch || pEntry->enmMicroarch < enmMicroarch
: pCur->enmMicroarch > pEntry->enmMicroarch)
pEntry = pCur;
}
/* We don't do closeness matching on family, we use the first
entry for the CPU vendor instead. (P4 workaround.) */
else if (!pEntry)
pEntry = pCur;
}
}
if (pEntry)
LogRel(("CPUM: Matched host CPU %s %#x/%#x/%#x %s with CPU DB entry '%s' (%s %#x/%#x/%#x %s).\n",
CPUMR3CpuVendorName(enmVendor), uFamily, uModel, uStepping, CPUMR3MicroarchName(enmMicroarch),
pEntry->pszName, CPUMR3CpuVendorName((CPUMCPUVENDOR)pEntry->enmVendor), pEntry->uFamily, pEntry->uModel,
pEntry->uStepping, CPUMR3MicroarchName(pEntry->enmMicroarch) ));
else
{
pEntry = g_apCpumDbEntries[0];
LogRel(("CPUM: No matching processor database entry %s %#x/%#x/%#x %s, falling back on '%s'.\n",
CPUMR3CpuVendorName(enmVendor), uFamily, uModel, uStepping, CPUMR3MicroarchName(enmMicroarch),
pEntry->pszName));
}
}
else
{
/*
* We're supposed to be emulating a specific CPU that is included in
* our CPU database. The CPUID tables needs to be copied onto the
* heap so the caller can modify them and so they can be freed like
* in the host case above.
*/
for (unsigned i = 0; i < RT_ELEMENTS(g_apCpumDbEntries); i++)
if (!strcmp(pszName, g_apCpumDbEntries[i]->pszName))
{
pEntry = g_apCpumDbEntries[i];
break;
}
if (!pEntry)
{
LogRel(("CPUM: Cannot locate any CPU by the name '%s'\n", pszName));
return VERR_CPUM_DB_CPU_NOT_FOUND;
}
pInfo->cCpuIdLeaves = pEntry->cCpuIdLeaves;
if (pEntry->cCpuIdLeaves)
{
pInfo->paCpuIdLeavesR3 = (PCPUMCPUIDLEAF)RTMemDup(pEntry->paCpuIdLeaves,
sizeof(pEntry->paCpuIdLeaves[0]) * pEntry->cCpuIdLeaves);
if (!pInfo->paCpuIdLeavesR3)
return VERR_NO_MEMORY;
}
else
pInfo->paCpuIdLeavesR3 = NULL;
pInfo->enmUnknownCpuIdMethod = pEntry->enmUnknownCpuId;
pInfo->DefCpuId = pEntry->DefUnknownCpuId;
LogRel(("CPUM: Using CPU DB entry '%s' (%s %#x/%#x/%#x %s).\n",
pEntry->pszName, CPUMR3CpuVendorName((CPUMCPUVENDOR)pEntry->enmVendor),
pEntry->uFamily, pEntry->uModel, pEntry->uStepping, CPUMR3MicroarchName(pEntry->enmMicroarch) ));
}
pInfo->fMsrMask = pEntry->fMsrMask;
pInfo->iFirstExtCpuIdLeaf = 0; /* Set by caller. */
pInfo->uPadding = 0;
pInfo->uScalableBusFreq = pEntry->uScalableBusFreq;
pInfo->paCpuIdLeavesR0 = NIL_RTR0PTR;
pInfo->paMsrRangesR0 = NIL_RTR0PTR;
pInfo->paCpuIdLeavesRC = NIL_RTRCPTR;
pInfo->paMsrRangesRC = NIL_RTRCPTR;
/*
* Copy the MSR range.
*/
uint32_t cMsrs = 0;
PCPUMMSRRANGE paMsrs = NULL;
PCCPUMMSRRANGE pCurMsr = pEntry->paMsrRanges;
uint32_t cLeft = pEntry->cMsrRanges;
while (cLeft-- > 0)
{
rc = cpumR3MsrRangesInsert(&paMsrs, &cMsrs, pCurMsr);
if (RT_FAILURE(rc))
{
Assert(!paMsrs); /* The above function frees this. */
RTMemFree(pInfo->paCpuIdLeavesR3);
pInfo->paCpuIdLeavesR3 = NULL;
return rc;
}
pCurMsr++;
}
pInfo->paMsrRangesR3 = paMsrs;
pInfo->cMsrRanges = cMsrs;
return VINF_SUCCESS;
}
示例14: DECLCALLBACK
static DECLCALLBACK(int) scriptRun(PVM pVM, RTFILE File)
{
RTPrintf("info: running script...\n");
uint64_t cb;
int rc = RTFileGetSize(File, &cb);
if (RT_SUCCESS(rc))
{
if (cb == 0)
return VINF_SUCCESS;
if (cb < _1M)
{
char *pszBuf = (char *)RTMemAllocZ(cb + 1);
if (pszBuf)
{
rc = RTFileRead(File, pszBuf, cb, NULL);
if (RT_SUCCESS(rc))
{
pszBuf[cb] = '\0';
/*
* Now process what's in the buffer.
*/
char *psz = pszBuf;
while (psz && *psz)
{
/* skip blanks. */
while (RT_C_IS_SPACE(*psz))
psz++;
if (!*psz)
break;
/* end of line */
char *pszNext;
char *pszEnd = strchr(psz, '\n');
if (!pszEnd)
pszEnd = strchr(psz, '\r');
if (!pszEnd)
pszNext = pszEnd = strchr(psz, '\0');
else
pszNext = pszEnd + 1;
if (*psz != ';' && *psz != '#' && *psz != '/')
{
/* strip end */
*pszEnd = '\0';
while (pszEnd > psz && RT_C_IS_SPACE(pszEnd[-1]))
*--pszEnd = '\0';
/* process the line */
RTPrintf("debug: executing script line '%s'\n", psz);
rc = scriptCommand(pVM, psz, pszEnd - psz);
if (RT_FAILURE(rc))
{
RTPrintf("error: '%s' failed: %Rrc\n", psz, rc);
break;
}
}
/* else comment line */
/* next */
psz = pszNext;
}
}
else
RTPrintf("error: failed to read script file: %Rrc\n", rc);
RTMemFree(pszBuf);
}
else
{
RTPrintf("error: Out of memory. (%d bytes)\n", cb + 1);
rc = VERR_NO_MEMORY;
}
}
else
RTPrintf("error: script file is too large (0x%llx bytes)\n", cb);
}
else
RTPrintf("error: couldn't get size of script file: %Rrc\n", rc);
return rc;
}
示例15: VBOXDDU_DECL
VBOXDDU_DECL(int) VDDbgIoLogEventGetStartDiscard(VDIOLOGGER hIoLogger, uint64_t *pidEvent, bool *pfAsync,
PRTRANGE *ppaRanges, unsigned *pcRanges)
{
int rc = VINF_SUCCESS;
PVDIOLOGGERINT pIoLogger = hIoLogger;
AssertPtrReturn(pIoLogger, VERR_INVALID_HANDLE);
AssertPtrReturn(pidEvent, VERR_INVALID_POINTER);
AssertPtrReturn(pfAsync, VERR_INVALID_POINTER);
rc = RTSemFastMutexRequest(pIoLogger->hMtx);
AssertRCReturn(rc, rc);
if ( pIoLogger->u32EventTypeNext == VDIOLOG_EVENT_START
&& pIoLogger->enmReqTypeNext == VDDBGIOLOGREQ_DISCARD)
{
IoLogEntryStart Entry;
rc = RTFileReadAt(pIoLogger->hFile, pIoLogger->offReadNext, &Entry, sizeof(Entry), NULL);
if (RT_SUCCESS(rc))
{
PRTRANGE paRanges = NULL;
IoLogEntryDiscard DiscardRange;
pIoLogger->offReadNext += sizeof(Entry);
*pfAsync = RT_BOOL(Entry.u8AsyncIo);
*pidEvent = RT_LE2H_U64(Entry.u64Id);
*pcRanges = RT_LE2H_U32(Entry.Discard.cRanges);
paRanges = (PRTRANGE)RTMemAllocZ(*pcRanges * sizeof(RTRANGE));
if (paRanges)
{
for (unsigned i = 0; i < *pcRanges; i++)
{
rc = RTFileReadAt(pIoLogger->hFile, pIoLogger->offReadNext + i*sizeof(DiscardRange),
&DiscardRange, sizeof(DiscardRange), NULL);
if (RT_FAILURE(rc))
break;
paRanges[i].offStart = RT_LE2H_U64(DiscardRange.u64Off);
paRanges[i].cbRange = RT_LE2H_U32(DiscardRange.u32Discard);
}
if (RT_SUCCESS(rc))
{
pIoLogger->offReadNext += *pcRanges * sizeof(DiscardRange);
*ppaRanges = paRanges;
}
else
{
pIoLogger->offReadNext -= sizeof(Entry);
RTMemFree(paRanges);
}
}
else
rc = VERR_NO_MEMORY;
}
}
else
rc = VERR_INVALID_STATE;
if (RT_SUCCESS(rc))
pIoLogger->u32EventTypeNext = 0;
RTSemFastMutexRelease(pIoLogger->hMtx);
return rc;
}