10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*3708Skrishna * Common Development and Distribution License (the "License"). 6*3708Skrishna * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*3708Skrishna * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * mdb dcmds for selected structures from 300Sstevel@tonic-gate * usr/src/uts/common/sys/crypto/impl.h 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate #include <stdio.h> 330Sstevel@tonic-gate #include <sys/mdb_modapi.h> 340Sstevel@tonic-gate #include <sys/modctl.h> 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <sys/crypto/api.h> 370Sstevel@tonic-gate #include <sys/crypto/common.h> 380Sstevel@tonic-gate #include <sys/crypto/impl.h> 390Sstevel@tonic-gate #include "crypto_cmds.h" 400Sstevel@tonic-gate 410Sstevel@tonic-gate int 420Sstevel@tonic-gate kcf_sched_info(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 430Sstevel@tonic-gate { 440Sstevel@tonic-gate kcf_sched_info_t sched; 450Sstevel@tonic-gate kcf_sched_info_t *sinfo = &sched; 460Sstevel@tonic-gate 470Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 480Sstevel@tonic-gate if ((argc == 1) && (argv->a_type == MDB_TYPE_IMMEDIATE)) 490Sstevel@tonic-gate sinfo = (kcf_sched_info_t *)(uintptr_t)argv->a_un.a_val; 500Sstevel@tonic-gate else 510Sstevel@tonic-gate return (DCMD_USAGE); 520Sstevel@tonic-gate } else if (addr == NULL) /* not allowed with DCMD_ADDRSPEC */ 530Sstevel@tonic-gate return (DCMD_USAGE); 540Sstevel@tonic-gate else { 550Sstevel@tonic-gate if (mdb_vread(sinfo, sizeof (kcf_sched_info_t), addr) == -1) { 560Sstevel@tonic-gate mdb_warn("cannot read %p", addr); 570Sstevel@tonic-gate return (DCMD_ERR); 580Sstevel@tonic-gate } 590Sstevel@tonic-gate } 600Sstevel@tonic-gate mdb_printf("ks_ndispatches:\t%llu\n", sinfo->ks_ndispatches); 610Sstevel@tonic-gate mdb_printf("ks_nfails:\t%llu\n", sinfo->ks_nfails); 620Sstevel@tonic-gate mdb_printf("ks_nbusy_rval:\t%llu\n", sinfo->ks_nbusy_rval); 630Sstevel@tonic-gate mdb_printf("ks_ntaskq:\t%p\n", sinfo->ks_taskq); 640Sstevel@tonic-gate return (DCMD_OK); 650Sstevel@tonic-gate } 660Sstevel@tonic-gate 670Sstevel@tonic-gate static const char *prov_states[] = { 680Sstevel@tonic-gate "none", 690Sstevel@tonic-gate "KCF_PROV_ALLOCATED", 700Sstevel@tonic-gate "KCF_PROV_UNVERIFIED", 710Sstevel@tonic-gate "KCF_PROV_READY", 720Sstevel@tonic-gate "KCF_PROV_BUSY", 730Sstevel@tonic-gate "KCF_PROV_FAILED", 740Sstevel@tonic-gate "KCF_PROV_DISABLED", 750Sstevel@tonic-gate "KCF_PROV_REMOVED", 760Sstevel@tonic-gate "KCF_PROV_FREED" 770Sstevel@tonic-gate }; 780Sstevel@tonic-gate 790Sstevel@tonic-gate static void 800Sstevel@tonic-gate pr_kstat_named(kstat_named_t *ks) 810Sstevel@tonic-gate { 820Sstevel@tonic-gate mdb_inc_indent(4); 830Sstevel@tonic-gate 840Sstevel@tonic-gate mdb_printf("name = %s\n", ks->name); 850Sstevel@tonic-gate mdb_printf("value = "); 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * The only data type used for the provider kstats is uint64. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate switch (ks->data_type) { 910Sstevel@tonic-gate case KSTAT_DATA_UINT64: 920Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE) 930Sstevel@tonic-gate mdb_printf("%llu\n", ks->value.ui64); 940Sstevel@tonic-gate #endif 950Sstevel@tonic-gate break; 960Sstevel@tonic-gate default: 970Sstevel@tonic-gate mdb_warn("Incorrect data type for kstat.\n"); 980Sstevel@tonic-gate } 990Sstevel@tonic-gate 1000Sstevel@tonic-gate mdb_dec_indent(4); 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /*ARGSUSED*/ 1040Sstevel@tonic-gate int 1050Sstevel@tonic-gate kcf_provider_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1060Sstevel@tonic-gate { 1070Sstevel@tonic-gate kcf_provider_desc_t desc; 1080Sstevel@tonic-gate kcf_provider_desc_t *ptr; 1090Sstevel@tonic-gate char string[MAXNAMELEN + 1]; 1100Sstevel@tonic-gate int i, j; 1110Sstevel@tonic-gate crypto_mech_info_t *mech_pointer; 1120Sstevel@tonic-gate mdb_arg_t arg; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) != DCMD_ADDRSPEC) 1150Sstevel@tonic-gate return (DCMD_USAGE); 1160Sstevel@tonic-gate ptr = (kcf_provider_desc_t *)addr; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate #ifdef DEBUG 1190Sstevel@tonic-gate mdb_printf("DEBUG: reading kcf_provider_desc at %p\n", ptr); 1200Sstevel@tonic-gate #endif 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate if (mdb_vread(&desc, sizeof (kcf_provider_desc_t), (uintptr_t)ptr) 1230Sstevel@tonic-gate == -1) { 1240Sstevel@tonic-gate mdb_warn("cannot read at address %p", (uintptr_t)ptr); 1250Sstevel@tonic-gate return (DCMD_ERR); 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate mdb_printf("%<b>kcf_provider_desc at %p%</b>\n", ptr); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate switch (desc.pd_prov_type) { 1300Sstevel@tonic-gate case CRYPTO_HW_PROVIDER: 1310Sstevel@tonic-gate mdb_printf("pd_prov_type:\t\tCRYPTO_HW_PROVIDER\n"); 1320Sstevel@tonic-gate break; 1330Sstevel@tonic-gate case CRYPTO_SW_PROVIDER: 1340Sstevel@tonic-gate mdb_printf("pd_prov_type:\t\tCRYPTO_SW_PROVIDER\n"); 1350Sstevel@tonic-gate break; 1360Sstevel@tonic-gate case CRYPTO_LOGICAL_PROVIDER: 1370Sstevel@tonic-gate mdb_printf("pd_prov_type:\t\tCRYPTO_LOGICAL_PROVIDER\n"); 1380Sstevel@tonic-gate break; 1390Sstevel@tonic-gate default: 1400Sstevel@tonic-gate mdb_printf("bad pd_prov_type:\t%d\n", desc.pd_prov_type); 1410Sstevel@tonic-gate } 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate mdb_printf("pd_prov_handle:\t\t%p\n", desc.pd_prov_handle); 1440Sstevel@tonic-gate mdb_printf("pd_kcf_prov_handle:\t%u\n", desc.pd_kcf_prov_handle); 1450Sstevel@tonic-gate mdb_printf("pd_prov_id:\t\t%u\n", desc.pd_prov_id); 1460Sstevel@tonic-gate if (desc.pd_description == NULL) 1470Sstevel@tonic-gate mdb_printf("pd_description:\t\tNULL\n"); 1480Sstevel@tonic-gate else if (mdb_readstr(string, MAXNAMELEN + 1, 1490Sstevel@tonic-gate (uintptr_t)desc.pd_description) == -1) { 1500Sstevel@tonic-gate mdb_warn("cannot read %p", desc.pd_description); 1510Sstevel@tonic-gate } else 1520Sstevel@tonic-gate mdb_printf("pd_description:\t\t%s\n", string); 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate mdb_printf("pd_ops_vector:\t\t%p\n", desc.pd_ops_vector); 1550Sstevel@tonic-gate mdb_printf("pd_mech_list_count:\t%u\n", desc.pd_mech_list_count); 1560Sstevel@tonic-gate /* mechanisms */ 1570Sstevel@tonic-gate mdb_inc_indent(4); 1580Sstevel@tonic-gate for (i = 0; i < desc.pd_mech_list_count; i++) { 1590Sstevel@tonic-gate mech_pointer = desc.pd_mechanisms + i; 1600Sstevel@tonic-gate mdb_call_dcmd("crypto_mech_info", 1610Sstevel@tonic-gate (uintptr_t)mech_pointer, DCMD_ADDRSPEC, 0, NULL); 1620Sstevel@tonic-gate } 1630Sstevel@tonic-gate mdb_dec_indent(4); 164*3708Skrishna mdb_printf("pd_mech_indx:\n"); 1650Sstevel@tonic-gate mdb_inc_indent(8); 1660Sstevel@tonic-gate for (i = 0; i < KCF_OPS_CLASSSIZE; i++) { 1670Sstevel@tonic-gate for (j = 0; j < KCF_MAXMECHTAB; j++) { 168*3708Skrishna if (desc.pd_mech_indx[i][j] == KCF_INVALID_INDX) 169*3708Skrishna mdb_printf("N "); 170*3708Skrishna else 171*3708Skrishna mdb_printf("%u ", desc.pd_mech_indx[i][j]); 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate mdb_printf("\n"); 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate mdb_dec_indent(8); 1760Sstevel@tonic-gate mdb_printf("pd_ks_data.ps_ops_total:\n", desc.pd_ks_data.ps_ops_total); 1770Sstevel@tonic-gate pr_kstat_named(&desc.pd_ks_data.ps_ops_total); 1780Sstevel@tonic-gate mdb_printf("pd_ks_data.ps_ops_passed:\n", 1790Sstevel@tonic-gate desc.pd_ks_data.ps_ops_passed); 1800Sstevel@tonic-gate pr_kstat_named(&desc.pd_ks_data.ps_ops_passed); 1810Sstevel@tonic-gate mdb_printf("pd_ks_data.ps_ops_failed:\n", 1820Sstevel@tonic-gate desc.pd_ks_data.ps_ops_failed); 1830Sstevel@tonic-gate pr_kstat_named(&desc.pd_ks_data.ps_ops_failed); 1840Sstevel@tonic-gate mdb_printf("pd_ks_data.ps_ops_busy_rval:\n", 1850Sstevel@tonic-gate desc.pd_ks_data.ps_ops_busy_rval); 1860Sstevel@tonic-gate pr_kstat_named(&desc.pd_ks_data.ps_ops_busy_rval); 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate mdb_printf("pd_kstat:\t\t%p\n", desc.pd_kstat); 1890Sstevel@tonic-gate mdb_printf("kcf_sched_info:\n"); 1900Sstevel@tonic-gate /* print pd_sched_info via existing function */ 1910Sstevel@tonic-gate mdb_inc_indent(8); 1920Sstevel@tonic-gate arg.a_type = MDB_TYPE_IMMEDIATE; 1930Sstevel@tonic-gate arg.a_un.a_val = (uintmax_t)(uintptr_t)&desc.pd_sched_info; 1940Sstevel@tonic-gate mdb_call_dcmd("kcf_sched_info", (uintptr_t)NULL, 0, 1, &arg); 1950Sstevel@tonic-gate mdb_dec_indent(8); 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate mdb_printf("pd_refcnt:\t\t%u\n", desc.pd_refcnt); 1980Sstevel@tonic-gate if (desc.pd_name == NULL) 1990Sstevel@tonic-gate mdb_printf("pd_name:\t\t NULL\n"); 2000Sstevel@tonic-gate else if (mdb_readstr(string, MAXNAMELEN + 1, (uintptr_t)desc.pd_name) 2010Sstevel@tonic-gate == -1) 2020Sstevel@tonic-gate mdb_warn("could not read pd_name from %X\n", desc.pd_name); 2030Sstevel@tonic-gate else 2040Sstevel@tonic-gate mdb_printf("pd_name:\t\t%s\n", string); 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate mdb_printf("pd_instance:\t\t%u\n", desc.pd_instance); 2070Sstevel@tonic-gate mdb_printf("pd_module_id:\t\t%d\n", desc.pd_module_id); 2080Sstevel@tonic-gate mdb_printf("pd_mctlp:\t\t%p\n", desc.pd_mctlp); 2090Sstevel@tonic-gate mdb_printf("pd_sid:\t\t\t%u\n", desc.pd_sid); 2100Sstevel@tonic-gate mdb_printf("pd_lock:\t\t%p\n", desc.pd_lock); 2110Sstevel@tonic-gate if (desc.pd_state < KCF_PROV_ALLOCATED || 2120Sstevel@tonic-gate desc.pd_state > KCF_PROV_FREED) 2130Sstevel@tonic-gate mdb_printf("pd_state is invalid:\t%d\n", desc.pd_state); 2140Sstevel@tonic-gate else 2150Sstevel@tonic-gate mdb_printf("pd_state:\t%s\n", prov_states[desc.pd_state]); 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate mdb_printf("pd_resume_cv:\t\t%hd\n", desc.pd_resume_cv._opaque); 2180Sstevel@tonic-gate mdb_printf("pd_remove_cv:\t\t%hd\n", desc.pd_remove_cv._opaque); 219*3708Skrishna mdb_printf("pd_flags:\t\t%s %s %s\n", 220*3708Skrishna (desc.pd_flags & CRYPTO_HIDE_PROVIDER) ? 221*3708Skrishna "CRYPTO_HIDE_PROVIDER" : " ", 222*3708Skrishna (desc.pd_flags & KCF_LPROV_MEMBER) ? 223*3708Skrishna "KCF_LPROV_MEMBER" : " ", 224*3708Skrishna (desc.pd_flags & KCF_PROV_RESTRICTED) ? 225*3708Skrishna "KCF_PROV_RESTRICTED" : " "); 2260Sstevel@tonic-gate mdb_printf("pd_provider_list:\t%p\n", desc.pd_provider_list); 2270Sstevel@tonic-gate return (DCMD_OK); 2280Sstevel@tonic-gate } 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate #define GOT_NONE (-2) 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate /*ARGSUSED*/ 2330Sstevel@tonic-gate int 2340Sstevel@tonic-gate prov_tab(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2350Sstevel@tonic-gate { 2360Sstevel@tonic-gate kcf_provider_desc_t **tab; 2370Sstevel@tonic-gate kcf_provider_desc_t desc; 2380Sstevel@tonic-gate kcf_provider_desc_t *ptr; 2390Sstevel@tonic-gate uint_t prov_tab_max; 2400Sstevel@tonic-gate int i; 2410Sstevel@tonic-gate int gotzero = GOT_NONE; 2420Sstevel@tonic-gate char string[MAXNAMELEN + 1]; 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) { 2450Sstevel@tonic-gate return (DCMD_USAGE); 2460Sstevel@tonic-gate } else if (mdb_readsym(&ptr, sizeof (void *), "prov_tab") 2470Sstevel@tonic-gate == -1) { 2480Sstevel@tonic-gate mdb_warn("cannot read prov_tab"); 2490Sstevel@tonic-gate return (DCMD_ERR); 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate } else if (mdb_readvar(&prov_tab_max, "prov_tab_max") == -1) { 2520Sstevel@tonic-gate mdb_warn("cannot read prov_tab_max"); 2530Sstevel@tonic-gate return (DCMD_ERR); 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate mdb_printf("%<b>prov_tab = %p%</b>\n", ptr); 2560Sstevel@tonic-gate tab = mdb_zalloc(prov_tab_max * sizeof (kcf_provider_desc_t *), 2570Sstevel@tonic-gate UM_SLEEP| UM_GC); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate #ifdef DEBUG 2600Sstevel@tonic-gate mdb_printf("DEBUG: tab = %p, prov_tab_max = %d\n", tab, prov_tab_max); 2610Sstevel@tonic-gate #endif 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate if (mdb_vread(tab, prov_tab_max * sizeof (kcf_provider_desc_t *), 2640Sstevel@tonic-gate (uintptr_t)ptr) == -1) { 2650Sstevel@tonic-gate mdb_warn("cannot read prov_tab"); 2660Sstevel@tonic-gate return (DCMD_ERR); 2670Sstevel@tonic-gate } 2680Sstevel@tonic-gate #ifdef DEBUG 2690Sstevel@tonic-gate mdb_printf("DEBUG: got past mdb_vread of tab\n"); 2700Sstevel@tonic-gate mdb_printf("DEBUG: *tab = %p\n", *tab); 2710Sstevel@tonic-gate #endif 2720Sstevel@tonic-gate for (i = 0; i < prov_tab_max; i++) { 2730Sstevel@tonic-gate /* save space, only print range for long list of nulls */ 2740Sstevel@tonic-gate if (tab[i] == NULL) { 2750Sstevel@tonic-gate if (gotzero == GOT_NONE) { 2760Sstevel@tonic-gate mdb_printf("prov_tab[%d", i); 2770Sstevel@tonic-gate gotzero = i; 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate } else { 2800Sstevel@tonic-gate /* first non-null in awhile, print index of prev null */ 2810Sstevel@tonic-gate if (gotzero != GOT_NONE) { 2820Sstevel@tonic-gate if (gotzero == (i - 1)) 2830Sstevel@tonic-gate mdb_printf("] = NULL\n", i - 1); 2840Sstevel@tonic-gate else 2850Sstevel@tonic-gate mdb_printf(" - %d] = NULL\n", i - 1); 2860Sstevel@tonic-gate gotzero = GOT_NONE; 2870Sstevel@tonic-gate } 2880Sstevel@tonic-gate /* interesting value, print it */ 2890Sstevel@tonic-gate mdb_printf("prov_tab[%d] = %p ", i, tab[i]); 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate if (mdb_vread(&desc, sizeof (kcf_provider_desc_t), 2920Sstevel@tonic-gate (uintptr_t)tab[i]) == -1) { 2930Sstevel@tonic-gate mdb_warn("cannot read at address %p", 2940Sstevel@tonic-gate (uintptr_t)tab[i]); 2950Sstevel@tonic-gate return (DCMD_ERR); 2960Sstevel@tonic-gate } 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate (void) mdb_readstr(string, MAXNAMELEN + 1, 2990Sstevel@tonic-gate (uintptr_t)desc.pd_name); 3000Sstevel@tonic-gate mdb_printf("(%s\t%s)\n", string, 3010Sstevel@tonic-gate prov_states[desc.pd_state]); 3020Sstevel@tonic-gate } 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate /* if we've printed the first of many nulls but left the brace open */ 3050Sstevel@tonic-gate if ((i > 0) && (tab[i-1] == NULL)) { 3060Sstevel@tonic-gate if (gotzero == GOT_NONE) 3070Sstevel@tonic-gate mdb_printf("] = NULL\n"); 3080Sstevel@tonic-gate else 3090Sstevel@tonic-gate mdb_printf(" - %d] = NULL\n", i - 1); 3100Sstevel@tonic-gate } 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate return (DCMD_OK); 3130Sstevel@tonic-gate } 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /*ARGSUSED*/ 3160Sstevel@tonic-gate int 3170Sstevel@tonic-gate policy_tab(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3180Sstevel@tonic-gate { 3190Sstevel@tonic-gate kcf_policy_desc_t **tab; 3200Sstevel@tonic-gate kcf_policy_desc_t *ptr; 3210Sstevel@tonic-gate uint_t policy_tab_max; 3220Sstevel@tonic-gate int num, i; 3230Sstevel@tonic-gate int gotzero = GOT_NONE; 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) { 3260Sstevel@tonic-gate return (DCMD_USAGE); 3270Sstevel@tonic-gate } else if (mdb_readsym(&ptr, sizeof (void *), "policy_tab") 3280Sstevel@tonic-gate == -1) { 3290Sstevel@tonic-gate mdb_warn("cannot read policy_tab"); 3300Sstevel@tonic-gate return (DCMD_ERR); 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate } else if (mdb_readvar(&policy_tab_max, "policy_tab_max") == -1) { 3330Sstevel@tonic-gate mdb_warn("cannot read policy_tab_max"); 3340Sstevel@tonic-gate return (DCMD_ERR); 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate /* get the current number of descriptors in the table */ 3380Sstevel@tonic-gate if (mdb_readvar(&num, "policy_tab_num") == -1) { 3390Sstevel@tonic-gate mdb_warn("cannot read policy_tab_num"); 3400Sstevel@tonic-gate return (DCMD_ERR); 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate mdb_printf("%<b>policy_tab = %p%</b> \tpolicy_tab_num = %d\n", 3430Sstevel@tonic-gate ptr, num); 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate tab = mdb_zalloc(policy_tab_max * sizeof (kcf_policy_desc_t *), 3460Sstevel@tonic-gate UM_SLEEP| UM_GC); 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate if (mdb_vread(tab, policy_tab_max * sizeof (kcf_policy_desc_t *), 3490Sstevel@tonic-gate (uintptr_t)ptr) == -1) { 3500Sstevel@tonic-gate mdb_warn("cannot read policy_tab"); 3510Sstevel@tonic-gate return (DCMD_ERR); 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate #ifdef DEBUG 3540Sstevel@tonic-gate mdb_printf("DEBUG: got past mdb_vread of tab\n"); 3550Sstevel@tonic-gate mdb_printf("DEBUG: *tab = %p\n", *tab); 3560Sstevel@tonic-gate #endif 3570Sstevel@tonic-gate for (i = 0; i < policy_tab_max; i++) { 3580Sstevel@tonic-gate /* save space, only print range for long list of nulls */ 3590Sstevel@tonic-gate if (tab[i] == NULL) { 3600Sstevel@tonic-gate if (gotzero == GOT_NONE) { 3610Sstevel@tonic-gate mdb_printf("policy_tab[%d", i); 3620Sstevel@tonic-gate gotzero = i; 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate } else { 3650Sstevel@tonic-gate /* first non-null in awhile, print index of prev null */ 3660Sstevel@tonic-gate if (gotzero != GOT_NONE) { 3670Sstevel@tonic-gate if (gotzero == (i - 1)) 3680Sstevel@tonic-gate mdb_printf("] = NULL\n", i - 1); 3690Sstevel@tonic-gate else 3700Sstevel@tonic-gate mdb_printf(" - %d] = NULL\n", i - 1); 3710Sstevel@tonic-gate gotzero = GOT_NONE; 3720Sstevel@tonic-gate } 3730Sstevel@tonic-gate /* interesting value, print it */ 3740Sstevel@tonic-gate mdb_printf("policy_tab[%d] = %p\n", i, tab[i]); 3750Sstevel@tonic-gate } 3760Sstevel@tonic-gate } 3770Sstevel@tonic-gate /* if we've printed the first of many nulls but left the brace open */ 3780Sstevel@tonic-gate if ((i > 0) && (tab[i-1] == NULL)) { 3790Sstevel@tonic-gate if (gotzero == GOT_NONE) 3800Sstevel@tonic-gate mdb_printf("] = NULL\n"); 3810Sstevel@tonic-gate else 3820Sstevel@tonic-gate mdb_printf(" - %d] = NULL\n", i - 1); 3830Sstevel@tonic-gate } 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate return (DCMD_OK); 3860Sstevel@tonic-gate } 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate static void 3890Sstevel@tonic-gate prt_mechs(int count, crypto_mech_name_t *mechs) 3900Sstevel@tonic-gate { 3910Sstevel@tonic-gate int i; 3920Sstevel@tonic-gate char name[CRYPTO_MAX_MECH_NAME + 1]; 3930Sstevel@tonic-gate char name2[CRYPTO_MAX_MECH_NAME + 3]; 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate for (i = 0; i < count; i++) { 3960Sstevel@tonic-gate if (mdb_readstr(name, CRYPTO_MAX_MECH_NAME, 3970Sstevel@tonic-gate (uintptr_t)((char *)mechs)) == -1) 3980Sstevel@tonic-gate continue; 3990Sstevel@tonic-gate /* put in quotes */ 4000Sstevel@tonic-gate (void) mdb_snprintf(name2, sizeof (name2), "\"%s\"", name); 4010Sstevel@tonic-gate /* yes, length is 32, but then it will wrap */ 4020Sstevel@tonic-gate /* this shorter size formats nicely for most cases */ 4030Sstevel@tonic-gate mdb_printf("mechs[%d]=%-28s", i, name2); 4040Sstevel@tonic-gate mdb_printf("%s", i%2 ? "\n" : " "); /* 2-columns */ 4050Sstevel@tonic-gate mechs++; 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate } 4080Sstevel@tonic-gate 4090Sstevel@tonic-gate /* ARGSUSED2 */ 4100Sstevel@tonic-gate static int 4110Sstevel@tonic-gate prt_soft_conf_entry(kcf_soft_conf_entry_t *addr, kcf_soft_conf_entry_t *entry, 4120Sstevel@tonic-gate void *cbdata) 4130Sstevel@tonic-gate { 4140Sstevel@tonic-gate char name[MAXNAMELEN + 1]; 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate mdb_printf("\n%<b>kcf_soft_conf_entry_t at %p:%</b>\n", addr); 4170Sstevel@tonic-gate mdb_printf("ce_next: %p", entry->ce_next); 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate if (entry->ce_name == NULL) 4200Sstevel@tonic-gate mdb_printf("\tce_name: NULL\n"); 4210Sstevel@tonic-gate else if (mdb_readstr(name, MAXNAMELEN, (uintptr_t)entry->ce_name) 4220Sstevel@tonic-gate == -1) 4230Sstevel@tonic-gate mdb_printf("could not read ce_name from %p\n", 4240Sstevel@tonic-gate entry->ce_name); 4250Sstevel@tonic-gate else 4260Sstevel@tonic-gate mdb_printf("\tce_name: %s\n", name); 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate mdb_printf("ce_count: %d\n", entry->ce_count); 4290Sstevel@tonic-gate prt_mechs(entry->ce_count, entry->ce_mechs); 4300Sstevel@tonic-gate return (WALK_NEXT); 4310Sstevel@tonic-gate } 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate int 4340Sstevel@tonic-gate soft_conf_walk_init(mdb_walk_state_t *wsp) 4350Sstevel@tonic-gate { 4360Sstevel@tonic-gate uintptr_t *soft; 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate if (mdb_readsym(&soft, sizeof (kcf_soft_conf_entry_t *), 4390Sstevel@tonic-gate "soft_config_list") == -1) { 4400Sstevel@tonic-gate mdb_warn("failed to find 'soft_config_list'"); 4410Sstevel@tonic-gate return (WALK_ERR); 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)soft; 4440Sstevel@tonic-gate wsp->walk_data = mdb_alloc(sizeof (kcf_soft_conf_entry_t), UM_SLEEP); 4450Sstevel@tonic-gate wsp->walk_callback = (mdb_walk_cb_t)prt_soft_conf_entry; 4460Sstevel@tonic-gate return (WALK_NEXT); 4470Sstevel@tonic-gate } 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate /* 4500Sstevel@tonic-gate * At each step, read a kcf_soft_conf_entry_t into our private storage, then 4510Sstevel@tonic-gate * invoke the callback function. We terminate when we reach a NULL ce_next 4520Sstevel@tonic-gate * pointer. 4530Sstevel@tonic-gate */ 4540Sstevel@tonic-gate int 4550Sstevel@tonic-gate soft_conf_walk_step(mdb_walk_state_t *wsp) 4560Sstevel@tonic-gate { 4570Sstevel@tonic-gate int status; 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate if (wsp->walk_addr == NULL) /* then we're done */ 4600Sstevel@tonic-gate return (WALK_DONE); 4610Sstevel@tonic-gate #ifdef DEBUG 4620Sstevel@tonic-gate else 4630Sstevel@tonic-gate mdb_printf("DEBUG: wsp->walk_addr == %p\n", wsp->walk_addr); 4640Sstevel@tonic-gate #endif 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate if (mdb_vread(wsp->walk_data, sizeof (kcf_soft_conf_entry_t), 4670Sstevel@tonic-gate wsp->walk_addr) == -1) { 4680Sstevel@tonic-gate mdb_warn("failed to read kcf_soft_conf_entry at %p", 4690Sstevel@tonic-gate wsp->walk_addr); 4700Sstevel@tonic-gate return (WALK_DONE); 4710Sstevel@tonic-gate } 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data, 4740Sstevel@tonic-gate wsp->walk_cbdata); 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate wsp->walk_addr = 4770Sstevel@tonic-gate (uintptr_t)(((kcf_soft_conf_entry_t *)wsp->walk_data)->ce_next); 4780Sstevel@tonic-gate return (status); 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate /* 4820Sstevel@tonic-gate * The walker's fini function is invoked at the end of each walk. Since we 4830Sstevel@tonic-gate * dynamically allocated a kcf_soft_conf_entry_t in soft_conf_walk_init, 4840Sstevel@tonic-gate * we must free it now. 4850Sstevel@tonic-gate */ 4860Sstevel@tonic-gate void 4870Sstevel@tonic-gate soft_conf_walk_fini(mdb_walk_state_t *wsp) 4880Sstevel@tonic-gate { 4890Sstevel@tonic-gate #ifdef DEBUG 4900Sstevel@tonic-gate mdb_printf("...end of kcf_soft_conf_entry walk\n"); 4910Sstevel@tonic-gate #endif 4920Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (kcf_soft_conf_entry_t)); 4930Sstevel@tonic-gate } 4940Sstevel@tonic-gate /* ARGSUSED2 */ 4950Sstevel@tonic-gate int 4960Sstevel@tonic-gate kcf_soft_conf_entry(uintptr_t addr, uint_t flags, int argc, 4970Sstevel@tonic-gate const mdb_arg_t *argv) 4980Sstevel@tonic-gate { 4990Sstevel@tonic-gate kcf_soft_conf_entry_t entry; 5000Sstevel@tonic-gate kcf_soft_conf_entry_t *ptr; 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) { 5030Sstevel@tonic-gate if (addr == NULL) /* not allowed with DCMD_ADDRSPEC */ 5040Sstevel@tonic-gate return (DCMD_USAGE); 5050Sstevel@tonic-gate else 5060Sstevel@tonic-gate ptr = (kcf_soft_conf_entry_t *)addr; 5070Sstevel@tonic-gate } else if (mdb_readsym(&ptr, sizeof (void *), "soft_config_list") 5080Sstevel@tonic-gate == -1) { 5090Sstevel@tonic-gate mdb_warn("cannot read soft_config_list"); 5100Sstevel@tonic-gate return (DCMD_ERR); 5110Sstevel@tonic-gate } else 5120Sstevel@tonic-gate mdb_printf("soft_config_list = %p\n", ptr); 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate if (ptr == NULL) 5150Sstevel@tonic-gate return (DCMD_OK); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate if (mdb_vread(&entry, sizeof (kcf_soft_conf_entry_t), (uintptr_t)ptr) 5180Sstevel@tonic-gate == -1) { 5190Sstevel@tonic-gate mdb_warn("cannot read at address %p", (uintptr_t)ptr); 5200Sstevel@tonic-gate return (DCMD_ERR); 5210Sstevel@tonic-gate } 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate /* this could change in the future to have more than one ret val */ 5240Sstevel@tonic-gate if (prt_soft_conf_entry(ptr, &entry, NULL) != WALK_ERR) 5250Sstevel@tonic-gate return (DCMD_OK); 5260Sstevel@tonic-gate return (DCMD_ERR); 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate /* ARGSUSED1 */ 5300Sstevel@tonic-gate int 5310Sstevel@tonic-gate kcf_policy_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5320Sstevel@tonic-gate { 5330Sstevel@tonic-gate kcf_policy_desc_t desc; 5340Sstevel@tonic-gate char name[MAXNAMELEN + 1]; 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) != DCMD_ADDRSPEC) 5380Sstevel@tonic-gate return (DCMD_USAGE); 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate if (mdb_vread(&desc, sizeof (kcf_policy_desc_t), (uintptr_t)addr) 5410Sstevel@tonic-gate == -1) { 5420Sstevel@tonic-gate mdb_warn("Could not read kcf_policy_desc_t at %p\n", addr); 5430Sstevel@tonic-gate return (DCMD_ERR); 5440Sstevel@tonic-gate } 5450Sstevel@tonic-gate mdb_printf("pd_prov_type: %s", 5460Sstevel@tonic-gate desc.pd_prov_type == CRYPTO_HW_PROVIDER ? "CRYPTO_HW_PROVIDER" 5470Sstevel@tonic-gate : "CRYPTO_SW_PROVIDER"); 5480Sstevel@tonic-gate 5490Sstevel@tonic-gate if (desc.pd_name == NULL) 5500Sstevel@tonic-gate mdb_printf("\tpd_name: NULL\n"); 5510Sstevel@tonic-gate else if (mdb_readstr(name, MAXNAMELEN, (uintptr_t)desc.pd_name) 5520Sstevel@tonic-gate == -1) 5530Sstevel@tonic-gate mdb_printf("could not read pd_name from %p\n", 5540Sstevel@tonic-gate desc.pd_name); 5550Sstevel@tonic-gate else 5560Sstevel@tonic-gate mdb_printf("\tpd_name: %s\n", name); 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate mdb_printf("pd_instance: %d ", desc.pd_instance); 5590Sstevel@tonic-gate mdb_printf("\t\tpd_refcnt: %d\n", desc.pd_refcnt); 5600Sstevel@tonic-gate mdb_printf("pd_mutex: %p", desc.pd_mutex); 5610Sstevel@tonic-gate mdb_printf("\t\tpd_disabled_count: %d", desc.pd_disabled_count); 5620Sstevel@tonic-gate mdb_printf("\npd_disabled_mechs:\n"); 5630Sstevel@tonic-gate mdb_inc_indent(4); 5640Sstevel@tonic-gate prt_mechs(desc.pd_disabled_count, desc.pd_disabled_mechs); 5650Sstevel@tonic-gate mdb_dec_indent(4); 5660Sstevel@tonic-gate return (DCMD_OK); 5670Sstevel@tonic-gate } 568