dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / common / modules / crypto / impl.c
blobf596e1e24b0eb81c6cf67a02d386fd28ad19f04f
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
26 * mdb dcmds for selected structures from include/sys/crypto/impl.h
28 #include <stdio.h>
29 #include <sys/mdb_modapi.h>
30 #include <sys/modctl.h>
31 #include <sys/types.h>
32 #include <sys/crypto/api.h>
33 #include <sys/crypto/common.h>
34 #include <sys/crypto/impl.h>
35 #include "crypto_cmds.h"
37 static const char *prov_states[] = {
38 "none",
39 "KCF_PROV_ALLOCATED",
40 "KCF_PROV_UNVERIFIED",
41 "KCF_PROV_VERIFICATION_FAILED",
42 "KCF_PROV_READY",
43 "KCF_PROV_BUSY",
44 "KCF_PROV_FAILED",
45 "KCF_PROV_DISABLED",
46 "KCF_PROV_UNREGISTERING",
47 "KCF_PROV_UNREGISTERED"
50 /*ARGSUSED*/
51 int
52 kcf_provider_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
54 kcf_provider_desc_t desc;
55 kcf_provider_desc_t *ptr;
56 char string[MAXNAMELEN + 1];
57 int i, j;
58 crypto_mech_info_t *mech_pointer;
59 kcf_prov_cpu_t stats;
60 uint64_t dtotal, ftotal, btotal;
61 int holdcnt, jobcnt;
63 if ((flags & DCMD_ADDRSPEC) != DCMD_ADDRSPEC)
64 return (DCMD_USAGE);
65 ptr = (kcf_provider_desc_t *)addr;
67 #ifdef DEBUG
68 mdb_printf("DEBUG: reading kcf_provider_desc at %p\n", ptr);
69 #endif
71 if (mdb_vread(&desc, sizeof (kcf_provider_desc_t), (uintptr_t)ptr)
72 == -1) {
73 mdb_warn("cannot read at address %p", (uintptr_t)ptr);
74 return (DCMD_ERR);
76 mdb_printf("%<b>kcf_provider_desc at %p%</b>\n", ptr);
78 switch (desc.pd_prov_type) {
79 case CRYPTO_HW_PROVIDER:
80 mdb_printf("pd_prov_type:\t\tCRYPTO_HW_PROVIDER\n");
81 break;
82 case CRYPTO_SW_PROVIDER:
83 mdb_printf("pd_prov_type:\t\tCRYPTO_SW_PROVIDER\n");
84 break;
85 case CRYPTO_LOGICAL_PROVIDER:
86 mdb_printf("pd_prov_type:\t\tCRYPTO_LOGICAL_PROVIDER\n");
87 break;
88 default:
89 mdb_printf("bad pd_prov_type:\t%d\n", desc.pd_prov_type);
92 mdb_printf("pd_prov_id:\t\t%u\n", desc.pd_prov_id);
93 if (desc.pd_description == NULL)
94 mdb_printf("pd_description:\t\tNULL\n");
95 else if (mdb_readstr(string, MAXNAMELEN + 1,
96 (uintptr_t)desc.pd_description) == -1) {
97 mdb_warn("cannot read %p", desc.pd_description);
98 } else
99 mdb_printf("pd_description:\t\t%s\n", string);
101 mdb_printf("pd_sid:\t\t\t%u\n", desc.pd_sid);
102 mdb_printf("pd_taskq:\t\t%p\n", desc.pd_taskq);
103 mdb_printf("pd_nbins:\t\t%u\n", desc.pd_nbins);
104 mdb_printf("pd_percpu_bins:\t\t%p\n", desc.pd_percpu_bins);
106 dtotal = ftotal = btotal = 0;
107 holdcnt = jobcnt = 0;
108 for (i = 0; i < desc.pd_nbins; i++) {
109 if (mdb_vread(&stats, sizeof (kcf_prov_cpu_t),
110 (uintptr_t)(desc.pd_percpu_bins + i)) == -1) {
111 mdb_warn("cannot read addr %p",
112 desc.pd_percpu_bins + i);
113 return (DCMD_ERR);
116 holdcnt += stats.kp_holdcnt;
117 jobcnt += stats.kp_jobcnt;
118 dtotal += stats.kp_ndispatches;
119 ftotal += stats.kp_nfails;
120 btotal += stats.kp_nbusy_rval;
122 mdb_inc_indent(4);
123 mdb_printf("total kp_holdcnt:\t\t%d\n", holdcnt);
124 mdb_printf("total kp_jobcnt:\t\t%u\n", jobcnt);
125 mdb_printf("total kp_ndispatches:\t%llu\n", dtotal);
126 mdb_printf("total kp_nfails:\t\t%llu\n", ftotal);
127 mdb_printf("total kp_nbusy_rval:\t%llu\n", btotal);
128 mdb_dec_indent(4);
130 mdb_printf("pd_prov_handle:\t\t%p\n", desc.pd_prov_handle);
131 mdb_printf("pd_kcf_prov_handle:\t%u\n", desc.pd_kcf_prov_handle);
133 mdb_printf("pd_ops_vector:\t\t%p\n", desc.pd_ops_vector);
134 mdb_printf("pd_mech_list_count:\t%u\n", desc.pd_mech_list_count);
135 /* mechanisms */
136 mdb_inc_indent(4);
137 for (i = 0; i < desc.pd_mech_list_count; i++) {
138 mech_pointer = desc.pd_mechanisms + i;
139 mdb_call_dcmd("crypto_mech_info",
140 (uintptr_t)mech_pointer, DCMD_ADDRSPEC, 0, NULL);
142 mdb_dec_indent(4);
143 mdb_printf("pd_mech_indx:\n");
144 mdb_inc_indent(8);
145 for (i = 0; i < KCF_OPS_CLASSSIZE; i++) {
146 for (j = 0; j < KCF_MAXMECHTAB; j++) {
147 if (desc.pd_mech_indx[i][j] == KCF_INVALID_INDX)
148 mdb_printf("N ");
149 else
150 mdb_printf("%u ", desc.pd_mech_indx[i][j]);
152 mdb_printf("\n");
154 mdb_dec_indent(8);
156 if (desc.pd_name == NULL)
157 mdb_printf("pd_name:\t\t NULL\n");
158 else if (mdb_readstr(string, MAXNAMELEN + 1, (uintptr_t)desc.pd_name)
159 == -1)
160 mdb_warn("could not read pd_name from %X\n", desc.pd_name);
161 else
162 mdb_printf("pd_name:\t\t%s\n", string);
164 mdb_printf("pd_instance:\t\t%u\n", desc.pd_instance);
165 mdb_printf("pd_module_id:\t\t%d\n", desc.pd_module_id);
166 mdb_printf("pd_mctlp:\t\t%p\n", desc.pd_mctlp);
167 mdb_printf("pd_lock:\t\t%p\n", desc.pd_lock);
168 if (desc.pd_state < KCF_PROV_ALLOCATED ||
169 desc.pd_state > KCF_PROV_UNREGISTERED)
170 mdb_printf("pd_state is invalid:\t%d\n", desc.pd_state);
171 else
172 mdb_printf("pd_state:\t%s\n", prov_states[desc.pd_state]);
173 mdb_printf("pd_provider_list:\t%p\n", desc.pd_provider_list);
175 mdb_printf("pd_resume_cv:\t\t%hd\n", desc.pd_resume_cv._opaque);
176 mdb_printf("pd_flags:\t\t%s %s %s %s %s\n",
177 (desc.pd_flags & CRYPTO_HIDE_PROVIDER) ?
178 "CRYPTO_HIDE_PROVIDER" : " ",
179 (desc.pd_flags & CRYPTO_HASH_NO_UPDATE) ?
180 "CRYPTO_HASH_NO_UPDATE" : " ",
181 (desc.pd_flags & CRYPTO_HMAC_NO_UPDATE) ?
182 "CRYPTO_HMAC_NO_UPDATE" : " ",
183 (desc.pd_flags & CRYPTO_SYNCHRONOUS) ?
184 "CRYPTO_SYNCHRONOUS" : " ",
185 (desc.pd_flags & KCF_LPROV_MEMBER) ?
186 "KCF_LPROV_MEMBER" : " ");
187 if (desc.pd_flags & CRYPTO_HASH_NO_UPDATE)
188 mdb_printf("pd_hash_limit:\t\t%u\n", desc.pd_hash_limit);
189 if (desc.pd_flags & CRYPTO_HMAC_NO_UPDATE)
190 mdb_printf("pd_hmac_limit:\t\t%u\n", desc.pd_hmac_limit);
192 mdb_printf("pd_kstat:\t\t%p\n", desc.pd_kstat);
194 return (DCMD_OK);
197 #define GOT_NONE (-2)
199 /*ARGSUSED*/
201 prov_tab(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
203 kcf_provider_desc_t **tab;
204 kcf_provider_desc_t desc;
205 kcf_provider_desc_t *ptr;
206 uint_t prov_tab_max;
207 int i;
208 int gotzero = GOT_NONE;
209 char string[MAXNAMELEN + 1];
211 if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) {
212 return (DCMD_USAGE);
213 } else if (mdb_readsym(&ptr, sizeof (void *), "prov_tab")
214 == -1) {
215 mdb_warn("cannot read prov_tab");
216 return (DCMD_ERR);
218 } else if (mdb_readvar(&prov_tab_max, "prov_tab_max") == -1) {
219 mdb_warn("cannot read prov_tab_max");
220 return (DCMD_ERR);
222 mdb_printf("%<b>prov_tab = %p%</b>\n", ptr);
223 tab = mdb_zalloc(prov_tab_max * sizeof (kcf_provider_desc_t *),
224 UM_SLEEP| UM_GC);
226 #ifdef DEBUG
227 mdb_printf("DEBUG: tab = %p, prov_tab_max = %d\n", tab, prov_tab_max);
228 #endif
230 if (mdb_vread(tab, prov_tab_max * sizeof (kcf_provider_desc_t *),
231 (uintptr_t)ptr) == -1) {
232 mdb_warn("cannot read prov_tab");
233 return (DCMD_ERR);
235 #ifdef DEBUG
236 mdb_printf("DEBUG: got past mdb_vread of tab\n");
237 mdb_printf("DEBUG: *tab = %p\n", *tab);
238 #endif
239 for (i = 0; i < prov_tab_max; i++) {
240 /* save space, only print range for long list of nulls */
241 if (tab[i] == NULL) {
242 if (gotzero == GOT_NONE) {
243 mdb_printf("prov_tab[%d", i);
244 gotzero = i;
246 } else {
247 /* first non-null in awhile, print index of prev null */
248 if (gotzero != GOT_NONE) {
249 if (gotzero == (i - 1))
250 mdb_printf("] = NULL\n", i - 1);
251 else
252 mdb_printf(" - %d] = NULL\n", i - 1);
253 gotzero = GOT_NONE;
255 /* interesting value, print it */
256 mdb_printf("prov_tab[%d] = %p ", i, tab[i]);
258 if (mdb_vread(&desc, sizeof (kcf_provider_desc_t),
259 (uintptr_t)tab[i]) == -1) {
260 mdb_warn("cannot read at address %p",
261 (uintptr_t)tab[i]);
262 return (DCMD_ERR);
265 (void) mdb_readstr(string, MAXNAMELEN + 1,
266 (uintptr_t)desc.pd_name);
267 mdb_printf("(%s\t%s)\n", string,
268 prov_states[desc.pd_state]);
271 /* if we've printed the first of many nulls but left the brace open */
272 if ((i > 0) && (tab[i-1] == NULL)) {
273 if (gotzero == GOT_NONE)
274 mdb_printf("] = NULL\n");
275 else
276 mdb_printf(" - %d] = NULL\n", i - 1);
279 return (DCMD_OK);
282 /*ARGSUSED*/
284 policy_tab(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
286 kcf_policy_desc_t **tab;
287 kcf_policy_desc_t *ptr;
288 uint_t policy_tab_max;
289 int num, i;
290 int gotzero = GOT_NONE;
292 if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) {
293 return (DCMD_USAGE);
294 } else if (mdb_readsym(&ptr, sizeof (void *), "policy_tab")
295 == -1) {
296 mdb_warn("cannot read policy_tab");
297 return (DCMD_ERR);
299 } else if (mdb_readvar(&policy_tab_max, "policy_tab_max") == -1) {
300 mdb_warn("cannot read policy_tab_max");
301 return (DCMD_ERR);
304 /* get the current number of descriptors in the table */
305 if (mdb_readvar(&num, "policy_tab_num") == -1) {
306 mdb_warn("cannot read policy_tab_num");
307 return (DCMD_ERR);
309 mdb_printf("%<b>policy_tab = %p%</b> \tpolicy_tab_num = %d\n",
310 ptr, num);
312 tab = mdb_zalloc(policy_tab_max * sizeof (kcf_policy_desc_t *),
313 UM_SLEEP| UM_GC);
315 if (mdb_vread(tab, policy_tab_max * sizeof (kcf_policy_desc_t *),
316 (uintptr_t)ptr) == -1) {
317 mdb_warn("cannot read policy_tab");
318 return (DCMD_ERR);
320 #ifdef DEBUG
321 mdb_printf("DEBUG: got past mdb_vread of tab\n");
322 mdb_printf("DEBUG: *tab = %p\n", *tab);
323 #endif
324 for (i = 0; i < policy_tab_max; i++) {
325 /* save space, only print range for long list of nulls */
326 if (tab[i] == NULL) {
327 if (gotzero == GOT_NONE) {
328 mdb_printf("policy_tab[%d", i);
329 gotzero = i;
331 } else {
332 /* first non-null in awhile, print index of prev null */
333 if (gotzero != GOT_NONE) {
334 if (gotzero == (i - 1))
335 mdb_printf("] = NULL\n", i - 1);
336 else
337 mdb_printf(" - %d] = NULL\n", i - 1);
338 gotzero = GOT_NONE;
340 /* interesting value, print it */
341 mdb_printf("policy_tab[%d] = %p\n", i, tab[i]);
344 /* if we've printed the first of many nulls but left the brace open */
345 if ((i > 0) && (tab[i-1] == NULL)) {
346 if (gotzero == GOT_NONE)
347 mdb_printf("] = NULL\n");
348 else
349 mdb_printf(" - %d] = NULL\n", i - 1);
352 return (DCMD_OK);
355 static void
356 prt_mechs(int count, crypto_mech_name_t *mechs)
358 int i;
359 char name[CRYPTO_MAX_MECH_NAME + 1];
360 char name2[CRYPTO_MAX_MECH_NAME + 3];
362 for (i = 0; i < count; i++) {
363 if (mdb_readstr(name, CRYPTO_MAX_MECH_NAME,
364 (uintptr_t)((char *)mechs)) == -1)
365 continue;
366 /* put in quotes */
367 (void) mdb_snprintf(name2, sizeof (name2), "\"%s\"", name);
368 /* yes, length is 32, but then it will wrap */
369 /* this shorter size formats nicely for most cases */
370 mdb_printf("mechs[%d]=%-28s", i, name2);
371 mdb_printf("%s", i%2 ? "\n" : " "); /* 2-columns */
372 mechs++;
376 /* ARGSUSED2 */
377 static int
378 prt_soft_conf_entry(kcf_soft_conf_entry_t *addr, kcf_soft_conf_entry_t *entry,
379 void *cbdata)
381 char name[MAXNAMELEN + 1];
383 mdb_printf("\n%<b>kcf_soft_conf_entry_t at %p:%</b>\n", addr);
384 mdb_printf("ce_next: %p", entry->ce_next);
386 if (entry->ce_name == NULL)
387 mdb_printf("\tce_name: NULL\n");
388 else if (mdb_readstr(name, MAXNAMELEN, (uintptr_t)entry->ce_name)
389 == -1)
390 mdb_printf("could not read ce_name from %p\n",
391 entry->ce_name);
392 else
393 mdb_printf("\tce_name: %s\n", name);
395 mdb_printf("ce_count: %d\n", entry->ce_count);
396 prt_mechs(entry->ce_count, entry->ce_mechs);
397 return (WALK_NEXT);
401 soft_conf_walk_init(mdb_walk_state_t *wsp)
403 uintptr_t *soft;
405 if (mdb_readsym(&soft, sizeof (kcf_soft_conf_entry_t *),
406 "soft_config_list") == -1) {
407 mdb_warn("failed to find 'soft_config_list'");
408 return (WALK_ERR);
410 wsp->walk_addr = (uintptr_t)soft;
411 wsp->walk_data = mdb_alloc(sizeof (kcf_soft_conf_entry_t), UM_SLEEP);
412 wsp->walk_callback = (mdb_walk_cb_t)prt_soft_conf_entry;
413 return (WALK_NEXT);
417 * At each step, read a kcf_soft_conf_entry_t into our private storage, then
418 * invoke the callback function. We terminate when we reach a NULL ce_next
419 * pointer.
422 soft_conf_walk_step(mdb_walk_state_t *wsp)
424 int status;
426 if (wsp->walk_addr == (uintptr_t)NULL) /* then we're done */
427 return (WALK_DONE);
428 #ifdef DEBUG
429 else
430 mdb_printf("DEBUG: wsp->walk_addr == %p\n", wsp->walk_addr);
431 #endif
433 if (mdb_vread(wsp->walk_data, sizeof (kcf_soft_conf_entry_t),
434 wsp->walk_addr) == -1) {
435 mdb_warn("failed to read kcf_soft_conf_entry at %p",
436 wsp->walk_addr);
437 return (WALK_DONE);
440 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
441 wsp->walk_cbdata);
443 wsp->walk_addr =
444 (uintptr_t)(((kcf_soft_conf_entry_t *)wsp->walk_data)->ce_next);
445 return (status);
449 * The walker's fini function is invoked at the end of each walk. Since we
450 * dynamically allocated a kcf_soft_conf_entry_t in soft_conf_walk_init,
451 * we must free it now.
453 void
454 soft_conf_walk_fini(mdb_walk_state_t *wsp)
456 #ifdef DEBUG
457 mdb_printf("...end of kcf_soft_conf_entry walk\n");
458 #endif
459 mdb_free(wsp->walk_data, sizeof (kcf_soft_conf_entry_t));
461 /* ARGSUSED2 */
463 kcf_soft_conf_entry(uintptr_t addr, uint_t flags, int argc,
464 const mdb_arg_t *argv)
466 kcf_soft_conf_entry_t entry;
467 kcf_soft_conf_entry_t *ptr;
469 if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) {
470 /* not allowed with DCMD_ADDRSPEC */
471 if (addr == (uintptr_t)NULL)
472 return (DCMD_USAGE);
473 else
474 ptr = (kcf_soft_conf_entry_t *)addr;
475 } else if (mdb_readsym(&ptr, sizeof (void *), "soft_config_list")
476 == -1) {
477 mdb_warn("cannot read soft_config_list");
478 return (DCMD_ERR);
479 } else
480 mdb_printf("soft_config_list = %p\n", ptr);
482 if (ptr == NULL)
483 return (DCMD_OK);
485 if (mdb_vread(&entry, sizeof (kcf_soft_conf_entry_t), (uintptr_t)ptr)
486 == -1) {
487 mdb_warn("cannot read at address %p", (uintptr_t)ptr);
488 return (DCMD_ERR);
491 /* this could change in the future to have more than one ret val */
492 if (prt_soft_conf_entry(ptr, &entry, NULL) != WALK_ERR)
493 return (DCMD_OK);
494 return (DCMD_ERR);
497 /* ARGSUSED1 */
499 kcf_policy_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
501 kcf_policy_desc_t desc;
502 char name[MAXNAMELEN + 1];
505 if ((flags & DCMD_ADDRSPEC) != DCMD_ADDRSPEC)
506 return (DCMD_USAGE);
508 if (mdb_vread(&desc, sizeof (kcf_policy_desc_t), (uintptr_t)addr)
509 == -1) {
510 mdb_warn("Could not read kcf_policy_desc_t at %p\n", addr);
511 return (DCMD_ERR);
513 mdb_printf("pd_prov_type: %s",
514 desc.pd_prov_type == CRYPTO_HW_PROVIDER ? "CRYPTO_HW_PROVIDER" :
515 "CRYPTO_SW_PROVIDER");
517 if (desc.pd_name == NULL)
518 mdb_printf("\tpd_name: NULL\n");
519 else if (mdb_readstr(name, MAXNAMELEN, (uintptr_t)desc.pd_name)
520 == -1)
521 mdb_printf("could not read pd_name from %p\n",
522 desc.pd_name);
523 else
524 mdb_printf("\tpd_name: %s\n", name);
526 mdb_printf("pd_instance: %d ", desc.pd_instance);
527 mdb_printf("\t\tpd_refcnt: %d\n", desc.pd_refcnt);
528 mdb_printf("pd_mutex: %p", desc.pd_mutex);
529 mdb_printf("\t\tpd_disabled_count: %d", desc.pd_disabled_count);
530 mdb_printf("\npd_disabled_mechs:\n");
531 mdb_inc_indent(4);
532 prt_mechs(desc.pd_disabled_count, desc.pd_disabled_mechs);
533 mdb_dec_indent(4);
534 return (DCMD_OK);