static int kmdb_kdi_mod_interp(struct modctl *mp, void *arg) { mod_interp_data_t *mid = arg; int rc; kmdb_dpi_restore_fault_hdlr(mid->mid_oldpcb); rc = mid->mid_usercb(mp, mid->mid_userarg); mid->mid_oldpcb = kmdb_dpi_set_fault_hdlr(&mid->mid_pcb); return (rc); }
/* * We need to protect ourselves against any problems that may occur while * executing the module iterator, currently located in krtld. If, for * example, one of the next pointers in the module list points to an invalid * address, we don't want kmdb to explode. As such, we protect ourselves * with the DPI fault-protection routines. We don't want our fault-protection * callback to protect the callback that the kmdb consumer provided, so we * provide our own interposition callback that removes our fault-protector * before invoking the user's callback. */ int kmdb_kdi_mod_iter(int (*cb)(struct modctl *, void *), void *arg) { mod_interp_data_t mid; int rc; if (setjmp(mid.mid_pcb) != 0) { /* We took a fault while iterating through the modules */ kmdb_dpi_restore_fault_hdlr(mid.mid_oldpcb); return (-1); } mid.mid_usercb = cb; mid.mid_userarg = arg; mid.mid_oldpcb = kmdb_dpi_set_fault_hdlr(&mid.mid_pcb); rc = mdb.m_kdi->kdi_mod_iter(kmdb_kdi_mod_interp, &mid); kmdb_dpi_restore_fault_hdlr(mid.mid_oldpcb); return (rc); }
int kmdb_kdi_vtop(uintptr_t va, physaddr_t *pap) { jmp_buf pcb, *oldpcb; int rc = 0; if (setjmp(pcb) == 0) { int err; oldpcb = kmdb_dpi_set_fault_hdlr(&pcb); if ((err = mdb.m_kdi->kdi_vtop(va, pap)) != 0) rc = set_errno(err == ENOENT ? EMDB_NOMAP : err); } else { /* We faulted during the translation */ rc = set_errno(EMDB_NOMAP); } kmdb_dpi_restore_fault_hdlr(oldpcb); return (rc); }
void kmdb_dpi_restore_fault_hdlr(jmp_buf *jb) { (void) kmdb_dpi_set_fault_hdlr(jb); }