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]
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
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
[] = {
40 "KCF_PROV_UNVERIFIED",
41 "KCF_PROV_VERIFICATION_FAILED",
46 "KCF_PROV_UNREGISTERING",
47 "KCF_PROV_UNREGISTERED"
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];
58 crypto_mech_info_t
*mech_pointer
;
60 uint64_t dtotal
, ftotal
, btotal
;
63 if ((flags
& DCMD_ADDRSPEC
) != DCMD_ADDRSPEC
)
65 ptr
= (kcf_provider_desc_t
*)addr
;
68 mdb_printf("DEBUG: reading kcf_provider_desc at %p\n", ptr
);
71 if (mdb_vread(&desc
, sizeof (kcf_provider_desc_t
), (uintptr_t)ptr
)
73 mdb_warn("cannot read at address %p", (uintptr_t)ptr
);
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");
82 case CRYPTO_SW_PROVIDER
:
83 mdb_printf("pd_prov_type:\t\tCRYPTO_SW_PROVIDER\n");
85 case CRYPTO_LOGICAL_PROVIDER
:
86 mdb_printf("pd_prov_type:\t\tCRYPTO_LOGICAL_PROVIDER\n");
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
);
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
);
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
;
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
);
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
);
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
);
143 mdb_printf("pd_mech_indx:\n");
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
)
150 mdb_printf("%u ", desc
.pd_mech_indx
[i
][j
]);
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
)
160 mdb_warn("could not read pd_name from %X\n", desc
.pd_name
);
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
);
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
);
197 #define GOT_NONE (-2)
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
;
208 int gotzero
= GOT_NONE
;
209 char string
[MAXNAMELEN
+ 1];
211 if ((flags
& DCMD_ADDRSPEC
) == DCMD_ADDRSPEC
) {
213 } else if (mdb_readsym(&ptr
, sizeof (void *), "prov_tab")
215 mdb_warn("cannot read prov_tab");
218 } else if (mdb_readvar(&prov_tab_max
, "prov_tab_max") == -1) {
219 mdb_warn("cannot read prov_tab_max");
222 mdb_printf("%<b>prov_tab = %p%</b>\n", ptr
);
223 tab
= mdb_zalloc(prov_tab_max
* sizeof (kcf_provider_desc_t
*),
227 mdb_printf("DEBUG: tab = %p, prov_tab_max = %d\n", tab
, prov_tab_max
);
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");
236 mdb_printf("DEBUG: got past mdb_vread of tab\n");
237 mdb_printf("DEBUG: *tab = %p\n", *tab
);
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
);
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);
252 mdb_printf(" - %d] = NULL\n", i
- 1);
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",
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");
276 mdb_printf(" - %d] = NULL\n", i
- 1);
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
;
290 int gotzero
= GOT_NONE
;
292 if ((flags
& DCMD_ADDRSPEC
) == DCMD_ADDRSPEC
) {
294 } else if (mdb_readsym(&ptr
, sizeof (void *), "policy_tab")
296 mdb_warn("cannot read policy_tab");
299 } else if (mdb_readvar(&policy_tab_max
, "policy_tab_max") == -1) {
300 mdb_warn("cannot read policy_tab_max");
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");
309 mdb_printf("%<b>policy_tab = %p%</b> \tpolicy_tab_num = %d\n",
312 tab
= mdb_zalloc(policy_tab_max
* sizeof (kcf_policy_desc_t
*),
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");
321 mdb_printf("DEBUG: got past mdb_vread of tab\n");
322 mdb_printf("DEBUG: *tab = %p\n", *tab
);
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
);
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);
337 mdb_printf(" - %d] = NULL\n", i
- 1);
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");
349 mdb_printf(" - %d] = NULL\n", i
- 1);
356 prt_mechs(int count
, crypto_mech_name_t
*mechs
)
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)
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 */
378 prt_soft_conf_entry(kcf_soft_conf_entry_t
*addr
, kcf_soft_conf_entry_t
*entry
,
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
)
390 mdb_printf("could not read ce_name from %p\n",
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
);
401 soft_conf_walk_init(mdb_walk_state_t
*wsp
)
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'");
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
;
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
422 soft_conf_walk_step(mdb_walk_state_t
*wsp
)
426 if (wsp
->walk_addr
== (uintptr_t)NULL
) /* then we're done */
430 mdb_printf("DEBUG: wsp->walk_addr == %p\n", wsp
->walk_addr
);
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",
440 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
444 (uintptr_t)(((kcf_soft_conf_entry_t
*)wsp
->walk_data
)->ce_next
);
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.
454 soft_conf_walk_fini(mdb_walk_state_t
*wsp
)
457 mdb_printf("...end of kcf_soft_conf_entry walk\n");
459 mdb_free(wsp
->walk_data
, sizeof (kcf_soft_conf_entry_t
));
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
)
474 ptr
= (kcf_soft_conf_entry_t
*)addr
;
475 } else if (mdb_readsym(&ptr
, sizeof (void *), "soft_config_list")
477 mdb_warn("cannot read soft_config_list");
480 mdb_printf("soft_config_list = %p\n", ptr
);
485 if (mdb_vread(&entry
, sizeof (kcf_soft_conf_entry_t
), (uintptr_t)ptr
)
487 mdb_warn("cannot read at address %p", (uintptr_t)ptr
);
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
)
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
)
508 if (mdb_vread(&desc
, sizeof (kcf_policy_desc_t
), (uintptr_t)addr
)
510 mdb_warn("Could not read kcf_policy_desc_t at %p\n", addr
);
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
)
521 mdb_printf("could not read pd_name from %p\n",
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");
532 prt_mechs(desc
.pd_disabled_count
, desc
.pd_disabled_mechs
);