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 53708Skrishna * Common Development and Distribution License (the "License"). 63708Skrishna * 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*12304SValerie.Fenwick@Oracle.COM * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate /* 260Sstevel@tonic-gate * mdb dcmds for selected structures from 270Sstevel@tonic-gate * usr/src/uts/common/sys/crypto/impl.h 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate #include <stdio.h> 300Sstevel@tonic-gate #include <sys/mdb_modapi.h> 310Sstevel@tonic-gate #include <sys/modctl.h> 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/crypto/api.h> 340Sstevel@tonic-gate #include <sys/crypto/common.h> 350Sstevel@tonic-gate #include <sys/crypto/impl.h> 360Sstevel@tonic-gate #include "crypto_cmds.h" 370Sstevel@tonic-gate 380Sstevel@tonic-gate static const char *prov_states[] = { 390Sstevel@tonic-gate "none", 400Sstevel@tonic-gate "KCF_PROV_ALLOCATED", 410Sstevel@tonic-gate "KCF_PROV_UNVERIFIED", 424373Skrishna "KCF_PROV_VERIFICATION_FAILED", 430Sstevel@tonic-gate "KCF_PROV_READY", 440Sstevel@tonic-gate "KCF_PROV_BUSY", 450Sstevel@tonic-gate "KCF_PROV_FAILED", 460Sstevel@tonic-gate "KCF_PROV_DISABLED", 479505SBhargava.Yenduri@Sun.COM "KCF_PROV_UNREGISTERING", 489505SBhargava.Yenduri@Sun.COM "KCF_PROV_UNREGISTERED" 490Sstevel@tonic-gate }; 500Sstevel@tonic-gate 510Sstevel@tonic-gate /*ARGSUSED*/ 520Sstevel@tonic-gate int 530Sstevel@tonic-gate kcf_provider_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 540Sstevel@tonic-gate { 550Sstevel@tonic-gate kcf_provider_desc_t desc; 560Sstevel@tonic-gate kcf_provider_desc_t *ptr; 570Sstevel@tonic-gate char string[MAXNAMELEN + 1]; 580Sstevel@tonic-gate int i, j; 590Sstevel@tonic-gate crypto_mech_info_t *mech_pointer; 609505SBhargava.Yenduri@Sun.COM kcf_prov_cpu_t stats; 619505SBhargava.Yenduri@Sun.COM uint64_t dtotal, ftotal, btotal; 629505SBhargava.Yenduri@Sun.COM int holdcnt, jobcnt; 630Sstevel@tonic-gate 640Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) != DCMD_ADDRSPEC) 650Sstevel@tonic-gate return (DCMD_USAGE); 660Sstevel@tonic-gate ptr = (kcf_provider_desc_t *)addr; 670Sstevel@tonic-gate 680Sstevel@tonic-gate #ifdef DEBUG 690Sstevel@tonic-gate mdb_printf("DEBUG: reading kcf_provider_desc at %p\n", ptr); 700Sstevel@tonic-gate #endif 710Sstevel@tonic-gate 720Sstevel@tonic-gate if (mdb_vread(&desc, sizeof (kcf_provider_desc_t), (uintptr_t)ptr) 730Sstevel@tonic-gate == -1) { 748384SBhargava.Yenduri@Sun.COM mdb_warn("cannot read at address %p", (uintptr_t)ptr); 758384SBhargava.Yenduri@Sun.COM return (DCMD_ERR); 760Sstevel@tonic-gate } 770Sstevel@tonic-gate mdb_printf("%<b>kcf_provider_desc at %p%</b>\n", ptr); 780Sstevel@tonic-gate 790Sstevel@tonic-gate switch (desc.pd_prov_type) { 800Sstevel@tonic-gate case CRYPTO_HW_PROVIDER: 810Sstevel@tonic-gate mdb_printf("pd_prov_type:\t\tCRYPTO_HW_PROVIDER\n"); 820Sstevel@tonic-gate break; 830Sstevel@tonic-gate case CRYPTO_SW_PROVIDER: 840Sstevel@tonic-gate mdb_printf("pd_prov_type:\t\tCRYPTO_SW_PROVIDER\n"); 850Sstevel@tonic-gate break; 860Sstevel@tonic-gate case CRYPTO_LOGICAL_PROVIDER: 870Sstevel@tonic-gate mdb_printf("pd_prov_type:\t\tCRYPTO_LOGICAL_PROVIDER\n"); 880Sstevel@tonic-gate break; 890Sstevel@tonic-gate default: 900Sstevel@tonic-gate mdb_printf("bad pd_prov_type:\t%d\n", desc.pd_prov_type); 910Sstevel@tonic-gate } 920Sstevel@tonic-gate 930Sstevel@tonic-gate mdb_printf("pd_prov_id:\t\t%u\n", desc.pd_prov_id); 940Sstevel@tonic-gate if (desc.pd_description == NULL) 950Sstevel@tonic-gate mdb_printf("pd_description:\t\tNULL\n"); 960Sstevel@tonic-gate else if (mdb_readstr(string, MAXNAMELEN + 1, 978384SBhargava.Yenduri@Sun.COM (uintptr_t)desc.pd_description) == -1) { 980Sstevel@tonic-gate mdb_warn("cannot read %p", desc.pd_description); 990Sstevel@tonic-gate } else 1008384SBhargava.Yenduri@Sun.COM mdb_printf("pd_description:\t\t%s\n", string); 1010Sstevel@tonic-gate 1029505SBhargava.Yenduri@Sun.COM mdb_printf("pd_sid:\t\t\t%u\n", desc.pd_sid); 1039505SBhargava.Yenduri@Sun.COM mdb_printf("pd_taskq:\t\t%p\n", desc.pd_taskq); 1049505SBhargava.Yenduri@Sun.COM mdb_printf("pd_nbins:\t\t%u\n", desc.pd_nbins); 1059505SBhargava.Yenduri@Sun.COM mdb_printf("pd_percpu_bins:\t\t%p\n", desc.pd_percpu_bins); 1069505SBhargava.Yenduri@Sun.COM 1079505SBhargava.Yenduri@Sun.COM dtotal = ftotal = btotal = 0; 1089505SBhargava.Yenduri@Sun.COM holdcnt = jobcnt = 0; 1099505SBhargava.Yenduri@Sun.COM for (i = 0; i < desc.pd_nbins; i++) { 1109505SBhargava.Yenduri@Sun.COM if (mdb_vread(&stats, sizeof (kcf_prov_cpu_t), 1119505SBhargava.Yenduri@Sun.COM (uintptr_t)(desc.pd_percpu_bins + i)) == -1) { 1129505SBhargava.Yenduri@Sun.COM mdb_warn("cannot read addr %p", 1139505SBhargava.Yenduri@Sun.COM desc.pd_percpu_bins + i); 1149505SBhargava.Yenduri@Sun.COM return (DCMD_ERR); 1159505SBhargava.Yenduri@Sun.COM } 1169505SBhargava.Yenduri@Sun.COM 1179505SBhargava.Yenduri@Sun.COM holdcnt += stats.kp_holdcnt; 1189505SBhargava.Yenduri@Sun.COM jobcnt += stats.kp_jobcnt; 1199505SBhargava.Yenduri@Sun.COM dtotal += stats.kp_ndispatches; 1209505SBhargava.Yenduri@Sun.COM ftotal += stats.kp_nfails; 1219505SBhargava.Yenduri@Sun.COM btotal += stats.kp_nbusy_rval; 1229505SBhargava.Yenduri@Sun.COM } 1239505SBhargava.Yenduri@Sun.COM mdb_inc_indent(4); 1249505SBhargava.Yenduri@Sun.COM mdb_printf("total kp_holdcnt:\t\t%d\n", holdcnt); 1259505SBhargava.Yenduri@Sun.COM mdb_printf("total kp_jobcnt:\t\t%u\n", jobcnt); 1269505SBhargava.Yenduri@Sun.COM mdb_printf("total kp_ndispatches:\t%llu\n", dtotal); 1279505SBhargava.Yenduri@Sun.COM mdb_printf("total kp_nfails:\t\t%llu\n", ftotal); 1289505SBhargava.Yenduri@Sun.COM mdb_printf("total kp_nbusy_rval:\t%llu\n", btotal); 1299505SBhargava.Yenduri@Sun.COM mdb_dec_indent(4); 1309505SBhargava.Yenduri@Sun.COM 1319505SBhargava.Yenduri@Sun.COM mdb_printf("pd_prov_handle:\t\t%p\n", desc.pd_prov_handle); 1329505SBhargava.Yenduri@Sun.COM mdb_printf("pd_kcf_prov_handle:\t%u\n", desc.pd_kcf_prov_handle); 1339505SBhargava.Yenduri@Sun.COM 1340Sstevel@tonic-gate mdb_printf("pd_ops_vector:\t\t%p\n", desc.pd_ops_vector); 1350Sstevel@tonic-gate mdb_printf("pd_mech_list_count:\t%u\n", desc.pd_mech_list_count); 1360Sstevel@tonic-gate /* mechanisms */ 1370Sstevel@tonic-gate mdb_inc_indent(4); 1380Sstevel@tonic-gate for (i = 0; i < desc.pd_mech_list_count; i++) { 1390Sstevel@tonic-gate mech_pointer = desc.pd_mechanisms + i; 1400Sstevel@tonic-gate mdb_call_dcmd("crypto_mech_info", 1418384SBhargava.Yenduri@Sun.COM (uintptr_t)mech_pointer, DCMD_ADDRSPEC, 0, NULL); 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate mdb_dec_indent(4); 1443708Skrishna mdb_printf("pd_mech_indx:\n"); 1450Sstevel@tonic-gate mdb_inc_indent(8); 1460Sstevel@tonic-gate for (i = 0; i < KCF_OPS_CLASSSIZE; i++) { 1478384SBhargava.Yenduri@Sun.COM for (j = 0; j < KCF_MAXMECHTAB; j++) { 1488384SBhargava.Yenduri@Sun.COM if (desc.pd_mech_indx[i][j] == KCF_INVALID_INDX) 1498384SBhargava.Yenduri@Sun.COM mdb_printf("N "); 1508384SBhargava.Yenduri@Sun.COM else 1518384SBhargava.Yenduri@Sun.COM mdb_printf("%u ", desc.pd_mech_indx[i][j]); 1528384SBhargava.Yenduri@Sun.COM } 1538384SBhargava.Yenduri@Sun.COM mdb_printf("\n"); 1540Sstevel@tonic-gate } 1550Sstevel@tonic-gate mdb_dec_indent(8); 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate if (desc.pd_name == NULL) 1588384SBhargava.Yenduri@Sun.COM mdb_printf("pd_name:\t\t NULL\n"); 1590Sstevel@tonic-gate else if (mdb_readstr(string, MAXNAMELEN + 1, (uintptr_t)desc.pd_name) 1608384SBhargava.Yenduri@Sun.COM == -1) 1610Sstevel@tonic-gate mdb_warn("could not read pd_name from %X\n", desc.pd_name); 1620Sstevel@tonic-gate else 1638384SBhargava.Yenduri@Sun.COM mdb_printf("pd_name:\t\t%s\n", string); 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate mdb_printf("pd_instance:\t\t%u\n", desc.pd_instance); 1660Sstevel@tonic-gate mdb_printf("pd_module_id:\t\t%d\n", desc.pd_module_id); 1670Sstevel@tonic-gate mdb_printf("pd_mctlp:\t\t%p\n", desc.pd_mctlp); 1680Sstevel@tonic-gate mdb_printf("pd_lock:\t\t%p\n", desc.pd_lock); 1690Sstevel@tonic-gate if (desc.pd_state < KCF_PROV_ALLOCATED || 1709505SBhargava.Yenduri@Sun.COM desc.pd_state > KCF_PROV_UNREGISTERED) 1710Sstevel@tonic-gate mdb_printf("pd_state is invalid:\t%d\n", desc.pd_state); 1720Sstevel@tonic-gate else 1730Sstevel@tonic-gate mdb_printf("pd_state:\t%s\n", prov_states[desc.pd_state]); 1749505SBhargava.Yenduri@Sun.COM mdb_printf("pd_provider_list:\t%p\n", desc.pd_provider_list); 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate mdb_printf("pd_resume_cv:\t\t%hd\n", desc.pd_resume_cv._opaque); 177*12304SValerie.Fenwick@Oracle.COM mdb_printf("pd_flags:\t\t%s %s %s %s %s\n", 1783708Skrishna (desc.pd_flags & CRYPTO_HIDE_PROVIDER) ? 1798384SBhargava.Yenduri@Sun.COM "CRYPTO_HIDE_PROVIDER" : " ", 1804072Skrishna (desc.pd_flags & CRYPTO_HASH_NO_UPDATE) ? 1818384SBhargava.Yenduri@Sun.COM "CRYPTO_HASH_NO_UPDATE" : " ", 18211304SJanie.Lu@Sun.COM (desc.pd_flags & CRYPTO_HMAC_NO_UPDATE) ? 18311304SJanie.Lu@Sun.COM "CRYPTO_HMAC_NO_UPDATE" : " ", 1848384SBhargava.Yenduri@Sun.COM (desc.pd_flags & CRYPTO_SYNCHRONOUS) ? 1858384SBhargava.Yenduri@Sun.COM "CRYPTO_SYNCHRONOUS" : " ", 1863708Skrishna (desc.pd_flags & KCF_LPROV_MEMBER) ? 187*12304SValerie.Fenwick@Oracle.COM "KCF_LPROV_MEMBER" : " "); 1884072Skrishna if (desc.pd_flags & CRYPTO_HASH_NO_UPDATE) 1894072Skrishna mdb_printf("pd_hash_limit:\t\t%u\n", desc.pd_hash_limit); 19011304SJanie.Lu@Sun.COM if (desc.pd_flags & CRYPTO_HMAC_NO_UPDATE) 19111304SJanie.Lu@Sun.COM mdb_printf("pd_hmac_limit:\t\t%u\n", desc.pd_hmac_limit); 1929505SBhargava.Yenduri@Sun.COM 1939505SBhargava.Yenduri@Sun.COM mdb_printf("pd_kstat:\t\t%p\n", desc.pd_kstat); 1949505SBhargava.Yenduri@Sun.COM 1950Sstevel@tonic-gate return (DCMD_OK); 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate #define GOT_NONE (-2) 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /*ARGSUSED*/ 2010Sstevel@tonic-gate int 2020Sstevel@tonic-gate prov_tab(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2030Sstevel@tonic-gate { 2040Sstevel@tonic-gate kcf_provider_desc_t **tab; 2050Sstevel@tonic-gate kcf_provider_desc_t desc; 2060Sstevel@tonic-gate kcf_provider_desc_t *ptr; 2070Sstevel@tonic-gate uint_t prov_tab_max; 2080Sstevel@tonic-gate int i; 2090Sstevel@tonic-gate int gotzero = GOT_NONE; 2100Sstevel@tonic-gate char string[MAXNAMELEN + 1]; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) { 2130Sstevel@tonic-gate return (DCMD_USAGE); 2140Sstevel@tonic-gate } else if (mdb_readsym(&ptr, sizeof (void *), "prov_tab") 2150Sstevel@tonic-gate == -1) { 2160Sstevel@tonic-gate mdb_warn("cannot read prov_tab"); 2170Sstevel@tonic-gate return (DCMD_ERR); 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate } else if (mdb_readvar(&prov_tab_max, "prov_tab_max") == -1) { 2200Sstevel@tonic-gate mdb_warn("cannot read prov_tab_max"); 2210Sstevel@tonic-gate return (DCMD_ERR); 2220Sstevel@tonic-gate } 2230Sstevel@tonic-gate mdb_printf("%<b>prov_tab = %p%</b>\n", ptr); 2240Sstevel@tonic-gate tab = mdb_zalloc(prov_tab_max * sizeof (kcf_provider_desc_t *), 2250Sstevel@tonic-gate UM_SLEEP| UM_GC); 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate #ifdef DEBUG 2280Sstevel@tonic-gate mdb_printf("DEBUG: tab = %p, prov_tab_max = %d\n", tab, prov_tab_max); 2290Sstevel@tonic-gate #endif 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate if (mdb_vread(tab, prov_tab_max * sizeof (kcf_provider_desc_t *), 2320Sstevel@tonic-gate (uintptr_t)ptr) == -1) { 2330Sstevel@tonic-gate mdb_warn("cannot read prov_tab"); 2340Sstevel@tonic-gate return (DCMD_ERR); 2350Sstevel@tonic-gate } 2360Sstevel@tonic-gate #ifdef DEBUG 2370Sstevel@tonic-gate mdb_printf("DEBUG: got past mdb_vread of tab\n"); 2380Sstevel@tonic-gate mdb_printf("DEBUG: *tab = %p\n", *tab); 2390Sstevel@tonic-gate #endif 2400Sstevel@tonic-gate for (i = 0; i < prov_tab_max; i++) { 2410Sstevel@tonic-gate /* save space, only print range for long list of nulls */ 2420Sstevel@tonic-gate if (tab[i] == NULL) { 2430Sstevel@tonic-gate if (gotzero == GOT_NONE) { 2448384SBhargava.Yenduri@Sun.COM mdb_printf("prov_tab[%d", i); 2458384SBhargava.Yenduri@Sun.COM gotzero = i; 2460Sstevel@tonic-gate } 2470Sstevel@tonic-gate } else { 2480Sstevel@tonic-gate /* first non-null in awhile, print index of prev null */ 2490Sstevel@tonic-gate if (gotzero != GOT_NONE) { 2500Sstevel@tonic-gate if (gotzero == (i - 1)) 2510Sstevel@tonic-gate mdb_printf("] = NULL\n", i - 1); 2520Sstevel@tonic-gate else 2530Sstevel@tonic-gate mdb_printf(" - %d] = NULL\n", i - 1); 2540Sstevel@tonic-gate gotzero = GOT_NONE; 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate /* interesting value, print it */ 2570Sstevel@tonic-gate mdb_printf("prov_tab[%d] = %p ", i, tab[i]); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate if (mdb_vread(&desc, sizeof (kcf_provider_desc_t), 2600Sstevel@tonic-gate (uintptr_t)tab[i]) == -1) { 2610Sstevel@tonic-gate mdb_warn("cannot read at address %p", 2620Sstevel@tonic-gate (uintptr_t)tab[i]); 2630Sstevel@tonic-gate return (DCMD_ERR); 2640Sstevel@tonic-gate } 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate (void) mdb_readstr(string, MAXNAMELEN + 1, 2670Sstevel@tonic-gate (uintptr_t)desc.pd_name); 2680Sstevel@tonic-gate mdb_printf("(%s\t%s)\n", string, 2690Sstevel@tonic-gate prov_states[desc.pd_state]); 2700Sstevel@tonic-gate } 2710Sstevel@tonic-gate } 2720Sstevel@tonic-gate /* if we've printed the first of many nulls but left the brace open */ 2730Sstevel@tonic-gate if ((i > 0) && (tab[i-1] == NULL)) { 2740Sstevel@tonic-gate if (gotzero == GOT_NONE) 2750Sstevel@tonic-gate mdb_printf("] = NULL\n"); 2760Sstevel@tonic-gate else 2770Sstevel@tonic-gate mdb_printf(" - %d] = NULL\n", i - 1); 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate return (DCMD_OK); 2810Sstevel@tonic-gate } 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate /*ARGSUSED*/ 2840Sstevel@tonic-gate int 2850Sstevel@tonic-gate policy_tab(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2860Sstevel@tonic-gate { 2870Sstevel@tonic-gate kcf_policy_desc_t **tab; 2880Sstevel@tonic-gate kcf_policy_desc_t *ptr; 2890Sstevel@tonic-gate uint_t policy_tab_max; 2900Sstevel@tonic-gate int num, i; 2910Sstevel@tonic-gate int gotzero = GOT_NONE; 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) { 2940Sstevel@tonic-gate return (DCMD_USAGE); 2950Sstevel@tonic-gate } else if (mdb_readsym(&ptr, sizeof (void *), "policy_tab") 2960Sstevel@tonic-gate == -1) { 2970Sstevel@tonic-gate mdb_warn("cannot read policy_tab"); 2980Sstevel@tonic-gate return (DCMD_ERR); 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate } else if (mdb_readvar(&policy_tab_max, "policy_tab_max") == -1) { 3010Sstevel@tonic-gate mdb_warn("cannot read policy_tab_max"); 3020Sstevel@tonic-gate return (DCMD_ERR); 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate /* get the current number of descriptors in the table */ 3060Sstevel@tonic-gate if (mdb_readvar(&num, "policy_tab_num") == -1) { 3070Sstevel@tonic-gate mdb_warn("cannot read policy_tab_num"); 3080Sstevel@tonic-gate return (DCMD_ERR); 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate mdb_printf("%<b>policy_tab = %p%</b> \tpolicy_tab_num = %d\n", 3110Sstevel@tonic-gate ptr, num); 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate tab = mdb_zalloc(policy_tab_max * sizeof (kcf_policy_desc_t *), 3140Sstevel@tonic-gate UM_SLEEP| UM_GC); 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate if (mdb_vread(tab, policy_tab_max * sizeof (kcf_policy_desc_t *), 3170Sstevel@tonic-gate (uintptr_t)ptr) == -1) { 3180Sstevel@tonic-gate mdb_warn("cannot read policy_tab"); 3190Sstevel@tonic-gate return (DCMD_ERR); 3200Sstevel@tonic-gate } 3210Sstevel@tonic-gate #ifdef DEBUG 3220Sstevel@tonic-gate mdb_printf("DEBUG: got past mdb_vread of tab\n"); 3230Sstevel@tonic-gate mdb_printf("DEBUG: *tab = %p\n", *tab); 3240Sstevel@tonic-gate #endif 3250Sstevel@tonic-gate for (i = 0; i < policy_tab_max; i++) { 3260Sstevel@tonic-gate /* save space, only print range for long list of nulls */ 3270Sstevel@tonic-gate if (tab[i] == NULL) { 3280Sstevel@tonic-gate if (gotzero == GOT_NONE) { 3298384SBhargava.Yenduri@Sun.COM mdb_printf("policy_tab[%d", i); 3308384SBhargava.Yenduri@Sun.COM gotzero = i; 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate } else { 3330Sstevel@tonic-gate /* first non-null in awhile, print index of prev null */ 3340Sstevel@tonic-gate if (gotzero != GOT_NONE) { 3350Sstevel@tonic-gate if (gotzero == (i - 1)) 3360Sstevel@tonic-gate mdb_printf("] = NULL\n", i - 1); 3370Sstevel@tonic-gate else 3380Sstevel@tonic-gate mdb_printf(" - %d] = NULL\n", i - 1); 3390Sstevel@tonic-gate gotzero = GOT_NONE; 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate /* interesting value, print it */ 3420Sstevel@tonic-gate mdb_printf("policy_tab[%d] = %p\n", i, tab[i]); 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate /* if we've printed the first of many nulls but left the brace open */ 3460Sstevel@tonic-gate if ((i > 0) && (tab[i-1] == NULL)) { 3470Sstevel@tonic-gate if (gotzero == GOT_NONE) 3480Sstevel@tonic-gate mdb_printf("] = NULL\n"); 3490Sstevel@tonic-gate else 3500Sstevel@tonic-gate mdb_printf(" - %d] = NULL\n", i - 1); 3510Sstevel@tonic-gate } 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate return (DCMD_OK); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate static void 3570Sstevel@tonic-gate prt_mechs(int count, crypto_mech_name_t *mechs) 3580Sstevel@tonic-gate { 3590Sstevel@tonic-gate int i; 3600Sstevel@tonic-gate char name[CRYPTO_MAX_MECH_NAME + 1]; 3610Sstevel@tonic-gate char name2[CRYPTO_MAX_MECH_NAME + 3]; 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate for (i = 0; i < count; i++) { 3640Sstevel@tonic-gate if (mdb_readstr(name, CRYPTO_MAX_MECH_NAME, 3650Sstevel@tonic-gate (uintptr_t)((char *)mechs)) == -1) 3660Sstevel@tonic-gate continue; 3670Sstevel@tonic-gate /* put in quotes */ 3680Sstevel@tonic-gate (void) mdb_snprintf(name2, sizeof (name2), "\"%s\"", name); 3690Sstevel@tonic-gate /* yes, length is 32, but then it will wrap */ 3700Sstevel@tonic-gate /* this shorter size formats nicely for most cases */ 3710Sstevel@tonic-gate mdb_printf("mechs[%d]=%-28s", i, name2); 3720Sstevel@tonic-gate mdb_printf("%s", i%2 ? "\n" : " "); /* 2-columns */ 3730Sstevel@tonic-gate mechs++; 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate } 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate /* ARGSUSED2 */ 3780Sstevel@tonic-gate static int 3790Sstevel@tonic-gate prt_soft_conf_entry(kcf_soft_conf_entry_t *addr, kcf_soft_conf_entry_t *entry, 3800Sstevel@tonic-gate void *cbdata) 3810Sstevel@tonic-gate { 3820Sstevel@tonic-gate char name[MAXNAMELEN + 1]; 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate mdb_printf("\n%<b>kcf_soft_conf_entry_t at %p:%</b>\n", addr); 3850Sstevel@tonic-gate mdb_printf("ce_next: %p", entry->ce_next); 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate if (entry->ce_name == NULL) 3888384SBhargava.Yenduri@Sun.COM mdb_printf("\tce_name: NULL\n"); 3890Sstevel@tonic-gate else if (mdb_readstr(name, MAXNAMELEN, (uintptr_t)entry->ce_name) 3908384SBhargava.Yenduri@Sun.COM == -1) 3910Sstevel@tonic-gate mdb_printf("could not read ce_name from %p\n", 3928384SBhargava.Yenduri@Sun.COM entry->ce_name); 3930Sstevel@tonic-gate else 3940Sstevel@tonic-gate mdb_printf("\tce_name: %s\n", name); 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate mdb_printf("ce_count: %d\n", entry->ce_count); 3970Sstevel@tonic-gate prt_mechs(entry->ce_count, entry->ce_mechs); 3980Sstevel@tonic-gate return (WALK_NEXT); 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate int 4020Sstevel@tonic-gate soft_conf_walk_init(mdb_walk_state_t *wsp) 4030Sstevel@tonic-gate { 4040Sstevel@tonic-gate uintptr_t *soft; 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate if (mdb_readsym(&soft, sizeof (kcf_soft_conf_entry_t *), 4070Sstevel@tonic-gate "soft_config_list") == -1) { 4080Sstevel@tonic-gate mdb_warn("failed to find 'soft_config_list'"); 4090Sstevel@tonic-gate return (WALK_ERR); 4100Sstevel@tonic-gate } 4110Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)soft; 4120Sstevel@tonic-gate wsp->walk_data = mdb_alloc(sizeof (kcf_soft_conf_entry_t), UM_SLEEP); 4130Sstevel@tonic-gate wsp->walk_callback = (mdb_walk_cb_t)prt_soft_conf_entry; 4140Sstevel@tonic-gate return (WALK_NEXT); 4150Sstevel@tonic-gate } 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate /* 4180Sstevel@tonic-gate * At each step, read a kcf_soft_conf_entry_t into our private storage, then 4190Sstevel@tonic-gate * invoke the callback function. We terminate when we reach a NULL ce_next 4200Sstevel@tonic-gate * pointer. 4210Sstevel@tonic-gate */ 4220Sstevel@tonic-gate int 4230Sstevel@tonic-gate soft_conf_walk_step(mdb_walk_state_t *wsp) 4240Sstevel@tonic-gate { 4250Sstevel@tonic-gate int status; 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate if (wsp->walk_addr == NULL) /* then we're done */ 4280Sstevel@tonic-gate return (WALK_DONE); 4290Sstevel@tonic-gate #ifdef DEBUG 4300Sstevel@tonic-gate else 4318384SBhargava.Yenduri@Sun.COM mdb_printf("DEBUG: wsp->walk_addr == %p\n", wsp->walk_addr); 4320Sstevel@tonic-gate #endif 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate if (mdb_vread(wsp->walk_data, sizeof (kcf_soft_conf_entry_t), 4350Sstevel@tonic-gate wsp->walk_addr) == -1) { 4360Sstevel@tonic-gate mdb_warn("failed to read kcf_soft_conf_entry at %p", 4370Sstevel@tonic-gate wsp->walk_addr); 4380Sstevel@tonic-gate return (WALK_DONE); 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data, 4420Sstevel@tonic-gate wsp->walk_cbdata); 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate wsp->walk_addr = 4450Sstevel@tonic-gate (uintptr_t)(((kcf_soft_conf_entry_t *)wsp->walk_data)->ce_next); 4460Sstevel@tonic-gate return (status); 4470Sstevel@tonic-gate } 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate /* 4500Sstevel@tonic-gate * The walker's fini function is invoked at the end of each walk. Since we 4510Sstevel@tonic-gate * dynamically allocated a kcf_soft_conf_entry_t in soft_conf_walk_init, 4520Sstevel@tonic-gate * we must free it now. 4530Sstevel@tonic-gate */ 4540Sstevel@tonic-gate void 4550Sstevel@tonic-gate soft_conf_walk_fini(mdb_walk_state_t *wsp) 4560Sstevel@tonic-gate { 4570Sstevel@tonic-gate #ifdef DEBUG 4580Sstevel@tonic-gate mdb_printf("...end of kcf_soft_conf_entry walk\n"); 4590Sstevel@tonic-gate #endif 4600Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (kcf_soft_conf_entry_t)); 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate /* ARGSUSED2 */ 4630Sstevel@tonic-gate int 4640Sstevel@tonic-gate kcf_soft_conf_entry(uintptr_t addr, uint_t flags, int argc, 4650Sstevel@tonic-gate const mdb_arg_t *argv) 4660Sstevel@tonic-gate { 4670Sstevel@tonic-gate kcf_soft_conf_entry_t entry; 4680Sstevel@tonic-gate kcf_soft_conf_entry_t *ptr; 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) { 4710Sstevel@tonic-gate if (addr == NULL) /* not allowed with DCMD_ADDRSPEC */ 4720Sstevel@tonic-gate return (DCMD_USAGE); 4730Sstevel@tonic-gate else 4740Sstevel@tonic-gate ptr = (kcf_soft_conf_entry_t *)addr; 4750Sstevel@tonic-gate } else if (mdb_readsym(&ptr, sizeof (void *), "soft_config_list") 4768384SBhargava.Yenduri@Sun.COM == -1) { 4778384SBhargava.Yenduri@Sun.COM mdb_warn("cannot read soft_config_list"); 4788384SBhargava.Yenduri@Sun.COM return (DCMD_ERR); 4790Sstevel@tonic-gate } else 4800Sstevel@tonic-gate mdb_printf("soft_config_list = %p\n", ptr); 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate if (ptr == NULL) 4830Sstevel@tonic-gate return (DCMD_OK); 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate if (mdb_vread(&entry, sizeof (kcf_soft_conf_entry_t), (uintptr_t)ptr) 4860Sstevel@tonic-gate == -1) { 4878384SBhargava.Yenduri@Sun.COM mdb_warn("cannot read at address %p", (uintptr_t)ptr); 4888384SBhargava.Yenduri@Sun.COM return (DCMD_ERR); 4890Sstevel@tonic-gate } 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate /* this could change in the future to have more than one ret val */ 4920Sstevel@tonic-gate if (prt_soft_conf_entry(ptr, &entry, NULL) != WALK_ERR) 4930Sstevel@tonic-gate return (DCMD_OK); 4940Sstevel@tonic-gate return (DCMD_ERR); 4950Sstevel@tonic-gate } 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate /* ARGSUSED1 */ 4980Sstevel@tonic-gate int 4990Sstevel@tonic-gate kcf_policy_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5000Sstevel@tonic-gate { 5010Sstevel@tonic-gate kcf_policy_desc_t desc; 5020Sstevel@tonic-gate char name[MAXNAMELEN + 1]; 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) != DCMD_ADDRSPEC) 5060Sstevel@tonic-gate return (DCMD_USAGE); 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate if (mdb_vread(&desc, sizeof (kcf_policy_desc_t), (uintptr_t)addr) 5090Sstevel@tonic-gate == -1) { 5100Sstevel@tonic-gate mdb_warn("Could not read kcf_policy_desc_t at %p\n", addr); 5110Sstevel@tonic-gate return (DCMD_ERR); 5120Sstevel@tonic-gate } 5130Sstevel@tonic-gate mdb_printf("pd_prov_type: %s", 5148384SBhargava.Yenduri@Sun.COM desc.pd_prov_type == CRYPTO_HW_PROVIDER ? "CRYPTO_HW_PROVIDER" : 5158384SBhargava.Yenduri@Sun.COM "CRYPTO_SW_PROVIDER"); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate if (desc.pd_name == NULL) 5180Sstevel@tonic-gate mdb_printf("\tpd_name: NULL\n"); 5190Sstevel@tonic-gate else if (mdb_readstr(name, MAXNAMELEN, (uintptr_t)desc.pd_name) 5200Sstevel@tonic-gate == -1) 5210Sstevel@tonic-gate mdb_printf("could not read pd_name from %p\n", 5220Sstevel@tonic-gate desc.pd_name); 5230Sstevel@tonic-gate else 5240Sstevel@tonic-gate mdb_printf("\tpd_name: %s\n", name); 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate mdb_printf("pd_instance: %d ", desc.pd_instance); 5270Sstevel@tonic-gate mdb_printf("\t\tpd_refcnt: %d\n", desc.pd_refcnt); 5280Sstevel@tonic-gate mdb_printf("pd_mutex: %p", desc.pd_mutex); 5290Sstevel@tonic-gate mdb_printf("\t\tpd_disabled_count: %d", desc.pd_disabled_count); 5300Sstevel@tonic-gate mdb_printf("\npd_disabled_mechs:\n"); 5310Sstevel@tonic-gate mdb_inc_indent(4); 5320Sstevel@tonic-gate prt_mechs(desc.pd_disabled_count, desc.pd_disabled_mechs); 5330Sstevel@tonic-gate mdb_dec_indent(4); 5340Sstevel@tonic-gate return (DCMD_OK); 5350Sstevel@tonic-gate } 536