xref: /illumos-gate/usr/src/cmd/mdb/common/modules/genunix/ctxop.c (revision 88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/mdb_modapi.h>
30 #include <sys/thread.h>
31 #include "ctxop.h"
32 
33 int
34 ctxop_walk_init(mdb_walk_state_t *wsp)
35 {
36 	kthread_t thread, *tp = &thread;
37 
38 	if (wsp->walk_addr == NULL) {
39 		mdb_warn("must specify thread for ctxop walk\n");
40 		return (WALK_ERR);
41 	}
42 	if (mdb_vread(tp, sizeof (*tp), wsp->walk_addr) == -1) {
43 		mdb_warn("failed to read thread at %p", wsp->walk_addr);
44 		return (WALK_ERR);
45 	}
46 
47 	wsp->walk_data = mdb_alloc(sizeof (ctxop_t), UM_SLEEP);
48 	wsp->walk_addr = (uintptr_t)tp->t_ctx;
49 
50 	return (WALK_NEXT);
51 }
52 
53 int
54 ctxop_walk_step(mdb_walk_state_t *wsp)
55 {
56 	int status;
57 
58 	if (wsp->walk_addr == NULL)
59 		return (WALK_DONE);
60 
61 	if (mdb_vread(wsp->walk_data,
62 	    sizeof (ctxop_t), wsp->walk_addr) == -1) {
63 		mdb_warn("failed to read ctxop at %p", wsp->walk_addr);
64 		return (WALK_DONE);
65 	}
66 
67 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
68 	    wsp->walk_cbdata);
69 
70 	wsp->walk_addr = (uintptr_t)(((ctxop_t *)wsp->walk_data)->next);
71 	return (status);
72 }
73 
74 void
75 ctxop_walk_fini(mdb_walk_state_t *wsp)
76 {
77 	mdb_free(wsp->walk_data, sizeof (ctxop_t));
78 }
79