本文整理汇总了C++中roundup函数的典型用法代码示例。如果您正苦于以下问题:C++ roundup函数的具体用法?C++ roundup怎么用?C++ roundup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了roundup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cpu_fork
/*
* Finish a fork operation, with process p2 nearly set up.
*/
void
cpu_fork(struct proc *p1, struct proc *p2, void *stack, size_t stacksize,
void (*func)(void *), void *arg)
{
struct trapframe *tf;
struct callframe *cf;
struct switchframe *sf;
caddr_t stktop1, stktop2;
extern void fork_trampoline(void);
struct pcb *pcb = &p2->p_addr->u_pcb;
struct cpu_info *ci = curcpu();
if (p1 == ci->ci_fpuproc)
save_fpu();
*pcb = p1->p_addr->u_pcb;
#ifdef ALTIVEC
if (p1->p_addr->u_pcb.pcb_vr != NULL) {
if (p1 == ci->ci_vecproc)
save_vec(p1);
pcb->pcb_vr = pool_get(&ppc_vecpl, PR_WAITOK);
*pcb->pcb_vr = *p1->p_addr->u_pcb.pcb_vr;
} else
pcb->pcb_vr = NULL;
#endif /* ALTIVEC */
pcb->pcb_pm = p2->p_vmspace->vm_map.pmap;
pmap_extract(pmap_kernel(),
(vaddr_t)pcb->pcb_pm, (paddr_t *)&pcb->pcb_pmreal);
/*
* Setup the trap frame for the new process
*/
stktop1 = (caddr_t)trapframe(p1);
stktop2 = (caddr_t)trapframe(p2);
bcopy(stktop1, stktop2, sizeof(struct trapframe));
/*
* If specified, give the child a different stack.
*/
if (stack != NULL) {
tf = trapframe(p2);
tf->fixreg[1] = (register_t)stack + stacksize;
}
stktop2 = (caddr_t)((u_long)stktop2 & ~15); /* Align stack pointer */
/*
* There happens to be a callframe, too.
*/
cf = (struct callframe *)stktop2;
cf->lr = (int)fork_trampoline;
/*
* Below the trap frame, there is another call frame:
*/
stktop2 -= 16;
cf = (struct callframe *)stktop2;
cf->r31 = (register_t)func;
cf->r30 = (register_t)arg;
/*
* Below that, we allocate the switch frame:
*/
/* must match SFRAMELEN in genassym */
stktop2 -= roundup(sizeof *sf, 16);
sf = (struct switchframe *)stktop2;
bzero((void *)sf, sizeof *sf); /* just in case */
sf->sp = (int)cf;
sf->user_sr = pmap_kernel()->pm_sr[PPC_USER_SR]; /* just in case */
pcb->pcb_sp = (int)stktop2;
}
示例2: generate_shlib
/*
* generate_shlib()
* Take relocatable input image of library, generate mappable one
*
* Updates library base after generation so successive libraries
* are allocated upwards in address.
* We place data immediately following text.
*/
static void
generate_shlib(void)
{
char buf[128], tmpf[32], tabf[32];
FILE *fp;
int x, cmdlen;
ulong txtsize, datasize, bsssize;
/*
* Build a jump table to prepend to the .shl output
*/
sprintf(tabf, "/tmp/sht%d.s", getpid());
fp = fopen(tabf, "w");
if (fp == NULL) {
perror(tabf);
exit(1);
}
fprintf(fp, "\t.text\n");
fprintf(fp, "tbl_%s:\n", curlib);
for (x = 0; db_syms[x]; ++x) {
fprintf(fp, "\t.long\t%s\n", db_syms[x]);
}
fclose(fp);
sprintf(buf, "cd /tmp; gcc -c %s", tabf);
do_system(buf);
unlink(tabf);
/*
* Convert jump table filename to a .o
*/
tabf[strlen(tabf)-1] = 'o';
/*
* Get shared library text size using size(1)
*/
sprintf(tmpf, "/tmp/shll%d", getpid());
sprintf(buf, "size %s > %s", curinput, tmpf);
do_system(buf);
fp = fopen(tmpf, "r");
(void)fgets(buf, sizeof(buf), fp);
if (fscanf(fp, "%ld", &txtsize) != 1) {
fprintf(stderr, "Error: corrupt size(1) output in %s\n",
tmpf);
exit(1);
}
fclose(fp);
unlink(tmpf);
/*
* Generate the library at its assigned address
*/
txtsize += (sizeof(struct aout) + (sizeof(ulong) * (ndb_syms-1)));
txtsize = roundup(txtsize, page_size);
sprintf(buf, "ld -o %s -Ttext %lx -Tdata %lx %s %s",
curoutput,
lib_base + sizeof(struct aout),
lib_base + txtsize,
tabf, curinput);
/*
* Run the command to get our object
*/
unlink(curoutput);
do_system(buf);
/*
* Dig up data size so we can bump lib_base forward
* the right amount. We couldn't calculate this until
* now, because BSS/common has an undecided size until
* finally linked.
*/
sprintf(tmpf, "/tmp/xsh%d", getpid());
sprintf(buf, "size %s > %s", curoutput, tmpf);
do_system(buf);
fp = fopen(tmpf, "r");
if (fp == NULL) {
perror(tmpf);
exit(1);
}
/*
* Skip header line, get data and BSS size
*/
(void)fgets(buf, sizeof(buf), fp);
if (fscanf(fp, "%ld\t%ld\t%ld", &txtsize, &datasize, &bsssize) != 3) {
fprintf(stderr, "Error: corrupt size(1) output in %s\n",
tmpf);
exit(1);
}
fclose(fp);
/*
//.........这里部分代码省略.........
示例3: pass2
void
pass2(void)
{
union dinode *dp;
struct inoinfo **inpp, *inp;
struct inoinfo **inpend;
struct inodesc curino;
union dinode dino;
int i;
char pathbuf[MAXPATHLEN + 1];
switch (inoinfo(ROOTINO)->ino_state) {
case USTATE:
pfatal("ROOT INODE UNALLOCATED");
if (reply("ALLOCATE") == 0) {
ckfini(0);
exit(EEXIT);
}
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
case DCLEAR:
pfatal("DUPS/BAD IN ROOT INODE");
if (reply("REALLOCATE")) {
freeino(ROOTINO);
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
}
if (reply("CONTINUE") == 0) {
ckfini(0);
exit(EEXIT);
}
break;
case FSTATE:
case FCLEAR:
case FZLINK:
pfatal("ROOT INODE NOT DIRECTORY");
if (reply("REALLOCATE")) {
freeino(ROOTINO);
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
}
if (reply("FIX") == 0) {
ckfini(0);
exit(EEXIT);
}
dp = ginode(ROOTINO);
DIP_SET(dp, di_mode, DIP(dp, di_mode) & ~IFMT);
DIP_SET(dp, di_mode, DIP(dp, di_mode) | IFDIR);
inodirty();
break;
case DSTATE:
case DZLINK:
break;
default:
errx(EEXIT, "BAD STATE %d FOR ROOT INODE",
inoinfo(ROOTINO)->ino_state);
}
inoinfo(ROOTINO)->ino_state = DFOUND;
inoinfo(WINO)->ino_state = FSTATE;
inoinfo(WINO)->ino_type = DT_WHT;
/*
* Sort the directory list into disk block order.
*/
qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort);
/*
* Check the integrity of each directory.
*/
memset(&curino, 0, sizeof(struct inodesc));
curino.id_type = DATA;
curino.id_func = pass2check;
inpend = &inpsort[inplast];
for (inpp = inpsort; inpp < inpend; inpp++) {
if (got_siginfo) {
printf("%s: phase 2: dir %td of %d (%d%%)\n", cdevname,
inpp - inpsort, (int)inplast,
(int)((inpp - inpsort) * 100 / inplast));
got_siginfo = 0;
}
if (got_sigalarm) {
setproctitle("%s p2 %d%%", cdevname,
(int)((inpp - inpsort) * 100 / inplast));
got_sigalarm = 0;
}
inp = *inpp;
if (inp->i_isize == 0)
continue;
if (inp->i_isize < MINDIRSIZE) {
direrror(inp->i_number, "DIRECTORY TOO SHORT");
inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ);
if (reply("FIX") == 1) {
dp = ginode(inp->i_number);
DIP_SET(dp, di_size, inp->i_isize);
//.........这里部分代码省略.........
示例4: mSize
NBLog::Writer::Writer(size_t size, void *shared)
: mSize(roundup(size)), mShared((Shared *) shared), mRear(0), mEnabled(mShared != NULL)
{
}
示例5: dt_buf_offset
size_t
dt_buf_offset(const dt_buf_t *bp, size_t align)
{
size_t off = (size_t)(bp->dbu_ptr - bp->dbu_buf);
return (roundup(off, align));
}
示例6: pass2
void
pass2()
{
register struct dinode *dp;
register struct inoinfo **inpp, *inp;
struct inoinfo **inpend;
struct inodesc curino;
struct dinode dino;
char pathbuf[MAXPATHLEN + 1];
switch (statemap[ROOTINO]) {
case USTATE:
pfatal("ROOT INODE UNALLOCATED");
if (reply("ALLOCATE") == 0)
exit(EEXIT);
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
case DCLEAR:
pfatal("DUPS/BAD IN ROOT INODE");
if (reply("REALLOCATE")) {
freeino(ROOTINO);
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
}
if (reply("CONTINUE") == 0)
exit(EEXIT);
break;
case FSTATE:
case FCLEAR:
pfatal("ROOT INODE NOT DIRECTORY");
if (reply("REALLOCATE")) {
freeino(ROOTINO);
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
}
if (reply("FIX") == 0)
exit(EEXIT);
dp = ginode(ROOTINO);
dp->di_mode &= ~IFMT;
dp->di_mode |= IFDIR;
inodirty();
break;
case DSTATE:
break;
default:
errx(EEXIT, "BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]);
}
statemap[ROOTINO] = DFOUND;
if (newinofmt) {
statemap[WINO] = FSTATE;
typemap[WINO] = DT_WHT;
}
/*
* Sort the directory list into disk block order.
*/
qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort);
/*
* Check the integrity of each directory.
*/
memset(&curino, 0, sizeof(struct inodesc));
curino.id_type = DATA;
curino.id_func = pass2check;
dp = &dino;
inpend = &inpsort[inplast];
for (inpp = inpsort; inpp < inpend; inpp++) {
inp = *inpp;
if (inp->i_isize == 0)
continue;
if (inp->i_isize < MINDIRSIZE) {
direrror(inp->i_number, "DIRECTORY TOO SHORT");
inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ);
if (reply("FIX") == 1) {
dp = ginode(inp->i_number);
dp->di_size = inp->i_isize;
inodirty();
dp = &dino;
}
} else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) {
getpathname(pathbuf, inp->i_number, inp->i_number);
pwarn("DIRECTORY %s: LENGTH %d NOT MULTIPLE OF %d",
pathbuf, inp->i_isize, DIRBLKSIZ);
if (preen)
printf(" (ADJUSTED)\n");
inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ);
if (preen || reply("ADJUST") == 1) {
dp = ginode(inp->i_number);
dp->di_size = roundup(inp->i_isize, DIRBLKSIZ);
inodirty();
dp = &dino;
}
}
memset(&dino, 0, sizeof(struct dinode));
//.........这里部分代码省略.........
示例7: zpl_encode_fh
static int
#ifdef HAVE_ENCODE_FH_WITH_INODE
zpl_encode_fh(struct inode *ip, __u32 *fh, int *max_len, struct inode *parent)
{
#else
zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable)
{
struct inode *ip = dentry->d_inode;
#endif /* HAVE_ENCODE_FH_WITH_INODE */
fstrans_cookie_t cookie;
fid_t *fid = (fid_t *)fh;
int len_bytes, rc;
len_bytes = *max_len * sizeof (__u32);
if (len_bytes < offsetof(fid_t, fid_data))
return (255);
fid->fid_len = len_bytes - offsetof(fid_t, fid_data);
cookie = spl_fstrans_mark();
if (zfsctl_is_node(ip))
rc = zfsctl_fid(ip, fid);
else
rc = zfs_fid(ip, fid);
spl_fstrans_unmark(cookie);
len_bytes = offsetof(fid_t, fid_data) + fid->fid_len;
*max_len = roundup(len_bytes, sizeof (__u32)) / sizeof (__u32);
return (rc == 0 ? FILEID_INO32_GEN : 255);
}
static struct dentry *
zpl_dentry_obtain_alias(struct inode *ip)
{
struct dentry *result;
#ifdef HAVE_D_OBTAIN_ALIAS
result = d_obtain_alias(ip);
#else
result = d_alloc_anon(ip);
if (result == NULL) {
iput(ip);
result = ERR_PTR(-ENOMEM);
}
#endif /* HAVE_D_OBTAIN_ALIAS */
return (result);
}
static struct dentry *
zpl_fh_to_dentry(struct super_block *sb, struct fid *fh,
int fh_len, int fh_type)
{
fid_t *fid = (fid_t *)fh;
fstrans_cookie_t cookie;
struct inode *ip;
int len_bytes, rc;
len_bytes = fh_len * sizeof (__u32);
if (fh_type != FILEID_INO32_GEN ||
len_bytes < offsetof(fid_t, fid_data) ||
len_bytes < offsetof(fid_t, fid_data) + fid->fid_len)
return (ERR_PTR(-EINVAL));
cookie = spl_fstrans_mark();
rc = zfs_vget(sb, &ip, fid);
spl_fstrans_unmark(cookie);
if (rc) {
/*
* If we see ENOENT it might mean that an NFSv4 * client
* is using a cached inode value in a file handle and
* that the sought after file has had its inode changed
* by a third party. So change the error to ESTALE
* which will trigger a full lookup by the client and
* will find the new filename/inode pair if it still
* exists.
*/
if (rc == ENOENT)
rc = ESTALE;
return (ERR_PTR(-rc));
}
ASSERT((ip != NULL) && !IS_ERR(ip));
return (zpl_dentry_obtain_alias(ip));
}
示例8: pch_gbe_check_options
/**
* pch_gbe_check_options - Range Checking for Command Line Parameters
* @adapter: Board private structure
*/
void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
{
struct pch_gbe_hw *hw = &adapter->hw;
struct net_device *dev = adapter->netdev;
int val;
{ /* Transmit Descriptor Count */
static const struct pch_gbe_option opt = {
.type = range_option,
.name = "Transmit Descriptors",
.err = "using default of "
__MODULE_STRING(PCH_GBE_DEFAULT_TXD),
.def = PCH_GBE_DEFAULT_TXD,
.arg = { .r = { .min = PCH_GBE_MIN_TXD,
.max = PCH_GBE_MAX_TXD } }
};
struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
tx_ring->count = TxDescriptors;
pch_gbe_validate_option(&tx_ring->count, &opt, adapter);
tx_ring->count = roundup(tx_ring->count,
PCH_GBE_TX_DESC_MULTIPLE);
}
{ /* Receive Descriptor Count */
static const struct pch_gbe_option opt = {
.type = range_option,
.name = "Receive Descriptors",
.err = "using default of "
__MODULE_STRING(PCH_GBE_DEFAULT_RXD),
.def = PCH_GBE_DEFAULT_RXD,
.arg = { .r = { .min = PCH_GBE_MIN_RXD,
.max = PCH_GBE_MAX_RXD } }
};
struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
rx_ring->count = RxDescriptors;
pch_gbe_validate_option(&rx_ring->count, &opt, adapter);
rx_ring->count = roundup(rx_ring->count,
PCH_GBE_RX_DESC_MULTIPLE);
}
{ /* Checksum Offload Enable/Disable */
static const struct pch_gbe_option opt = {
.type = enable_option,
.name = "Checksum Offload",
.err = "defaulting to Enabled",
.def = PCH_GBE_DEFAULT_RX_CSUM
};
val = XsumRX;
pch_gbe_validate_option(&val, &opt, adapter);
if (!val)
dev->features &= ~NETIF_F_RXCSUM;
}
{ /* Checksum Offload Enable/Disable */
static const struct pch_gbe_option opt = {
.type = enable_option,
.name = "Checksum Offload",
.err = "defaulting to Enabled",
.def = PCH_GBE_DEFAULT_TX_CSUM
};
val = XsumTX;
pch_gbe_validate_option(&val, &opt, adapter);
if (!val)
dev->features &= ~NETIF_F_ALL_CSUM;
}
{ /* Flow Control */
static const struct pch_gbe_option opt = {
.type = list_option,
.name = "Flow Control",
.err = "reading default settings from EEPROM",
.def = PCH_GBE_FC_DEFAULT,
.arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
.p = fc_list } }
};
hw->mac.fc = FlowControl;
pch_gbe_validate_option((int *)(&hw->mac.fc),
&opt, adapter);
}
pch_gbe_check_copper_options(adapter);
}
示例9: main
//.........这里部分代码省略.........
else
msg("Date of last level %d dump: %s", lastlevel, tmsg);
msg("Dumping %s%s ", snapdump ? "snapshot of ": "", disk);
if (dt != NULL)
msgtail("(%s) ", dt->fs_file);
if (host)
msgtail("to %s on host %s\n", tape, host);
else
msgtail("to %s\n", tape);
sync();
sblock = (struct fs *)sblock_buf;
for (i = 0; sblock_try[i] != -1; i++) {
sblock->fs_fsize = SBLOCKSIZE; /* needed in bread */
bread(sblock_try[i] >> dev_bshift, (char *) sblock, SBLOCKSIZE);
if ((sblock->fs_magic == FS_UFS1_MAGIC ||
(sblock->fs_magic == FS_UFS2_MAGIC &&
sblock->fs_sblockloc == sblock_try[i])) &&
sblock->fs_bsize <= MAXBSIZE &&
sblock->fs_bsize >= sizeof(struct fs))
break;
}
if (sblock_try[i] == -1)
quit("Cannot find file system superblock\n");
dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1);
dev_bshift = ffs(dev_bsize) - 1;
if (dev_bsize != (1 << dev_bshift))
quit("dev_bsize (%ld) is not a power of 2", dev_bsize);
tp_bshift = ffs(TP_BSIZE) - 1;
if (TP_BSIZE != (1 << tp_bshift))
quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE);
maxino = sblock->fs_ipg * sblock->fs_ncg;
mapsize = roundup(howmany(maxino, CHAR_BIT), TP_BSIZE);
usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char));
dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
tapesize = 3 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
nonodump = spcl.c_level < honorlevel;
passno = 1;
setproctitle("%s: pass 1: regular files", disk);
msg("mapping (Pass I) [regular files]\n");
anydirskipped = mapfiles(maxino, &tapesize);
passno = 2;
setproctitle("%s: pass 2: directories", disk);
msg("mapping (Pass II) [directories]\n");
while (anydirskipped) {
anydirskipped = mapdirs(maxino, &tapesize);
}
if (pipeout || unlimited) {
tapesize += 10; /* 10 trailer blocks */
msg("estimated %ld tape blocks.\n", tapesize);
} else {
double fetapes;
if (blocksperfile)
fetapes = (double) tapesize / blocksperfile;
else if (cartridge) {
/* Estimate number of tapes, assuming streaming stops at
the end of each block written, and not in mid-block.
Assume no erroneous blocks; this can be compensated
for with an artificially low tape size. */
示例10: _dl_try_allocate_static_tls
/* We are trying to perform a static TLS relocation in MAP, but it was
dynamically loaded. This can only work if there is enough surplus in
the static TLS area already allocated for each running thread. If this
object's TLS segment is too big to fit, we fail. If it fits,
we set MAP->l_tls_offset and return.
This function intentionally does not return any value but signals error
directly, as static TLS should be rare and code handling it should
not be inlined as much as possible. */
int
internal_function
_dl_try_allocate_static_tls (struct link_map *map)
{
/* If we've already used the variable with dynamic access, or if the
alignment requirements are too high, fail. */
if (map->l_tls_offset == FORCED_DYNAMIC_TLS_OFFSET
|| map->l_tls_align > GL(dl_tls_static_align))
{
fail:
return -1;
}
#if TLS_TCB_AT_TP
size_t freebytes;
size_t n;
size_t blsize;
freebytes = GL(dl_tls_static_size) - GL(dl_tls_static_used);
if (freebytes < TLS_TCB_SIZE)
goto fail;
freebytes -= TLS_TCB_SIZE;
blsize = map->l_tls_blocksize + map->l_tls_firstbyte_offset;
if (freebytes < blsize)
goto fail;
n = (freebytes - blsize) / map->l_tls_align;
size_t offset = GL(dl_tls_static_used) + (freebytes - n * map->l_tls_align
- map->l_tls_firstbyte_offset);
map->l_tls_offset = GL(dl_tls_static_used) = offset;
#elif TLS_DTV_AT_TP
size_t used;
size_t check;
size_t offset = roundup (GL(dl_tls_static_used), map->l_tls_align);
used = offset + map->l_tls_blocksize;
check = used;
/* dl_tls_static_used includes the TCB at the beginning. */
if (check > GL(dl_tls_static_size))
goto fail;
map->l_tls_offset = offset;
GL(dl_tls_static_used) = used;
#else
# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
#endif
/* If the object is not yet relocated we cannot initialize the
static TLS region. Delay it. */
if (map->l_real->l_relocated)
{
#ifdef SHARED
if (__builtin_expect (THREAD_DTV()[0].counter != GL(dl_tls_generation),
0))
/* Update the slot information data for at least the generation of
the DSO we are allocating data for. */
(void) _dl_update_slotinfo (map->l_tls_modid);
#endif
GL(dl_init_static_tls) (map);
}
else
map->l_need_tls_init = 1;
return 0;
}
示例11: md_load
/*
* Load the information expected by a sparc64 kernel.
*
* - The 'boothowto' argument is constructed
* - The 'bootdev' argument is constructed
* - The kernel environment is copied into kernel space.
* - Module metadata are formatted and placed in kernel space.
*/
int
md_load(char *args, vm_offset_t *modulep)
{
struct preloaded_file *kfp;
struct preloaded_file *xp;
struct file_metadata *md;
vm_offset_t kernend;
vm_offset_t addr;
vm_offset_t envp;
vm_offset_t size;
char *rootdevname;
int howto;
howto = md_getboothowto(args);
/*
* Allow the environment variable 'rootdev' to override the supplied device
* This should perhaps go to MI code and/or have $rootdev tested/set by
* MI code before launching the kernel.
*/
if ((rootdevname = getenv("rootdev")) == NULL)
rootdevname = getenv("currdev");
getrootmount(rootdevname);
/* find the last module in the chain */
addr = 0;
for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
if (addr < (xp->f_addr + xp->f_size))
addr = xp->f_addr + xp->f_size;
}
/* pad to a page boundary */
addr = roundup(addr, PAGE_SIZE);
/* copy our environment */
envp = addr;
addr = md_copyenv(addr);
/* pad to a page boundary */
addr = roundup(addr, PAGE_SIZE);
kernend = 0;
kfp = file_findfile(NULL, "elf64 kernel");
if (kfp == NULL)
kfp = file_findfile(NULL, "elf kernel");
if (kfp == NULL)
panic("can't find kernel file");
file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto);
file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
file_addmetadata(kfp, MODINFOMD_DTLB_SLOTS, sizeof dtlb_slot, &dtlb_slot);
file_addmetadata(kfp, MODINFOMD_ITLB_SLOTS, sizeof itlb_slot, &itlb_slot);
file_addmetadata(kfp, MODINFOMD_DTLB,
dtlb_slot * sizeof(*dtlb_store), dtlb_store);
file_addmetadata(kfp, MODINFOMD_ITLB,
itlb_slot * sizeof(*itlb_store), itlb_store);
*modulep = addr;
size = md_copymodules(0);
kernend = roundup(addr + size, PAGE_SIZE);
md = file_findmetadata(kfp, MODINFOMD_KERNEND);
bcopy(&kernend, md->md_data, sizeof kernend);
(void)md_copymodules(addr);
return(0);
}
示例12: add_host
static int
add_host(int pref, const char *host, int port, struct mx_hostentry **he, size_t *ps)
{
struct addrinfo hints, *res, *res0 = NULL;
char servname[10];
struct mx_hostentry *p;
const int count_inc = 10;
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
snprintf(servname, sizeof(servname), "%d", port);
switch (getaddrinfo(host, servname, &hints, &res0)) {
case 0:
break;
case EAI_AGAIN:
case EAI_NONAME:
/*
* EAI_NONAME gets returned for:
* SMARTHOST set but DNS server not reachable -> defer
* SMARTHOST set but DNS server returns "host does not exist"
* -> buggy configuration
* -> either defer or bounce would be ok -> defer
* MX entry was returned by DNS server but name doesn't resolve
* -> hopefully transient situation -> defer
* all other DNS problems should have been caught earlier
* in dns_get_mx_list().
*/
goto out;
default:
return(-1);
}
for (res = res0; res != NULL; res = res->ai_next) {
if (*ps + 1 >= roundup(*ps, count_inc)) {
size_t newsz = roundup(*ps + 2, count_inc);
*he = reallocf(*he, newsz * sizeof(**he));
if (*he == NULL)
goto out;
}
p = &(*he)[*ps];
strlcpy(p->host, host, sizeof(p->host));
p->pref = pref;
p->ai = *res;
p->ai.ai_addr = NULL;
bcopy(res->ai_addr, &p->sa, p->ai.ai_addrlen);
getnameinfo((struct sockaddr *)&p->sa, p->ai.ai_addrlen,
p->addr, sizeof(p->addr),
NULL, 0, NI_NUMERICHOST);
(*ps)++;
}
freeaddrinfo(res0);
return (0);
out:
if (res0 != NULL)
freeaddrinfo(res0);
return (1);
}
示例13: elfreadsyms
static int
elfreadsyms (int fd, Elf32_Ehdr *eh, Elf32_Shdr *shtab, int flags)
{
Elf32_Shdr *sh, *strh, *shstrh, *ksh;
Elf32_Sym *symtab;
Elf32_Ehdr *keh;
char *shstrtab, *strtab, *symend;
int nsym, offs, size, i;
int *symptr;
/* Fix up twirl */
if (bootseg++ > 0) {
fprintf (stderr, "\b + ");
}
/*
* If we are loading symbols to support kernel DDB symbol handling
* make room for an ELF header at _end and after that a section
* header. DDB then finds the symbols using the data put here.
*/
if(flags & KFLAG) {
tablebase = roundup(tablebase, sizeof(long));
symptr = (int *)tablebase;
tablebase += sizeof(int *) * 2;
keh = (Elf32_Ehdr *)tablebase;
tablebase += sizeof(Elf32_Ehdr);
tablebase = roundup(tablebase, sizeof(long));
ksh = (Elf32_Shdr *)tablebase;
tablebase += roundup((sizeof(Elf32_Shdr) * eh->e_shnum), sizeof(long));
memcpy(ksh, shtab, roundup((sizeof(Elf32_Shdr) * eh->e_shnum), sizeof(long)));
sh = ksh;
}
else {
sh = shtab;
}
shstrh = &sh[eh->e_shstrndx];
for (i = 0; i < eh->e_shnum; sh++, i++) {
if (sh->sh_type == SHT_SYMTAB) {
break;
}
}
if (i >= eh->e_shnum) {
return (0);
}
if(flags & KFLAG) {
strh = &ksh[sh->sh_link];
nsym = sh->sh_size / sh->sh_entsize;
offs = sh->sh_offset;
size = sh->sh_size;
fprintf (stderr, "%d syms ", nsym);
} else {
strh = &shtab[sh->sh_link];
nsym = (sh->sh_size / sh->sh_entsize) - sh->sh_info;
offs = sh->sh_offset + (sh->sh_info * sh->sh_entsize);
size = nsym * sh->sh_entsize;
fprintf (stderr, "%d syms ", nsym);
}
/*
* Allocate tables in correct order so the kernel grooks it.
* Then we read them in the order they are in the ELF file.
*/
shstrtab = gettable(shstrh->sh_size, "shstrtab", flags);
strtab = gettable(strh->sh_size, "strtab", flags);
symtab = gettable(size, "symtab", flags);
symend = (char *)symtab + size;
do {
if(shstrh->sh_offset < offs && shstrh->sh_offset < strh->sh_offset) {
#if 0
/*
* We would like to read the shstrtab from the file but since this
* table is located in front of the shtab it is already gone. We can't
* position backwards outside the current segment when using tftp.
* Instead we create the names we need in the string table because
* it can be reconstructed from the info we now have access to.
*/
if (!readtable (shstrh->sh_offset, (void *)shstrtab,
shstrh->sh_size, "shstring", flags)) {
return(0);
}
#else
memset(shstrtab, 0, shstrh->sh_size);
strcpy(shstrtab + shstrh->sh_name, ".shstrtab");
strcpy(shstrtab + strh->sh_name, ".strtab");
strcpy(shstrtab + sh->sh_name, ".symtab");
#endif
shstrh->sh_offset = 0x7fffffff;
}
if (offs < strh->sh_offset && offs < shstrh->sh_offset) {
if (!(readtable(fd, offs, (void *)symtab, size, "sym", flags))) {
return (0);
}
offs = 0x7fffffff;
//.........这里部分代码省略.........
示例14: dtrace_dof_create
//.........这里部分代码省略.........
/*
* Now finally, add the DOF_SECT_ECBDESC referencing all the
* previously created sub-sections.
*/
dofe.dofe_probes = probesec;
dofe.dofe_pred = prdsec;
dofe.dofe_actions = actsec;
dofe.dofe_pad = 0;
dofe.dofe_uarg = edp->dted_uarg;
(void) dof_add_lsect(ddo, &dofe, DOF_SECT_ECBDESC,
sizeof (uint64_t), 0, 0, sizeof (dof_ecbdesc_t));
}
/*
* If any providers are user-defined, output DOF sections corresponding
* to the providers and the probes and arguments that they define.
*/
if (flags & DTRACE_D_PROBES) {
for (pvp = dt_list_next(&dtp->dt_provlist);
pvp != NULL; pvp = dt_list_next(pvp))
dof_add_provider(ddo, pvp);
}
/*
* If we're not stripping unloadable sections, generate compiler
* comments and any other unloadable miscellany.
*/
if (!(flags & DTRACE_D_STRIP)) {
(void) dof_add_usect(ddo, _dtrace_version, DOF_SECT_COMMENTS,
sizeof (char), 0, 0, strlen(_dtrace_version) + 1);
(void) dof_add_usect(ddo, &dtp->dt_uts, DOF_SECT_UTSNAME,
sizeof (char), 0, 0, sizeof (struct utsname));
}
/*
* Compute and fill in the appropriate values for the dof_hdr_t's
* dofh_secnum, dofh_loadsz, and dofh_filez values.
*/
h.dofh_secnum = ddo->ddo_nsecs;
ssize = sizeof (h) + dt_buf_len(&ddo->ddo_secs);
h.dofh_loadsz = ssize +
dt_buf_len(&ddo->ddo_ldata) +
dt_buf_len(&ddo->ddo_strs);
if (dt_buf_len(&ddo->ddo_udata) != 0) {
lsize = roundup(h.dofh_loadsz, sizeof (uint64_t));
h.dofh_filesz = lsize + dt_buf_len(&ddo->ddo_udata);
} else {
lsize = h.dofh_loadsz;
h.dofh_filesz = lsize;
}
/*
* Set the global DOF_SECT_STRTAB's offset to be after the header,
* section headers, and other loadable data. Since we're going to
* iterate over the buffer data directly, we must check for errors.
*/
if ((i = dt_buf_error(&ddo->ddo_secs)) != 0) {
(void) dt_set_errno(dtp, i);
return (NULL);
}
sp = dt_buf_ptr(&ddo->ddo_secs);
assert(sp[ddo->ddo_strsec].dofs_type == DOF_SECT_STRTAB);
assert(ssize == sizeof (h) + sizeof (dof_sec_t) * ddo->ddo_nsecs);
sp[ddo->ddo_strsec].dofs_offset = ssize + dt_buf_len(&ddo->ddo_ldata);
sp[ddo->ddo_strsec].dofs_size = dt_buf_len(&ddo->ddo_strs);
/*
* Now relocate all the other section headers by adding the appropriate
* delta to their respective dofs_offset values.
*/
for (i = 0; i < ddo->ddo_nsecs; i++, sp++) {
if (i == ddo->ddo_strsec)
continue; /* already relocated above */
if (sp->dofs_flags & DOF_SECF_LOAD)
sp->dofs_offset += ssize;
else
sp->dofs_offset += lsize;
}
/*
* Finally, assemble the complete in-memory DOF buffer by writing the
* header and then concatenating all our buffers. dt_buf_concat() will
* propagate any errors and cause dt_buf_claim() to return NULL.
*/
dt_buf_create(dtp, &dof, "dof", h.dofh_filesz);
dt_buf_write(dtp, &dof, &h, sizeof (h), sizeof (uint64_t));
dt_buf_concat(dtp, &dof, &ddo->ddo_secs, sizeof (uint64_t));
dt_buf_concat(dtp, &dof, &ddo->ddo_ldata, sizeof (uint64_t));
dt_buf_concat(dtp, &dof, &ddo->ddo_strs, sizeof (char));
dt_buf_concat(dtp, &dof, &ddo->ddo_udata, sizeof (uint64_t));
return (dt_buf_claim(dtp, &dof));
}
示例15: load_elf
//.........这里部分代码省略.........
}
}else
#endif /* NGZIP */
if (lseek (fd, ep->e_phoff, SEEK_SET) != ep->e_phoff ||
read (fd, (void *)phtab, nbytes) != nbytes) {
perror ("program header");
free (phtab);
return (-2);
}
/*
* From now on we've got no guarantee about the file order,
* even where the section header is. Hopefully most linkers
* will put the section header after the program header, when
* they know that the executable is not demand paged. We assume
* that the symbol and string tables always follow the program
* segments.
*/
/* read section table (if before first program segment) */
if (!(flags & NFLAG) && ep->e_shoff < phtab[0].p_offset)
shtab = elfgetshdr (fd, ep);
/* load program segments */
if (!(flags & YFLAG)) {
/* We cope with a badly sorted program header, as produced by
* older versions of the GNU linker, by loading the segments
* in file offset order, not in program header order. */
while (1) {
Elf32_Off lowest_offset = ~0;
Elf32_Phdr *ph = 0;
/* find nearest loadable segment */
for (i = 0; i < ep->e_phnum; i++)
if (phtab[i].p_type == PT_LOAD && phtab[i].p_offset < lowest_offset) {
ph = &phtab[i];
lowest_offset = ph->p_offset;
}
if (!ph)
break; /* none found, finished */
/* load the segment */
if (ph->p_filesz) {
#if NGZIP > 0
if(myflags&ZFLAG){
if (gz_lseek (fd, ph->p_offset, SEEK_SET) != ph->p_offset) {
fprintf (stderr, "seek failed (corrupt object file?)\n");
if (shtab)
free (shtab);
free (phtab);
gz_close(fd);
return (-2);
}
}else
#endif /* NGZIP */
if (lseek (fd, ph->p_offset, SEEK_SET) != ph->p_offset) {
fprintf (stderr, "seek failed (corrupt object file?)\n");
if (shtab)
free (shtab);
free (phtab);
return (-2);
}
if (bootread (fd, (void *)ph->p_vaddr, ph->p_filesz) != ph->p_filesz) {
if (shtab) free (shtab);
free (phtab);
#if NGZIP > 0
if(myflags&ZFLAG) gz_close(fd);
#endif /* NGZIP */
return (-2);
}
}
if((ph->p_vaddr + ph->p_memsz) > highest_load) {
highest_load = ph->p_vaddr + ph->p_memsz;
}
if (ph->p_filesz < ph->p_memsz)
bootclear (fd, (void *)ph->p_vaddr + ph->p_filesz, ph->p_memsz - ph->p_filesz);
ph->p_type = PT_NULL; /* remove from consideration */
}
}
if (flags & KFLAG) {
highest_load = roundup(highest_load, sizeof(long));
tablebase = highest_load;
}
if (!(flags & NFLAG)) {
/* read section table (if after last program segment) */
if (!shtab)
shtab = elfgetshdr (fd, ep);
if (shtab) {
elfreadsyms (fd, ep, shtab, flags);
free (shtab);
}
}
free (phtab);
#if NGZIP > 0
if(myflags&ZFLAG) gz_close(fd);
#endif /* NGZIP */
return (ep->e_entry + dl_offset);
}