xref: /illumos-gate/usr/src/cmd/mdb/common/modules/genunix/ctxop.c (revision 33c72b7598992897b94815b1f47b7b8077e53808)
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 #include <sys/mdb_modapi.h>
28 #include <sys/thread.h>
29 #include "ctxop.h"
30 
31 int
32 ctxop_walk_init(mdb_walk_state_t *wsp)
33 {
34 	kthread_t thread, *tp = &thread;
35 
36 	if (wsp->walk_addr == 0) {
37 		mdb_warn("must specify thread for ctxop walk\n");
38 		return (WALK_ERR);
39 	}
40 	if (mdb_vread(tp, sizeof (*tp), wsp->walk_addr) == -1) {
41 		mdb_warn("failed to read thread at %p", wsp->walk_addr);
42 		return (WALK_ERR);
43 	}
44 
45 	wsp->walk_data = mdb_alloc(sizeof (ctxop_t), UM_SLEEP);
46 	wsp->walk_addr = (uintptr_t)tp->t_ctx;
47 
48 	return (WALK_NEXT);
49 }
50 
51 int
52 ctxop_walk_step(mdb_walk_state_t *wsp)
53 {
54 	int status;
55 
56 	if (wsp->walk_addr == 0)
57 		return (WALK_DONE);
58 
59 	if (mdb_vread(wsp->walk_data,
60 	    sizeof (ctxop_t), wsp->walk_addr) == -1) {
61 		mdb_warn("failed to read ctxop at %p", wsp->walk_addr);
62 		return (WALK_DONE);
63 	}
64 
65 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
66 	    wsp->walk_cbdata);
67 
68 	wsp->walk_addr = (uintptr_t)(((ctxop_t *)wsp->walk_data)->next);
69 	return (status);
70 }
71 
72 void
73 ctxop_walk_fini(mdb_walk_state_t *wsp)
74 {
75 	mdb_free(wsp->walk_data, sizeof (ctxop_t));
76 }
77