本文整理汇总了C++中RTMemTmpFree函数的典型用法代码示例。如果您正苦于以下问题:C++ RTMemTmpFree函数的具体用法?C++ RTMemTmpFree怎么用?C++ RTMemTmpFree使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTMemTmpFree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rawFreeImage
/**
* Internal. Free all allocated space for representing an image except pImage,
* and optionally delete the image from disk.
*/
static int rawFreeImage(PRAWIMAGE pImage, bool fDelete)
{
int rc = VINF_SUCCESS;
/* Freeing a never allocated image (e.g. because the open failed) is
* not signalled as an error. After all nothing bad happens. */
if (pImage)
{
if (pImage->pStorage)
{
/* No point updating the file that is deleted anyway. */
if (!fDelete)
{
/* For newly created images in sequential mode fill it to
* the nominal size. */
if ( pImage->uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL
&& !(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
&& pImage->fCreate)
{
/* Fill rest of image with zeroes, a must for sequential
* images to reach the nominal size. */
uint64_t uOff;
void *pvBuf = RTMemTmpAllocZ(RAW_FILL_SIZE);
if (!pvBuf)
goto out;
uOff = pImage->offAccess;
/* Write data to all image blocks. */
while (uOff < pImage->cbSize)
{
unsigned cbChunk = (unsigned)RT_MIN(pImage->cbSize - uOff,
RAW_FILL_SIZE);
rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage,
uOff, pvBuf, cbChunk);
if (RT_FAILURE(rc))
goto out;
uOff += cbChunk;
}
out:
if (pvBuf)
RTMemTmpFree(pvBuf);
}
rawFlushImage(pImage);
}
rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
pImage->pStorage = NULL;
}
if (fDelete && pImage->pszFilename)
vdIfIoIntFileDelete(pImage->pIfIo, pImage->pszFilename);
}
LogFlowFunc(("returns %Rrc\n", rc));
return rc;
}
示例2: tst1
static void tst1(size_t cTest, size_t cchDigits, char chSep)
{
RTTestISubF("tst #%u (digits: %u; sep: %c)", cTest, cchDigits, chSep ? chSep : ' ');
/* We try to create max possible + one. */
size_t cTimes = 1;
for (size_t i = 0; i < cchDigits; ++i)
cTimes *= 10;
/* Allocate the result array. */
char **papszNames = (char **)RTMemTmpAllocZ(cTimes * sizeof(char *));
RTTESTI_CHECK_RETV(papszNames != NULL);
int rc = VERR_INTERNAL_ERROR;
/* The test loop. */
size_t i;
for (i = 0; i < cTimes; i++)
{
char szName[RTPATH_MAX];
RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), "RTDirCreateUniqueNumbered"), VINF_SUCCESS);
if (RT_FAILURE(rc))
break;
RTTESTI_CHECK_RC(rc = RTDirCreateUniqueNumbered(szName, sizeof(szName), 0700, cchDigits, chSep), VINF_SUCCESS);
if (RT_FAILURE(rc))
{
RTTestIFailed("RTDirCreateUniqueNumbered(%s) call #%u -> %Rrc\n", szName, i, rc);
break;
}
RTTESTI_CHECK(papszNames[i] = RTStrDup(szName));
if (!papszNames[i])
break;
RTTestIPrintf(RTTESTLVL_DEBUG, "%s\n", papszNames[i]);
}
/* Try to create one more, which shouldn't be possible. */
if (RT_SUCCESS(rc))
{
char szName[RTPATH_MAX];
RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), "RTDirCreateUniqueNumbered"), VINF_SUCCESS);
if (RT_SUCCESS(rc))
RTTESTI_CHECK_RC(rc = RTDirCreateUniqueNumbered(szName, sizeof(szName), 0700, cchDigits, chSep), VERR_ALREADY_EXISTS);
}
/* cleanup */
while (i-- > 0)
{
RTTESTI_CHECK_RC(RTDirRemove(papszNames[i]), VINF_SUCCESS);
RTStrFree(papszNames[i]);
}
RTMemTmpFree(papszNames);
}
示例3: RTR3DECL
RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed,
PFNRTPROGRESS pfnProgressCallback, void *pvUser)
{
/* Validate input */
AssertPtrReturn(pszManifestFile, VERR_INVALID_POINTER);
AssertPtrReturn(papszFiles, VERR_INVALID_POINTER);
AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_POINTER);
int rc = VINF_SUCCESS;
/* Create our compare list */
PRTMANIFESTTEST paFiles = (PRTMANIFESTTEST)RTMemTmpAllocZ(sizeof(RTMANIFESTTEST) * cFiles);
if (!paFiles)
return VERR_NO_MEMORY;
RTMANIFESTCALLBACKDATA callback = { pfnProgressCallback, pvUser, cFiles, 0 };
/* Fill our compare list */
for (size_t i = 0; i < cFiles; ++i)
{
char *pszDigest;
if (pfnProgressCallback)
{
callback.cCurrentFile = i;
rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback);
}
else
rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, NULL, NULL);
if (RT_FAILURE(rc))
break;
paFiles[i].pszTestFile = (char*)papszFiles[i];
paFiles[i].pszTestDigest = pszDigest;
}
/* Do the verification */
if (RT_SUCCESS(rc))
rc = RTManifestVerify(pszManifestFile, paFiles, cFiles, piFailed);
/* Cleanup */
for (size_t i = 0; i < cFiles; ++i)
{
if (paFiles[i].pszTestDigest)
RTStrFree((char*)paFiles[i].pszTestDigest);
}
RTMemTmpFree(paFiles);
return rc;
}
示例4: tstDirCreateTemp
static void tstDirCreateTemp(const char *pszSubTest, const char *pszTemplate, unsigned cTimes, bool fSkipXCheck)
{
RTTestISub(pszSubTest);
/* Allocate the result array. */
char **papszNames = (char **)RTMemTmpAllocZ(cTimes * sizeof(char *));
RTTESTI_CHECK_RETV(papszNames != NULL);
/* The test loop. */
unsigned i;
for (i = 0; i < cTimes; i++)
{
int rc;
char szName[RTPATH_MAX];
RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), pszTemplate), VINF_SUCCESS);
if (RT_FAILURE(rc))
break;
RTTESTI_CHECK(papszNames[i] = RTStrDup(szName));
if (!papszNames[i])
break;
rc = RTDirCreateTemp(papszNames[i]);
if (rc != VINF_SUCCESS)
{
RTTestIFailed("RTDirCreateTemp(%s) call #%u -> %Rrc\n", szName, i, rc);
RTStrFree(papszNames[i]);
papszNames[i] = NULL;
break;
}
RTTestIPrintf(RTTESTLVL_DEBUG, "%s\n", papszNames[i]);
RTTESTI_CHECK_MSG(strlen(szName) == strlen(papszNames[i]), ("szName %s\nReturned %s\n", szName, papszNames[i]));
if (!fSkipXCheck)
RTTESTI_CHECK_MSG(strchr(RTPathFilename(papszNames[i]), 'X') == NULL, ("szName %s\nReturned %s\n", szName, papszNames[i]));
}
/* cleanup */
while (i-- > 0)
{
RTTESTI_CHECK_RC(RTDirRemove(papszNames[i]), VINF_SUCCESS);
RTStrFree(papszNames[i]);
}
RTMemTmpFree(papszNames);
}
示例5: 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();
}
示例6: GMMR3DECL
/**
* Frees allocated pages, for bailing out on failure.
*
* This will not call VMSetError on failure but will use AssertLogRel instead.
*
* @param pVM The cross context VM structure.
* @param pAllocReq The allocation request to undo.
*/
GMMR3DECL(void) GMMR3FreeAllocatedPages(PVM pVM, GMMALLOCATEPAGESREQ const *pAllocReq)
{
uint32_t cb = RT_OFFSETOF(GMMFREEPAGESREQ, aPages[pAllocReq->cPages]);
PGMMFREEPAGESREQ pReq = (PGMMFREEPAGESREQ)RTMemTmpAllocZ(cb);
AssertLogRelReturnVoid(pReq);
pReq->Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
pReq->Hdr.cbReq = cb;
pReq->enmAccount = pAllocReq->enmAccount;
pReq->cPages = pAllocReq->cPages;
uint32_t iPage = pAllocReq->cPages;
while (iPage-- > 0)
{
Assert(pAllocReq->aPages[iPage].idPage != NIL_GMM_PAGEID);
pReq->aPages[iPage].idPage = pAllocReq->aPages[iPage].idPage;
}
int rc = VMMR3CallR0(pVM, VMMR0_DO_GMM_FREE_PAGES, 0, &pReq->Hdr);
AssertLogRelRC(rc);
RTMemTmpFree(pReq);
}
示例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: RTDECL
RTDECL(int) RTEnvSetUtf8(const char *pszVar, const char *pszValue)
{
AssertReturn(strchr(pszVar, '=') == NULL, VERR_ENV_INVALID_VAR_NAME);
size_t cwcVar;
int rc = RTStrCalcUtf16LenEx(pszVar, RTSTR_MAX, &cwcVar);
if (RT_SUCCESS(rc))
{
size_t cwcValue;
rc = RTStrCalcUtf16LenEx(pszVar, RTSTR_MAX, &cwcValue);
if (RT_SUCCESS(rc))
{
PRTUTF16 pwszTmp = (PRTUTF16)RTMemTmpAlloc((cwcVar + 1 + cwcValue + 1) * sizeof(RTUTF16));
if (pwszTmp)
{
rc = RTStrToUtf16Ex(pszVar, RTSTR_MAX, &pwszTmp, cwcVar + 1, NULL);
if (RT_SUCCESS(rc))
{
PRTUTF16 pwszTmpValue = &pwszTmp[cwcVar];
*pwszTmpValue++ = '=';
rc = RTStrToUtf16Ex(pszValue, RTSTR_MAX, &pwszTmpValue, cwcValue + 1, NULL);
if (RT_SUCCESS(rc))
{
if (!_wputenv(pwszTmp))
rc = VINF_SUCCESS;
else
rc = RTErrConvertFromErrno(errno);
}
}
RTMemTmpFree(pwszTmp);
}
else
rc = VERR_NO_TMP_MEMORY;
}
}
return rc;
}
示例9: rtCheckCredentials
/**
* Check the credentials and return the gid/uid of user.
*
* @param pszUser username
* @param pszPasswd password
* @param gid where to store the GID of the user
* @param uid where to store the UID of the user
* @returns IPRT status code
*/
static int rtCheckCredentials(const char *pszUser, const char *pszPasswd, gid_t *pGid, uid_t *pUid)
{
#if defined(RT_OS_LINUX)
struct passwd *pw;
pw = getpwnam(pszUser);
if (!pw)
return VERR_AUTHENTICATION_FAILURE;
if (!pszPasswd)
pszPasswd = "";
struct spwd *spwd;
/* works only if /etc/shadow is accessible */
spwd = getspnam(pszUser);
if (spwd)
pw->pw_passwd = spwd->sp_pwdp;
/* Default fCorrect=true if no password specified. In that case, pw->pw_passwd
* must be NULL (no password set for this user). Fail if a password is specified
* but the user does not have one assigned. */
int fCorrect = !pszPasswd || !*pszPasswd;
if (pw->pw_passwd && *pw->pw_passwd)
{
struct crypt_data *data = (struct crypt_data*)RTMemTmpAllocZ(sizeof(*data));
/* be reentrant */
char *pszEncPasswd = crypt_r(pszPasswd, pw->pw_passwd, data);
fCorrect = pszEncPasswd && !strcmp(pszEncPasswd, pw->pw_passwd);
RTMemTmpFree(data);
}
if (!fCorrect)
return VERR_AUTHENTICATION_FAILURE;
*pGid = pw->pw_gid;
*pUid = pw->pw_uid;
return VINF_SUCCESS;
#elif defined(RT_OS_SOLARIS)
struct passwd *ppw, pw;
char szBuf[1024];
if (getpwnam_r(pszUser, &pw, szBuf, sizeof(szBuf), &ppw) != 0 || ppw == NULL)
return VERR_AUTHENTICATION_FAILURE;
if (!pszPasswd)
pszPasswd = "";
struct spwd spwd;
char szPwdBuf[1024];
/* works only if /etc/shadow is accessible */
if (getspnam_r(pszUser, &spwd, szPwdBuf, sizeof(szPwdBuf)) != NULL)
ppw->pw_passwd = spwd.sp_pwdp;
char *pszEncPasswd = crypt(pszPasswd, ppw->pw_passwd);
if (strcmp(pszEncPasswd, ppw->pw_passwd))
return VERR_AUTHENTICATION_FAILURE;
*pGid = ppw->pw_gid;
*pUid = ppw->pw_uid;
return VINF_SUCCESS;
#else
NOREF(pszUser); NOREF(pszPasswd); NOREF(pGid); NOREF(pUid);
return VERR_AUTHENTICATION_FAILURE;
#endif
}
示例10: 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);
}
}
示例11: rtManifestHashesDestroy
/**
* Destroys the hashes.
*
* @param pHashes The hashes structure. NULL is ignored.
*/
static void rtManifestHashesDestroy(PRTMANIFESTHASHES pHashes)
{
RTMemTmpFree(pHashes);
}
示例12: 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;
}
示例13: VBoxUSBMonSolarisIOCtl
static int VBoxUSBMonSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg, int Mode, cred_t *pCred, int *pVal)
{
LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl Dev=%d Cmd=%d pArg=%p Mode=%d\n", Dev, Cmd, pArg));
/*
* Get the session from the soft state item.
*/
vboxusbmon_state_t *pState = ddi_get_soft_state(g_pVBoxUSBMonSolarisState, getminor(Dev));
if (!pState)
{
LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: no state data for %d\n", getminor(Dev)));
return EINVAL;
}
/*
* Read the request wrapper. Though We don't really need wrapper struct. now
* it's room for the future as Solaris isn't generous regarding the size.
*/
VBOXUSBREQ ReqWrap;
if (IOCPARM_LEN(Cmd) != sizeof(ReqWrap))
{
LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: 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 ": VBoxUSBMonSolarisIOCtl: ddi_copyin failed to read header pArg=%p Cmd=%d. rc=%d.\n", pArg, Cmd, rc));
return EINVAL;
}
if (ReqWrap.u32Magic != VBOXUSBMON_MAGIC)
{
LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: bad magic %#x; pArg=%p Cmd=%d.\n", ReqWrap.u32Magic, pArg, Cmd));
return EINVAL;
}
if (RT_UNLIKELY( ReqWrap.cbData == 0
|| ReqWrap.cbData > _1M*16))
{
LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: bad size %#x; pArg=%p Cmd=%d.\n", ReqWrap.cbData, pArg, Cmd));
return EINVAL;
}
/*
* Read the request.
*/
void *pvBuf = RTMemTmpAlloc(ReqWrap.cbData);
if (RT_UNLIKELY(!pvBuf))
{
LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: 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 ":VBoxUSBMonSolarisIOCtl: ddi_copyin failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd, rc));
return EFAULT;
}
if (RT_UNLIKELY( ReqWrap.cbData != 0
&& !VALID_PTR(pvBuf)))
{
RTMemTmpFree(pvBuf);
LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: pvBuf invalid pointer %p\n", pvBuf));
return EINVAL;
}
Log((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: pid=%d.\n", (int)RTProcSelf()));
/*
* Process the IOCtl.
*/
size_t cbDataReturned;
rc = vboxUSBMonSolarisProcessIOCtl(Cmd, pState, pvBuf, ReqWrap.cbData, &cbDataReturned);
ReqWrap.rc = rc;
rc = 0;
if (RT_UNLIKELY(cbDataReturned > ReqWrap.cbData))
{
LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: too much output data %d expected %d\n", cbDataReturned, ReqWrap.cbData));
cbDataReturned = ReqWrap.cbData;
}
ReqWrap.cbData = cbDataReturned;
/*
* Copy the request back to user space.
*/
rc = ddi_copyout(&ReqWrap, (void *)pArg, sizeof(ReqWrap), Mode);
if (RT_LIKELY(!rc))
{
/*
* Copy the payload (if any) back to user space.
*/
if (cbDataReturned > 0)
{
rc = ddi_copyout(pvBuf, (void *)(uintptr_t)ReqWrap.pvDataR3, cbDataReturned, Mode);
if (RT_UNLIKELY(rc))
{
//.........这里部分代码省略.........
示例14: rawCreateImage
//.........这里部分代码省略.........
pImage->fCreate = true;
pImage->PCHSGeometry = *pPCHSGeometry;
pImage->LCHSGeometry = *pLCHSGeometry;
pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
if (uImageFlags & VD_IMAGE_FLAGS_DIFF)
{
rc = vdIfError(pImage->pIfError, VERR_VD_RAW_INVALID_TYPE, RT_SRC_POS, N_("Raw: cannot create diff image '%s'"), pImage->pszFilename);
goto out;
}
/* Create image file. */
fOpen = VDOpenFlagsToFileOpenFlags(pImage->uOpenFlags, true /* fCreate */);
if (uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL)
fOpen &= ~RTFILE_O_READ;
rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename, fOpen, &pImage->pStorage);
if (RT_FAILURE(rc))
{
rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Raw: cannot create image '%s'"), pImage->pszFilename);
goto out;
}
if (!(uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL))
{
/* Check the free space on the disk and leave early if there is not
* sufficient space available. */
rc = vdIfIoIntFileGetFreeSpace(pImage->pIfIo, pImage->pszFilename, &cbFree);
if (RT_SUCCESS(rc) /* ignore errors */ && ((uint64_t)cbFree < cbSize))
{
rc = vdIfError(pImage->pIfError, VERR_DISK_FULL, RT_SRC_POS, N_("Raw: disk would overflow creating image '%s'"), pImage->pszFilename);
goto out;
}
/* Allocate & commit whole file if fixed image, it must be more
* effective than expanding file by write operations. */
rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, cbSize);
if (RT_FAILURE(rc))
{
rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Raw: setting image size failed for '%s'"), pImage->pszFilename);
goto out;
}
/* Fill image with zeroes. We do this for every fixed-size image since
* on some systems (for example Windows Vista), it takes ages to write
* a block near the end of a sparse file and the guest could complain
* about an ATA timeout. */
pvBuf = RTMemTmpAllocZ(RAW_FILL_SIZE);
if (!pvBuf)
{
rc = VERR_NO_MEMORY;
goto out;
}
uOff = 0;
/* Write data to all image blocks. */
while (uOff < cbSize)
{
unsigned cbChunk = (unsigned)RT_MIN(cbSize, RAW_FILL_SIZE);
rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, uOff,
pvBuf, cbChunk, NULL);
if (RT_FAILURE(rc))
{
rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Raw: writing block failed for '%s'"), pImage->pszFilename);
goto out;
}
uOff += cbChunk;
if (pfnProgress)
{
rc = pfnProgress(pvUser,
uPercentStart + uOff * uPercentSpan * 98 / (cbSize * 100));
if (RT_FAILURE(rc))
goto out;
}
}
}
if (RT_SUCCESS(rc) && pfnProgress)
pfnProgress(pvUser, uPercentStart + uPercentSpan * 98 / 100);
pImage->cbSize = cbSize;
rc = rawFlushImage(pImage);
out:
if (pvBuf)
RTMemTmpFree(pvBuf);
if (RT_SUCCESS(rc) && pfnProgress)
pfnProgress(pvUser, uPercentStart + uPercentSpan);
if (RT_FAILURE(rc))
rawFreeImage(pImage, rc != VERR_ALREADY_EXISTS);
return rc;
}
示例15: 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;
//.........这里部分代码省略.........