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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Debugger co-routine context support. kmdb co-routines are essentially the
31 * same as the ones used by mdb, with the exception that we allocate the stack
32 * for the co-routine from our heap.
35 #include <kmdb/kmdb_context_impl.h>
36 #include <mdb/mdb_modapi.h>
37 #include <mdb/mdb_debug.h>
38 #include <mdb/mdb_err.h>
39 #include <mdb/mdb_umem.h>
42 #include <sys/types.h>
48 context_init(mdb_context_t
*volatile c
)
50 c
->ctx_status
= c
->ctx_func();
51 ASSERT(c
->ctx_resumes
> 0);
52 longjmp(c
->ctx_pcb
, 1);
56 mdb_context_create(int (*func
)(void))
58 mdb_context_t
*c
= mdb_zalloc(sizeof (mdb_context_t
), UM_NOSLEEP
);
59 size_t pagesize
= mdb
.m_pagesize
;
65 c
->ctx_stacksize
= pagesize
* 4;
66 c
->ctx_stack
= mdb_alloc_align(c
->ctx_stacksize
, pagesize
, UM_NOSLEEP
);
68 if (c
->ctx_stack
== NULL
) {
69 mdb_free(c
, sizeof (mdb_context_t
));
73 kmdb_makecontext(&c
->ctx_uc
, (void (*)(void *))context_init
, c
,
74 c
->ctx_stack
, c
->ctx_stacksize
);
80 mdb_context_destroy(mdb_context_t
*c
)
82 mdb_free_align(c
->ctx_stack
, c
->ctx_stacksize
);
83 mdb_free(c
, sizeof (mdb_context_t
));
87 mdb_context_switch(mdb_context_t
*c
)
89 if (setjmp(c
->ctx_pcb
) == 0 && kmdb_setcontext(&c
->ctx_uc
) == -1)
90 fail("failed to change context to %p", (void *)c
);
92 fail("unexpectedly returned from context %p", (void *)c
);
96 mdb_context_getpcb(mdb_context_t
*c
)