本文整理汇总了C++中RT_ALIGN_Z函数的典型用法代码示例。如果您正苦于以下问题:C++ RT_ALIGN_Z函数的具体用法?C++ RT_ALIGN_Z怎么用?C++ RT_ALIGN_Z使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RT_ALIGN_Z函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RT_ALIGN_Z
RTCString::printfOutputCallback(void *pvArg, const char *pachChars, size_t cbChars)
{
RTCString *pThis = (RTCString *)pvArg;
if (cbChars)
{
size_t cchBoth = pThis->m_cch + cbChars;
if (cchBoth >= pThis->m_cbAllocated)
{
/* Double the buffer size, if it's less that _4M. Align sizes like
for append. */
size_t cbAlloc = RT_ALIGN_Z(pThis->m_cbAllocated, IPRT_MINISTRING_APPEND_ALIGNMENT);
cbAlloc += RT_MIN(cbAlloc, _4M);
if (cbAlloc <= cchBoth)
cbAlloc = RT_ALIGN_Z(cchBoth + 1, IPRT_MINISTRING_APPEND_ALIGNMENT);
pThis->reserve(cbAlloc);
#ifndef RT_EXCEPTIONS_ENABLED
AssertReleaseReturn(pThis->capacity() > cchBoth, 0);
#endif
}
memcpy(&pThis->m_psz[pThis->m_cch], pachChars, cbChars);
pThis->m_cch = cchBoth;
pThis->m_psz[cchBoth] = '\0';
}
return cbChars;
}
示例2: rtAsn1DefaultAllocator_AlignSize
/**
* Aligns allocation sizes a little.
*
* @returns Aligned size.
* @param cb Requested size.
*/
static size_t rtAsn1DefaultAllocator_AlignSize(size_t cb)
{
if (cb >= 64)
return RT_ALIGN_Z(cb, 64);
if (cb >= 32)
return RT_ALIGN_Z(cb, 32);
if (cb >= 16)
return RT_ALIGN_Z(cb, 16);
return cb;
}
示例3: RTDECL
RTDECL(int) RTUtf16ReallocTag(PRTUTF16 *ppwsz, size_t cbNew, const char *pszTag)
{
PRTUTF16 pwszOld = *ppwsz;
cbNew = RT_ALIGN_Z(cbNew, sizeof(RTUTF16));
if (!cbNew)
{
RTMemFree(pwszOld);
*ppwsz = NULL;
}
else if (pwszOld)
{
PRTUTF16 pwszNew = (PRTUTF16)RTMemReallocTag(pwszOld, cbNew, pszTag);
if (!pwszNew)
return VERR_NO_STR_MEMORY;
pwszNew[cbNew / sizeof(RTUTF16) - 1] = '\0';
*ppwsz = pwszNew;
}
else
{
PRTUTF16 pwszNew = (PRTUTF16)RTMemAllocTag(cbNew, pszTag);
if (!pwszNew)
return VERR_NO_UTF16_MEMORY;
pwszNew[0] = '\0';
pwszNew[cbNew / sizeof(RTUTF16) - 1] = '\0';
*ppwsz = pwszNew;
}
return VINF_SUCCESS;
}
示例4: RTR0DECL
/**
* Frees memory allocated using RTMemContAlloc().
*
* @param pv Pointer to return from RTMemContAlloc().
* @param cb The cb parameter passed to RTMemContAlloc().
*/
RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
{
if (pv)
{
int cOrder;
unsigned cPages;
unsigned iPage;
struct page *paPages;
IPRT_LINUX_SAVE_EFL_AC();
/* validate */
AssertMsg(!((uintptr_t)pv & PAGE_OFFSET_MASK), ("pv=%p\n", pv));
Assert(cb > 0);
/* calc order and get pages */
cb = RT_ALIGN_Z(cb, PAGE_SIZE);
cPages = cb >> PAGE_SHIFT;
cOrder = CalcPowerOf2Order(cPages);
paPages = virt_to_page(pv);
/*
* Restore page attributes freeing the pages.
*/
for (iPage = 0; iPage < cPages; iPage++)
{
ClearPageReserved(&paPages[iPage]);
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 20) /** @todo find the exact kernel where change_page_attr was introduced. */
MY_SET_PAGES_NOEXEC(&paPages[iPage], 1);
#endif
}
__free_pages(paPages, cOrder);
IPRT_LINUX_RESTORE_EFL_AC();
}
}
示例5: DECLHIDDEN
/**
* OS specific allocation function.
*/
DECLHIDDEN(int) rtR0MemAllocEx(size_t cb, uint32_t fFlags, PRTMEMHDR *ppHdr)
{
size_t cbAllocated = cb;
PRTMEMHDR pHdr;
#ifdef RT_ARCH_AMD64
if (fFlags & RTMEMHDR_FLAG_EXEC)
{
AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL);
cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE) - sizeof(*pHdr);
pHdr = (PRTMEMHDR)segkmem_alloc(heaptext_arena, cbAllocated + sizeof(*pHdr), KM_SLEEP);
}
else
#endif
{
unsigned fKmFlags = fFlags & RTMEMHDR_FLAG_ANY_CTX_ALLOC ? KM_NOSLEEP : KM_SLEEP;
if (fFlags & RTMEMHDR_FLAG_ZEROED)
pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), fKmFlags);
else
pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), fKmFlags);
}
if (RT_UNLIKELY(!pHdr))
{
LogRel(("rtMemAllocEx(%u, %#x) failed\n", (unsigned)cb + sizeof(*pHdr), fFlags));
return VERR_NO_MEMORY;
}
pHdr->u32Magic = RTMEMHDR_MAGIC;
pHdr->fFlags = fFlags;
pHdr->cb = cbAllocated;
pHdr->cbReq = cb;
*ppHdr = pHdr;
return VINF_SUCCESS;
}
示例6: DECLCALLBACK
/**
* @interface_method_impl{TXSTRANSPORT,pfnSendPkt}
*/
static DECLCALLBACK(int) txsTcpSendPkt(PCTXSPKTHDR pPktHdr)
{
Assert(pPktHdr->cb >= sizeof(TXSPKTHDR));
/*
* Fail if no client connection.
*/
RTSOCKET hTcpClient = g_hTcpClient;
if (hTcpClient == NIL_RTSOCKET)
return VERR_NET_NOT_CONNECTED;
/*
* Write it.
*/
size_t cbToSend = RT_ALIGN_Z(pPktHdr->cb, TXSPKT_ALIGNMENT);
int rc = RTTcpWrite(hTcpClient, pPktHdr, cbToSend);
if ( RT_FAILURE(rc)
&& rc != VERR_INTERRUPTED)
{
/* assume fatal connection error. */
Log(("RTTcpWrite -> %Rrc -> txsTcpDisconnectClient(%RTsock)\n", rc, g_hTcpClient));
txsTcpDisconnectClient();
}
return rc;
}
示例7: RT_ALIGN_Z
static void *alloc_bounce_buffer(size_t *tmp_sizep, PRTCCPHYS physp, size_t
xfer_size, const char *caller)
{
size_t tmp_size;
void *tmp;
/* try for big first. */
tmp_size = RT_ALIGN_Z(xfer_size, PAGE_SIZE);
if (tmp_size > 16U*_1K)
tmp_size = 16U*_1K;
tmp = kmalloc(tmp_size, GFP_KERNEL);
if (!tmp)
{
/* fall back on a page sized buffer. */
tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!tmp)
{
LogRel(("%s: could not allocate bounce buffer for xfer_size=%zu %s\n", caller, xfer_size));
return NULL;
}
tmp_size = PAGE_SIZE;
}
*tmp_sizep = tmp_size;
*physp = virt_to_phys(tmp);
return tmp;
}
示例8: RTDECL
RTDECL(void *) RTHeapOffsetAllocZ(RTHEAPOFFSET hHeap, size_t cb, size_t cbAlignment)
{
PRTHEAPOFFSETINTERNAL pHeapInt = hHeap;
PRTHEAPOFFSETBLOCK pBlock;
/*
* Validate and adjust the input.
*/
AssertPtrReturn(pHeapInt, NULL);
if (cb < RTHEAPOFFSET_MIN_BLOCK)
cb = RTHEAPOFFSET_MIN_BLOCK;
else
cb = RT_ALIGN_Z(cb, RTHEAPOFFSET_ALIGNMENT);
if (!cbAlignment)
cbAlignment = RTHEAPOFFSET_ALIGNMENT;
else
{
Assert(!(cbAlignment & (cbAlignment - 1)));
Assert((cbAlignment & ~(cbAlignment - 1)) == cbAlignment);
if (cbAlignment < RTHEAPOFFSET_ALIGNMENT)
cbAlignment = RTHEAPOFFSET_ALIGNMENT;
}
/*
* Do the allocation.
*/
pBlock = rtHeapOffsetAllocBlock(pHeapInt, cb, cbAlignment);
if (RT_LIKELY(pBlock))
{
void *pv = pBlock + 1;
memset(pv, 0, cb);
return pv;
}
return NULL;
}
示例9: AssertReturn
RTCString &RTCString::appendCodePoint(RTUNICP uc)
{
/*
* Single byte encoding.
*/
if (uc < 0x80)
return RTCString::append((char)uc);
/*
* Multibyte encoding.
* Assume max encoding length when resizing the string, that's simpler.
*/
AssertReturn(uc <= UINT32_C(0x7fffffff), *this);
if (m_cch + 6 >= m_cbAllocated)
{
reserve(RT_ALIGN_Z(m_cch + 6 + 1, IPRT_MINISTRING_APPEND_ALIGNMENT));
// calls realloc(cbBoth) and sets m_cbAllocated; may throw bad_alloc.
#ifndef RT_EXCEPTIONS_ENABLED
AssertRelease(capacity() > m_cch + 6);
#endif
}
char *pszNext = RTStrPutCp(&m_psz[m_cch], uc);
m_cch = pszNext - m_psz;
*pszNext = '\0';
return *this;
}
示例10: rtEnvCreate
/**
* Internal worker that creates an environment handle with a specified capacity.
*
* @returns IPRT status code.
* @param ppIntEnv Where to store the result.
* @param cAllocated The initial array size.
* @param fCaseSensitive Whether the environment block is case sensitive or
* not.
* @param fPutEnvBlock Indicates whether this is a special environment
* block that will be used to record change another
* block. We will keep unsets in putenv format, i.e.
* just the variable name without any equal sign.
*/
static int rtEnvCreate(PRTENVINTERNAL *ppIntEnv, size_t cAllocated, bool fCaseSensitive, bool fPutEnvBlock)
{
/*
* Allocate environment handle.
*/
PRTENVINTERNAL pIntEnv = (PRTENVINTERNAL)RTMemAlloc(sizeof(*pIntEnv));
if (pIntEnv)
{
/*
* Pre-allocate the variable array.
*/
pIntEnv->u32Magic = RTENV_MAGIC;
pIntEnv->fPutEnvBlock = fPutEnvBlock;
pIntEnv->pfnCompare = fCaseSensitive ? RTStrNCmp : RTStrNICmp;
pIntEnv->papszEnvOtherCP = NULL;
pIntEnv->cVars = 0;
pIntEnv->cAllocated = RT_ALIGN_Z(RT_MAX(cAllocated, RTENV_GROW_SIZE), RTENV_GROW_SIZE);
pIntEnv->papszEnv = (char **)RTMemAllocZ(sizeof(pIntEnv->papszEnv[0]) * pIntEnv->cAllocated);
if (pIntEnv->papszEnv)
{
*ppIntEnv = pIntEnv;
return VINF_SUCCESS;
}
RTMemFree(pIntEnv);
}
return VERR_NO_MEMORY;
}
示例11: DECLHIDDEN
DECLHIDDEN(int) rtMemAllocEx16BitReach(size_t cbAlloc, uint32_t fFlags, void **ppv)
{
cbAlloc = RT_ALIGN_Z(cbAlloc, PAGE_SIZE);
AssertReturn(cbAlloc <= _64K - PAGE_SIZE, VERR_NO_MEMORY);
/* Seems this doesn't work on W7/64... */
return rtMemAllocExInRange(cbAlloc, fFlags, ppv, PAGE_SIZE, _64K - cbAlloc);
}
示例12: dbgfR3TraceEnable
/**
* Initializes the tracing.
*
* @returns VBox status code
* @param pVM The cross context VM structure.
* @param cbEntry The trace entry size.
* @param cEntries The number of entries.
*/
static int dbgfR3TraceEnable(PVM pVM, uint32_t cbEntry, uint32_t cEntries)
{
/*
* Don't enable it twice.
*/
if (pVM->hTraceBufR3 != NIL_RTTRACEBUF)
return VERR_ALREADY_EXISTS;
/*
* Resolve default parameter values.
*/
int rc;
if (!cbEntry)
{
rc = CFGMR3QueryU32Def(CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF"), "TraceBufEntrySize", &cbEntry, 128);
AssertRCReturn(rc, rc);
}
if (!cEntries)
{
rc = CFGMR3QueryU32Def(CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF"), "TraceBufEntries", &cEntries, 4096);
AssertRCReturn(rc, rc);
}
/*
* Figure the required size.
*/
RTTRACEBUF hTraceBuf;
size_t cbBlock = 0;
rc = RTTraceBufCarve(&hTraceBuf, cEntries, cbEntry, 0 /*fFlags*/, NULL, &cbBlock);
if (rc != VERR_BUFFER_OVERFLOW)
{
AssertReturn(!RT_SUCCESS_NP(rc), VERR_IPE_UNEXPECTED_INFO_STATUS);
return rc;
}
/*
* Allocate a hyper heap block and carve a trace buffer out of it.
*
* Note! We ASSUME that the returned trace buffer handle has the same value
* as the heap block.
*/
cbBlock = RT_ALIGN_Z(cbBlock, PAGE_SIZE);
void *pvBlock;
rc = MMR3HyperAllocOnceNoRel(pVM, cbBlock, PAGE_SIZE, MM_TAG_DBGF, &pvBlock);
if (RT_FAILURE(rc))
return rc;
rc = RTTraceBufCarve(&hTraceBuf, cEntries, cbEntry, 0 /*fFlags*/, pvBlock, &cbBlock);
AssertRCReturn(rc, rc);
AssertRelease(hTraceBuf == (RTTRACEBUF)pvBlock);
AssertRelease((void *)hTraceBuf == pvBlock);
pVM->hTraceBufR3 = hTraceBuf;
pVM->hTraceBufR0 = MMHyperCCToR0(pVM, hTraceBuf);
pVM->hTraceBufRC = MMHyperCCToRC(pVM, hTraceBuf);
return VINF_SUCCESS;
}
示例13: vboxfuseNodeAlloc
/**
* Allocates a new node and initialize the node part of it.
*
* The returned node has one reference.
*
* @returns VBox status code.
*
* @param cbNode The size of the node.
* @param pszName The name of the node.
* @param enmType The node type.
* @param pDir The directory (parent).
* @param ppNode Where to return the pointer to the node.
*/
static int vboxfuseNodeAlloc(size_t cbNode, const char *pszName, VBOXFUSETYPE enmType, PVBOXFUSEDIR pDir,
PVBOXFUSENODE *ppNode)
{
Assert(cbNode >= sizeof(VBOXFUSENODE));
/*
* Allocate the memory for it and init the critical section.
*/
size_t cchName = strlen(pszName);
PVBOXFUSENODE pNode = (PVBOXFUSENODE)RTMemAlloc(cchName + 1 + RT_ALIGN_Z(cbNode, 8));
if (!pNode)
return VERR_NO_MEMORY;
int rc = RTCritSectInit(&pNode->CritSect);
if (RT_FAILURE(rc))
{
RTMemFree(pNode);
return rc;
}
/*
* Initialize the members.
*/
pNode->pszName = (char *)memcpy((uint8_t *)pNode + RT_ALIGN_Z(cbNode, 8), pszName, cchName + 1);
pNode->cchName = cchName;
pNode->enmType = enmType;
pNode->cRefs = 1;
pNode->pDir = pDir;
#if 0
pNode->fMode = enmType == VBOXFUSETYPE_DIRECTORY ? S_IFDIR | 0755 : S_IFREG | 0644;
#else
pNode->fMode = enmType == VBOXFUSETYPE_DIRECTORY ? S_IFDIR | 0777 : S_IFREG | 0666;
#endif
pNode->Uid = 0;
pNode->Gid = 0;
pNode->cLinks = 0;
pNode->Ino = g_NextIno++; /** @todo make this safe! */
pNode->cbPrimary = 0;
*ppNode = pNode;
return VINF_SUCCESS;
}
示例14: RTDECL
RTDECL(PRTUTF16) RTUtf16AllocTag(size_t cb, const char *pszTag)
{
if (cb > sizeof(RTUTF16))
cb = RT_ALIGN_Z(cb, sizeof(RTUTF16));
else
cb = sizeof(RTUTF16);
PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag(cb, pszTag);
if (pwsz)
*pwsz = '\0';
return pwsz;
}
示例15: Elf64NoteSectionSize
/**
* Returns the size of the NOTE section given the name and size of the data.
*
* @param pszName Name of the note section.
* @param cb Size of the data portion of the note section.
*
* @return The size of the NOTE section as rounded to the file alignment.
*/
static uint64_t Elf64NoteSectionSize(const char *pszName, uint64_t cbData)
{
uint64_t cbNote = sizeof(Elf64_Nhdr);
size_t cbName = strlen(pszName) + 1;
size_t cbNameAlign = RT_ALIGN_Z(cbName, g_NoteAlign);
cbNote += cbNameAlign;
cbNote += RT_ALIGN_64(cbData, g_NoteAlign);
return cbNote;
}