本文整理汇总了C++中RNDUP函数的典型用法代码示例。如果您正苦于以下问题:C++ RNDUP函数的具体用法?C++ RNDUP怎么用?C++ RNDUP使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RNDUP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_mem_alloc
/*
* Simple memory allocator, allocates aligned physical memory.
* Note that startup_kernel() only allocates memory, never frees.
* Memory usage just grows in an upward direction.
*/
static void *
do_mem_alloc(uint32_t size, uint32_t align)
{
uint_t i;
uint64_t best;
uint64_t start;
uint64_t end;
/*
* make sure size is a multiple of pagesize
*/
size = RNDUP(size, MMU_PAGESIZE);
next_avail_addr = RNDUP(next_avail_addr, align);
/*
* XXPV fixme joe
*
* a really large bootarchive that causes you to run out of memory
* may cause this to blow up
*/
/* LINTED E_UNEXPECTED_UINT_PROMOTION */
best = (uint64_t)-size;
for (i = 0; i < memlists_used; ++i) {
start = memlists[i].addr;
#if defined(__xpv)
start += mfn_base;
#endif
end = start + memlists[i].size;
/*
* did we find the desired address?
*/
if (start <= next_avail_addr && next_avail_addr + size <= end) {
best = next_avail_addr;
goto done;
}
/*
* if not is this address the best so far?
*/
if (start > next_avail_addr && start < best &&
RNDUP(start, align) + size <= end)
best = RNDUP(start, align);
}
/*
* We didn't find exactly the address we wanted, due to going off the
* end of a memory region. Return the best found memory address.
*/
done:
next_avail_addr = best + size;
#if defined(__xpv)
if (next_avail_addr > scratch_end)
dboot_panic("Out of mem next_avail: 0x%lx, scratch_end: "
"0x%lx", (ulong_t)next_avail_addr,
(ulong_t)scratch_end);
#endif
(void) memset((void *)(uintptr_t)best, 0, size);
return ((void *)(uintptr_t)best);
}
示例2: PLListListImport
PPLLIST PLListListImport(PPLLIST pList, PPLLIST pImport, HNDPLLITEM hNode)
{
PPLLNODE pParent, pi;
ULONG cb;
INT i;
char buffer[256]; // only for TRACE messages
if ( !pList ) return NULL;
// allocation needed for the current item
cb = pImport->cbTot - sizeof(PLLIST);
// if the current allocation size is not enough reallocate the list
sprintf (buffer, "total (pList->cbTot): %ld, new item: %ld, pImport->cbTot: %ld sizeof(PLLIST): %ld", pList->cbTot, cb, pImport->cbTot, sizeof(PLLIST));
TRACE1("%s", buffer);
sprintf (buffer, "try to reallocate %ld (0x%X),cb: %ld", RNDUP(pList->cbTot + cb, pList->cbGrow), RNDUP(pList->cbTot + cb, pList->cbGrow), cb );
TRACE1("%s", buffer);
TRACE2("sizeof(pList) %d (0x%X)", sizeof(pList), sizeof(pList));
TRACE2("pointer to pList before realloc: 0x%X, pImport: 0x%X", pList, pImport);
if ( (RNDUP(pList->cbTot, pList->cbGrow) >= (pList->cbTot + cb)) ||
(NULL != (pList =
realloc(pList, RNDUP(pList->cbTot + cb, pList->cbGrow)))) )
{
TRACE1("pList after realloc 0x%X", pList);
pi = (PPLLNODE)((PBYTE)pList + pList->cbTot);
// get the address of the parent node
pParent = PNODEFROMHITEM(pList, hNode);
TRACE1("pParent 0x%X", pParent);
PREVITEM(pList, pParent)->offNext = pList->cbTot;
pParent->offLast = pList->cbTot;
// copy the data from the previous list to the current list
memcpy(pi, (PBYTE)pImport + sizeof(PLLIST), cb);
// update the offsets
pParent->count += pImport->count;
TRACE1("pParent->count %ld", pParent->count);
for ( i = 0, cb = pList->cbTot - sizeof(PLLIST); i < pImport->count; ++i )
{
if ( pi->offNext )
{
pi->offNext += cb;
}
else
{
pParent->offLast = (HNDPLLITEM)((PBYTE)pi - (PBYTE)pList);
} /* endif */
// if the current item is a node
if ( pi->isNode )
{
updateImpListOffsets((PPLLIST)((PBYTE)pList + cb), pi, cb);
pi->offFirst += cb;
pi->offLast += cb;
pi->offParent = hNode;
} /* endif */
pi = (PPLLNODE)NEXTITEM(pList, pi);
} /* endfor */
pList->cbTot += pImport->cbTot - sizeof(PLLIST);
TRACE1("pList->cbTot %ld", pList->cbTot);
} /* endif */
TRACE1("pList after realloc 0x%X", pList);
return pList;
}
示例3: svcauth_gss_validate
static bool_t
svcauth_gss_validate(struct svc_req *rqst, struct svc_rpc_gss_data *gd, struct rpc_msg *msg)
{
struct opaque_auth *oa;
gss_buffer_desc rpcbuf, checksum;
OM_uint32 maj_stat, min_stat, qop_state;
u_char rpchdr[128];
int32_t *buf;
log_debug("in svcauth_gss_validate()");
memset(rpchdr, 0, sizeof(rpchdr));
/* XXX - Reconstruct RPC header for signing (from xdr_callmsg). */
oa = &msg->rm_call.cb_cred;
if (oa->oa_length > MAX_AUTH_BYTES)
return (FALSE);
/* 8 XDR units from the IXDR macro calls. */
if (sizeof(rpchdr) < (8 * BYTES_PER_XDR_UNIT +
RNDUP(oa->oa_length)))
return (FALSE);
buf = (int32_t *)(void *)rpchdr;
IXDR_PUT_LONG(buf, msg->rm_xid);
IXDR_PUT_ENUM(buf, msg->rm_direction);
IXDR_PUT_LONG(buf, msg->rm_call.cb_rpcvers);
IXDR_PUT_LONG(buf, msg->rm_call.cb_prog);
IXDR_PUT_LONG(buf, msg->rm_call.cb_vers);
IXDR_PUT_LONG(buf, msg->rm_call.cb_proc);
IXDR_PUT_ENUM(buf, oa->oa_flavor);
IXDR_PUT_LONG(buf, oa->oa_length);
if (oa->oa_length) {
memcpy((caddr_t)buf, oa->oa_base, oa->oa_length);
buf += RNDUP(oa->oa_length) / sizeof(int32_t);
}
rpcbuf.value = rpchdr;
rpcbuf.length = (u_char *)buf - rpchdr;
checksum.value = msg->rm_call.cb_verf.oa_base;
checksum.length = msg->rm_call.cb_verf.oa_length;
maj_stat = gss_verify_mic(&min_stat, gd->ctx, &rpcbuf, &checksum,
&qop_state);
if (maj_stat != GSS_S_COMPLETE) {
log_status("gss_verify_mic", maj_stat, min_stat);
if (log_badverf != NULL)
(*log_badverf)(gd->client_name,
svcauth_gss_name,
rqst, msg, log_badverf_data);
return (FALSE);
}
return (TRUE);
}
示例4: PLListExport
PPLLIST PLListExport(PPLLIST pList, HNDPLLITEM hNode,
BOOL inclNode, ULONG cbGrow)
{
PPLLIST pnew, p;
ULONG cbTot;
PPLLNODE pnode, pn;
// check the cbGrow parameter
if ( !cbGrow ) cbGrow = pList->cbGrow;
// if hNode is 0 just duplicate the list
if ( !hNode )
{
if ( NULL != (pnew = malloc(RNDUP(pList->cbTot, cbGrow))) )
{
memcpy(pnew, pList, pList->cbTot);
pnew->cbGrow = cbGrow;
} /* endif */
pnew;
} /* endif */
// calculate the size of the allocation needed for the new list
cbTot = sizeof(PLLIST);
pnode = PNODEFROMHITEM(pList, hNode);
// size of the current node (if requested)
if ( inclNode ) cbTot += pnode->offFirst - hNode;
// total size of the node content
for ( pn = pnode; !pn->offNext; pn = PNODEFROMHITEM(pList, pn->offParent) ) ;
cbTot += pn->offNext - pnode->offFirst;
// allocate the new list
if ( NULL != (pnew = malloc(RNDUP(cbTot, cbGrow))) )
{
pnew->cbTot = cbTot;
pnew->offFirst = sizeof(PLLIST);
pnew->offParent = 0;
pnew->cbGrow = cbGrow;
if ( inclNode )
{
memcpy((PBYTE)pnew + sizeof(PLLIST), pnode, cbTot - sizeof(PLLIST));
pnew->count = 1;
pnew->offLast = pnew->offFirst;
updateExpListOffsets(pnew, (PPLLNODE)pnew,
hNode - sizeof(PLLIST));
}
else
{
memcpy((PBYTE)pnew + sizeof(PLLIST), FIRSTITEM(pList, pnode),
cbTot - sizeof(PLLIST));
pnew->count = pnode->count;
pnew->offLast = pnode->offLast - pnode->offFirst + sizeof(PLLIST);
updateExpListOffsets(pnew, (PPLLNODE)pnew,
pnode->offFirst - sizeof(PLLIST));
} /* endif */
} /* endif */
return pnew;
}
示例5: fix_buf_size
static u_int
fix_buf_size(u_int s)
{
if (s < 100)
s = 4000;
return (RNDUP(s));
}
示例6: xdrmblk_control
static bool_t
xdrmblk_control(XDR *xdrs, int request, void *info)
{
mblk_t *m;
int32_t *int32p;
int len;
switch (request) {
case XDR_PEEK:
/*
* Return the next 4 byte unit in the XDR stream.
*/
if (xdrs->x_handy < sizeof (int32_t))
return (FALSE);
/* LINTED pointer alignment */
m = (mblk_t *)xdrs->x_base;
if (m == NULL)
return (FALSE);
/*
* If the pointer is not aligned, fail the peek
*/
if (!IS_P2ALIGNED(m->b_rptr, sizeof (int32_t)))
return (FALSE);
int32p = (int32_t *)info;
/* LINTED pointer alignment */
*int32p = ntohl(*((int32_t *)(m->b_rptr)));
return (TRUE);
case XDR_SKIPBYTES:
/* LINTED pointer alignment */
m = (mblk_t *)xdrs->x_base;
if (m == NULL)
return (FALSE);
int32p = (int32_t *)info;
len = RNDUP((int)(*int32p));
if (len < 0)
return (FALSE);
while ((xdrs->x_handy -= len) < 0) {
if ((xdrs->x_handy += len) > 0) {
m->b_rptr += xdrs->x_handy;
len -= xdrs->x_handy;
}
m = m->b_cont;
xdrs->x_base = (caddr_t)m;
if (m == NULL) {
xdrs->x_handy = 0;
return (FALSE);
}
xdrs->x_handy = (int)(m->b_wptr - m->b_rptr);
}
m->b_rptr += len;
return (TRUE);
default:
return (FALSE);
}
}
示例7: check_higher
/*
* During memory allocation, find the highest address not used yet.
*/
static void
check_higher(paddr_t a)
{
if (a < next_avail_addr)
return;
next_avail_addr = RNDUP(a + 1, MMU_PAGESIZE);
DBG(next_avail_addr);
}
示例8: fix_buf_size
static unsigned
fix_buf_size(
register unsigned s)
{
if (s < 100)
s = 4000;
return (RNDUP(s));
}
示例9: heapIncrease
static void* heapIncrease(Heap_t uhp, size_t* plen, int* pfl)
{
PVOID p = NULL;
*plen = (size_t)RNDUP(*plen, CB_HEAPBLOCK);
*pfl = !_BLOCK_CLEAN;
logwrite("increaseHeap - size : %8u\n", *plen, 0);
if ( DosSubAllocMem(pbasemem, &p, *plen) )
return NULL;
return p;
}
示例10: PLListDup
PPLLIST PLListDup(PPLLIST pList, ULONG cb)
{
PPLLIST plist;
if ( pList && !cb )
cb = RNDUP(pList->cbTot, pList->cbGrow);
TRACE1("allocate %d bytes", cb);
if ( NULL != (plist = malloc(cb)) )
{
if ( pList ) memcpy(plist, pList, pList->cbTot);
} /* endif */
return plist;
}
示例11: __svcauth_sys
/*
* System (Unix) longhand authenticator
*/
enum auth_stat
__svcauth_sys(struct svc_req *rqst, struct rpc_msg *msg)
{
struct authsys_parms *aup;
int32_t *buf;
struct authsys_area *area;
uint_t auth_len;
uint_t str_len, gid_len;
int i;
/* LINTED pointer cast */
area = (struct authsys_area *)rqst->rq_clntcred;
aup = &area->area_aup;
aup->aup_machname = area->area_machname;
aup->aup_gids = area->area_gids;
auth_len = msg->rm_call.cb_cred.oa_length;
if (auth_len == 0)
return (AUTH_BADCRED);
/* LINTED pointer cast */
buf = (int32_t *)msg->rm_call.cb_cred.oa_base;
aup->aup_time = IXDR_GET_INT32(buf);
str_len = IXDR_GET_U_INT32(buf);
if (str_len > MAX_MACHINE_NAME)
return (AUTH_BADCRED);
(void) memcpy(aup->aup_machname, buf, str_len);
aup->aup_machname[str_len] = 0;
str_len = RNDUP(str_len);
buf += str_len / (int)sizeof (int32_t);
aup->aup_uid = IXDR_GET_INT32(buf);
aup->aup_gid = IXDR_GET_INT32(buf);
gid_len = IXDR_GET_U_INT32(buf);
if (gid_len > NGRPS)
return (AUTH_BADCRED);
aup->aup_len = gid_len;
for (i = 0; i < gid_len; i++) {
aup->aup_gids[i] = (gid_t)IXDR_GET_INT32(buf);
}
/*
* five is the smallest unix credentials structure -
* timestamp, hostname len (0), uid, gid, and gids len (0).
*/
if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
return (AUTH_BADCRED);
rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
rqst->rq_xprt->xp_verf.oa_length = 0;
return (AUTH_OK);
}
示例12: PLListNodeAdd
PPLLIST PLListNodeAdd(PPLLIST pList, HNDPLLITEM hNode, PHNDPLLITEM pNode,
PPLLISTADDITEM pFunc, PVOID pParm)
{
PPLLNODE pParent, pi;
ULONG cbItem;
size_t stSize;
char buffer[128];
if ( !pList || !pFunc ) return NULL;
// allocation needed for the current item
cbItem = pFunc(NULL, pParm) + sizeof(PLLNODE);
// if the current allocation size is not enough reallocate the list
stSize = RNDUP(pList->cbTot + cbItem, pList->cbGrow);
sprintf (buffer, "new size to allocate %ld, total: %ld, item: %ld", stSize, pList->cbTot, cbItem);
TRACE1("%s", buffer);
if ( (RNDUP(pList->cbTot, pList->cbGrow) >= (pList->cbTot + cbItem)) ||
(NULL != (pList =
realloc(pList, stSize ))) )
{
TRACE1("pList after realloc: 0x%X", pList);
pi = (PPLLNODE)((PBYTE)pList + pList->cbTot);
if ( pNode ) *pNode = pList->cbTot;
// get the address of the parent node
pParent = PNODEFROMHITEM(pList, hNode);
PREVITEM(pList, pParent)->offNext = pList->cbTot;
pParent->offLast = pList->cbTot;
pi->offFirst = (pList->cbTot += cbItem);
pi->offNext = 0;
pi->isNode = 1;
pi->offLast = 0;
pi->offParent = (ULONG)hNode;
pi->count = 0;
// set the item data via the callback procedure
pFunc(pi + 1, pParm);
pParent->count++; // update the items count
} /* endif */
return pList;
}
示例13: PLListItemAdd
PPLLIST PLListItemAdd(PPLLIST pList, HNDPLLITEM hNode, PHNDPLLITEM phItem,
PPLLISTADDITEM pFunc, PVOID pParm)
{
PPLLNODE pParent;
ULONG cbItem;
PPLLITEM pi;
if ( !pList || !pFunc ) return NULL;
// allocation needed for the current item
cbItem = pFunc(NULL, pParm) + sizeof(PLLITEM);
// if the current allocation size is not enough reallocate the list
if ( RNDUP(pList->cbTot, pList->cbGrow) < RNDUP(pList->cbTot + cbItem, pList->cbGrow) )
{
TRACE("reallocating");
TRACE2("pList->cbTot: %ld, cbItem: %ld", pList->cbTot, cbItem);
pList = realloc(pList, RNDUP(pList->cbTot + cbItem, pList->cbGrow));
TRACE("reallocating OKAY");
}
if ( pList )
{
pi = (PPLLITEM)((PBYTE)pList + pList->cbTot);
if ( phItem ) *phItem = pList->cbTot;
// get the address of the parent node
pParent = PNODEFROMHITEM(pList, hNode);
PREVITEM(pList, pParent)->offNext = pList->cbTot;
pParent->offLast = pList->cbTot;
pList->cbTot += cbItem;
pi->offNext = 0;
pi->isNode = 0;
// set the other item data via the callback procedure
pFunc(pi + 1, pParm);
pParent->count++; // update the items count
} /* endif */
if ( pList == NULL )
{
TRACE("ERROR: reallocate");
}
return pList;
}
示例14: svcauth_gss_validate
static int
svcauth_gss_validate(struct svc_req *req,
struct svc_rpc_gss_data *gd,
struct rpc_msg *msg)
{
struct opaque_auth *oa;
gss_buffer_desc rpcbuf, checksum;
OM_uint32 maj_stat, min_stat, qop_state;
u_char rpchdr[RPCHDR_LEN];
int32_t *buf;
memset(rpchdr, 0, RPCHDR_LEN);
/* XXX - Reconstruct RPC header for signing (from xdr_callmsg). */
oa = &msg->rm_call.cb_cred;
if (oa->oa_length > MAX_AUTH_BYTES)
return GSS_S_CALL_BAD_STRUCTURE;
/* XXX since MAX_AUTH_BYTES is 400, the following code trivially
* overruns (up to 431 per Coverity, but compare RPCHDR_LEN with
* what is marshalled below). */
buf = (int32_t *) rpchdr;
IXDR_PUT_LONG(buf, msg->rm_xid);
IXDR_PUT_ENUM(buf, msg->rm_direction);
IXDR_PUT_LONG(buf, msg->rm_call.cb_rpcvers);
IXDR_PUT_LONG(buf, msg->rm_call.cb_prog);
IXDR_PUT_LONG(buf, msg->rm_call.cb_vers);
IXDR_PUT_LONG(buf, msg->rm_call.cb_proc);
IXDR_PUT_ENUM(buf, oa->oa_flavor);
IXDR_PUT_LONG(buf, oa->oa_length);
if (oa->oa_length) {
memcpy((caddr_t) buf, oa->oa_base, oa->oa_length);
buf += RNDUP(oa->oa_length) / sizeof(int32_t);
}
rpcbuf.value = rpchdr;
rpcbuf.length = (u_char *) buf - rpchdr;
checksum.value = msg->rm_call.cb_verf.oa_base;
checksum.length = msg->rm_call.cb_verf.oa_length;
maj_stat =
gss_verify_mic(&min_stat, gd->ctx, &rpcbuf, &checksum, &qop_state);
if (maj_stat != GSS_S_COMPLETE) {
__warnx(TIRPC_DEBUG_FLAG_AUTH, "%s: %d %d", __func__, maj_stat,
min_stat);
return (maj_stat);
}
return GSS_S_COMPLETE;
}
示例15: PLListNew
PPLLIST PLListNew(ULONG cbGrow)
{
PPLLIST pList;
if ( !cbGrow ) cbGrow = SLPL_DEFCBGROW;
if ( NULL != (pList = malloc(RNDUP(sizeof(PLLIST), cbGrow))) )
{
pList->isNode = 1;
pList->offLast = pList->cbTot = pList->offFirst = sizeof(PLLIST);
pList->offParent = pList->count = 0;
pList->cbGrow = cbGrow;
TRACE4("addr=0x%X, size requested=%d, actual size=%d, pList->count=%d", pList, cbGrow, RNDUP(sizeof(PLLIST), cbGrow), pList->count );
return pList;
} /* endif */
return NULL;
}