getcontext.c revision d8aa0f5a4ea4104dc1ff58a1431463e2f7ace57b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/privregs.h>
#include <sys/ucontext.h>
#include <sys/asm_linkage.h>
#include <sys/archsystm.h>
#include <sys/schedctl.h>
#include <sys/sysmacros.h>
/*
* Save user context.
*/
void
{
/*
* We unconditionally assign to every field through the end
* of the gregs, but we need to bzero() everything -after- that
* to avoid having any kernel stack garbage escape to userland.
*/
/*
* Try to copyin() the ustack if one is registered. If the stack
* has zero size, this indicates that stack bounds checking has
* been disabled for this LWP. If stack bounds checking is disabled
* or the copyin() fails, we fall back to the legacy behavior.
*/
} else {
}
}
else
/*
* If the trace flag is set, arrange for single-stepping and
* turn off the trace flag.
*/
/*
* We always check DEBUG_PENDING before checking for any
* pending signal. This at times can potentially lead to
* DEBUG_PENDING not being honoured. (for eg: the lwp is
* stopped by stop_on_fault() called from trap(), after
* being awakened it might see a pending signal and call
* savecontext(), however on the way back to userland there
* is no place it can be detected). Hence in anticipation of
* such occassion, we set AST flag for the thread which will
* make the thread take an excursion through trap() where
* we will handle it appropriately.
*/
}
}
/*
* Restore user context.
*/
void
{
else
}
/*
* If the trace flag is set, mark the lwp to take a
* single-step trap on return to user level (below).
* The x86 lcall interface and sysenter has already done this,
* and turned off the flag, but amd64 syscall interface has not.
*/
t->t_post_sys = 1;
}
mutex_enter(&p->p_lock);
if (sigcheck(p, t))
t->t_sig_check = 1;
mutex_exit(&p->p_lock);
}
}
int
{
/*
* In future releases, when the ucontext structure grows,
* getcontext should be modified to only return the fields
* specified in the uc_flags. That way, the structure can grow
* and still be binary compatible will all .o's which will only
* have old fields defined in uc_flags
*/
switch (flag) {
default:
case GETCONTEXT:
if (schedctl_sigblock(curthread)) {
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
}
return (0);
case SETCONTEXT:
exit(CLD_EXITED, 0);
/*
* Don't copyin filler or floating state unless we need it.
* The ucontext_t struct and fields are specified in the ABI.
*/
}
}
restorecontext(&uc);
return (0);
case GETUSTACK:
return (0);
case SETUSTACK:
return (0);
}
}
#ifdef _SYSCALL32_IMPL
/*
* Save user context for 32-bit processes.
*/
void
{
} else {
(p->p_usrstack - p->p_stksize);
}
}
else
/*
* If the trace flag is set, arrange for single-stepping and
* turn off the trace flag.
*/
/*
* See comments in savecontext().
*/
}
}
int
{
switch (flag) {
default:
case GETCONTEXT:
if (schedctl_sigblock(curthread)) {
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
}
return (0);
case SETCONTEXT:
exit(CLD_EXITED, 0);
}
}
return (0);
case GETUSTACK:
return (0);
case SETUSTACK:
return (0);
}
}
#endif /* _SYSCALL32_IMPL */