/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Debugger co-routine context support: In order to implement the context-
* switching necessary for MDB pipes, we need the ability to establish a
* co-routine context that has a separate stack. We use this stack to execute
* the MDB parser, and then switch back and forth between this code and the
* dcmd which is producing output to be consumed. We implement a context by
* mapping a few pages of anonymous memory, and then using setcontext(2) to
* switch to this stack and begin execution of a new function.
*/
#include <mdb/mdb_context_impl.h>
#include <mdb/mdb_modapi.h>
#include <mdb/mdb_debug.h>
#include <ucontext.h>
#include <unistd.h>
#include <setjmp.h>
#include <fcntl.h>
#include <errno.h>
static void
{
c->ctx_status = c->ctx_func();
ASSERT(c->ctx_resumes > 0);
}
{
if (c == NULL)
return (NULL);
if (prot == -1)
/*
* If the mmap failed with EBADFD, this kernel doesn't have MAP_ANON
* that to mmap chunks of anonymous memory.
*/
if (zfd >= 0) {
MAP_PRIVATE, zfd, 0);
}
}
mdb_free(c, sizeof (mdb_context_t));
return (NULL);
}
return (c);
}
void
{
mdb_free(c, sizeof (mdb_context_t));
}
void
{
fail("failed to change context to %p", (void *)c);
else
fail("unexpectedly returned from context %p", (void *)c);
}
jmp_buf *
{
c->ctx_resumes++;
return (&c->ctx_pcb);
}