Lines Matching defs:xkb
169 typedef struct xkb {
338 xkb_fail(xkb_t *xkb, const char *msg, ...)
343 if (xkb != NULL)
344 (void) fprintf(stderr, "%s: ", xkb->xkb_path);
348 if (xkb != NULL)
349 (void) xkb_close(xkb);
357 xkb_build_m2p(xkb_t *xkb)
361 for (i = 0; i <= xkb->xkb_max_pfn; i++) {
362 if (xkb->xkb_p2m[i] != MFN_INVALID &&
363 xkb->xkb_p2m[i] > xkb->xkb_max_mfn)
364 xkb->xkb_max_mfn = xkb->xkb_p2m[i];
367 xkb->xkb_m2p = mdb_alloc((xkb->xkb_max_mfn + 1) * sizeof (xen_pfn_t),
370 for (i = 0; i <= xkb->xkb_max_mfn; i++)
371 xkb->xkb_m2p[i] = PFN_INVALID;
373 for (i = 0; i <= xkb->xkb_max_pfn; i++) {
374 if (xkb->xkb_p2m[i] != MFN_INVALID)
375 xkb->xkb_m2p[xkb->xkb_p2m[i]] = i;
386 xkb_map_p2m(xkb_t *xkb)
390 xkb_core_t *xc = &xkb->xkb_core;
391 size_t count = xkb->xkb_nr_pages;
400 MAP_SHARED, xkb->xkb_fd, off);
403 (void) xkb_fail(xkb, "cannot map p2m table");
408 xkb->xkb_p2m = (mfn_t *)((char *)xc->xc_p2m_buf +
421 xkb_build_p2m(xkb_t *xkb)
423 xkb_elf_t *xe = &xkb->xkb_elf;
436 (void) xkb_fail(xkb, "cannot find section .xen_p2m");
441 (void) xkb_fail(xkb, "couldn't read .xen_p2m");
445 for (i = 0; i < xkb->xkb_nr_pages; i++) {
446 if (p2m[i].pfn > xkb->xkb_max_pfn)
447 xkb->xkb_max_pfn = p2m[i].pfn;
450 size = sizeof (xen_pfn_t) * (xkb->xkb_max_pfn + 1);
451 xkb->xkb_p2m = mdb_alloc(size, UM_SLEEP);
452 size = sizeof (size_t) * (xkb->xkb_max_pfn + 1);
455 for (i = 0; i <= xkb->xkb_max_pfn; i++) {
456 xkb->xkb_p2m[i] = PFN_INVALID;
460 for (i = 0; i < xkb->xkb_nr_pages; i++) {
461 xkb->xkb_p2m[p2m[i].pfn] = p2m[i].gmfn;
475 xkb_build_fake_p2m(xkb_t *xkb)
477 xkb_elf_t *xe = &xkb->xkb_elf;
487 (void) xkb_fail(xkb, "cannot find section .xen_pfn");
492 (void) xkb_fail(xkb, "couldn't read .xen_pfn");
496 for (i = 0; i < xkb->xkb_nr_pages; i++) {
497 if (p2pfn[i] != PFN_INVALID && p2pfn[i] > xkb->xkb_max_pfn)
498 xkb->xkb_max_pfn = p2pfn[i];
501 size = sizeof (xen_pfn_t) * (xkb->xkb_max_pfn + 1);
502 xkb->xkb_p2m = mdb_alloc(size, UM_SLEEP);
504 size = sizeof (size_t) * (xkb->xkb_max_pfn + 1);
507 for (i = 0; i <= xkb->xkb_max_pfn; i++) {
508 xkb->xkb_p2m[i] = PFN_INVALID;
512 for (i = 0; i < xkb->xkb_nr_pages; i++) {
515 xkb->xkb_p2m[p2pfn[i]] = p2pfn[i];
526 xkb_as_to_mfn(xkb_t *xkb, struct as *as)
533 if (!xkb_read_word(xkb, asp + offsetof(struct as, a_hat), &hatp))
535 if (!xkb_read_word(xkb, hatp + xkb->xkb_info.di_hat_htable_off,
538 if (!xkb_read_word(xkb, htablep + xkb->xkb_info.di_ht_pfn_off,
542 if (pfn > xkb->xkb_max_pfn)
545 return (xkb->xkb_p2m[pfn]);
549 xkb_cr3_to_pfn(xkb_t *xkb)
551 uint64_t cr3 = xkb->xkb_vcpus[0]->ctrlreg[3];
552 if (xkb->xkb_is_hvm)
558 xkb_read_helper(xkb_t *xkb, struct as *as, int phys, uint64_t addr,
562 int windowed = (xkb->xkb_pages == NULL);
563 mfn_t tlmfn = xkb_cr3_to_pfn(xkb);
565 if (as != NULL && (tlmfn = xkb_as_to_mfn(xkb, as)) == MFN_INVALID)
576 mfn = xkb_va_to_mfn(xkb, pos, tlmfn);
581 if (pfn > xkb->xkb_max_pfn)
583 mfn = xkb->xkb_p2m[pfn];
592 offset_t off = xkb_mfn_to_offset(xkb, mfn);
600 ret = pread64(xkb->xkb_fd, outpos, sz, off);
608 if (xkb_map_mfn(xkb, mfn, &xkb->xkb_map) == NULL)
611 bcopy(xkb->xkb_map.mm_map + pageoff, outpos, sz);
621 xkb_pread(xkb_t *xkb, uint64_t addr, void *buf, size_t size)
623 return (xkb_read_helper(xkb, NULL, 1, addr, buf, size));
627 xkb_aread(xkb_t *xkb, uintptr_t addr, void *buf, size_t size, struct as *as)
629 return (xkb_read_helper(xkb, as, 0, addr, buf, size));
633 xkb_read(xkb_t *xkb, uintptr_t addr, void *buf, size_t size)
635 return (xkb_aread(xkb, addr, buf, size, NULL));
639 xkb_read_word(xkb_t *xkb, uintptr_t addr, uintptr_t *buf)
641 if (xkb_read(xkb, addr, buf, sizeof (uintptr_t)) !=
648 xkb_readstr(xkb_t *xkb, uintptr_t addr)
654 if (xkb_read(xkb, addr + i, &str[i], 1) != 1) {
672 xkb_pfn_to_off(xkb_t *xkb, xen_pfn_t pfn)
674 if (pfn == PFN_INVALID || pfn > xkb->xkb_max_pfn)
677 if (xkb->xkb_type == XKB_FORMAT_CORE)
680 return (PAGE_SIZE * (xkb->xkb_elf.xe_off[pfn]));
684 xkb_mfn_to_offset(xkb_t *xkb, mfn_t mfn)
688 if (mfn > xkb->xkb_max_mfn)
691 pfn = xkb->xkb_m2p[mfn];
696 return (xkb->xkb_pages_off + xkb_pfn_to_off(xkb, pfn));
700 xkb_map_mfn(xkb_t *xkb, mfn_t mfn, mfn_map_t *mm)
702 int windowed = (xkb->xkb_pages == NULL);
716 if ((off = xkb_mfn_to_offset(xkb, mfn)) == (-1ULL))
720 xkb->xkb_fd, off);
729 if (mfn > xkb->xkb_max_mfn)
732 pfn = xkb->xkb_m2p[mfn];
737 mm->mm_map = xkb->xkb_pages + xkb_pfn_to_off(xkb, pfn);
776 xkb_va_to_mfn(xkb_t *xkb, uintptr_t va, mfn_t mfn)
778 mmu_info_t *mmu = &xkb->xkb_mmu;
785 if (xkb_map_mfn(xkb, mfn, &xkb->xkb_pt_map[level]) == NULL)
790 pte = xkb_get_pte(mmu, (char *)xkb->xkb_pt_map[level].mm_map +
816 xkb_read_module(xkb_t *xkb, uintptr_t modulep, struct module *module,
819 if (xkb_read(xkb, modulep, module, sizeof (struct module)) !=
823 if (!xkb_read_word(xkb, (uintptr_t)module->symhdr +
827 if (!xkb_read_word(xkb, (uintptr_t)module->strhdr +
831 if (!xkb_read_word(xkb, (uintptr_t)module->symhdr +
840 xkb_read_modsyms(xkb_t *xkb, char **buf, size_t *sizes, int types,
851 if (xkb_read(xkb, sym_addr + i * sizeof (sym), &sym,
858 name = xkb_readstr(xkb, str_addr + sym.st_name);
885 xkb_walk_syms(xkb_t *xkb, uintptr_t modhead, char **buf,
918 if (!xkb_read_word(xkb,
925 if (!xkb_read_module(xkb, modulep, &module, &sym_addr,
932 if (!xkb_read_modsyms(xkb, buf, sizes, types, sym_addr,
937 if (!xkb_read_word(xkb,
959 xkb_build_ksyms(xkb_t *xkb)
961 debug_info_t *info = &xkb->xkb_info;
969 if (xkb_read(xkb, info->di_modules, &modules,
975 if (!xkb_walk_syms(xkb, info->di_modules, NULL, sizes,
979 xkb->xkb_namesize = sizeof (xkb_namelist_t);
980 xkb->xkb_namesize += sizes[XKB_WALK_LOCAL];
981 xkb->xkb_namesize += sizes[XKB_WALK_GLOBAL];
982 xkb->xkb_namesize += sizes[XKB_WALK_STR];
984 if ((xkb->xkb_namelist = mdb_zalloc(xkb->xkb_namesize, UM_SLEEP))
989 hdr = (xkb_namelist_t *)xkb->xkb_namelist;
991 if (xkb_read(xkb, module + offsetof(struct module, hdr),
1020 shp->sh_addr = (Addr)(xkb->xkb_namelist + shp->sh_offset);
1030 shp->sh_addr = (Addr)(xkb->xkb_namelist + shp->sh_offset);
1039 shp->sh_addr = (Addr)(xkb->xkb_namelist + shp->sh_offset);
1043 buf = xkb->xkb_namelist + sizeof (xkb_namelist_t);
1045 if (!xkb_walk_syms(xkb, info->di_modules, &buf, sizes,
1048 if (!xkb_walk_syms(xkb, info->di_modules, &buf, sizes,
1051 if (!xkb_walk_syms(xkb, info->di_modules, &buf, sizes,
1059 xkb_open_core(xkb_t *xkb)
1061 xkb_core_t *xc = &xkb->xkb_core;
1066 xkb->xkb_type = XKB_FORMAT_CORE;
1068 if ((xkb->xkb_fd = open64(xkb->xkb_path, O_RDONLY)) == -1)
1069 return (xkb_fail(xkb, "cannot open %s", xkb->xkb_path));
1071 if (pread64(xkb->xkb_fd, &xc->xc_hdr, sizeof (xc->xc_hdr), 0) !=
1073 return (xkb_fail(xkb, "invalid dump file"));
1076 return (xkb_fail(xkb, "cannot process HVM images"));
1079 return (xkb_fail(xkb, "invalid magic %d",
1087 xkb->xkb_nr_pages = xc->xc_hdr.xch_nr_pages;
1088 xkb->xkb_pages_off = xc->xc_hdr.xch_pages_offset;
1089 xkb->xkb_max_pfn = xc->xc_hdr.xch_nr_pages - 1;
1090 xkb->xkb_nr_vcpus = xc->xc_hdr.xch_nr_vcpus;
1092 sz = xkb->xkb_nr_vcpus * sizeof (struct vcpu_guest_context);
1093 xkb->xkb_vcpu_data_sz = sz;
1094 xkb->xkb_vcpu_data = mdb_alloc(sz, UM_SLEEP);
1096 if (pread64(xkb->xkb_fd, xkb->xkb_vcpu_data, sz,
1098 return (xkb_fail(xkb, "cannot read VCPU contexts"));
1100 sz = xkb->xkb_nr_vcpus * sizeof (struct vcpu_guest_context *);
1101 xkb->xkb_vcpus = mdb_alloc(sz, UM_SLEEP);
1103 vcp = xkb->xkb_vcpu_data;
1104 for (i = 0; i < xkb->xkb_nr_vcpus; i++)
1105 xkb->xkb_vcpus[i] = &vcp[i];
1111 xkb->xkb_pages = mmap(NULL, PAGE_SIZE * xkb->xkb_nr_pages,
1112 PROT_READ, MAP_SHARED, xkb->xkb_fd, xc->xc_hdr.xch_pages_offset);
1114 if (xkb->xkb_pages == (char *)MAP_FAILED)
1115 xkb->xkb_pages = NULL;
1121 xkb->xkb_is_pae = 1;
1123 if (!xkb_map_p2m(xkb))
1126 return (xkb);
1130 xkb_open_elf(xkb_t *xkb)
1132 xkb_elf_t *xe = &xkb->xkb_elf;
1141 if ((io = mdb_fdio_create_path(NULL, xkb->xkb_path,
1143 return (xkb_fail(xkb, "failed to open"));
1149 return (xkb);
1152 xkb->xkb_fd = mdb_fdio_fileno(io);
1157 return (xkb);
1160 return (xkb);
1166 xkb->xkb_type = XKB_FORMAT_ELF;
1186 return (xkb_fail(xkb, "invalid ELF note "
1196 return (xkb_fail(xkb, "invalid ELF note "
1208 return (xkb_fail(xkb, "unknown major "
1227 xkb->xkb_is_hvm = xe->xe_hdr.xeh_magic == XC_CORE_MAGIC_HVM;
1231 return (xkb_fail(xkb, "invalid magic %d",
1235 xkb->xkb_nr_pages = xe->xe_hdr.xeh_nr_pages;
1236 xkb->xkb_is_pae = (strstr(xe->xe_version.xev_capabilities,
1242 return (xkb_fail(xkb, "cannot find section .xen_prstatus"));
1245 return (xkb_fail(xkb, "invalid section .xen_prstatus"));
1247 xkb->xkb_nr_vcpus = sect->gs_shdr.sh_size / sect->gs_shdr.sh_entsize;
1249 xkb->xkb_vcpu_data = mdb_gelf_sect_load(xe->xe_gelf, sect);
1250 if (xkb->xkb_vcpu_data == NULL)
1251 return (xkb_fail(xkb, "cannot load section .xen_prstatus"));
1252 xkb->xkb_vcpu_data_sz = sect->gs_shdr.sh_size;
1260 sz = xkb->xkb_nr_vcpus * sizeof (struct vcpu_guest_context *);
1261 xkb->xkb_vcpus = mdb_alloc(sz, UM_SLEEP);
1262 for (i = 0; i < xkb->xkb_nr_vcpus; i++) {
1263 dp = ((char *)xkb->xkb_vcpu_data +
1265 xkb->xkb_vcpus[i] = dp;
1271 return (xkb_fail(xkb, "cannot find section .xen_pages"));
1274 return (xkb_fail(xkb, ".xen_pages is not page aligned"));
1277 return (xkb_fail(xkb, "invalid section .xen_pages"));
1279 xkb->xkb_pages_off = sect->gs_shdr.sh_offset;
1285 xkb->xkb_pages = mmap(NULL, PAGE_SIZE * xkb->xkb_nr_pages,
1286 PROT_READ, MAP_SHARED, xkb->xkb_fd, xkb->xkb_pages_off);
1288 if (xkb->xkb_pages == (char *)MAP_FAILED)
1289 xkb->xkb_pages = NULL;
1291 if (xkb->xkb_is_hvm) {
1292 if (!xkb_build_fake_p2m(xkb))
1295 if (!xkb_build_p2m(xkb))
1299 return (xkb);
1303 xkb_init_mmu(xkb_t *xkb)
1306 xkb->xkb_mmu.mi_max = 3;
1307 xkb->xkb_mmu.mi_shift[0] = 12;
1308 xkb->xkb_mmu.mi_shift[1] = 21;
1309 xkb->xkb_mmu.mi_shift[2] = 30;
1310 xkb->xkb_mmu.mi_shift[3] = 39;
1311 xkb->xkb_mmu.mi_ptes = 512;
1312 xkb->xkb_mmu.mi_ptesize = 8;
1314 if (xkb->xkb_is_pae) {
1315 xkb->xkb_mmu.mi_max = 2;
1316 xkb->xkb_mmu.mi_shift[0] = 12;
1317 xkb->xkb_mmu.mi_shift[1] = 21;
1318 xkb->xkb_mmu.mi_shift[2] = 30;
1319 xkb->xkb_mmu.mi_ptes = 512;
1320 xkb->xkb_mmu.mi_ptesize = 8;
1322 xkb->xkb_mmu.mi_max = 1;
1323 xkb->xkb_mmu.mi_shift[0] = 12;
1324 xkb->xkb_mmu.mi_shift[1] = 22;
1325 xkb->xkb_mmu.mi_ptes = 1024;
1326 xkb->xkb_mmu.mi_ptesize = 4;
1338 xkb_t *xkb = NULL;
1342 return (xkb_fail(xkb, "cannot stat %s", corefile));
1345 return (xkb_fail(xkb, "invalid open flags"));
1347 xkb = mdb_zalloc(sizeof (*xkb), UM_SLEEP);
1350 xkb->xkb_pt_map[i].mm_mfn = MFN_INVALID;
1351 xkb->xkb_pt_map[i].mm_map = (char *)MAP_FAILED;
1354 xkb->xkb_type = XKB_FORMAT_UNKNOWN;
1355 xkb->xkb_map.mm_mfn = MFN_INVALID;
1356 xkb->xkb_map.mm_map = (char *)MAP_FAILED;
1357 xkb->xkb_core.xc_p2m_buf = (char *)MAP_FAILED;
1358 xkb->xkb_fd = -1;
1360 xkb->xkb_path = strdup(corefile);
1362 if ((xkb = xkb_open_elf(xkb)) == NULL)
1365 if (xkb->xkb_type == XKB_FORMAT_UNKNOWN) {
1366 if (!xkb_open_core(xkb))
1370 xkb_init_mmu(xkb);
1372 if (!xkb_build_m2p(xkb))
1375 if (xkb->xkb_is_hvm)
1378 if (xkb_read(xkb, debug_info, &xkb->xkb_info,
1379 sizeof (xkb->xkb_info)) != sizeof (xkb->xkb_info))
1380 return (xkb_fail(xkb, "cannot read debug_info"));
1382 if (xkb->xkb_info.di_magic != DEBUG_INFO_MAGIC) {
1383 return (xkb_fail(xkb, "invalid debug info magic %d",
1384 xkb->xkb_info.di_magic));
1387 if (xkb->xkb_info.di_version != DEBUG_INFO_VERSION) {
1388 return (xkb_fail(xkb, "unknown debug info version %d",
1389 xkb->xkb_info.di_version));
1392 if (!xkb_build_ksyms(xkb))
1393 return (xkb_fail(xkb, "cannot construct namelist"));
1395 return (xkb);
1399 xkb_close(xkb_t *xkb)
1403 if (xkb == NULL)
1406 if (xkb->xkb_m2p != NULL) {
1407 mdb_free(xkb->xkb_m2p,
1408 (xkb->xkb_max_mfn + 1) * sizeof (xen_pfn_t));
1411 if (xkb->xkb_pages != NULL) {
1412 (void) munmap((void *)xkb->xkb_pages,
1413 PAGE_SIZE * xkb->xkb_nr_pages);
1416 char *addr = xkb->xkb_pt_map[i].mm_map;
1420 if (xkb->xkb_map.mm_map != (char *)MAP_FAILED) {
1421 (void) munmap((void *)xkb->xkb_map.mm_map,
1426 if (xkb->xkb_namelist != NULL)
1427 mdb_free(xkb->xkb_namelist, xkb->xkb_namesize);
1429 if (xkb->xkb_type == XKB_FORMAT_ELF) {
1430 xkb_elf_t *xe = &xkb->xkb_elf;
1435 sz = sizeof (xen_pfn_t) * (xkb->xkb_max_pfn + 1);
1437 if (xkb->xkb_p2m != NULL)
1438 mdb_free(xkb->xkb_p2m, sz);
1440 sz = sizeof (size_t) * (xkb->xkb_max_pfn + 1);
1445 } else if (xkb->xkb_type == XKB_FORMAT_CORE) {
1446 xkb_core_t *xc = &xkb->xkb_core;
1448 if (xkb->xkb_fd != -1)
1449 (void) close(xkb->xkb_fd);
1451 sz = (xkb->xkb_nr_pages * sizeof (mfn_t)) + (PAGE_SIZE * 2);
1457 if (xkb->xkb_vcpu_data != NULL)
1458 mdb_free(xkb->xkb_vcpu_data, xkb->xkb_vcpu_data_sz);
1461 if (xkb->xkb_vcpus != NULL) {
1463 xkb->xkb_nr_vcpus;
1464 mdb_free(xkb->xkb_vcpus, sz);
1467 free(xkb->xkb_path);
1469 mdb_free(xkb, sizeof (*xkb));
1475 xkb_sym_io(xkb_t *xkb, const char *symfile)
1477 mdb_io_t *io = mdb_memio_create(xkb->xkb_namelist, xkb->xkb_namesize);
1480 mdb_warn("failed to create namelist from %s", xkb->xkb_path);
1486 xkb_vtop(xkb_t *xkb, struct as *as, uintptr_t addr)
1488 mfn_t tlmfn = xkb_cr3_to_pfn(xkb);
1491 if (as != NULL && (tlmfn = xkb_as_to_mfn(xkb, as)) == MFN_INVALID)
1494 mfn = xkb_va_to_mfn(xkb, addr, tlmfn);
1496 if (mfn == MFN_INVALID || mfn > xkb->xkb_max_mfn)
1499 return (((uint64_t)xkb->xkb_m2p[mfn] << PAGE_SHIFT)
1504 xkb_getmregs(xkb_t *xkb, uint_t cpu, struct privmregs *mregs)
1510 if (cpu >= xkb->xkb_nr_vcpus) {
1517 vcpu = xkb->xkb_vcpus[cpu];