本文整理汇总了C++中RTMemAlloc函数的典型用法代码示例。如果您正苦于以下问题:C++ RTMemAlloc函数的具体用法?C++ RTMemAlloc怎么用?C++ RTMemAlloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTMemAlloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: i_vbvaFetchCmd
//.........这里部分代码省略.........
{
return false;
}
}
if (!(cbRecordCurrent & VBVA_F_RECORD_PARTIAL))
{
/* The record is completed by guest. Return it to the caller. */
*ppHdr = (VBVACMDHDR *)pVideoAccel->pu8VbvaPartial;
*pcbCmd = pVideoAccel->cbVbvaPartial;
pVideoAccel->pu8VbvaPartial = NULL;
pVideoAccel->cbVbvaPartial = 0;
/* Advance the record index. */
pVbvaMemory->indexRecordFirst = (indexRecordFirst + 1) % VBVA_MAX_RECORDS;
#ifdef DEBUG_sunlover
LogFlowFunc(("partial done ok, data = %d, free = %d\n",
pVbvaMemory->off32Data, pVbvaMemory->off32Free));
#endif /* DEBUG_sunlover */
}
return true;
}
/* A new record need to be processed. */
if (cbRecordCurrent & VBVA_F_RECORD_PARTIAL)
{
/* Current record is being written by guest. '=' is important here. */
if (cbRecord >= VBVA_RING_BUFFER_SIZE - VBVA_RING_BUFFER_THRESHOLD)
{
/* Partial read must be started. */
if (!i_vbvaPartialRead(&pVideoAccel->pu8VbvaPartial, &pVideoAccel->cbVbvaPartial, cbRecord, pVbvaMemory))
{
return false;
}
LogFlowFunc(("started partial record cbVbvaPartial = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
pVideoAccel->cbVbvaPartial, cbRecordCurrent, indexRecordFirst, indexRecordFree));
}
return true;
}
/* Current record is complete. If it is not empty, process it. */
if (cbRecord)
{
/* The size of largest contiguous chunk in the ring biffer. */
uint32_t u32BytesTillBoundary = VBVA_RING_BUFFER_SIZE - pVbvaMemory->off32Data;
/* The ring buffer pointer. */
uint8_t *au8RingBuffer = &pVbvaMemory->au8RingBuffer[0];
/* The pointer to data in the ring buffer. */
uint8_t *src = &au8RingBuffer[pVbvaMemory->off32Data];
/* Fetch or point the data. */
if (u32BytesTillBoundary >= cbRecord)
{
/* The command does not cross buffer boundary. Return address in the buffer. */
*ppHdr = (VBVACMDHDR *)src;
/* Advance data offset. */
pVbvaMemory->off32Data = (pVbvaMemory->off32Data + cbRecord) % VBVA_RING_BUFFER_SIZE;
}
else
{
/* The command crosses buffer boundary. Rare case, so not optimized. */
uint8_t *dst = (uint8_t *)RTMemAlloc(cbRecord);
if (!dst)
{
LogRelFlowFunc(("could not allocate %d bytes from heap!!!\n", cbRecord));
pVbvaMemory->off32Data = (pVbvaMemory->off32Data + cbRecord) % VBVA_RING_BUFFER_SIZE;
return false;
}
i_vbvaFetchBytes(pVbvaMemory, dst, cbRecord);
*ppHdr = (VBVACMDHDR *)dst;
#ifdef DEBUG_sunlover
LogFlowFunc(("Allocated from heap %p\n", dst));
#endif /* DEBUG_sunlover */
}
}
*pcbCmd = cbRecord;
/* Advance the record index. */
pVbvaMemory->indexRecordFirst = (indexRecordFirst + 1) % VBVA_MAX_RECORDS;
#ifdef DEBUG_sunlover
LogFlowFunc(("done ok, data = %d, free = %d\n",
pVbvaMemory->off32Data, pVbvaMemory->off32Free));
#endif /* DEBUG_sunlover */
return true;
}
示例2: VBoxServiceReadProp
/**
* Reads a guest property.
*
* @returns VBox status code, fully bitched.
*
* @param u32ClientId The HGCM client ID for the guest property session.
* @param pszPropName The property name.
* @param ppszValue Where to return the value. This is always set
* to NULL. Free it using RTStrFree().
* @param ppszFlags Where to return the value flags. Free it
* using RTStrFree(). Optional.
* @param puTimestamp Where to return the timestamp. This is only set
* on success. Optional.
*/
int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName,
char **ppszValue, char **ppszFlags, uint64_t *puTimestamp)
{
AssertPtrReturn(pszPropName, VERR_INVALID_POINTER);
AssertPtrReturn(ppszValue, VERR_INVALID_POINTER);
uint32_t cbBuf = _1K;
void *pvBuf = NULL;
int rc;
*ppszValue = NULL;
for (unsigned cTries = 0; cTries < 10; cTries++)
{
/*
* (Re-)Allocate the buffer and try read the property.
*/
RTMemFree(pvBuf);
pvBuf = RTMemAlloc(cbBuf);
if (!pvBuf)
{
VBoxServiceError("Guest Property: Failed to allocate %zu bytes\n", cbBuf);
rc = VERR_NO_MEMORY;
break;
}
char *pszValue;
char *pszFlags;
uint64_t uTimestamp;
rc = VbglR3GuestPropRead(u32ClientId, pszPropName,
pvBuf, cbBuf,
&pszValue, &uTimestamp, &pszFlags, NULL);
if (RT_FAILURE(rc))
{
if (rc == VERR_BUFFER_OVERFLOW)
{
/* try again with a bigger buffer. */
cbBuf *= 2;
continue;
}
if (rc == VERR_NOT_FOUND)
VBoxServiceVerbose(2, "Guest Property: %s not found\n", pszPropName);
else
VBoxServiceError("Guest Property: Failed to query \"%s\": %Rrc\n", pszPropName, rc);
break;
}
VBoxServiceVerbose(2, "Guest Property: Read \"%s\" = \"%s\", timestamp %RU64n\n",
pszPropName, pszValue, uTimestamp);
*ppszValue = RTStrDup(pszValue);
if (!*ppszValue)
{
VBoxServiceError("Guest Property: RTStrDup failed for \"%s\"\n", pszValue);
rc = VERR_NO_MEMORY;
break;
}
if (puTimestamp)
*puTimestamp = uTimestamp;
if (ppszFlags)
*ppszFlags = RTStrDup(pszFlags);
break; /* done */
}
if (pvBuf)
RTMemFree(pvBuf);
return rc;
}
示例3: vbglR3DnDHGProcessURIMessages
static int vbglR3DnDHGProcessURIMessages(uint32_t uClientId,
uint32_t *puScreenId,
char *pszFormat,
uint32_t cbFormat,
uint32_t *pcbFormatRecv,
void **ppvData,
uint32_t cbData,
size_t *pcbDataRecv)
{
/* Make a string list out of the uri data. */
RTCList<RTCString> uriList = RTCString(static_cast<char*>(*ppvData), *pcbDataRecv - 1).split("\r\n");
if (uriList.isEmpty())
return VINF_SUCCESS;
uint32_t cbTmpData = _1M * 10;
void *pvTmpData = RTMemAlloc(cbTmpData);
if (!pvTmpData)
return VERR_NO_MEMORY;
/* Create and query the drop target directory. */
char pszDropDir[RTPATH_MAX];
int rc = vbglR3DnDCreateDropDir(pszDropDir, sizeof(pszDropDir));
if (RT_FAILURE(rc))
{
RTMemFree(pvTmpData);
return rc;
}
/* Patch the old drop data with the new drop directory, so the drop target
* can find the files. */
RTCList<RTCString> guestUriList;
for (size_t i = 0; i < uriList.size(); ++i)
{
const RTCString &strUri = uriList.at(i);
/* Query the path component of a file URI. If this hasn't a
* file scheme, null is returned. */
if (char *pszFilePath = RTUriFilePath(strUri.c_str(), URI_FILE_FORMAT_AUTO))
{
RTCString strFullPath = RTCString().printf("%s%c%s", pszDropDir, RTPATH_SLASH, pszFilePath);
char *pszNewUri = RTUriFileCreate(strFullPath.c_str());
if (pszNewUri)
{
guestUriList.append(pszNewUri);
RTStrFree(pszNewUri);
}
}
else
guestUriList.append(strUri);
}
/* Cleanup the old data and write the new data back to the event. */
RTMemFree(*ppvData);
RTCString newData = RTCString::join(guestUriList, "\r\n") + "\r\n";
*ppvData = RTStrDupN(newData.c_str(), newData.length());
*pcbDataRecv = newData.length() + 1;
/* Lists for holding created files & directories in the case of a
* rollback. */
RTCList<RTCString> guestDirList;
RTCList<RTCString> guestFileList;
char pszPathname[RTPATH_MAX];
uint32_t cbPathname = 0;
bool fLoop = true;
do
{
uint32_t uNextMsg;
uint32_t cNextParms;
rc = vbglR3DnDQueryNextHostMessageType(uClientId, &uNextMsg, &cNextParms, false);
DO(("%Rrc - %d\n", rc , uNextMsg));
if (RT_SUCCESS(rc))
{
switch(uNextMsg)
{
case DragAndDropSvc::HOST_DND_HG_SND_DIR:
{
uint32_t fMode = 0;
rc = vbglR3DnDHGProcessSendDirMessage(uClientId,
pszPathname,
sizeof(pszPathname),
&cbPathname,
&fMode);
if (RT_SUCCESS(rc))
{
DO(("Got drop dir: %s - %o - %Rrc\n", pszPathname, fMode, rc));
char *pszNewDir = RTPathJoinA(pszDropDir, pszPathname);
rc = RTDirCreate(pszNewDir, (fMode & RTFS_UNIX_MASK) | RTFS_UNIX_IRWXU, 0);
if (!guestDirList.contains(pszNewDir))
guestDirList.append(pszNewDir);
}
break;
}
case DragAndDropSvc::HOST_DND_HG_SND_FILE:
{
uint32_t cbDataRecv;
uint32_t fMode = 0;
rc = vbglR3DnDHGProcessSendFileMessage(uClientId,
pszPathname,
sizeof(pszPathname),
&cbPathname,
pvTmpData,
//.........这里部分代码省略.........
示例4: VBoxServiceVMStatsReport
/**
* Gathers VM statistics and reports them to the host.
*/
static void VBoxServiceVMStatsReport(void)
{
#if defined(RT_OS_WINDOWS)
SYSTEM_INFO systemInfo;
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pProcInfo;
MEMORYSTATUSEX memStatus;
uint32_t cbStruct;
DWORD cbReturned;
Assert(gCtx.pfnGlobalMemoryStatusEx && gCtx.pfnNtQuerySystemInformation);
if ( !gCtx.pfnGlobalMemoryStatusEx
|| !gCtx.pfnNtQuerySystemInformation)
return;
/* Clear the report so we don't report garbage should NtQuerySystemInformation
behave in an unexpected manner. */
VMMDevReportGuestStats req;
RT_ZERO(req);
/* Query and report guest statistics */
GetSystemInfo(&systemInfo);
memStatus.dwLength = sizeof(memStatus);
gCtx.pfnGlobalMemoryStatusEx(&memStatus);
req.guestStats.u32PageSize = systemInfo.dwPageSize;
req.guestStats.u32PhysMemTotal = (uint32_t)(memStatus.ullTotalPhys / _4K);
req.guestStats.u32PhysMemAvail = (uint32_t)(memStatus.ullAvailPhys / _4K);
/* The current size of the committed memory limit, in bytes. This is physical
memory plus the size of the page file, minus a small overhead. */
req.guestStats.u32PageFileSize = (uint32_t)(memStatus.ullTotalPageFile / _4K) - req.guestStats.u32PhysMemTotal;
req.guestStats.u32MemoryLoad = memStatus.dwMemoryLoad;
req.guestStats.u32StatCaps = VBOX_GUEST_STAT_PHYS_MEM_TOTAL
| VBOX_GUEST_STAT_PHYS_MEM_AVAIL
| VBOX_GUEST_STAT_PAGE_FILE_SIZE
| VBOX_GUEST_STAT_MEMORY_LOAD;
#ifdef VBOX_WITH_MEMBALLOON
req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryPages(_4K);
req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PHYS_MEM_BALLOON;
#else
req.guestStats.u32PhysMemBalloon = 0;
#endif
if (gCtx.pfnGetPerformanceInfo)
{
PERFORMANCE_INFORMATION perfInfo;
if (gCtx.pfnGetPerformanceInfo(&perfInfo, sizeof(perfInfo)))
{
req.guestStats.u32Processes = perfInfo.ProcessCount;
req.guestStats.u32Threads = perfInfo.ThreadCount;
req.guestStats.u32Handles = perfInfo.HandleCount;
req.guestStats.u32MemCommitTotal = perfInfo.CommitTotal; /* already in pages */
req.guestStats.u32MemKernelTotal = perfInfo.KernelTotal; /* already in pages */
req.guestStats.u32MemKernelPaged = perfInfo.KernelPaged; /* already in pages */
req.guestStats.u32MemKernelNonPaged = perfInfo.KernelNonpaged; /* already in pages */
req.guestStats.u32MemSystemCache = perfInfo.SystemCache; /* already in pages */
req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PROCESSES | VBOX_GUEST_STAT_THREADS | VBOX_GUEST_STAT_HANDLES
| VBOX_GUEST_STAT_MEM_COMMIT_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_TOTAL
| VBOX_GUEST_STAT_MEM_KERNEL_PAGED | VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED
| VBOX_GUEST_STAT_MEM_SYSTEM_CACHE;
}
else
VBoxServiceVerbose(3, "VBoxServiceVMStatsReport: GetPerformanceInfo failed with %d\n", GetLastError());
}
/* Query CPU load information */
cbStruct = systemInfo.dwNumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
pProcInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)RTMemAlloc(cbStruct);
if (!pProcInfo)
return;
/* Unfortunately GetSystemTimes is XP SP1 and up only, so we need to use the semi-undocumented NtQuerySystemInformation */
NTSTATUS rc = gCtx.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned);
if ( !rc
&& cbReturned == cbStruct)
{
if (gCtx.au64LastCpuLoad_Kernel == 0)
{
/* first time */
gCtx.au64LastCpuLoad_Idle[0] = pProcInfo->IdleTime.QuadPart;
gCtx.au64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart;
gCtx.au64LastCpuLoad_User[0] = pProcInfo->UserTime.QuadPart;
Sleep(250);
rc = gCtx.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned);
Assert(!rc);
}
uint64_t deltaIdle = (pProcInfo->IdleTime.QuadPart - gCtx.au64LastCpuLoad_Idle[0]);
uint64_t deltaKernel = (pProcInfo->KernelTime.QuadPart - gCtx.au64LastCpuLoad_Kernel[0]);
uint64_t deltaUser = (pProcInfo->UserTime.QuadPart - gCtx.au64LastCpuLoad_User[0]);
deltaKernel -= deltaIdle; /* idle time is added to kernel time */
uint64_t ullTotalTime = deltaIdle + deltaKernel + deltaUser;
if (ullTotalTime == 0) /* Prevent division through zero. */
ullTotalTime = 1;
//.........这里部分代码省略.........
示例5: RT_NOREF
//.........这里部分代码省略.........
DROPFILES *pDropFiles = (DROPFILES *)pvData;
AssertPtr(pDropFiles);
bool fUnicode = RT_BOOL(pDropFiles->fWide);
/* Get the offset of the file list. */
Assert(pDropFiles->pFiles >= sizeof(DROPFILES));
/* Note: This is *not* pDropFiles->pFiles! DragQueryFile only
* will work with the plain storage medium pointer! */
HDROP hDrop = (HDROP)(pvData);
/* First, get the file count. */
/** @todo Does this work on Windows 2000 / NT4? */
char *pszFiles = NULL;
uint32_t cchFiles = 0;
UINT cFiles = DragQueryFile(hDrop, UINT32_MAX /* iFile */,
NULL /* lpszFile */, 0 /* cchFile */);
LogFlowFunc(("CF_HDROP got %RU16 file(s)\n", cFiles));
for (UINT i = 0; i < cFiles; i++)
{
UINT cch = DragQueryFile(hDrop, i /* File index */,
NULL /* Query size first */,
0 /* cchFile */);
Assert(cch);
if (RT_FAILURE(rc))
break;
char *pszFile = NULL; /* UTF-8 version. */
UINT cchFile = 0;
if (fUnicode)
{
/* Allocate enough space (including terminator). */
WCHAR *pwszFile = (WCHAR *)RTMemAlloc((cch + 1) * sizeof(WCHAR));
if (pwszFile)
{
cchFile = DragQueryFileW(hDrop, i /* File index */,
pwszFile, cch + 1 /* Include terminator */);
AssertMsg(cchFile == cch, ("cchCopied (%RU16) does not match cchFile (%RU16)\n",
cchFile, cch));
rc = RTUtf16ToUtf8(pwszFile, &pszFile);
AssertRC(rc);
RTMemFree(pwszFile);
}
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));
示例6: VBoxD3DIfCreateForRc
HRESULT VBoxD3DIfCreateForRc(struct VBOXWDDMDISP_RESOURCE *pRc)
{
PVBOXWDDMDISP_DEVICE pDevice = pRc->pDevice;
HRESULT hr = E_FAIL;
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
if (VBOXWDDMDISP_IS_TEXTURE(pRc->RcDesc.fFlags))
{
PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0];
IDirect3DBaseTexture9 *pD3DIfTex;
HANDLE hSharedHandle = pAllocation->hSharedHandle;
void **pavClientMem = NULL;
VBOXDISP_D3DIFTYPE enmD3DIfType = VBOXDISP_D3DIFTYPE_UNDEFINED;
hr = S_OK;
if (pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)
{
pavClientMem = (void**)RTMemAlloc(sizeof (pavClientMem[0]) * pRc->cAllocations);
Assert(pavClientMem);
if (pavClientMem)
{
for (UINT i = 0; i < pRc->cAllocations; ++i)
{
Assert(pRc->aAllocations[i].pvMem);
pavClientMem[i] = pRc->aAllocations[i].pvMem;
}
}
else
hr = E_FAIL;
}
#ifdef DEBUG
if (!pRc->RcDesc.fFlags.CubeMap)
{
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[0];
uint32_t tstW = pAlloc->SurfDesc.width;
uint32_t tstH = pAlloc->SurfDesc.height;
for (UINT i = 1; i < pRc->cAllocations; ++i)
{
tstW /= 2;
tstH /= 2;
pAlloc = &pRc->aAllocations[i];
Assert((pAlloc->SurfDesc.width == tstW) || (!tstW && (pAlloc->SurfDesc.width==1)));
Assert((pAlloc->SurfDesc.height == tstH) || (!tstH && (pAlloc->SurfDesc.height==1)));
}
}
#endif
if (SUCCEEDED(hr))
{
if (pRc->RcDesc.fFlags.CubeMap)
{
if ( (pAllocation->SurfDesc.width!=pAllocation->SurfDesc.height)
|| (pRc->cAllocations%6!=0))
{
WARN(("unexpected cubemap texture config: (%d ; %d), allocs: %d",
pAllocation->SurfDesc.width, pAllocation->SurfDesc.height, pRc->cAllocations));
hr = E_INVALIDARG;
}
else
{
hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9CreateCubeTexture((IDirect3DDevice9Ex *)pDevice9If,
pAllocation->SurfDesc.d3dWidth,
VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc),
vboxDDI2D3DUsage(pRc->RcDesc.fFlags),
vboxDDI2D3DFormat(pRc->RcDesc.enmFormat),
vboxDDI2D3DPool(pRc->RcDesc.enmPool),
(IDirect3DCubeTexture9**)&pD3DIfTex,
#ifdef VBOXWDDMDISP_DEBUG_NOSHARED
NULL,
#else
pRc->RcDesc.fFlags.SharedResource ? &hSharedHandle : NULL,
#endif
pavClientMem);
Assert(hr == S_OK);
Assert(pD3DIfTex);
enmD3DIfType = VBOXDISP_D3DIFTYPE_CUBE_TEXTURE;
}
}
else if (pRc->RcDesc.fFlags.Volume)
{
hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9CreateVolumeTexture((IDirect3DDevice9Ex *)pDevice9If,
pAllocation->SurfDesc.d3dWidth,
pAllocation->SurfDesc.height,
pAllocation->SurfDesc.depth,
pRc->cAllocations,
vboxDDI2D3DUsage(pRc->RcDesc.fFlags),
vboxDDI2D3DFormat(pRc->RcDesc.enmFormat),
vboxDDI2D3DPool(pRc->RcDesc.enmPool),
(IDirect3DVolumeTexture9**)&pD3DIfTex,
#ifdef VBOXWDDMDISP_DEBUG_NOSHARED
NULL,
#else
pRc->RcDesc.fFlags.SharedResource ? &hSharedHandle : NULL,
#endif
pavClientMem);
Assert(hr == S_OK);
Assert(pD3DIfTex);
enmD3DIfType = VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE;
}
else
//.........这里部分代码省略.........
示例7: RTDECL
RTDECL(int) RTLocalIpcSessionConnect(PRTLOCALIPCSESSION phSession, const char *pszName, uint32_t fFlags)
{
AssertPtrReturn(phSession, VERR_INVALID_POINTER);
AssertPtrReturn(pszName, VERR_INVALID_POINTER);
AssertReturn(*pszName, VERR_INVALID_PARAMETER);
AssertReturn(!fFlags, VERR_INVALID_PARAMETER); /* Flags currently unused, must be 0. */
PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)RTMemAlloc(sizeof(*pThis));
if (!pThis)
return VERR_NO_MEMORY;
pThis->u32Magic = RTLOCALIPCSESSION_MAGIC;
pThis->cRefs = 1; /* The one we return. */
pThis->fIOPending = false;
pThis->fZeroByteRead = false;
pThis->fCancelled = false;
pThis->pbBounceBuf = NULL;
pThis->cbBounceBufAlloc = 0;
pThis->cbBounceBufUsed = 0;
int rc = RTCritSectInit(&pThis->CritSect);
if (RT_SUCCESS(rc))
{
pThis->hEvent = CreateEvent(NULL /*lpEventAttributes*/, TRUE /*bManualReset*/,
FALSE /*bInitialState*/, NULL /*lpName*/);
if (pThis->hEvent != NULL)
{
RT_ZERO(pThis->OverlappedIO);
pThis->OverlappedIO.Internal = STATUS_PENDING;
pThis->OverlappedIO.hEvent = pThis->hEvent;
PSECURITY_DESCRIPTOR pSecDesc;
rc = rtLocalIpcServerWinAllocSecurityDescriptior(&pSecDesc, false /* Client */);
if (RT_SUCCESS(rc))
{
char *pszPipe;
if (RTStrAPrintf(&pszPipe, "%s%s", RTLOCALIPC_WIN_PREFIX, pszName))
{
SECURITY_ATTRIBUTES SecAttrs;
SecAttrs.nLength = sizeof(SECURITY_ATTRIBUTES);
SecAttrs.lpSecurityDescriptor = pSecDesc;
SecAttrs.bInheritHandle = FALSE;
HANDLE hPipe = CreateFile(pszPipe, /* pipe name */
GENERIC_READ /* read and write access */
| GENERIC_WRITE,
0, /* no sharing */
&SecAttrs, /* lpSecurityAttributes */
OPEN_EXISTING, /* opens existing pipe */
FILE_FLAG_OVERLAPPED, /* default attributes */
NULL); /* no template file */
RTStrFree(pszPipe);
if (hPipe != INVALID_HANDLE_VALUE)
{
LocalFree(pSecDesc);
pThis->hNmPipe = hPipe;
*phSession = pThis;
return VINF_SUCCESS;
}
else
rc = RTErrConvertFromWin32(GetLastError());
}
else
rc = VERR_NO_MEMORY;
LocalFree(pSecDesc);
}
BOOL fRc = CloseHandle(pThis->hEvent);
AssertMsg(fRc, ("%d\n", GetLastError())); NOREF(fRc);
}
else
rc = RTErrConvertFromWin32(GetLastError());
int rc2 = RTCritSectDelete(&pThis->CritSect);
AssertRC(rc2);
}
RTMemFree(pThis);
return rc;
}
示例8: RTDECL
RTDECL(int) RTGetOptArgvFromString(char ***ppapszArgv, int *pcArgs, const char *pszCmdLine, const char *pszSeparators)
{
/*
* Some input validation.
*/
AssertPtr(pszCmdLine);
AssertPtr(pcArgs);
AssertPtr(ppapszArgv);
if (!pszSeparators)
pszSeparators = " \t\n\r";
else
AssertPtr(pszSeparators);
size_t const cchSeparators = strlen(pszSeparators);
AssertReturn(cchSeparators > 0, VERR_INVALID_PARAMETER);
/*
* Parse the command line and chop off it into argv individual argv strings.
*/
int rc = VINF_SUCCESS;
const char *pszSrc = pszCmdLine;
char *pszDup = (char *)RTMemAlloc(strlen(pszSrc) + 1);
char *pszDst = pszDup;
if (!pszDup)
return VERR_NO_STR_MEMORY;
char **papszArgs = NULL;
unsigned iArg = 0;
while (*pszSrc)
{
/* Skip stuff */
rc = rtGetOptSkipDelimiters(&pszSrc, pszSeparators, cchSeparators);
if (RT_FAILURE(rc))
break;
if (!*pszSrc)
break;
/* Start a new entry. */
if ((iArg % 32) == 0)
{
void *pvNew = RTMemRealloc(papszArgs, (iArg + 33) * sizeof(char *));
if (!pvNew)
{
rc = VERR_NO_MEMORY;
break;
}
papszArgs = (char **)pvNew;
}
papszArgs[iArg++] = pszDst;
/* Parse and copy the string over. */
RTUNICP CpQuote = 0;
RTUNICP Cp;
for (;;)
{
rc = RTStrGetCpEx(&pszSrc, &Cp);
if (RT_FAILURE(rc) || !Cp)
break;
if (!CpQuote)
{
if (Cp == '"' || Cp == '\'')
CpQuote = Cp;
else if (rtGetOptIsCpInSet(Cp, pszSeparators, cchSeparators))
break;
else
pszDst = RTStrPutCp(pszDst, Cp);
}
else if (CpQuote != Cp)
pszDst = RTStrPutCp(pszDst, Cp);
else
CpQuote = 0;
}
*pszDst++ = '\0';
if (RT_FAILURE(rc) || !Cp)
break;
}
if (RT_FAILURE(rc))
{
RTMemFree(pszDup);
RTMemFree(papszArgs);
return rc;
}
/*
* Terminate the array.
* Check for empty string to make sure we've got an array.
*/
if (iArg == 0)
{
RTMemFree(pszDup);
papszArgs = (char **)RTMemAlloc(1 * sizeof(char *));
if (!papszArgs)
return VERR_NO_MEMORY;
}
papszArgs[iArg] = NULL;
*pcArgs = iArg;
*ppapszArgv = papszArgs;
return VINF_SUCCESS;
}
示例9: RTDECL
RTDECL(int) RTHandleTableAlloc(RTHANDLETABLE hHandleTable, void *pvObj, uint32_t *ph)
{
/* validate the input */
PRTHANDLETABLEINT pThis = (PRTHANDLETABLEINT)hHandleTable;
AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, VERR_INVALID_HANDLE);
AssertReturn(!(pThis->fFlags & RTHANDLETABLE_FLAGS_CONTEXT), VERR_INVALID_FUNCTION);
AssertReturn(!RTHT_IS_FREE(pvObj), VERR_INVALID_PARAMETER);
AssertPtrReturn(ph, VERR_INVALID_POINTER);
*ph = pThis->uBase - 1;
/*
* Allocation loop.
*/
rtHandleTableLock(pThis);
int rc;
do
{
/*
* Try grab a free entry from the head of the free list.
*/
uint32_t i = pThis->iFreeHead;
if (i != NIL_RTHT_INDEX)
{
PRTHTENTRYFREE pFree = (PRTHTENTRYFREE)rtHandleTableLookupSimpleIdx(pThis, i);
Assert(pFree);
if (i == pThis->iFreeTail)
pThis->iFreeTail = pThis->iFreeHead = NIL_RTHT_INDEX;
else
pThis->iFreeHead = RTHT_GET_FREE_IDX(pFree);
pThis->cCurAllocated++;
Assert(pThis->cCurAllocated <= pThis->cCur);
/*
* Setup the entry and return.
*/
PRTHTENTRY pEntry = (PRTHTENTRY)pFree;
pEntry->pvObj = pvObj;
*ph = i + pThis->uBase;
rc = VINF_SUCCESS;
}
/*
* Must expand the handle table, unless it's full.
*/
else if (pThis->cCur >= pThis->cMax)
{
rc = VERR_NO_MORE_HANDLES;
Assert(pThis->cCur == pThis->cCurAllocated);
}
else
{
/*
* Do we have to expand the 1st level table too?
*/
uint32_t const iLevel1 = pThis->cCur / RTHT_LEVEL2_ENTRIES;
uint32_t cLevel1 = iLevel1 >= pThis->cLevel1
? pThis->cLevel1 + PAGE_SIZE / sizeof(void *)
: 0;
if (cLevel1 > pThis->cMax / RTHT_LEVEL2_ENTRIES)
cLevel1 = pThis->cMax / RTHT_LEVEL2_ENTRIES;
Assert(!cLevel1 || pThis->cMax / RTHT_LEVEL2_ENTRIES >= RTHT_LEVEL1_DYN_ALLOC_THRESHOLD);
/* leave the lock (never do fancy stuff from behind a spinlock). */
rtHandleTableUnlock(pThis);
/*
* Do the allocation(s).
*/
rc = VERR_TRY_AGAIN;
void **papvLevel1 = NULL;
if (cLevel1)
{
papvLevel1 = (void **)RTMemAlloc(sizeof(void *) * cLevel1);
if (!papvLevel1)
return VERR_NO_MEMORY;
}
PRTHTENTRY paTable = (PRTHTENTRY)RTMemAlloc(sizeof(*paTable) * RTHT_LEVEL2_ENTRIES);
if (!paTable)
{
RTMemFree(papvLevel1);
return VERR_NO_MEMORY;
}
/* re-enter the lock. */
rtHandleTableLock(pThis);
/*
* Insert the new bits, but be a bit careful as someone might have
* raced us expanding the table.
*/
/* deal with the 1st level lookup expansion first */
if (cLevel1)
{
Assert(papvLevel1);
if (cLevel1 > pThis->cLevel1)
{
/* Replace the 1st level table. */
memcpy(papvLevel1, pThis->papvLevel1, sizeof(void *) * pThis->cLevel1);
//.........这里部分代码省略.........
示例10: RTCritSectEnter
/**
* Allocate memory from the heap.
*
* @returns Pointer to allocated memory.
* @param pHeap Heap handle.
* @param enmTag Statistics tag. Statistics are collected on a per tag
* basis in addition to a global one. Thus we can easily
* identify how memory is used by the VM. See MM_TAG_*.
* @param cbSize Size of the block.
* @param fZero Whether or not to zero the memory block.
*/
void *mmR3HeapAlloc(PMMHEAP pHeap, MMTAG enmTag, size_t cbSize, bool fZero)
{
#ifdef MMR3HEAP_WITH_STATISTICS
RTCritSectEnter(&pHeap->Lock);
/*
* Find/alloc statistics nodes.
*/
pHeap->Stat.cAllocations++;
PMMHEAPSTAT pStat = (PMMHEAPSTAT)RTAvlULGet(&pHeap->pStatTree, (AVLULKEY)enmTag);
if (pStat)
{
pStat->cAllocations++;
RTCritSectLeave(&pHeap->Lock);
}
else
{
pStat = (PMMHEAPSTAT)RTMemAllocZ(sizeof(MMHEAPSTAT));
if (!pStat)
{
pHeap->Stat.cFailures++;
AssertMsgFailed(("Failed to allocate heap stat record.\n"));
RTCritSectLeave(&pHeap->Lock);
return NULL;
}
pStat->Core.Key = (AVLULKEY)enmTag;
pStat->pHeap = pHeap;
RTAvlULInsert(&pHeap->pStatTree, &pStat->Core);
pStat->cAllocations++;
RTCritSectLeave(&pHeap->Lock);
/* register the statistics */
PUVM pUVM = pHeap->pUVM;
const char *pszTag = mmGetTagName(enmTag);
STAMR3RegisterFU(pUVM, &pStat->cbCurAllocated, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes currently allocated.", "/MM/R3Heap/%s", pszTag);
STAMR3RegisterFU(pUVM, &pStat->cAllocations, STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "Number or MMR3HeapAlloc() calls.", "/MM/R3Heap/%s/cAllocations", pszTag);
STAMR3RegisterFU(pUVM, &pStat->cReallocations, STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "Number of MMR3HeapRealloc() calls.", "/MM/R3Heap/%s/cReallocations", pszTag);
STAMR3RegisterFU(pUVM, &pStat->cFrees, STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "Number of MMR3HeapFree() calls.", "/MM/R3Heap/%s/cFrees", pszTag);
STAMR3RegisterFU(pUVM, &pStat->cFailures, STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failures.", "/MM/R3Heap/%s/cFailures", pszTag);
STAMR3RegisterFU(pUVM, &pStat->cbAllocated, STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total number of bytes allocated.", "/MM/R3Heap/%s/cbAllocated", pszTag);
STAMR3RegisterFU(pUVM, &pStat->cbFreed, STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total number of bytes freed.", "/MM/R3Heap/%s/cbFreed", pszTag);
}
#endif
/*
* Validate input.
*/
if (cbSize == 0)
{
#ifdef MMR3HEAP_WITH_STATISTICS
RTCritSectEnter(&pHeap->Lock);
pStat->cFailures++;
pHeap->Stat.cFailures++;
RTCritSectLeave(&pHeap->Lock);
#endif
return NULL;
}
/*
* Allocate heap block.
*/
cbSize = RT_ALIGN_Z(cbSize, MMR3HEAP_SIZE_ALIGNMENT) + sizeof(MMHEAPHDR);
PMMHEAPHDR pHdr = (PMMHEAPHDR)(fZero ? RTMemAllocZ(cbSize) : RTMemAlloc(cbSize));
if (!pHdr)
{
AssertMsgFailed(("Failed to allocate heap block %d, enmTag=%x(%.4s).\n", cbSize, enmTag, &enmTag));
#ifdef MMR3HEAP_WITH_STATISTICS
RTCritSectEnter(&pHeap->Lock);
pStat->cFailures++;
pHeap->Stat.cFailures++;
RTCritSectLeave(&pHeap->Lock);
#endif
return NULL;
}
Assert(!((uintptr_t)pHdr & (RTMEM_ALIGNMENT - 1)));
RTCritSectEnter(&pHeap->Lock);
/*
* Init and link in the header.
*/
pHdr->pNext = NULL;
pHdr->pPrev = pHeap->pTail;
if (pHdr->pPrev)
pHdr->pPrev->pNext = pHdr;
else
pHeap->pHead = pHdr;
//.........这里部分代码省略.........
示例11: drvWinHostGetparportAddr
/**
* Get Parallel port address and update the shared data
* structure.
* @returns VBox status code.
* @param pThis The host parallel port instance data.
*/
static int drvWinHostGetparportAddr(PDRVHOSTPARALLEL pThis)
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
uint32_t u32Idx;
uint32_t u32ParportAddr;
int rc = VINF_SUCCESS;
hDevInfo = SetupDiGetClassDevs(NULL, 0, 0, DIGCF_PRESENT | DIGCF_ALLCLASSES);
if (hDevInfo == INVALID_HANDLE_VALUE)
return VERR_INVALID_HANDLE;
/* Enumerate through all devices in Set. */
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (u32Idx = 0; SetupDiEnumDeviceInfo(hDevInfo, u32Idx, &DeviceInfoData); u32Idx++)
{
DWORD dwDataType;
uint8_t *pBuf = NULL;
DWORD dwBufSize = 0;
while (!SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME,
(PDWORD)&dwDataType, (uint8_t *)pBuf,
dwBufSize, (PDWORD)&dwBufSize))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
LogFlow(("ERROR_INSUFF_BUFF = %d. dwBufSz = %d\n", GetLastError(), dwBufSize));
if (pBuf)
RTMemFree(pBuf);
pBuf = (uint8_t *)RTMemAlloc(dwBufSize * 2);
}
else
{
/* No need to bother about this error (in most cases its errno=13,
* INVALID_DATA . Just break from here and proceed to next device
* enumerated item
*/
LogFlow(("GetDevProp Error = %d & dwBufSz = %d\n", GetLastError(), dwBufSize));
break;
}
}
if (RTStrStr((char*)pBuf, "LPT"))
{
u32ParportAddr = drvHostWinFindIORangeResource(DeviceInfoData.DevInst);
if (u32ParportAddr)
{
/* Find parallel port name and update the shared data struncture */
char *pCh = RTStrStr((char*)pBuf, "(");
char *pTmpCh = RTStrStr((char *)pBuf, ")");
/* check for the confirmation for the availability of parallel port */
if (!(pCh && pTmpCh))
{
LogFlowFunc(("Parallel port Not Found. \n"));
return VERR_NOT_FOUND;
}
if (((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) < 0) {
LogFlowFunc(("Parallel port string not properly formatted.\n"));
return VERR_NOT_FOUND;
}
/* check for the confirmation for the availability of parallel port */
if (RTStrCopyEx((char *)(pThis->szParportName), sizeof(pThis->szParportName),
pCh+1, ((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) - 1))
{
LogFlowFunc(("Parallel Port Not Found.\n"));
return VERR_NOT_FOUND;
}
*((char *)pThis->szParportName + (pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf) + 1 ) = '\0';
/* checking again to make sure that we have got a valid name and in valid format too. */
if (RTStrNCmp((char *)pThis->szParportName, "LPT", 3)) {
LogFlowFunc(("Parallel Port name \"LPT\" Not Found.\n"));
return VERR_NOT_FOUND;
}
if (!RTStrStr((char *)pThis->szParportName, "LPT")
|| !(pThis->szParportName[3] >= '0'
&& pThis->szParportName[3] <= '9'))
{
RT_BZERO(pThis->szParportName, sizeof(pThis->szParportName));
LogFlowFunc(("Printer Port Name Not Found.\n"));
return VERR_NOT_FOUND;
}
pThis->fParportAvail = true;
pThis->u32LptAddr = u32ParportAddr;
pThis->u32LptAddrControl = pThis->u32LptAddr + CTRL_REG_OFFSET;
pThis->u32LptAddrStatus = pThis->u32LptAddr + STATUS_REG_OFFSET;
}
else
LogFlowFunc(("u32Parport Addr No Available \n"));
if (pThis->fParportAvail)
break;
}
if (pBuf)
//.........这里部分代码省略.........
示例12: drvHostWinFindIORangeResource
/**
* Find IO port range for the parallel port and return the lower address.
*
* @returns parallel port IO address.
* @param DevInst Device Instance for parallel port.
*/
static uint32_t drvHostWinFindIORangeResource(const DEVINST DevInst)
{
uint8_t *pBuf = NULL;
short wHeaderSize;
uint32_t u32Size;
CONFIGRET cmRet;
LOG_CONF firstLogConf;
LOG_CONF nextLogConf;
RES_DES rdPrevResDes;
uint32_t u32ParportAddr = 0;
wHeaderSize = sizeof(IO_DES);
cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, ALLOC_LOG_CONF);
if (cmRet != CR_SUCCESS)
{
cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, BOOT_LOG_CONF);
if (cmRet != CR_SUCCESS)
return 0;
}
cmRet = CM_Get_Next_Res_Des(&nextLogConf, firstLogConf, 2, 0L, 0L);
if (cmRet != CR_SUCCESS)
{
CM_Free_Res_Des_Handle(firstLogConf);
return 0;
}
/* This loop is based on the fact that only one resourece is assigned to
* the LPT port. If multiple resources (address range) are assigned to
* to LPT port, it will pick and return the last one
*/
for (;;)
{
u32Size = 0;
cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L);
if (cmRet != CR_SUCCESS)
{
LogFlowFunc(("Failed to get Size \n"));
CM_Free_Res_Des_Handle(nextLogConf);
break;
}
pBuf = (uint8_t *)RTMemAlloc(u32Size + 1);
if (!pBuf)
{
LogFlowFunc(("Failed to get Buf %d\n", u32Size));
CM_Free_Res_Des_Handle(nextLogConf);
break;
}
cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L);
if (cmRet != CR_SUCCESS)
{
LogFlowFunc(("Failed to get Des Data \n"));
CM_Free_Res_Des_Handle(nextLogConf);
if (pBuf)
RTMemFree(pBuf);
break;
}
LogFlowFunc(("call GetIOResource\n"));
if (pBuf)
u32ParportAddr = ((IO_DES *)pBuf)->IOD_Alloc_Base;
LogFlowFunc(("called GetIOResource, ret=%#x\n", u32ParportAddr));
rdPrevResDes = 0;
cmRet = CM_Get_Next_Res_Des(&rdPrevResDes,
nextLogConf,
2,
0L,
0L);
if (pBuf)
RTMemFree(pBuf);
if (cmRet != CR_SUCCESS)
break;
CM_Free_Res_Des_Handle(nextLogConf);
nextLogConf = rdPrevResDes;
}
CM_Free_Res_Des_Handle(nextLogConf);
LogFlowFunc(("return u32ParportAddr=%#x", u32ParportAddr));
return u32ParportAddr;
}
示例13: vbsfPathGuestToHost
int vbsfPathGuestToHost(SHFLCLIENTDATA *pClient, SHFLROOT hRoot,
PCSHFLSTRING pGuestString, uint32_t cbGuestString,
char **ppszHostPath, uint32_t *pcbHostPathRoot,
uint32_t fu32Options,
uint32_t *pfu32PathFlags)
{
#ifdef VBOX_STRICT
/*
* Check that the pGuestPath has correct size and encoding.
*/
if (ShflStringIsValidIn(pGuestString, cbGuestString, RT_BOOL(pClient->fu32Flags & SHFL_CF_UTF8)) == false)
{
LogFunc(("Invalid input string\n"));
return VERR_INTERNAL_ERROR;
}
#else
NOREF(cbGuestString);
#endif
/*
* Resolve the root handle into a string.
*/
uint32_t cbRootLen = 0;
const char *pszRoot = NULL;
int rc = vbsfMappingsQueryHostRootEx(hRoot, &pszRoot, &cbRootLen);
if (RT_FAILURE(rc))
{
LogFunc(("invalid root\n"));
return rc;
}
AssertReturn(cbRootLen > 0, VERR_INTERNAL_ERROR_2); /* vbsfMappingsQueryHostRootEx ensures this. */
/*
* Get the UTF8 string with the relative path provided by the guest.
* If guest uses UTF-16 then convert it to UTF-8.
*/
uint32_t cbGuestPath = 0; /* Shut up MSC */
const char *pchGuestPath = NULL; /* Ditto. */
char *pchGuestPathAllocated = NULL; /* Converted from UTF-16. */
if (BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8))
{
/* UTF-8 */
cbGuestPath = pGuestString->u16Length;
pchGuestPath = pGuestString->String.ach;
}
else
{
/* UTF-16 */
#ifdef RT_OS_DARWIN /* Misplaced hack! See todo! */
uint32_t cwcSrc = 0;
PRTUTF16 pwszSrc = NULL;
rc = vbsfNormalizeStringDarwin(&pGuestString->String.ucs2[0],
pGuestString->u16Length / sizeof(RTUTF16),
&pwszSrc, &cwcSrc);
#else
uint32_t const cwcSrc = pGuestString->u16Length / sizeof(RTUTF16);
PCRTUTF16 const pwszSrc = &pGuestString->String.ucs2[0];
#endif
if (RT_SUCCESS(rc))
{
size_t cbPathAsUtf8 = RTUtf16CalcUtf8Len(pwszSrc);
if (cbPathAsUtf8 >= cwcSrc)
{
/* Allocate buffer that will be able to contain the converted UTF-8 string. */
pchGuestPathAllocated = (char *)RTMemAlloc(cbPathAsUtf8 + 1);
if (RT_LIKELY(pchGuestPathAllocated != NULL))
{
if (RT_LIKELY(cbPathAsUtf8))
{
size_t cchActual;
char *pszDst = pchGuestPathAllocated;
rc = RTUtf16ToUtf8Ex(pwszSrc, cwcSrc, &pszDst, cbPathAsUtf8 + 1, &cchActual);
AssertRC(rc);
AssertStmt(RT_FAILURE(rc) || cchActual == cbPathAsUtf8, rc = VERR_INTERNAL_ERROR_4);
Assert(strlen(pszDst) == cbPathAsUtf8);
}
if (RT_SUCCESS(rc))
{
/* Terminate the string. */
pchGuestPathAllocated[cbPathAsUtf8] = '\0';
cbGuestPath = (uint32_t)cbPathAsUtf8; Assert(cbGuestPath == cbPathAsUtf8);
pchGuestPath = pchGuestPathAllocated;
}
}
else
{
rc = VERR_NO_MEMORY;
}
}
else
{
AssertFailed();
rc = VERR_INTERNAL_ERROR_3;
}
//.........这里部分代码省略.........
示例14: RTDECL
RTDECL(int) RTTimerCreate(PRTTIMER *ppTimer, unsigned uMilliesInterval, PFNRTTIMER pfnTimer, void *pvUser)
{
#ifndef USE_WINMM
/*
* On windows we'll have to set the timer resolution before
* we start the timer.
*/
ULONG ulMax = UINT32_MAX;
ULONG ulMin = UINT32_MAX;
ULONG ulCur = UINT32_MAX;
NtQueryTimerResolution(&ulMax, &ulMin, &ulCur);
Log(("NtQueryTimerResolution -> ulMax=%lu00ns ulMin=%lu00ns ulCur=%lu00ns\n", ulMax, ulMin, ulCur));
if (ulCur > ulMin && ulCur > 10000 /* = 1ms */)
{
if (NtSetTimerResolution(10000, TRUE, &ulCur) >= 0)
Log(("Changed timer resolution to 1ms.\n"));
else if (NtSetTimerResolution(20000, TRUE, &ulCur) >= 0)
Log(("Changed timer resolution to 2ms.\n"));
else if (NtSetTimerResolution(40000, TRUE, &ulCur) >= 0)
Log(("Changed timer resolution to 4ms.\n"));
else if (ulMin <= 50000 && NtSetTimerResolution(ulMin, TRUE, &ulCur) >= 0)
Log(("Changed timer resolution to %lu *100ns.\n", ulMin));
else
{
AssertMsgFailed(("Failed to configure timer resolution!\n"));
return VERR_INTERNAL_ERROR;
}
}
#endif /* !USE_WINN */
/*
* Create new timer.
*/
int rc = VERR_IPE_UNINITIALIZED_STATUS;
PRTTIMER pTimer = (PRTTIMER)RTMemAlloc(sizeof(*pTimer));
if (pTimer)
{
pTimer->u32Magic = RTTIMER_MAGIC;
pTimer->pvUser = pvUser;
pTimer->pfnTimer = pfnTimer;
pTimer->iTick = 0;
pTimer->uMilliesInterval = uMilliesInterval;
#ifdef USE_WINMM
/* sync kill doesn't work. */
pTimer->TimerId = timeSetEvent(uMilliesInterval, 0, rttimerCallback, (DWORD_PTR)pTimer, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
if (pTimer->TimerId)
{
ULONG ulMax = UINT32_MAX;
ULONG ulMin = UINT32_MAX;
ULONG ulCur = UINT32_MAX;
NtQueryTimerResolution(&ulMax, &ulMin, &ulCur);
Log(("NtQueryTimerResolution -> ulMax=%lu00ns ulMin=%lu00ns ulCur=%lu00ns\n", ulMax, ulMin, ulCur));
*ppTimer = pTimer;
return VINF_SUCCESS;
}
rc = VERR_INVALID_PARAMETER;
#else /* !USE_WINMM */
/*
* Create Win32 event semaphore.
*/
pTimer->iError = 0;
pTimer->hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
if (pTimer->hTimer)
{
#ifdef USE_APC
/*
* Create wait semaphore.
*/
pTimer->hevWait = CreateEvent(NULL, FALSE, FALSE, NULL);
if (pTimer->hevWait)
#endif
{
/*
* Kick off the timer thread.
*/
rc = RTThreadCreate(&pTimer->Thread, rttimerCallback, pTimer, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "Timer");
if (RT_SUCCESS(rc))
{
/*
* Wait for the timer to successfully create the timer
* If we don't get a response in 10 secs, then we assume we're screwed.
*/
rc = RTThreadUserWait(pTimer->Thread, 10000);
if (RT_SUCCESS(rc))
{
rc = pTimer->iError;
if (RT_SUCCESS(rc))
{
*ppTimer = pTimer;
return VINF_SUCCESS;
}
}
ASMAtomicXchgU32(&pTimer->u32Magic, RTTIMER_MAGIC + 1);
RTThreadWait(pTimer->Thread, 250, NULL);
CancelWaitableTimer(pTimer->hTimer);
}
#ifdef USE_APC
//.........这里部分代码省略.........
示例15: vbsfCorrectCasing
/**
* Corrects the casing of the final component
*
* @returns
* @param pClient .
* @param pszFullPath .
* @param pszStartComponent .
*/
static int vbsfCorrectCasing(SHFLCLIENTDATA *pClient, char *pszFullPath, char *pszStartComponent)
{
Log2(("vbsfCorrectCasing: %s %s\n", pszFullPath, pszStartComponent));
AssertReturn((uintptr_t)pszFullPath < (uintptr_t)pszStartComponent - 1U, VERR_INTERNAL_ERROR_2);
AssertReturn(pszStartComponent[-1] == RTPATH_DELIMITER, VERR_INTERNAL_ERROR_5);
/*
* Allocate a buffer that can hold really long file name entries as well as
* the initial search pattern.
*/
size_t cchComponent = strlen(pszStartComponent);
size_t cchParentDir = pszStartComponent - pszFullPath;
size_t cchFullPath = cchParentDir + cchComponent;
Assert(strlen(pszFullPath) == cchFullPath);
size_t cbDirEntry = 4096;
if (cchFullPath + 4 > cbDirEntry - RT_OFFSETOF(RTDIRENTRYEX, szName))
cbDirEntry = RT_OFFSETOF(RTDIRENTRYEX, szName) + cchFullPath + 4;
PRTDIRENTRYEX pDirEntry = (PRTDIRENTRYEX)RTMemAlloc(cbDirEntry);
if (pDirEntry == NULL)
return VERR_NO_MEMORY;
/*
* Construct the search criteria in the szName member of pDirEntry.
*/
/** @todo This is quite inefficient, especially for directories with many
* files. If any of the typically case sensitive host systems start
* supporting opendir wildcard filters, it would make sense to build
* one here with '?' for case foldable charaters. */
/** @todo Use RTDirOpen here and drop the whole uncessary path copying? */
int rc = RTPathJoinEx(pDirEntry->szName, cbDirEntry - RT_OFFSETOF(RTDIRENTRYEX, szName),
pszFullPath, cchParentDir,
RT_STR_TUPLE("*"));
AssertRC(rc);
if (RT_SUCCESS(rc))
{
RTDIR hSearch = NULL;
rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, 0 /*fFlags*/);
if (RT_SUCCESS(rc))
{
for (;;)
{
size_t cbDirEntrySize = cbDirEntry;
rc = RTDirReadEx(hSearch, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
if (rc == VERR_NO_MORE_FILES)
break;
if ( rc != VINF_SUCCESS
&& rc != VWRN_NO_DIRENT_INFO)
{
if ( rc == VERR_NO_TRANSLATION
|| rc == VERR_INVALID_UTF8_ENCODING)
continue;
AssertMsgFailed(("%Rrc\n", rc));
break;
}
Log2(("vbsfCorrectCasing: found %s\n", &pDirEntry->szName[0]));
if ( pDirEntry->cbName == cchComponent
&& !RTStrICmp(pszStartComponent, &pDirEntry->szName[0]))
{
Log(("Found original name %s (%s)\n", &pDirEntry->szName[0], pszStartComponent));
strcpy(pszStartComponent, &pDirEntry->szName[0]);
rc = VINF_SUCCESS;
break;
}
}
RTDirClose(hSearch);
}
}
if (RT_FAILURE(rc))
Log(("vbsfCorrectCasing %s failed with %Rrc\n", pszStartComponent, rc));
RTMemFree(pDirEntry);
return rc;
}