int uutil_list_node_walk_init(mdb_walk_state_t *wsp) { uutil_list_node_walk_t *ulnw; uu_list_t ul; uu_list_pool_t ulp; if (mdb_vread(&ul, sizeof (uu_list_t), wsp->walk_addr) == -1) { mdb_warn("failed to read uu_list_t at given address\n"); return (WALK_ERR); } if (mdb_vread(&ulp, sizeof (uu_list_pool_t), (uintptr_t)ul.ul_pool) == -1) { mdb_warn("failed to read supporting uu_list_pool_t\n"); return (WALK_ERR); } ulnw = mdb_alloc(sizeof (uutil_list_node_walk_t), UM_SLEEP); ulnw->ulnw_offset = ul.ul_offset; ulnw->ulnw_final = wsp->walk_addr + offsetof(uu_list_t, ul_null_node); ulnw->ulnw_current = (uintptr_t)ul.ul_null_node.uln_next; ulnw->ulnw_buf = mdb_alloc(ulp.ulp_objsize, UM_SLEEP); ulnw->ulnw_bufsz = ulp.ulp_objsize; wsp->walk_data = ulnw; return (WALK_NEXT); }
int rctl_dict_walk_init(mdb_walk_state_t *wsp) { uintptr_t ptr; int nlists; GElf_Sym sym; rctl_dict_entry_t **dicts; dict_walk_data_t *dwd; if (mdb_lookup_by_name("rctl_lists", &sym) == -1) { mdb_warn("failed to find 'rctl_lists'\n"); return (WALK_ERR); } nlists = sym.st_size / sizeof (rctl_dict_entry_t *); ptr = (uintptr_t)sym.st_value; dicts = mdb_alloc(nlists * sizeof (rctl_dict_entry_t *), UM_SLEEP); mdb_vread(dicts, sym.st_size, ptr); dwd = mdb_alloc(sizeof (dict_walk_data_t), UM_SLEEP); dwd->num_dicts = nlists; dwd->num_cur = 0; dwd->curdict = dicts; wsp->walk_addr = 0; wsp->walk_data = dwd; return (WALK_NEXT); }
static int sctp_sock_print(struct sonode *socknode) { sctp_t sctp_t; conn_t conns; struct sockaddr *laddr = mdb_alloc(sizeof (struct sockaddr), UM_SLEEP); struct sockaddr *faddr = mdb_alloc(sizeof (struct sockaddr), UM_SLEEP); if (mdb_vread(&sctp_t, sizeof (sctp_t), (uintptr_t)socknode->so_proto_handle) == -1) { mdb_warn("failed to read sctp_t"); return (-1); } if (mdb_vread(&conns, sizeof (conn_t), (uintptr_t)sctp_t.sctp_connp) == -1) { mdb_warn("failed to read conn_t at %p", (uintptr_t)sctp_t.sctp_connp); return (-1); } sctp_t.sctp_connp = &conns; if (sctp_getsockaddr(&sctp_t, laddr) == 0) { mdb_printf("socket:"); pfiles_print_addr(laddr); } if (sctp_getpeeraddr(&sctp_t, faddr) == 0) { mdb_printf("remote:"); pfiles_print_addr(faddr); } return (0); }
mdb_demangler_t * mdb_dem_load(const char *path) { mdb_demangler_t *dmp; void *hdl, *func; if (access(path, F_OK) == -1) return (NULL); if ((hdl = dlmopen(LM_ID_BASE, path, RTLD_LAZY | RTLD_LOCAL)) == NULL) { (void) set_errno(EMDB_RTLD); return (NULL); } if ((func = dlsym(hdl, "cplus_demangle")) == NULL) { (void) dlclose(hdl); (void) set_errno(EMDB_NODEM); return (NULL); } dmp = mdb_alloc(sizeof (mdb_demangler_t), UM_SLEEP); (void) strncpy(dmp->dm_pathname, path, MAXPATHLEN); dmp->dm_pathname[MAXPATHLEN - 1] = '\0'; dmp->dm_handle = hdl; dmp->dm_convert = (int (*)())func; dmp->dm_len = MDB_SYM_NAMLEN * 2; dmp->dm_buf = mdb_alloc(dmp->dm_len, UM_SLEEP); dmp->dm_flags = MDB_DM_SCOPE; return (dmp); }
void mdb_cmdbuf_create(mdb_cmdbuf_t *cmd) { size_t i; cmd->cmd_halloc = MDB_DEF_HISTLEN < mdb.m_histlen ? MDB_DEF_HISTLEN : mdb.m_histlen; cmd->cmd_history = mdb_alloc(cmd->cmd_halloc * sizeof (char *), UM_SLEEP); cmd->cmd_linebuf = mdb_alloc(CMDBUF_LINELEN, UM_SLEEP); for (i = 0; i < cmd->cmd_halloc; i++) cmd->cmd_history[i] = mdb_alloc(CMDBUF_LINELEN, UM_SLEEP); cmd->cmd_buf = cmd->cmd_history[0]; cmd->cmd_linelen = CMDBUF_LINELEN; cmd->cmd_histlen = mdb.m_histlen; cmd->cmd_buflen = 0; cmd->cmd_bufidx = 0; cmd->cmd_hold = 0; cmd->cmd_hnew = 0; cmd->cmd_hcur = 0; cmd->cmd_hlen = 0; }
static int tpi_sock_print(sotpi_sonode_t *sotpi_sonode) { if (sotpi_sonode->st_info.sti_laddr_valid == 1) { struct sockaddr *laddr = mdb_alloc(sotpi_sonode->st_info.sti_laddr_len, UM_SLEEP); if (mdb_vread(laddr, sotpi_sonode->st_info.sti_laddr_len, (uintptr_t)sotpi_sonode->st_info.sti_laddr_sa) == -1) { mdb_warn("failed to read sotpi_sonode socket addr"); return (-1); } mdb_printf("socket: "); pfiles_print_addr(laddr); } if (sotpi_sonode->st_info.sti_faddr_valid == 1) { struct sockaddr *faddr = mdb_alloc(sotpi_sonode->st_info.sti_faddr_len, UM_SLEEP); if (mdb_vread(faddr, sotpi_sonode->st_info.sti_faddr_len, (uintptr_t)sotpi_sonode->st_info.sti_faddr_sa) == -1) { mdb_warn("failed to read sotpi_sonode remote addr"); return (-1); } mdb_printf("remote: "); pfiles_print_addr(faddr); } return (0); }
/*ARGSUSED*/ static int action_format( uintptr_t addr, const void *data, void *arg) { afdata_t *afp = (afdata_t *)arg; ipp_action_t *ap; int rc; ap = mdb_alloc(sizeof (ipp_action_t), UM_SLEEP); if (mdb_vread(ap, sizeof (ipp_action_t), addr) == -1) { mdb_warn("failed to read ipp_action_t at %p", addr); rc = WALK_ERR; goto done; } if (afp->af_flags & AF_VERBOSE) rc = action_dump(addr, ap, afp->af_banner); else rc = action_summary(addr, ap, afp->af_banner); afp->af_banner = B_FALSE; done: mdb_free(ap, sizeof (ipp_action_t)); return (rc); }
int uutil_listpool_walk_init(mdb_walk_state_t *wsp) { uu_list_pool_t null_lpool; uutil_listpool_walk_t *ulpw; GElf_Sym sym; bzero(&null_lpool, sizeof (uu_list_pool_t)); if (mdb_lookup_by_obj("libuutil.so.1", "uu_null_lpool", &sym) == -1) { mdb_warn("failed to find 'uu_null_lpool'\n"); return (WALK_ERR); } if (mdb_vread(&null_lpool, sym.st_size, (uintptr_t)sym.st_value) == -1) { mdb_warn("failed to read data from 'uu_null_lpool' address\n"); return (WALK_ERR); } ulpw = mdb_alloc(sizeof (uutil_listpool_walk_t), UM_SLEEP); ulpw->ulpw_final = (uintptr_t)null_lpool.ulp_prev; ulpw->ulpw_current = (uintptr_t)null_lpool.ulp_next; wsp->walk_data = ulpw; return (WALK_NEXT); }
int swapinfof(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { struct swapinfo si; char *name; if (!(flags & DCMD_ADDRSPEC)) { if (mdb_walk_dcmd("swapinfo", "swapinfo", argc, argv) == -1) { mdb_warn("can't walk swapinfo"); return (DCMD_ERR); } return (DCMD_OK); } if (DCMD_HDRSPEC(flags)) { mdb_printf("%<u>%?s %?s %9s %9s %s%</u>\n", "ADDR", "VNODE", "PAGES", "FREE", "NAME"); } if (mdb_vread(&si, sizeof (struct swapinfo), addr) == -1) { mdb_warn("can't read swapinfo at %#lx", addr); return (DCMD_ERR); } name = mdb_alloc(si.si_pnamelen, UM_SLEEP | UM_GC); if (mdb_vread(name, si.si_pnamelen, (uintptr_t)si.si_pname) == -1) name = "*error*"; mdb_printf("%0?lx %?p %9d %9d %s\n", addr, si.si_vp, si.si_npgs, si.si_nfpgs, name); return (DCMD_OK); }
/* ARGSUSED */ static int pdesc_slab_print(uintptr_t addr, q_walk_t *qwp, mmd_data_t *data) { pdesc_slab_t *slab; uint_t pdslab_sz, slab_sz; /* Figure out how many descriptors in a slab */ mdb_readvar(&pdslab_sz, "pdslab_sz"); /* This shouldn't be true, unless something awful has happened */ if (pdslab_sz < 1) { mdb_warn("incorrect pdslab_sz (0)"); pdslab_sz = 1; } /* Read in the entire slab chunk; may be of use one day */ slab_sz = PDESC_SLAB_SIZE(pdslab_sz); slab = mdb_alloc(slab_sz, UM_SLEEP); if (mdb_vread(slab, slab_sz, addr) == -1) { mdb_free(slab, slab_sz); mdb_warn("failed to read pdesc_slab_t at %p", addr); return (WALK_ERR); } if (!qwp->qw_step) mdb_printf("\n%<b>%<u>%-?s %7s %7s%</u>%</b>\n", "PDESC SLAB ADDR", "SIZE", "CLAIMED"); mdb_printf("%016p %7d %7d\n", addr, slab->pds_sz, slab->pds_used); mdb_free(slab, slab_sz); return (WALK_NEXT); }
static int ptms_walk_init(mdb_walk_state_t *wsp) { size_t nslots; if (wsp->walk_addr != NULL) { mdb_warn("ptms supports only global walks"); return (WALK_ERR); } if (mdb_readvar(&wsp->walk_addr, "ptms_slots") == -1) { mdb_warn("failed to read 'ptms_slots'"); return (WALK_ERR); } if (mdb_readvar(&nslots, "ptms_nslots") == -1) { mdb_warn("failed to read 'ptms_nslots'"); return (WALK_ERR); } /* * We remember the pointer value at the end of the array. When * the walk gets there, we're done. */ wsp->walk_arg = (((struct pt_ttys **)wsp->walk_addr) + (nslots - 1)); wsp->walk_data = mdb_alloc(sizeof (struct pt_ttys), UM_SLEEP); return (WALK_NEXT); }
static void dump_log( uintptr_t ptr, uint_t nelt) { ipp_log_t *array; ipp_log_t *lp; uint_t i; boolean_t first_time = B_TRUE; char buf[MAXNAMELEN]; array = mdb_alloc(sizeof (ipp_log_t) * nelt, UM_SLEEP); if (mdb_vread(array, sizeof (ipp_log_t) * nelt, ptr) == -1) { mdb_warn("failed to read ipp_log_t array at %p", ptr); return; } for (i = 0; i < nelt; i++) { if (first_time) { mdb_printf("%20s %?s %<u>%15s %15s%</u>\n", "", "log", "CLASS NAME", "ACTION"); first_time = B_FALSE; } lp = &(array[i]); aid2aname(lp->ippl_aid, buf); mdb_printf("%20s %?p: %15s %15s\n", "", ptr + (i * sizeof (ipp_class_t)), lp->ippl_name, buf); } mdb_free(lp, sizeof (ipp_log_t) * nelt); }
/*ARGSUSED*/ static int packet( uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { ipp_packet_t *pp; if ((flags & DCMD_ADDRSPEC) == 0) return (DCMD_ERR); pp = mdb_alloc(sizeof (ipp_packet_t), UM_SLEEP); if (mdb_vread(pp, sizeof (ipp_packet_t), addr) == -1) { mdb_warn("failed to read ipp_packet_t at %p", addr); mdb_free(pp, sizeof (ipp_packet_t)); return (DCMD_ERR); } mdb_printf("%?p: %20s = 0x%p\n", addr, "data", pp->ippp_data); mdb_printf("%?s %20s = 0x%p\n", "", "private", pp->ippp_private); dump_classes((uintptr_t)pp->ippp_class_array, pp->ippp_class_windex); dump_log((uintptr_t)pp->ippp_log, pp->ippp_log_windex); mdb_free(pp, sizeof (ipp_packet_t)); return (DCMD_OK); }
static int ref_walk_step( mdb_walk_state_t *wsp) { ipp_ref_t *rp; int status; if (wsp->walk_addr == NULL) return (WALK_DONE); rp = mdb_alloc(sizeof (ipp_ref_t), UM_SLEEP); if (mdb_vread(rp, sizeof (ipp_ref_t), wsp->walk_addr) == -1) { mdb_warn("failed to read ipp_ref_t at %p", wsp->walk_addr); mdb_free(rp, sizeof (ipp_ref_t)); return (WALK_ERR); } status = wsp->walk_callback((uintptr_t)rp->ippr_ptr, NULL, wsp->walk_cbdata); wsp->walk_addr = (uintptr_t)(rp->ippr_nextp); mdb_free(rp, sizeof (ipp_ref_t)); return (status); }
/*ARGSUSED*/ static int mod_format( uintptr_t addr, const void *data, void *arg) { mfdata_t *mfp = (mfdata_t *)arg; ipp_mod_t *imp; int rc; imp = mdb_alloc(sizeof (ipp_mod_t), UM_SLEEP); if (mdb_vread(imp, sizeof (ipp_mod_t), addr) == -1) { mdb_warn("failed to read ipp_mod_t at %p", addr); rc = WALK_ERR; goto done; } if (mfp->mf_flags & MF_VERBOSE) rc = mod_dump(addr, imp, mfp->mf_banner); else rc = mod_summary(addr, imp, mfp->mf_banner); mfp->mf_banner = B_FALSE; done: mdb_free(imp, sizeof (ipp_mod_t)); return (rc); }
/*ARGSUSED*/ static int cfglock( uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { cfglock_t *clp; if ((flags & DCMD_ADDRSPEC) == 0) return (DCMD_ERR); clp = mdb_alloc(sizeof (cfglock_t), UM_SLEEP); if (mdb_vread(clp, sizeof (cfglock_t), addr) == -1) { mdb_warn("failed to read cfglock_t at %p", addr); mdb_free(clp, sizeof (cfglock_t)); return (WALK_ERR); } mdb_printf("%?p: %20s = %p\n", addr, "owner", clp->cl_owner); mdb_printf("%?s %20s = %s\n", "", "reader", clp->cl_reader ? "TRUE" : "FALSE"); mdb_printf("%?s %20s = %d\n", "", "writers", clp->cl_writers); mdb_printf("%?s %20s = 0x%p\n", "", "mutex", addr + ((uintptr_t)clp->cl_mutex - (uintptr_t)clp)); mdb_printf("%?s %20s = 0x%p\n", "", "cv", addr + ((uintptr_t)clp->cl_cv - (uintptr_t)clp)); mdb_printf("\n"); mdb_free(clp, sizeof (cfglock_t)); return (DCMD_OK); }
static int hash_walk_init(mdb_walk_state_t *wsp, uintptr_t addr, uint_t hashlen, const char *name, size_t size, size_t next) { hashwalk_data_t *hwp; size_t len = sizeof (uintptr_t) * hashlen; if (len == 0) { mdb_warn("failed to walk hash: invalid hash length\n"); return (WALK_ERR); } hwp = mdb_alloc(sizeof (hashwalk_data_t), UM_SLEEP); hwp->hw_hash = mdb_zalloc(len, UM_SLEEP); (void) mdb_vread(hwp->hw_hash, len, addr); hwp->hw_hashlen = hashlen; hwp->hw_hashidx = 0; hwp->hw_name = name; hwp->hw_data = mdb_zalloc(size, UM_SLEEP); hwp->hw_size = size; hwp->hw_next = next; wsp->walk_addr = hwp->hw_hash[0]; wsp->walk_data = hwp; return (WALK_NEXT); }
static int fcf_sec_walk_init(mdb_walk_state_t *wsp) { fcf_hdr_t h, *hp; size_t size; if (mdb_vread(&h, sizeof (h), wsp->walk_addr) != sizeof (h)) { mdb_warn("failed to read FCF header at %p", wsp->walk_addr); return (WALK_ERR); } size = sizeof (fcf_hdr_t) + sizeof (fcf_sec_t) * h.fcfh_secnum; hp = mdb_alloc(size, UM_SLEEP); if (mdb_vread(hp, size, wsp->walk_addr) != size) { mdb_warn("failed to read FCF sections at %p", wsp->walk_addr); mdb_free(hp, size); return (WALK_ERR); } wsp->walk_data = hp; wsp->walk_arg = 0; return (WALK_NEXT); }
static int action_summary( uintptr_t addr, ipp_action_t *ap, boolean_t banner) { ipp_mod_t *imp; uintptr_t ptr; if (banner) mdb_printf("%?s %<u>%20s %5s %20s%</u>\n", "", "NAME", "ID", "MODNAME"); imp = mdb_alloc(sizeof (ipp_mod_t), UM_SLEEP); ptr = (uintptr_t)ap->ippa_mod; if (mdb_vread(imp, sizeof (ipp_mod_t), ptr) == -1) { mdb_warn("failed to read ipp_mod_t at %p", ptr); mdb_free(imp, sizeof (ipp_mod_t)); return (WALK_ERR); } mdb_printf("%?p:%20s %5d %20s\n", addr, ap->ippa_name, ap->ippa_id, imp->ippm_name); mdb_free(imp, sizeof (ipp_mod_t)); return (WALK_NEXT); }
int sonode_walk_init(mdb_walk_state_t *wsp) { if (wsp->walk_addr == 0) { GElf_Sym sym; struct socklist *slp; if (mdb_lookup_by_obj("sockfs", "socklist", &sym) == -1) { mdb_warn("failed to lookup sockfs`socklist"); return (WALK_ERR); } slp = (struct socklist *)(uintptr_t)sym.st_value; if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr), (uintptr_t)&slp->sl_list) == -1) { mdb_warn("failed to read address of initial sonode " "at %p", &slp->sl_list); return (WALK_ERR); } } wsp->walk_data = mdb_alloc(sizeof (struct sotpi_sonode), UM_SLEEP); return (WALK_NEXT); }
static int targets_walk_i(mdb_walk_state_t *wsp) { if (wsp->walk_addr == NULL) { mdb_warn("Can not perform global walk\n"); return (WALK_ERR); } /* * Input should be a fcp_port, so read it to get the port_tgt * table's head */ if (mdb_vread(&port, sizeof (struct fcp_port), wsp->walk_addr) != sizeof (struct fcp_port)) { mdb_warn("Unable to read in the port structure address\n"); return (WALK_ERR); } tgt_hash_index = 0; while ((port.port_tgt_hash_table[tgt_hash_index] == NULL) && (tgt_hash_index < FCP_NUM_HASH)) { tgt_hash_index++; } wsp->walk_addr = (uintptr_t)(port.port_tgt_hash_table[tgt_hash_index]); wsp->walk_data = mdb_alloc(sizeof (struct fcp_tgt), UM_SLEEP); return (WALK_NEXT); }
static int pkt_walk_i(mdb_walk_state_t *wsp) { if (wsp->walk_addr == NULL) { mdb_warn("The address of a fcp_port" " structure must be given\n"); return (WALK_ERR); } /* * Input should be an fcp_port, so read it to get the pkt * list's head */ if (mdb_vread(&port, sizeof (struct fcp_port), wsp->walk_addr) != sizeof (struct fcp_port)) { mdb_warn("Failed to read in the fcp_port" " at 0x%p\n", wsp->walk_addr); return (WALK_ERR); } wsp->walk_addr = (uintptr_t)(port.port_pkt_head); wsp->walk_data = mdb_alloc(sizeof (struct fcp_pkt), UM_SLEEP); return (WALK_NEXT); }
static int oldc_walk_init(mdb_walk_state_t *wsp) { ssize_t nbytes = mdb_get_xdata("lwpstatus", NULL, 0); if (nbytes <= 0) { mdb_warn("lwpstatus information not available"); return (WALK_ERR); } if (wsp->walk_addr != NULL) { mdb_warn("walker only supports global walk\n"); return (WALK_ERR); } wsp->walk_addr = nbytes; /* Use walk_addr to track size */ wsp->walk_data = mdb_alloc(nbytes, UM_SLEEP); if (mdb_get_xdata("lwpstatus", wsp->walk_data, nbytes) != nbytes) { mdb_warn("failed to read lwpstatus information"); mdb_free(wsp->walk_data, nbytes); return (WALK_ERR); } wsp->walk_arg = wsp->walk_data; /* Use walk_arg to track pointer */ return (WALK_NEXT); }
/* * usb_pipe_handle walker * Given a pointer to a usba_device_t, walk the array of endpoint * pipe_handle lists. * For each list, traverse the list, invoking the callback on each element. * * Note this function takes the address of a usba_device struct (which is * easily obtainable), but actually traverses a sub-portion of the struct * (which address is not so easily obtainable). */ int usb_pipe_handle_walk_init(mdb_walk_state_t *wsp) { if (wsp->walk_addr == NULL) { mdb_warn("not a global walk; usba_device_t required\n"); return (WALK_ERR); } wsp->walk_data = mdb_alloc((sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS, UM_SLEEP | UM_GC); /* * Read the usb_ph_list array into local memory. * Set start address to first element/endpoint in usb_pipehandle_list */ if (mdb_vread(wsp->walk_data, (sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS, (uintptr_t)((size_t)(wsp->walk_addr) + offsetof(usba_device_t, usb_ph_list))) == -1) { mdb_warn("failed to read usb_pipehandle_list at %p", wsp->walk_addr); return (WALK_ERR); } wsp->walk_arg = 0; return (WALK_NEXT); }
static int dof_sect_strtab(uintptr_t addr, dof_sec_t *sec) { char *strtab; size_t sz, i; sz = (size_t)sec->dofs_size; strtab = mdb_alloc(sz, UM_SLEEP | UM_GC); if (mdb_vread(strtab, sz, addr + sec->dofs_offset) != sz) { mdb_warn("failed to read string table"); return (1); } mdb_printf("size = %lx\n", sz); for (i = 0; i < sz; i++) { if (strtab[i] == '\0') mdb_printf("\\0"); else mdb_printf("%c", strtab[i]); } mdb_printf("\n"); return (0); }
/* * tab_command -- * * This function is executed anytime a tab is entered. It checks * the current buffer to determine if there is a valid dmcd, * if that dcmd has a tab completion handler it will invoke it. * * This function returns the string (if any) that should be added to the * existing buffer to complete it. */ int mdb_tab_command(mdb_tab_cookie_t *mcp, const char *buf) { char *data; char *dcmd = NULL; int argc = 0; mdb_arg_t *argv = NULL; int ret = 0; mdb_idcmd_t *cp; uint_t flags = 0; /* * Parsing the command and arguments will modify the buffer * (replacing spaces with \0), so make a copy of the specified * buffer first. */ data = mdb_alloc(strlen(buf) + 1, UM_SLEEP | UM_GC); (void) strcpy(data, buf); /* * Get the specified dcmd and arguments from the buffer. */ ret = tab_parse_buf(data, &dcmd, &argc, &argv, &flags); /* * Match against global symbols if the input is not a dcmd */ if (ret != 0) { (void) mdb_tab_complete_global(mcp, buf); goto out; } /* * Check to see if the buffer contains a valid dcmd */ cp = mdb_dcmd_lookup(dcmd); /* * When argc is zero it indicates that we are trying to tab complete * a dcmd or a global symbol. Note, that if there isn't the start of * a dcmd, i.e. ::, then we will have already bailed in the call to * tab_parse_buf. */ if (cp == NULL && argc != 0) { goto out; } /* * Invoke the command specific tab completion handler or the built in * dcmd one if there is no dcmd. */ if (cp == NULL) (void) mdb_tab_complete_dcmd(mcp, dcmd); else mdb_call_tab(cp, mcp, flags, argc, argv); out: return (mdb_tab_size(mcp)); }
mdb_io_t * mdb_memio_create(char *buf, size_t size) { mdb_io_t *io = mdb_alloc(sizeof (mdb_io_t), UM_SLEEP); mem_data_t *mdp = mdb_alloc(sizeof (mem_data_t), UM_SLEEP); mdp->md_buf = buf; mdp->md_size = size; mdp->md_off = 0; io->io_ops = &memio_ops; io->io_data = mdp; io->io_next = NULL; io->io_refcnt = 0; return (io); }
/* * Create a copy of string s using the mdb allocator interface. */ char * strdup(const char *s) { char *s1 = mdb_alloc(strlen(s) + 1, UM_SLEEP); (void) strcpy(s1, s); return (s1); }
static void mdb_cmdbuf_allocchunk(mdb_cmdbuf_t *cmd) { int i; char **newhistory; ssize_t newhalloc = cmd->cmd_halloc + MDB_DEF_HISTLEN; if (newhalloc > cmd->cmd_histlen) newhalloc = cmd->cmd_histlen; newhistory = mdb_alloc(newhalloc * sizeof (char *), UM_SLEEP); bcopy(cmd->cmd_history, newhistory, cmd->cmd_halloc * sizeof (char *)); mdb_free(cmd->cmd_history, cmd->cmd_halloc * sizeof (char *)); for (i = cmd->cmd_halloc; i < newhalloc; i++) newhistory[i] = mdb_alloc(CMDBUF_LINELEN, UM_SLEEP); cmd->cmd_history = newhistory; cmd->cmd_halloc = newhalloc; }
/* * Create a copy of string s, but only duplicate the first n bytes. */ char * strndup(const char *s, size_t n) { char *s2 = mdb_alloc(n + 1, UM_SLEEP); (void) strncpy(s2, s, n); s2[n] = '\0'; return (s2); }