本文整理汇总了C++中RT_ELEMENTS函数的典型用法代码示例。如果您正苦于以下问题:C++ RT_ELEMENTS函数的具体用法?C++ RT_ELEMENTS怎么用?C++ RT_ELEMENTS使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RT_ELEMENTS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vrdpDrvStrokePath
//.........这里部分代码省略.........
PATHOBJ_vEnumStart(ppo);
order.points.c = 0;
do {
POINTFIX *pptfx;
VRDEORDERPOINT pt;
bMore = PATHOBJ_bEnum (ppo, &pd);
LOG(("pd: flags = 0x%08X, count = %d", pd.flags, pd.count));
pptfx = &pd.pptfx[0];
if (pd.flags & PD_BEGINSUBPATH)
{
/* Setup first point. Start a new order. */
LOG(("BEGINSUBPATH"));
Assert(order.points.c == 0);
vrdpPointFX2Point(pptfx, &ptStart);
order.ptStart = ptStart;
pt = ptStart;
bounds.pt1 = bounds.pt2 = ptStart;
pptfx++;
i = 1;
}
else
{
LOG(("Continue order"));
i = 0;
}
for (; i < pd.count; i++, pptfx++)
{
LOG(("pd: %2d: %x,%x %d,%d",
i, pptfx->x, pptfx->y, FXTOLROUND(pptfx->x), FXTOLROUND(pptfx->y)));
vrdpPointFX2Point (pptfx, &pt);
vrdpPolyPointsAdd (&order.points, &pt);
vrdpExtendOrderBounds (&bounds, &pt);
if (order.points.c == RT_ELEMENTS(order.points.a))
{
/* Flush the order and start a new order. */
LOG(("Report order, points overflow."));
vrdpReportOrderGenericBounds(pDev, &clipRects, &bounds, &order, sizeof (order), VRDE_ORDER_POLYLINE);
order.points.c = 0;
order.ptStart = pt;
bounds.pt1 = bounds.pt2 = pt;
}
}
if (pd.flags & PD_CLOSEFIGURE)
{
/* Encode the start point as the end point. */
LOG(("Report order, CLOSEFIGURE"));
if ( ptStart.x != pt.x
|| ptStart.y != pt.y)
{
Assert(order.points.c < RT_ELEMENTS(order.points.a));
vrdpPolyPointsAdd (&order.points, &ptStart);
vrdpExtendOrderBounds (&bounds, &ptStart);
}
}
if (pd.flags & PD_ENDSUBPATH)
{
/* Finish the order. */
LOG(("Report order, ENDSUBPATH"));
if (order.points.c > 0)
{
vrdpReportOrderGenericBounds(pDev, &clipRects, &bounds, &order, sizeof (order), VRDE_ORDER_POLYLINE);
}
order.points.c = 0;
}
} while (bMore);
}
else
{
/* Not supported. */
WARN(("not supported: ppo->fl = %08X, plineattrs->fl = %08X, plineattrs->pstyle = %08X",
ppo->fl, plineattrs->fl, plineattrs->pstyle));
vrdpReportDirtyRects(pDev, &clipRects);
}
return;
}
示例2: Test4
static void Test4(unsigned cThreads, unsigned cSeconds, unsigned uWritePercent, bool fYield, bool fQuiet)
{
unsigned i;
uint64_t acIterations[32];
RTTHREAD aThreads[RT_ELEMENTS(acIterations)];
AssertRelease(cThreads <= RT_ELEMENTS(acIterations));
RTTestSubF(g_hTest, "Test4 - %u threads, %u sec, %u%% writes, %syielding",
cThreads, cSeconds, uWritePercent, fYield ? "" : "non-");
/*
* Init globals.
*/
g_fYield = fYield;
g_fQuiet = fQuiet;
g_fTerminate = false;
g_uWritePercent = uWritePercent;
g_cConcurrentWriters = 0;
g_cConcurrentReaders = 0;
RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectRwInit(&g_CritSectRw), VINF_SUCCESS);
/*
* Create the threads and let them block on the semrw.
*/
RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectRwEnterExcl(&g_CritSectRw), VINF_SUCCESS);
for (i = 0; i < cThreads; i++)
{
acIterations[i] = 0;
RTTEST_CHECK_RC_RETV(g_hTest, RTThreadCreateF(&aThreads[i], Test4Thread, &acIterations[i], 0,
RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE,
"test-%u", i), VINF_SUCCESS);
}
/*
* Do the test run.
*/
uint32_t cErrorsBefore = RTTestErrorCount(g_hTest);
uint64_t u64StartTS = RTTimeNanoTS();
RTTEST_CHECK_RC(g_hTest, RTCritSectRwLeaveExcl(&g_CritSectRw), VINF_SUCCESS);
RTThreadSleep(cSeconds * 1000);
ASMAtomicWriteBool(&g_fTerminate, true);
uint64_t ElapsedNS = RTTimeNanoTS() - u64StartTS;
/*
* Clean up the threads and semaphore.
*/
for (i = 0; i < cThreads; i++)
RTTEST_CHECK_RC(g_hTest, RTThreadWait(aThreads[i], 5000, NULL), VINF_SUCCESS);
RTTEST_CHECK_MSG(g_hTest, g_cConcurrentWriters == 0, (g_hTest, "g_cConcurrentWriters=%u at end of test\n", g_cConcurrentWriters));
RTTEST_CHECK_MSG(g_hTest, g_cConcurrentReaders == 0, (g_hTest, "g_cConcurrentReaders=%u at end of test\n", g_cConcurrentReaders));
RTTEST_CHECK_RC(g_hTest, RTCritSectRwDelete(&g_CritSectRw), VINF_SUCCESS);
if (RTTestErrorCount(g_hTest) != cErrorsBefore)
RTThreadSleep(100);
/*
* Collect and display the results.
*/
uint64_t cItrTotal = acIterations[0];
for (i = 1; i < cThreads; i++)
cItrTotal += acIterations[i];
uint64_t cItrNormal = cItrTotal / cThreads;
uint64_t cItrMinOK = cItrNormal / 20; /* 5% */
uint64_t cItrMaxDeviation = 0;
for (i = 0; i < cThreads; i++)
{
uint64_t cItrDelta = RT_ABS((int64_t)(acIterations[i] - cItrNormal));
if (acIterations[i] < cItrMinOK)
RTTestFailed(g_hTest, "Thread %u did less than 5%% of the iterations - %llu (it) vs. %llu (5%%) - %llu%%\n",
i, acIterations[i], cItrMinOK, cItrDelta * 100 / cItrNormal);
else if (cItrDelta > cItrNormal / 2)
RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
"Warning! Thread %u deviates by more than 50%% - %llu (it) vs. %llu (avg) - %llu%%\n",
i, acIterations[i], cItrNormal, cItrDelta * 100 / cItrNormal);
if (cItrDelta > cItrMaxDeviation)
cItrMaxDeviation = cItrDelta;
}
//RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
// "Threads: %u Total: %llu Per Sec: %llu Avg: %llu ns Max dev: %llu%%\n",
// cThreads,
// cItrTotal,
// cItrTotal / cSeconds,
// ElapsedNS / cItrTotal,
// cItrMaxDeviation * 100 / cItrNormal
// );
//
RTTestValue(g_hTest, "Thruput", cItrTotal * UINT32_C(1000000000) / ElapsedNS, RTTESTUNIT_CALLS_PER_SEC);
RTTestValue(g_hTest, "Max diviation", cItrMaxDeviation * 100 / cItrNormal, RTTESTUNIT_PCT);
}
示例3: DECLEXPORT
DECLEXPORT(EGLSurface) eglCreatePbufferSurface(EGLDisplay hDisplay, EGLConfig config, EGLint const *paAttributes)
{
Display *pDisplay = (Display *)hDisplay;
enum { CPS_WIDTH = 0, CPS_HEIGHT, CPS_LARGEST, CPS_PRESERVED, CPS_TEX_FORMAT, CPS_TEX_TARGET, CPS_MIPMAP_TEX, CPS_END };
int acIndices[CPS_END];
int aAttributes[CPS_END * 2];
int cIndex = 0;
unsigned i;
GLXPbuffer hPbuffer;
if (!VALID_PTR(hDisplay))
{
setEGLError(EGL_NOT_INITIALIZED);
return EGL_NO_SURFACE;
}
for (i = 0; i < RT_ELEMENTS(acIndices); ++i)
acIndices[i] = -1;
if (paAttributes != NULL)
while (*paAttributes != EGL_NONE)
{
switch (*paAttributes)
{
case EGL_WIDTH:
setAttribute(&acIndices[CPS_WIDTH], &cIndex, aAttributes, GLX_PBUFFER_WIDTH, paAttributes[1]);
break;
case EGL_HEIGHT:
setAttribute(&acIndices[CPS_HEIGHT], &cIndex, aAttributes, GLX_LARGEST_PBUFFER, paAttributes[1]);
break;
case EGL_LARGEST_PBUFFER:
setAttribute(&acIndices[CPS_LARGEST], &cIndex, aAttributes, GLX_PBUFFER_HEIGHT, paAttributes[1]);
break;
case EGL_BUFFER_PRESERVED:
setAttribute(&acIndices[CPS_PRESERVED], &cIndex, aAttributes, GLX_PRESERVED_CONTENTS, paAttributes[1]);
break;
case EGL_TEXTURE_FORMAT:
setAttribute(&acIndices[CPS_TEX_FORMAT], &cIndex, aAttributes, GLX_TEXTURE_FORMAT_EXT, paAttributes[1]);
break;
case EGL_TEXTURE_TARGET:
setAttribute(&acIndices[CPS_TEX_TARGET], &cIndex, aAttributes, GLX_TEXTURE_TARGET_EXT, paAttributes[1]);
break;
case EGL_MIPMAP_TEXTURE:
setAttribute(&acIndices[CPS_MIPMAP_TEX], &cIndex, aAttributes, GLX_MIPMAP_TEXTURE_EXT, paAttributes[1]);
break;
case EGL_VG_ALPHA_FORMAT:
case EGL_VG_COLORSPACE:
{
setEGLError(EGL_BAD_MATCH);
return EGL_NO_SURFACE;
}
}
paAttributes += 2;
}
AssertRelease(cIndex < RT_ELEMENTS(aAttributes) - 1);
aAttributes[cIndex + 1] = None;
hPbuffer = glXCreatePbuffer(pDisplay, (GLXFBConfig)config, aAttributes);
if (hPbuffer == None)
{
setEGLError(EGL_BAD_ALLOC);
return EGL_NO_SURFACE;
}
AssertRelease(hPbuffer < VBEGL_WINDOW_SURFACE); /* Greater than the maximum XID. */
clearEGLError();
return (EGLSurface)(hPbuffer | VBEGL_PBUFFER_SURFACE);
}
示例4: main
int main(int argc, char **argv)
{
RTR3InitExe(argc, &argv, 0);
RTDIGESTTYPE enmDigestType = RTDIGESTTYPE_INVALID;
const char *pszDigestType = "NotSpecified";
enum
{
kMethod_Full,
kMethod_Block,
kMethod_File,
kMethod_CVAS
} enmMethod = kMethod_Block;
uint64_t offStart = 0;
uint64_t cbMax = UINT64_MAX;
bool fTestcase = false;
static const RTGETOPTDEF s_aOptions[] =
{
{ "--type", 't', RTGETOPT_REQ_STRING },
{ "--method", 'm', RTGETOPT_REQ_STRING },
{ "--help", 'h', RTGETOPT_REQ_NOTHING },
{ "--length", 'l', RTGETOPT_REQ_UINT64 },
{ "--offset", 'o', RTGETOPT_REQ_UINT64 },
{ "--testcase", 'x', RTGETOPT_REQ_NOTHING },
};
int ch;
RTGETOPTUNION ValueUnion;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
while ((ch = RTGetOpt(&GetState, &ValueUnion)))
{
switch (ch)
{
case 't':
if (!RTStrICmp(ValueUnion.psz, "crc32"))
{
pszDigestType = "CRC32";
enmDigestType = RTDIGESTTYPE_CRC32;
}
else if (!RTStrICmp(ValueUnion.psz, "crc64"))
{
pszDigestType = "CRC64";
enmDigestType = RTDIGESTTYPE_CRC64;
}
else if (!RTStrICmp(ValueUnion.psz, "md2"))
{
pszDigestType = "MD2";
enmDigestType = RTDIGESTTYPE_MD2;
}
else if (!RTStrICmp(ValueUnion.psz, "md5"))
{
pszDigestType = "MD5";
enmDigestType = RTDIGESTTYPE_MD5;
}
else if (!RTStrICmp(ValueUnion.psz, "sha1"))
{
pszDigestType = "SHA-1";
enmDigestType = RTDIGESTTYPE_SHA1;
}
else if (!RTStrICmp(ValueUnion.psz, "sha224"))
{
pszDigestType = "SHA-224";
enmDigestType = RTDIGESTTYPE_SHA224;
}
else if (!RTStrICmp(ValueUnion.psz, "sha256"))
{
pszDigestType = "SHA-256";
enmDigestType = RTDIGESTTYPE_SHA256;
}
else if (!RTStrICmp(ValueUnion.psz, "sha384"))
{
pszDigestType = "SHA-384";
enmDigestType = RTDIGESTTYPE_SHA384;
}
else if (!RTStrICmp(ValueUnion.psz, "sha512"))
{
pszDigestType = "SHA-512";
enmDigestType = RTDIGESTTYPE_SHA512;
}
else if (!RTStrICmp(ValueUnion.psz, "sha512/224"))
{
pszDigestType = "SHA-512/224";
enmDigestType = RTDIGESTTYPE_SHA512T224;
}
else if (!RTStrICmp(ValueUnion.psz, "sha512/256"))
{
pszDigestType = "SHA-512/256";
enmDigestType = RTDIGESTTYPE_SHA512T256;
}
else
{
Error("Invalid digest type: %s\n", ValueUnion.psz);
return 1;
}
break;
//.........这里部分代码省略.........
示例5: main
int main(int argc, char **argv)
{
RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
/*
* Options are mandatory.
*/
if (argc <= 1)
return usage();
/*
* Parse the options.
*/
static const RTGETOPTDEF s_aOptions[] =
{
{ "--flags", 'f', RTGETOPT_REQ_STRING },
{ "--groups", 'g', RTGETOPT_REQ_STRING },
{ "--dest", 'd', RTGETOPT_REQ_STRING },
{ "--what", 'o', RTGETOPT_REQ_STRING },
{ "--which", 'l', RTGETOPT_REQ_STRING },
};
const char *pszFlags = "";
const char *pszGroups = "";
const char *pszDest = "";
SUPLOGGER enmWhich = SUPLOGGER_DEBUG;
enum
{
kSupLoggerCtl_Set, kSupLoggerCtl_Create, kSupLoggerCtl_Destroy
} enmWhat = kSupLoggerCtl_Set;
int ch;
int i = 1;
RTGETOPTUNION Val;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
while ((ch = RTGetOpt(&GetState, &Val)))
{
switch (ch)
{
case 'f':
pszFlags = Val.psz;
break;
case 'g':
pszGroups = Val.psz;
break;
case 'd':
pszDest = Val.psz;
break;
case 'o':
if (!strcmp(Val.psz, "set"))
enmWhat = kSupLoggerCtl_Set;
else if (!strcmp(Val.psz, "create"))
enmWhat = kSupLoggerCtl_Create;
else if (!strcmp(Val.psz, "destroy"))
enmWhat = kSupLoggerCtl_Destroy;
else
{
RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unknown operation '%s'.\n", Val.psz);
return 1;
}
break;
case 'l':
if (!strcmp(Val.psz, "debug"))
enmWhich = SUPLOGGER_DEBUG;
else if (!strcmp(Val.psz, "release"))
enmWhich = SUPLOGGER_RELEASE;
else
{
RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unknown logger '%s'.\n", Val.psz);
return 1;
}
break;
case 'h':
return usage();
case 'V':
RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
return 0;
case VINF_GETOPT_NOT_OPTION:
RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unexpected argument '%s'.\n", Val.psz);
return 1;
default:
return RTGetOptPrintError(ch, &Val);
}
}
/*
* Do the requested job.
*/
int rc;
switch (enmWhat)
{
//.........这里部分代码省略.........
示例6: dbgfR3GetCoreCpu
/**
* Gets the guest-CPU context suitable for dumping into the core file.
*
* @param pVM Pointer to the VM.
* @param pCtx Pointer to the guest-CPU context.
* @param pDbgfCpu Where to dump the guest-CPU data.
*/
static void dbgfR3GetCoreCpu(PVM pVM, PCPUMCTX pCtx, PDBGFCORECPU pDbgfCpu)
{
#define DBGFCOPYSEL(a_dbgfsel, a_cpumselreg) \
do { \
(a_dbgfsel).uBase = (a_cpumselreg).u64Base; \
(a_dbgfsel).uLimit = (a_cpumselreg).u32Limit; \
(a_dbgfsel).uAttr = (a_cpumselreg).Attr.u; \
(a_dbgfsel).uSel = (a_cpumselreg).Sel; \
} while (0)
pDbgfCpu->rax = pCtx->rax;
pDbgfCpu->rbx = pCtx->rbx;
pDbgfCpu->rcx = pCtx->rcx;
pDbgfCpu->rdx = pCtx->rdx;
pDbgfCpu->rsi = pCtx->rsi;
pDbgfCpu->rdi = pCtx->rdi;
pDbgfCpu->r8 = pCtx->r8;
pDbgfCpu->r9 = pCtx->r9;
pDbgfCpu->r10 = pCtx->r10;
pDbgfCpu->r11 = pCtx->r11;
pDbgfCpu->r12 = pCtx->r12;
pDbgfCpu->r13 = pCtx->r13;
pDbgfCpu->r14 = pCtx->r14;
pDbgfCpu->r15 = pCtx->r15;
pDbgfCpu->rip = pCtx->rip;
pDbgfCpu->rsp = pCtx->rsp;
pDbgfCpu->rbp = pCtx->rbp;
DBGFCOPYSEL(pDbgfCpu->cs, pCtx->cs);
DBGFCOPYSEL(pDbgfCpu->ds, pCtx->ds);
DBGFCOPYSEL(pDbgfCpu->es, pCtx->es);
DBGFCOPYSEL(pDbgfCpu->fs, pCtx->fs);
DBGFCOPYSEL(pDbgfCpu->gs, pCtx->gs);
DBGFCOPYSEL(pDbgfCpu->ss, pCtx->ss);
pDbgfCpu->cr0 = pCtx->cr0;
pDbgfCpu->cr2 = pCtx->cr2;
pDbgfCpu->cr3 = pCtx->cr3;
pDbgfCpu->cr4 = pCtx->cr4;
AssertCompile(RT_ELEMENTS(pDbgfCpu->dr) == RT_ELEMENTS(pCtx->dr));
for (unsigned i = 0; i < RT_ELEMENTS(pDbgfCpu->dr); i++)
pDbgfCpu->dr[i] = pCtx->dr[i];
pDbgfCpu->gdtr.uAddr = pCtx->gdtr.pGdt;
pDbgfCpu->gdtr.cb = pCtx->gdtr.cbGdt;
pDbgfCpu->idtr.uAddr = pCtx->idtr.pIdt;
pDbgfCpu->idtr.cb = pCtx->idtr.cbIdt;
DBGFCOPYSEL(pDbgfCpu->ldtr, pCtx->ldtr);
DBGFCOPYSEL(pDbgfCpu->tr, pCtx->tr);
pDbgfCpu->sysenter.cs = pCtx->SysEnter.cs;
pDbgfCpu->sysenter.eip = pCtx->SysEnter.eip;
pDbgfCpu->sysenter.esp = pCtx->SysEnter.esp;
pDbgfCpu->msrEFER = pCtx->msrEFER;
pDbgfCpu->msrSTAR = pCtx->msrSTAR;
pDbgfCpu->msrPAT = pCtx->msrPAT;
pDbgfCpu->msrLSTAR = pCtx->msrLSTAR;
pDbgfCpu->msrCSTAR = pCtx->msrCSTAR;
pDbgfCpu->msrSFMASK = pCtx->msrSFMASK;
pDbgfCpu->msrKernelGSBase = pCtx->msrKERNELGSBASE;
pDbgfCpu->msrApicBase = pCtx->msrApicBase;
pDbgfCpu->aXcr[0] = pCtx->aXcr[0];
pDbgfCpu->aXcr[1] = pCtx->aXcr[1];
AssertCompile(sizeof(pDbgfCpu->ext) == sizeof(*pCtx->pXStateR3));
pDbgfCpu->cbExt = pVM->cpum.ro.GuestFeatures.cbMaxExtendedState;
if (RT_LIKELY(pDbgfCpu->cbExt))
memcpy(&pDbgfCpu->ext, pCtx->pXStateR3, pDbgfCpu->cbExt);
#undef DBGFCOPYSEL
}
示例7: VMMR3_INT_DECL
/**
* Initializes the KVM GIM provider.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param uVersion The interface version this VM should use.
*/
VMMR3_INT_DECL(int) gimR3KvmInit(PVM pVM)
{
AssertReturn(pVM, VERR_INVALID_PARAMETER);
AssertReturn(pVM->gim.s.enmProviderId == GIMPROVIDERID_KVM, VERR_INTERNAL_ERROR_5);
int rc;
PGIMKVM pKvm = &pVM->gim.s.u.Kvm;
/*
* Determine interface capabilities based on the version.
*/
if (!pVM->gim.s.u32Version)
{
/* Basic features. */
pKvm->uBaseFeat = 0
| GIM_KVM_BASE_FEAT_CLOCK_OLD
//| GIM_KVM_BASE_FEAT_NOP_IO_DELAY
//| GIM_KVM_BASE_FEAT_MMU_OP
| GIM_KVM_BASE_FEAT_CLOCK
//| GIM_KVM_BASE_FEAT_ASYNC_PF
//| GIM_KVM_BASE_FEAT_STEAL_TIME
//| GIM_KVM_BASE_FEAT_PV_EOI
| GIM_KVM_BASE_FEAT_PV_UNHALT
;
/* Rest of the features are determined in gimR3KvmInitCompleted(). */
}
/*
* Expose HVP (Hypervisor Present) bit to the guest.
*/
CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_HVP);
/*
* Modify the standard hypervisor leaves for KVM.
*/
CPUMCPUIDLEAF HyperLeaf;
RT_ZERO(HyperLeaf);
HyperLeaf.uLeaf = UINT32_C(0x40000000);
HyperLeaf.uEax = UINT32_C(0x40000001); /* Minimum value for KVM is 0x40000001. */
HyperLeaf.uEbx = 0x4B4D564B; /* 'KVMK' */
HyperLeaf.uEcx = 0x564B4D56; /* 'VMKV' */
HyperLeaf.uEdx = 0x0000004D; /* 'M000' */
rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
AssertLogRelRCReturn(rc, rc);
/*
* Add KVM specific leaves.
*/
HyperLeaf.uLeaf = UINT32_C(0x40000001);
HyperLeaf.uEax = pKvm->uBaseFeat;
HyperLeaf.uEbx = 0; /* Reserved */
HyperLeaf.uEcx = 0; /* Reserved */
HyperLeaf.uEdx = 0; /* Reserved */
rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
AssertLogRelRCReturn(rc, rc);
/*
* Insert all MSR ranges of KVM.
*/
for (unsigned i = 0; i < RT_ELEMENTS(g_aMsrRanges_Kvm); i++)
{
rc = CPUMR3MsrRangesInsert(pVM, &g_aMsrRanges_Kvm[i]);
AssertLogRelRCReturn(rc, rc);
}
/*
* Setup hypercall and #UD handling.
*/
for (VMCPUID i = 0; i < pVM->cCpus; i++)
VMMHypercallsEnable(&pVM->aCpus[i]);
if (ASMIsAmdCpu())
{
pKvm->fTrapXcptUD = true;
pKvm->uOpCodeNative = OP_VMMCALL;
}
else
{
Assert(ASMIsIntelCpu() || ASMIsViaCentaurCpu());
pKvm->fTrapXcptUD = false;
pKvm->uOpCodeNative = OP_VMCALL;
}
/* We always need to trap VMCALL/VMMCALL hypercall using #UDs for raw-mode VMs. */
if (!HMIsEnabled(pVM))
pKvm->fTrapXcptUD = true;
return VINF_SUCCESS;
}
示例8: Initialize
//.........这里部分代码省略.........
int vrc = GetVBoxUserHomeDirectory(szCompReg, sizeof(szCompReg));
AssertRCReturn(vrc, NS_ERROR_FAILURE);
strcpy(szXptiDat, szCompReg);
vrc = RTPathAppend(szCompReg, sizeof(szCompReg), "compreg.dat");
AssertRCReturn(vrc, NS_ERROR_FAILURE);
vrc = RTPathAppend(szXptiDat, sizeof(szXptiDat), "xpti.dat");
AssertRCReturn(vrc, NS_ERROR_FAILURE);
LogFlowFunc(("component registry : \"%s\"\n", szCompReg));
LogFlowFunc(("XPTI data file : \"%s\"\n", szXptiDat));
#if defined (XPCOM_GLUE)
XPCOMGlueStartup(nsnull);
#endif
static const char *kAppPathsToProbe[] =
{
NULL, /* 0: will use VBOX_APP_HOME */
NULL, /* 1: will try RTPathAppPrivateArch() */
#ifdef RT_OS_LINUX
"/usr/lib/virtualbox",
"/opt/VirtualBox",
#elif RT_OS_SOLARIS
"/opt/VirtualBox/amd64",
"/opt/VirtualBox/i386",
#elif RT_OS_DARWIN
"/Application/VirtualBox.app/Contents/MacOS",
#endif
};
/* Find out the directory where VirtualBox binaries are located */
for (size_t i = 0; i < RT_ELEMENTS(kAppPathsToProbe); ++ i)
{
char szAppHomeDir[RTPATH_MAX];
if (i == 0)
{
/* Use VBOX_APP_HOME if present */
vrc = RTEnvGetEx(RTENV_DEFAULT, "VBOX_APP_HOME", szAppHomeDir, sizeof(szAppHomeDir), NULL);
if (vrc == VERR_ENV_VAR_NOT_FOUND)
continue;
AssertRC(vrc);
}
else if (i == 1)
{
/* Use RTPathAppPrivateArch() first */
vrc = RTPathAppPrivateArch(szAppHomeDir, sizeof(szAppHomeDir));
AssertRC(vrc);
}
else
{
/* Iterate over all other paths */
szAppHomeDir[RTPATH_MAX - 1] = '\0';
strncpy(szAppHomeDir, kAppPathsToProbe[i], RTPATH_MAX - 1);
vrc = VINF_SUCCESS;
}
if (RT_FAILURE(vrc))
{
rc = NS_ERROR_FAILURE;
continue;
}
char szCompDir[RTPATH_MAX];
vrc = RTPathAppend(strcpy(szCompDir, szAppHomeDir), sizeof(szCompDir), "components");
示例9: VBoxGuestHaikuAttach
static status_t VBoxGuestHaikuAttach(const pci_info *pDevice)
{
status_t status;
int rc = VINF_SUCCESS;
int iResId = 0;
struct VBoxGuestDeviceState *pState = &sState;
static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
PRTLOGGER pRelLogger;
cUsers = 0;
/*
* Initialize IPRT R0 driver, which internally calls OS-specific r0 init.
*/
rc = RTR0Init(0);
if (RT_FAILURE(rc))
{
LogFunc(("RTR0Init failed.\n"));
return ENXIO;
}
#ifdef DO_LOG
/*
* Create the release log.
* (We do that here instead of common code because we want to log
* early failures using the LogRel macro.)
*/
rc = RTLogCreate(&pRelLogger, 0|RTLOGFLAGS_PREFIX_THREAD /* fFlags */, "all",
"VBOX_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups,
RTLOGDEST_STDOUT | RTLOGDEST_DEBUGGER | RTLOGDEST_USER, NULL);
dprintf(MODULE_NAME ": RTLogCreate: %d\n", rc);
if (RT_SUCCESS(rc))
{
//RTLogGroupSettings(pRelLogger, g_szLogGrp);
//RTLogFlags(pRelLogger, g_szLogFlags);
//RTLogDestinations(pRelLogger, "/var/log/vboxguest.log");
RTLogRelSetDefaultInstance(pRelLogger);
RTLogSetDefaultInstance(pRelLogger);//XXX
}
#endif
Log((MODULE_NAME ": plip!\n"));
LogAlways((MODULE_NAME ": plop!\n"));
/*
* Allocate I/O port resource.
*/
pState->uIOPortBase = pDevice->u.h0.base_registers[0];
//XXX check flags for IO ?
if (pState->uIOPortBase)
{
/*
* Map the MMIO region.
*/
uint32 phys = pDevice->u.h0.base_registers[1];
//XXX check flags for mem ?
pState->VMMDevMemSize = pDevice->u.h0.base_register_sizes[1];
pState->iVMMDevMemAreaId = map_physical_memory("VirtualBox Guest MMIO",
phys, pState->VMMDevMemSize, B_ANY_KERNEL_BLOCK_ADDRESS,
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, &pState->pMMIOBase);
if (pState->iVMMDevMemAreaId > 0 && pState->pMMIOBase)
{
/*
* Call the common device extension initializer.
*/
rc = VBoxGuestInitDevExt(&g_DevExt, pState->uIOPortBase,
pState->pMMIOBase, pState->VMMDevMemSize,
#if ARCH_BITS == 64
VBOXOSTYPE_Haiku_x64,
#else
VBOXOSTYPE_Haiku,
#endif
VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
if (RT_SUCCESS(rc))
{
/*
* Add IRQ of VMMDev.
*/
pState->iIrqResId = pDevice->u.h0.interrupt_line;
rc = VBoxGuestHaikuAddIRQ(pState);
if (RT_SUCCESS(rc))
{
dprintf(MODULE_NAME ": loaded successfully\n");
return 0;
}
else
dprintf((MODULE_NAME ":VBoxGuestInitDevExt failed.\n"));
VBoxGuestDeleteDevExt(&g_DevExt);
}
else
dprintf((MODULE_NAME ":VBoxGuestHaikuAddIRQ failed.\n"));
}
else
dprintf((MODULE_NAME ":MMIO region setup failed.\n"));
}
else
dprintf((MODULE_NAME ":IOport setup failed.\n"));
RTR0Term();
return ENXIO;
//.........这里部分代码省略.........
示例10: RTDECL
RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags)
{
/** @todo Symlinks: Find[First|Next]FileW will return info about
the link, so RTPATH_F_FOLLOW_LINK is not handled correctly. */
/*
* Validate input.
*/
if (!pDir || pDir->u32Magic != RTDIR_MAGIC)
{
AssertMsgFailed(("Invalid pDir=%p\n", pDir));
return VERR_INVALID_PARAMETER;
}
if (!pDirEntry)
{
AssertMsgFailed(("Invalid pDirEntry=%p\n", pDirEntry));
return VERR_INVALID_PARAMETER;
}
if ( enmAdditionalAttribs < RTFSOBJATTRADD_NOTHING
|| enmAdditionalAttribs > RTFSOBJATTRADD_LAST)
{
AssertMsgFailed(("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs));
return VERR_INVALID_PARAMETER;
}
AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
size_t cbDirEntry = sizeof(*pDirEntry);
if (pcbDirEntry)
{
cbDirEntry = *pcbDirEntry;
if (cbDirEntry < RT_UOFFSETOF(RTDIRENTRYEX, szName[2]))
{
AssertMsgFailed(("Invalid *pcbDirEntry=%d (min %d)\n", *pcbDirEntry, RT_OFFSETOF(RTDIRENTRYEX, szName[2])));
return VERR_INVALID_PARAMETER;
}
}
/*
* Fetch data?
*/
if (!pDir->fDataUnread)
{
RTStrFree(pDir->pszName);
pDir->pszName = NULL;
BOOL fRc = FindNextFileW(pDir->hDir, &pDir->Data);
if (!fRc)
{
int iErr = GetLastError();
if (pDir->hDir == INVALID_HANDLE_VALUE || iErr == ERROR_NO_MORE_FILES)
return VERR_NO_MORE_FILES;
return RTErrConvertFromWin32(iErr);
}
}
/*
* Convert the filename to UTF-8.
*/
if (!pDir->pszName)
{
int rc = RTUtf16ToUtf8((PCRTUTF16)pDir->Data.cFileName, &pDir->pszName);
if (RT_FAILURE(rc))
{
pDir->pszName = NULL;
return rc;
}
pDir->cchName = strlen(pDir->pszName);
}
/*
* Check if we've got enough space to return the data.
*/
const char *pszName = pDir->pszName;
const size_t cchName = pDir->cchName;
const size_t cbRequired = RT_OFFSETOF(RTDIRENTRYEX, szName[1]) + cchName;
if (pcbDirEntry)
*pcbDirEntry = cbRequired;
if (cbRequired > cbDirEntry)
return VERR_BUFFER_OVERFLOW;
/*
* Setup the returned data.
*/
pDir->fDataUnread = false;
pDirEntry->cbName = (uint16_t)cchName;
Assert(pDirEntry->cbName == cchName);
memcpy(pDirEntry->szName, pszName, cchName + 1);
if (pDir->Data.cAlternateFileName[0])
{
/* copy and calc length */
PCRTUTF16 pwszSrc = (PCRTUTF16)pDir->Data.cAlternateFileName;
PRTUTF16 pwszDst = pDirEntry->wszShortName;
uint32_t off = 0;
while (pwszSrc[off] && off < RT_ELEMENTS(pDirEntry->wszShortName) - 1U)
{
pwszDst[off] = pwszSrc[off];
off++;
}
pDirEntry->cwcShortName = (uint16_t)off;
/* zero the rest */
do
//.........这里部分代码省略.........
示例11: VMMDECL
/**
* Change the traceing configuration of the VM.
*
* @returns VBox status code.
* @retval VINF_SUCCESS
* @retval VERR_NOT_FOUND if any of the trace point groups mentioned in the
* config string cannot be found. (Or if the string cannot be made
* sense of.) No change made.
* @retval VERR_INVALID_VM_HANDLE
* @retval VERR_INVALID_POINTER
*
* @param pVM The cross context VM structure.
* @param pszConfig The configuration change specification.
*
* Trace point group names, optionally prefixed by a '-' to
* indicate that the group is being disabled. A special
* group 'all' can be used to enable or disable all trace
* points.
*
* Drivers, devices and USB devices each have their own
* trace point group which can be accessed by prefixing
* their official PDM name by 'drv', 'dev' or 'usb'
* respectively.
*/
VMMDECL(int) DBGFR3TraceConfig(PVM pVM, const char *pszConfig)
{
VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
AssertPtrReturn(pszConfig, VERR_INVALID_POINTER);
if (pVM->hTraceBufR3 == NIL_RTTRACEBUF)
return VERR_DBGF_NO_TRACE_BUFFER;
/*
* We do this in two passes, the first pass just validates the input string
* and the second applies the changes.
*/
for (uint32_t uPass = 0; uPass < 1; uPass++)
{
char ch;
while ((ch = *pszConfig) != '\0')
{
if (RT_C_IS_SPACE(ch))
continue;
/*
* Operation prefix.
*/
bool fNo = false;
do
{
if (ch == 'n' && pszConfig[1] == 'o')
{
fNo = !fNo;
pszConfig++;
}
else if (ch == '+')
fNo = false;
else if (ch == '-' || ch == '!' || ch == '~')
fNo = !fNo;
else
break;
} while ((ch = *++pszConfig) != '\0');
if (ch == '\0')
break;
/*
* Extract the name.
*/
const char *pszName = pszConfig;
while ( ch != '\0'
&& !RT_C_IS_SPACE(ch)
&& !RT_C_IS_PUNCT(ch))
ch = *++pszConfig;
size_t const cchName = pszConfig - pszName;
/*
* 'all' - special group that enables or disables all trace points.
*/
if (cchName == 3 && !strncmp(pszName, "all", 3))
{
if (uPass != 0)
{
uint32_t iCpu = pVM->cCpus;
if (!fNo)
while (iCpu-- > 0)
pVM->aCpus[iCpu].fTraceGroups = UINT32_MAX;
else
while (iCpu-- > 0)
pVM->aCpus[iCpu].fTraceGroups = 0;
PDMR3TracingConfig(pVM, NULL, 0, !fNo, uPass > 0);
}
}
else
{
/*
* A specific group, try the VMM first then PDM.
*/
uint32_t i = RT_ELEMENTS(g_aVmmTpGroups);
while (i-- > 0)
if ( g_aVmmTpGroups[i].cchName == cchName
&& !strncmp(g_aVmmTpGroups[i].pszName, pszName, cchName))
//.........这里部分代码省略.........
示例12: supdrvOSLdrLoad
int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq)
{
NOREF(pDevExt); NOREF(pReq);
if (pImage->pvNtSectionObj)
{
/*
* Usually, the entire image matches exactly.
*/
if (!memcmp(pImage->pvImage, pbImageBits, pImage->cbImageBits))
return VINF_SUCCESS;
/*
* However, on Windows Server 2003 (sp2 x86) both import thunk tables
* are fixed up and we typically get a mismatch in the INIT section.
*
* So, lets see if everything matches when excluding the
* OriginalFirstThunk tables. To make life simpler, set the max number
* of imports to 16 and just record and sort the locations that needs
* to be excluded from the comparison.
*/
IMAGE_NT_HEADERS const *pNtHdrs;
pNtHdrs = (IMAGE_NT_HEADERS const *)(pbImageBits
+ ( *(uint16_t *)pbImageBits == IMAGE_DOS_SIGNATURE
? ((IMAGE_DOS_HEADER const *)pbImageBits)->e_lfanew
: 0));
if ( pNtHdrs->Signature == IMAGE_NT_SIGNATURE
&& pNtHdrs->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR_MAGIC
&& pNtHdrs->OptionalHeader.NumberOfRvaAndSizes > IMAGE_DIRECTORY_ENTRY_IMPORT
&& pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size >= sizeof(IMAGE_IMPORT_DESCRIPTOR)
&& pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress > sizeof(IMAGE_NT_HEADERS)
&& pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress < pImage->cbImageBits
)
{
struct MyRegion
{
uint32_t uRva;
uint32_t cb;
} aExcludeRgns[16];
unsigned cExcludeRgns = 0;
uint32_t cImpsLeft = pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size
/ sizeof(IMAGE_IMPORT_DESCRIPTOR);
IMAGE_IMPORT_DESCRIPTOR const *pImp;
pImp = (IMAGE_IMPORT_DESCRIPTOR const *)(pbImageBits
+ pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
while ( cImpsLeft-- > 0
&& cExcludeRgns < RT_ELEMENTS(aExcludeRgns))
{
uint32_t uRvaThunk = pImp->OriginalFirstThunk;
if ( uRvaThunk > sizeof(IMAGE_NT_HEADERS)
&& uRvaThunk <= pImage->cbImageBits - sizeof(IMAGE_THUNK_DATA)
&& uRvaThunk != pImp->FirstThunk)
{
/* Find the size of the thunk table. */
IMAGE_THUNK_DATA const *paThunk = (IMAGE_THUNK_DATA const *)(pbImageBits + uRvaThunk);
uint32_t cMaxThunks = (pImage->cbImageBits - uRvaThunk) / sizeof(IMAGE_THUNK_DATA);
uint32_t cThunks = 0;
while (cThunks < cMaxThunks && paThunk[cThunks].u1.Function != 0)
cThunks++;
/* Ordered table insert. */
unsigned i = 0;
for (; i < cExcludeRgns; i++)
if (uRvaThunk < aExcludeRgns[i].uRva)
break;
if (i != cExcludeRgns)
memmove(&aExcludeRgns[i + 1], &aExcludeRgns[i], (cExcludeRgns - i) * sizeof(aExcludeRgns[0]));
aExcludeRgns[i].uRva = uRvaThunk;
aExcludeRgns[i].cb = cThunks * sizeof(IMAGE_THUNK_DATA);
cExcludeRgns++;
}
/* advance */
pImp++;
}
/*
* Ok, do the comparison.
*/
int iDiff = 0;
uint32_t uRvaNext = 0;
for (unsigned i = 0; !iDiff && i < cExcludeRgns; i++)
{
if (uRvaNext < aExcludeRgns[i].uRva)
iDiff = supdrvNtCompare(pImage, pbImageBits, uRvaNext, aExcludeRgns[i].uRva - uRvaNext);
uRvaNext = aExcludeRgns[i].uRva + aExcludeRgns[i].cb;
}
if (!iDiff && uRvaNext < pImage->cbImageBits)
iDiff = supdrvNtCompare(pImage, pbImageBits, uRvaNext, pImage->cbImageBits - uRvaNext);
if (!iDiff)
return VINF_SUCCESS;
}
else
supdrvNtCompare(pImage, pbImageBits, 0, pImage->cbImageBits);
return VERR_LDR_MISMATCH_NATIVE;
}
return VERR_INTERNAL_ERROR_4;
}
示例13: rtStrVersionParseBlock
/**
* Parses a out the next block from a version string.
*
* @returns true if numeric, false if not.
* @param ppszVer The string cursor, IN/OUT.
* @param pi32Value Where to return the value if numeric.
* @param pcchBlock Where to return the block length.
*/
static bool rtStrVersionParseBlock(const char **ppszVer, int32_t *pi32Value, size_t *pcchBlock)
{
const char *psz = *ppszVer;
/*
* Check for end-of-string.
*/
if (!*psz)
{
*pi32Value = 0;
*pcchBlock = 0;
return false;
}
/*
* Try convert the block to a number the simple way.
*/
char ch;
bool fNumeric = RT_C_IS_DIGIT(*psz);
if (fNumeric)
{
do
ch = *++psz;
while (ch && RT_C_IS_DIGIT(ch));
int rc = RTStrToInt32Ex(*ppszVer, NULL, 10, pi32Value);
if (RT_FAILURE(rc) || rc == VWRN_NUMBER_TOO_BIG)
{
AssertRC(rc);
fNumeric = false;
*pi32Value = 0;
}
}
else
{
/*
* Find the end of the current string. Make a special case for SVN
* revision numbers that immediately follows a release tag string.
*/
do
ch = *++psz;
while ( ch
&& !RT_C_IS_DIGIT(ch)
&& !RTSTRVER_IS_PUNCTUACTION(ch));
size_t cchBlock = psz - *ppszVer;
if ( cchBlock > 1
&& psz[-1] == 'r'
&& RT_C_IS_DIGIT(*psz))
{
psz--;
cchBlock--;
}
/*
* Translate standard pre release terms to negative values.
*/
static const struct
{
size_t cch;
const char *psz;
int32_t iValue;
} s_aTerms[] =
{
{ 2, "RC", -100000 },
{ 3, "PRE", -200000 },
{ 5, "GAMMA", -300000 },
{ 4, "BETA", -400000 },
{ 5, "ALPHA", -500000 }
};
int32_t iVal1 = 0;
for (unsigned i = 0; i < RT_ELEMENTS(s_aTerms); i++)
if ( cchBlock == s_aTerms[i].cch
&& !RTStrNCmp(s_aTerms[i].psz, *ppszVer, cchBlock))
{
iVal1 = s_aTerms[i].iValue;
break;
}
if (iVal1 != 0)
{
/*
* Does the prelease term have a trailing number?
* Add it assuming BETA == BETA1.
*/
if (RT_C_IS_DIGIT(*psz))
{
const char *psz2 = psz;
do
ch = *++psz;
while ( ch
//.........这里部分代码省略.........
示例14: vbglR3Init
/**
* Implementation of VbglR3Init and VbglR3InitUser
*/
static int vbglR3Init(const char *pszDeviceName)
{
uint32_t cInits = ASMAtomicIncU32(&g_cInits);
Assert(cInits > 0);
if (cInits > 1)
{
/*
* This will fail if two (or more) threads race each other calling VbglR3Init.
* However it will work fine for single threaded or otherwise serialized
* processed calling us more than once.
*/
#ifdef RT_OS_WINDOWS
if (g_hFile == INVALID_HANDLE_VALUE)
#elif !defined (VBOX_VBGLR3_XSERVER)
if (g_File == NIL_RTFILE)
#else
if (g_File == -1)
#endif
return VERR_INTERNAL_ERROR;
return VINF_SUCCESS;
}
#if defined(RT_OS_WINDOWS)
if (g_hFile != INVALID_HANDLE_VALUE)
#elif !defined(VBOX_VBGLR3_XSERVER)
if (g_File != NIL_RTFILE)
#else
if (g_File != -1)
#endif
return VERR_INTERNAL_ERROR;
#if defined(RT_OS_WINDOWS)
/*
* Have to use CreateFile here as we want to specify FILE_FLAG_OVERLAPPED
* and possible some other bits not available thru iprt/file.h.
*/
HANDLE hFile = CreateFile(pszDeviceName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
return VERR_OPEN_FAILED;
g_hFile = hFile;
#elif defined(RT_OS_OS2)
/*
* We might wish to compile this with Watcom, so stick to
* the OS/2 APIs all the way. And in any case we have to use
* DosDevIOCtl for the requests, why not use Dos* for everything.
*/
HFILE hf = NULLHANDLE;
ULONG ulAction = 0;
APIRET rc = DosOpen((PCSZ)pszDeviceName, &hf, &ulAction, 0, FILE_NORMAL,
OPEN_ACTION_OPEN_IF_EXISTS,
OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
NULL);
if (rc)
return RTErrConvertFromOS2(rc);
if (hf < 16)
{
HFILE ahfs[16];
unsigned i;
for (i = 0; i < RT_ELEMENTS(ahfs); i++)
{
ahfs[i] = 0xffffffff;
rc = DosDupHandle(hf, &ahfs[i]);
if (rc)
break;
}
if (i-- > 1)
{
ULONG fulState = 0;
rc = DosQueryFHState(ahfs[i], &fulState);
if (!rc)
{
fulState |= OPEN_FLAGS_NOINHERIT;
fulState &= OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT; /* Turn off non-participating bits. */
rc = DosSetFHState(ahfs[i], fulState);
}
if (!rc)
{
rc = DosClose(hf);
AssertMsg(!rc, ("%ld\n", rc));
hf = ahfs[i];
}
else
i++;
while (i-- > 0)
DosClose(ahfs[i]);
}
}
g_File = (RTFILE)hf;
//.........这里部分代码省略.........
示例15: RTDECL
//.........这里部分代码省略.........
while (*psz)
{
if (*psz == ')')
{
char *psz2 = RTStrStripL(psz + 1);
if (*psz2 == '=')
{
*psz = '\0';
psz = psz2;
break;
}
}
psz++;
}
if (*psz != '=')
{
RTStrPrintf(pszErr, cbErr, "Expected ')=' at %zu on line %u", psz - szLine, iLine);
return VERR_PARSE_ERROR;
}
/*
* The value.
*/
psz = RTStrStrip(psz + 1);
const char * const pszValue = psz;
if (!*psz)
{
RTStrPrintf(pszErr, cbErr, "Expected value at %zu on line %u", psz - szLine, iLine);
return VERR_PARSE_ERROR;
}
/*
* Detect attribute type and sanity check the value.
*/
uint32_t fType = RTMANIFEST_ATTR_UNKNOWN;
static const struct
{
const char *pszAttr;
uint32_t fType;
unsigned cBits;
unsigned uBase;
} s_aDecAttrs[] =
{
{ "SIZE", RTMANIFEST_ATTR_SIZE, 64, 10}
};
for (unsigned i = 0; i < RT_ELEMENTS(s_aDecAttrs); i++)
if (!strcmp(s_aDecAttrs[i].pszAttr, pszAttr))
{
fType = s_aDecAttrs[i].fType;
rc = RTStrToUInt64Full(pszValue, s_aDecAttrs[i].uBase, NULL);
if (rc != VINF_SUCCESS)
{
RTStrPrintf(pszErr, cbErr, "Malformed value ('%s') at %zu on line %u: %Rrc", pszValue, psz - szLine, iLine, rc);
return VERR_PARSE_ERROR;
}
break;
}
if (fType == RTMANIFEST_ATTR_UNKNOWN)
{
static const struct
{
const char *pszAttr;
uint32_t fType;
unsigned cchHex;
} s_aHexAttrs[] =
{
{ "MD5", RTMANIFEST_ATTR_MD5, RTMD5_DIGEST_LEN },
{ "SHA1", RTMANIFEST_ATTR_SHA1, RTSHA1_DIGEST_LEN },
{ "SHA256", RTMANIFEST_ATTR_SHA256, RTSHA256_DIGEST_LEN },
{ "SHA512", RTMANIFEST_ATTR_SHA512, RTSHA512_DIGEST_LEN }
};
for (unsigned i = 0; i < RT_ELEMENTS(s_aHexAttrs); i++)
if (!strcmp(s_aHexAttrs[i].pszAttr, pszAttr))
{
fType = s_aHexAttrs[i].fType;
for (unsigned off = 0; off < s_aHexAttrs[i].cchHex; off++)
if (!RT_C_IS_XDIGIT(pszValue[off]))
{
RTStrPrintf(pszErr, cbErr, "Expected hex digit at %zu on line %u (value '%s', pos %u)",
pszValue - szLine + off, iLine, pszValue, off);
return VERR_PARSE_ERROR;
}
break;
}
}
/*
* Finally, add it.
*/
rc = RTManifestEntrySetAttr(hManifest, pszName, pszAttr, pszValue, fType);
if (RT_FAILURE(rc))
{
RTStrPrintf(pszErr, cbErr, "RTManifestEntrySetAttr(,'%s','%s', '%s', %#x) failed on line %u: %Rrc",
pszName, pszAttr, pszValue, fType, iLine, rc);
return rc;
}
}
}