trap.c revision 0baeff3d96eae184e775c1064f1836090446a7bf
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
/* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
/* All Rights Reserved */
/* */
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
/* */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/mutex_impl.h>
#include <sys/machsystm.h>
#include <sys/archsystm.h>
#include <vm/seg_kmem.h>
#include <sys/debugreg.h>
#include <sys/aio_impl.h>
#include <sys/tnf_probe.h>
#include <sys/x86_archext.h>
#include <sys/traptrace.h>
#include <sys/cpc_impl.h>
static const char *trap_type_mnemonic[] = {
"de", "db", "2", "bp",
"of", "br", "ud", "nm",
"df", "9", "ts", "np",
"ss", "gp", "pf", "15",
"mf", "ac", "mc", "xf"
};
static const char *trap_type[] = {
"Divide error", /* trap id 0 */
"Debug", /* trap id 1 */
"NMI interrupt", /* trap id 2 */
"Breakpoint", /* trap id 3 */
"Overflow", /* trap id 4 */
"BOUND range exceeded", /* trap id 5 */
"Invalid opcode", /* trap id 6 */
"Device not available", /* trap id 7 */
"Double fault", /* trap id 8 */
"Coprocessor segment overrun", /* trap id 9 */
"Invalid TSS", /* trap id 10 */
"Segment not present", /* trap id 11 */
"Stack segment fault", /* trap id 12 */
"General protection", /* trap id 13 */
"Page fault", /* trap id 14 */
"Reserved", /* trap id 15 */
"x87 floating point error", /* trap id 16 */
"Alignment check", /* trap id 17 */
"Machine check", /* trap id 18 */
"SIMD floating point exception", /* trap id 19 */
};
int tudebug = 0;
int tudebugbpt = 0;
int tudebugfpe = 0;
int tudebugsse = 0;
int tdebug = 0;
int lodebug = 0;
int faultdebug = 0;
#else
#define tdebug 0
#define lodebug 0
#define faultdebug 0
#endif /* defined(TRAPDEBUG) || defined(lint) */
#if defined(TRAPTRACE)
static void dump_ttrace(void);
#endif /* TRAPTRACE */
static void dump_tss(void);
static int kern_gpfault(struct regs *);
struct trap_info {
};
/*ARGSUSED*/
static int
{
const char *trap_name, *trap_mnemonic;
if (type < TRAP_TYPES) {
} else {
trap_name = "trap";
trap_mnemonic = "-";
}
#ifdef TRAPTRACE
#endif
panic("BAD TRAP: type=%x (#%s %s) rp=%p addr=%p "
"occurred in module \"%s\" due to %s",
"a NULL pointer dereference" :
"an illegal access to a user address");
} else
panic("BAD TRAP: type=%x (#%s %s) rp=%p addr=%p",
return (0);
}
/*
* Rewrite the instruction at pc to be an int $T_SYSCALLINT instruction.
*
* int <vector> is two bytes: 0xCD <vector>
*/
#define SLOW_SCALL_SIZE 2
static int
{
return (1);
return (0);
}
/*
* Test to see if the instruction at pc is sysenter or syscall. The second
* argument should be the x86 feature flag corresponding to the expected
* instruction.
*
* sysenter is two bytes: 0x0F 0x34
* syscall is two bytes: 0x0F 0x05
*/
#define FAST_SCALL_SIZE 2
static int
{
instr[0] != 0x0F)
return (0);
return (1);
return (0);
}
/*
* Test to see if the instruction at pc is a system call instruction.
*
* The bytes of an lcall instruction used for the syscall trap.
* static uchar_t lcall[7] = { 0x9a, 0, 0, 0, 0, 0x7, 0 };
* static uchar_t lcallalt[7] = { 0x9a, 0, 0, 0, 0, 0x27, 0 };
*/
#define LCALLSIZE 7
static int
{
instr[0] == 0x9a &&
instr[1] == 0 &&
instr[2] == 0 &&
instr[3] == 0 &&
instr[4] == 0 &&
instr[6] == 0)
return (1);
return (0);
}
#ifdef OPTERON_ERRATUM_91
/*
* Test to see if the instruction at pc is a prefetch instruction.
*
* The first byte of prefetch instructions is always 0x0F.
* The second byte is 0x18 for regular prefetch or 0x0D for AMD 3dnow prefetch.
* The third byte is between 0 and 3 inclusive.
*/
#define PREFETCHSIZE 3
static int
{
if (*p == 0x0F && (*(p+1) == 0x18 || *(p+1) == 0x0D) && *(p+2) <= 3)
return (1);
return (0);
}
static int
{
int error;
return (1);
return (0);
}
#endif /* OPTERON_ERRATUM_91 */
/*
* Called from the trap handler when a processor trap occurs.
*
* Note: All user-level traps that might call stop() must exit
* trap() by 'goto out' or by falling through.
*/
void
{
unsigned type;
enum fault_type fault_type;
int mstate;
int sicode = 0;
int watchcode;
int watchpage;
int ta;
if (errcode & PF_ERR_WRITE)
else
#if defined(__i386)
/*
* Pentium Pro work-around
*/
== -1) {
errcode &= ~PF_ERR_PROT;
} else {
!(attr & PROT_WRITE);
if (!priv_violation && !access_violation)
goto cleanup;
}
}
#endif /* __i386 */
}
if (tdebug)
/*
* Set up the current cred to use during this trap. u_cred
* no longer exists. t_cred is used instead.
* The current process credential applies to the thread for
* the entire trap. If trapping from the kernel, this
* should already be set up.
*/
/*
* DTrace accesses t_cred in probe context. t_cred
* must always be either NULL, or point to a valid,
* allocated cred structure.
*/
}
switch (type) {
mstate = LMS_TFAULT;
else
mstate = LMS_DFAULT;
break;
default:
break;
}
/* Kernel probe */
}
switch (type) {
case T_SGLSTP:
break;
default:
FTRACE_2("trap(): type=0x%lx, regs=0x%lx",
break;
}
switch (type) {
case T_MCE: /* Machine check exception */
if (x86_feature & X86_MCA) {
if (mca_exception(rp))
goto cleanup;
}
default:
if (tudebug)
printf("trap: Unknown trap type %d in user mode\n",
break;
} else {
/*NOTREACHED*/
}
case T_PGFLT: /* system page fault */
/*
* set ot_trap and longjmp back to the on_trap() call site.
*/
}
/*
* See if we can handle as pagefault. Save lofault
* across this. Here we assume that an address
* less than KERNELBASE is a user fault.
* We can do this as copy.s routines verify that the
* starting address is less than KERNELBASE before
* starting and because we know that we always have
* KERNELBASE mapped as invalid to serve as a "barrier".
*/
cur_thread->t_lofault = 0;
addr < p->p_usrstack &&
res = 0;
} else {
}
/*
* Restore lofault. If we resolved the fault, exit.
* If we didn't and lofault wasn't set, die.
*/
if (res == 0)
goto cleanup;
#if defined(OPTERON_ERRATUM_93) && defined(_LP64)
if (lofault == 0 && opteron_erratum_93) {
/*
* Workaround for Opteron Erratum 93. On return from
* a System Managment Interrupt at a HLT instruction
* the %rip might be truncated to a 32 bit value.
* BIOS is supposed to fix this, but some don't.
* If this occurs we simply restore the high order bits.
* The HLT instruction is 1 byte of 0xf4.
*/
PFN_INVALID &&
goto cleanup;
}
}
}
#endif /* OPTERON_ERRATUM_93 && _LP64 */
#ifdef OPTERON_ERRATUM_91
if (lofault == 0 && opteron_erratum_91) {
/*
* Workaround for Opteron Erratum 91. Prefetches may
* generate a page fault (they're not supposed to do
* that!). If this occurs we simply return back to the
* instruction.
*/
/*
* If the faulting PC is not mapped, this is a
* legitimate kernel page fault that must result in a
* panic. If the faulting PC is mapped, it could contain
* a prefetch instruction. Check for that here.
*/
#ifdef DEBUG
"occurred: kernel prefetch"
" at %p generated a page fault!",
#endif /* DEBUG */
goto cleanup;
}
}
}
#endif /* OPTERON_ERRATUM_91 */
if (lofault == 0)
/*
* Cannot resolve fault. Return to lofault.
*/
if (lodebug) {
}
else
goto cleanup;
if (faultdebug) {
char *fault_str;
switch (rw) {
case S_READ:
fault_str = "read";
break;
case S_WRITE:
fault_str = "write";
break;
case S_EXEC:
fault_str = "exec";
break;
default:
fault_str = "";
break;
}
printf("user %s fault: addr=0x%lx errcode=0x%x\n",
}
#if defined(OPTERON_ERRATUM_100) && defined(_LP64)
/*
* Workaround for AMD erratum 100
*
* A 32-bit process may receive a page fault on a non
* 32-bit address by mistake. The range of the faulting
* address will be
*
* 0xffffffff80000000 .. 0xffffffffffffffff or
* 0x0000000100000000 .. 0x000000017fffffff
*
* The fault is always due to an instruction fetch, however
* the value of r_pc should be correct (in 32 bit range),
* so we ignore the page fault on the bogus address.
*/
if (p->p_model == DATAMODEL_ILP32 &&
if (!opteron_erratum_100)
panic("unexpected erratum #100");
goto out;
}
#endif /* OPTERON_ERRATUM_100 && _LP64 */
#ifdef __i386
/*
* In 32-bit mode, the lcall (system call) instruction fetches
* one word from the stack, at the stack pointer, because of the
* way the call gate is constructed. This is a bogus
* read and should not be counted as a read watchpoint.
* We work around the problem here by testing to see if
* this situation applies and, if so, simply jumping to
* the code in locore.s that fields the system call trap.
* The registers on the stack are already set up properly
* due to the match between the call gate sequence and the
* trap gate sequence. We just have to adjust the pc.
*/
extern void watch_syscall(void);
watch_syscall(); /* never returns */
/* NOTREACHED */
}
#endif /* __i386 */
if (ta) {
} else {
siginfo.si_trapafter = 0;
break;
}
} else {
/* XXX pr_watch_emul() never succeeds (for now) */
goto out;
}
/*
* If pagefault() succeeded, ok.
* Otherwise attempt to grow the stack.
*/
if (res == 0 ||
addr < p->p_usrstack &&
}
goto out;
report_stack_exec(p, addr);
}
#ifdef OPTERON_ERRATUM_91
/*
* Workaround for Opteron Erratum 91. Prefetches may generate a
* page fault (they're not supposed to do that!). If this
* occurs we simply return back to the instruction.
*
* We rely on copyin to properly fault in the page with r_pc.
*/
if (opteron_erratum_91 &&
#ifdef DEBUG
"prefetch at %p in pid %d generated a trap!",
#endif /* DEBUG */
goto out;
}
#endif /* OPTERON_ERRATUM_91 */
if (tudebug)
/*
* In the case where both pagefault and grow fail,
* set the code to the value provided by pagefault.
* We map all errors returned from pagefault() to SIGSEGV.
*/
case FC_HWERR:
case FC_NOSUPPORT:
break;
case FC_ALIGN:
break;
case FC_OBJERR:
}
break;
default: /* FC_NOMAP or FC_PROT */
break;
}
break;
/*
* If the syscall instruction is disabled due to LDT usage, a
* user program that attempts to execute it will trigger a #ud
* trap. Check for that case here. If this occurs on a CPU which
* doesn't even support syscall, the result of all of this will
* be to emulate that particular instruction.
*/
goto out;
#ifdef DEBUG
else
"instruction in process %d",
#endif /* DEBUG */
}
/*FALLTHROUGH*/
if (tudebug)
break;
if (tudebug && tudebugfpe)
break;
if (tudebug && tudebugfpe)
break;
if (tudebug && tudebugfpe)
if (fpnoextflt(rp)) {
}
break;
case T_EXTOVRFLT: /* extension overrun fault */
/* check if we took a kernel trap on behalf of user */
{
extern void ndptrap_frstor(void);
}
/*FALLTHROUGH*/
if (tudebug && tudebugfpe)
if (fpextovrflt(rp)) {
}
break;
case T_EXTERRFLT: /* x87 floating point exception pending */
/* check if we took a kernel trap on behalf of user */
{
extern void ndptrap_frstor(void);
}
/*FALLTHROUGH*/
if (tudebug && tudebugfpe)
}
break;
if (tudebug && tudebugsse)
/*
* There are rumours that some user instructions
* on older CPUs can cause this trap to occur; in
* which case send a SIGILL instead of a SIGFPE.
*/
}
break;
case T_BPTFLT: /* breakpoint trap */
/*
* Kernel breakpoint traps should only happen when kmdb is
* active, and even then, it'll have interposed on the IDT, so
* control won't get here. If it does, we've hit a breakpoint
* without the debugger, which is very strange, and very
* fatal.
*/
if (tudebug && tudebugbpt)
break;
if (tudebug && tudebugbpt)
/* Now evaluate how we got here */
/*
* i386 single-steps even through lcalls which
* change the privilege level. So we take a trap at
* the first instruction in privileged mode.
*
* Set a flag to indicate that upon completion of
* the system call, deal with the single-step trap.
*
* The same thing happens for sysenter, too.
*/
#if defined(__amd64)
/*
* Adjust the pc so that we don't execute the
* swapgs instruction at the head of the
* handler and completely confuse things.
*/
#endif
goto cleanup;
}
}
/* XXX - needs review on debugger interface? */
debug_enter((char *)NULL);
else
break;
case T_NMIFLT: /* NMI interrupt */
printf("Unexpected NMI in system mode\n");
goto cleanup;
printf("Unexpected NMI in user mode\n");
break;
case T_GPFLT: /* general protection violation */
#if defined(__amd64)
/*
* On amd64, we can get a #gp from referencing addresses
* in the virtual address hole e.g. from a copyin.
*/
/*
* set ot_trap and longjmp back to the on_trap() call site.
*/
}
/*
* If we're under lofault protection (copyin etc.),
* longjmp back to lofault with an EFAULT.
*/
if (cur_thread->t_lofault) {
/*
* Fault is not resolvable, so just return to lofault
*/
if (lodebug) {
}
goto cleanup;
}
/*FALLTHROUGH*/
#endif
case T_STKFLT: /* stack fault */
case T_TSSFLT: /* invalid TSS fault */
case T_SEGFLT: /* segment not present fault */
if (tudebug)
if (kern_gpfault(rp))
goto cleanup;
/*FALLTHROUGH*/
/*
* ONLY 32-bit PROCESSES can USE a PRIVATE LDT! 64-bit apps should have
* no legacy need for them, so we put a stop to it here.
*
* So: not-present fault is ONLY valid for 32-bit processes with a private LDT
* trying to do a system call. Emulate it.
*
* #gp fault is ONLY valid for 32-bit processes also, which DO NOT have private
* LDT, and are trying to do a system call. Emulate it.
*/
#ifdef _SYSCALL32_IMPL
if (p->p_model != DATAMODEL_NATIVE) {
#endif /* _SYSCALL32_IMPL */
/*
* The user attempted a system call via the obsolete
* call gate mechanism. Because the process doesn't have
* an LDT (i.e. the ldtr contains 0), a #gp results.
* Emulate the syscall here, just as we do above for a
* #np trap.
*/
/*
* Since this is a not-present trap, rp->r_pc points to
* the trapping lcall instruction. We need to bump it
* to the next insn so the app can continue on.
*/
/*
* Normally the microstate of the LWP is forced back to
* LMS_USER by the syscall handlers. Emulate that
* behavior here.
*/
dosyscall();
goto out;
}
}
#ifdef _SYSCALL32_IMPL
}
#endif /* _SYSCALL32_IMPL */
/*
* If the current process is using a private LDT and the
* trapping instruction is sysenter, the sysenter instruction
* has been disabled on the CPU because it destroys segment
* registers. If this is the case, rewrite the instruction to
* be a safe system call and retry it. If this occurs on a CPU
* which doesn't even support sysenter, the result of all of
* this will be to emulate that particular instruction.
*/
goto out;
#ifdef DEBUG
else
"instruction in process %d",
#endif /* DEBUG */
}
/*FALLTHROUGH*/
if (tudebug)
break;
if (tudebug)
break;
if (tudebug && tudebugbpt)
/* Was it single-stepping? */
/*
* If both NORMAL_STEP and WATCH_STEP are in effect,
* give precedence to NORMAL_STEP. If neither is set,
* user must have set the PS_T bit in %efl; treat this
* as NORMAL_STEP.
*/
(void) undo_watch_step(NULL);
} else {
}
} else {
"Unexpected INT 1 in user mode, dr6=%lx",
}
break;
if (tudebug && tudebugbpt)
/*
* int 3 (the breakpoint instruction) leaves the pc referring
* to the address one byte after the breakpointed address.
* If the P_PR_BPTADJ flag has been set via /proc, We adjust
* it back so it refers to the breakpointed address.
*/
if (p->p_proc_flag & P_PR_BPTADJ)
break;
case T_AST:
/*
* This occurs only after the cs register has been made to
* look like a kernel selector, either through debugging or
* possibly by functions like setcontext(). The thread is
* about to cause a general protection fault at common_iret()
* in locore. We let that happen immediately instead of
* doing the T_AST processing.
*/
goto cleanup;
if (kcpc_overflow_ast()) {
/*
* Signal performance counter overflow
*/
if (tudebug)
}
}
break;
}
/*
* We can't get here from a system trap
*/
if (fault) {
/*
* Remember the fault and fault adddress
* for real-time (SIGPROF) profiling.
*/
/*
* If a debugger has declared this fault to be an
* event of interest, stop the lwp. Otherwise just
* deliver the associated signal.
*/
}
if (lwp->lwp_oweupc)
/*
* Turn off the AST flag before checking all the conditions that
* may have caused an AST. This flag is on whenever a signal or
* unusual condition should be handled after the next trap or
* syscall.
*/
cur_thread->t_sig_check = 0;
mutex_enter(&p->p_lock);
}
mutex_exit(&p->p_lock);
/*
* for kaio requests that are on the per-process poll queue,
* aiop->aio_pollq, they're AIO_POLL bit is set, the kernel
* should copyout their result_t to user memory. by copying
* out the result_t, the user can poll on memory waiting
* for the kaio request to complete.
*/
if (p->p_aio)
aio_cleanup(0);
/*
* If this LWP was asked to hold, call holdlwp(), which will
* stop. holdlwps() sets this up and calls pokelwps() which
* sets the AST flag.
*
* Also check TP_EXITLWP, since this is used by fresh new LWPs
* through lwp_rtt(). That flag is set if the lwp_create(2)
* syscall failed after creating the LWP.
*/
if (ISHOLD(p))
holdlwp();
/*
* All code that sets signals and makes ISSIG evaluate true must
* set t_astflag afterwards.
*/
psig();
}
realsigprof(0, 0);
}
}
out: /* We can't get here from a system trap */
if (ISHOLD(p))
holdlwp();
/*
* Set state to LWP_USER here so preempt won't give us a kernel
* priority if it occurs after this point. Call CL_TRAPRET() to
* restore the user-level priority.
*
* It is important that no locks (other than spinlocks) be entered
* after this point before returning to user mode (unless lwp_state
* is set back to LWP_SYS).
*/
if (cur_thread->t_trapret) {
cur_thread->t_trapret = 0;
}
if (CPU->cpu_runrun)
preempt();
/* Kernel probe */
return;
cleanup: /* system traps end up here */
}
/*
* Patch non-zero to disable preemption of threads in the kernel.
*/
int IGNORE_KERNEL_PREEMPTION = 0; /* XXX - delete this someday */
struct kpreempt_cnts { /* kernel preemption statistics */
int kpc_idle; /* executing idle thread */
int kpc_intr; /* executing interrupt thread */
int kpc_clock; /* executing clock thread */
int kpc_blocked; /* thread has blocked preemption (t_preempt) */
int kpc_notonproc; /* thread is surrendering processor */
int kpc_inswtch; /* thread has ratified scheduling decision */
int kpc_prilevel; /* processor interrupt level is too high */
int kpc_apreempt; /* asynchronous preemption */
int kpc_spreempt; /* synchronous preemption */
/*
* kernel preemption: forced rescheduling, preempt the running kernel thread.
* the argument is old PIL for an interrupt,
* or the distingished value KPREEMPT_SYNC.
*/
void
{
if (IGNORE_KERNEL_PREEMPTION) {
return;
}
/*
* Check that conditions are right for kernel preemption
*/
do {
if (cur_thread->t_preempt) {
/*
* either a privileged thread (idle, panic, interrupt)
* or will check when t_preempt is lowered
*/
if (cur_thread->t_pri < 0)
} else
return;
}
/* this thread will be calling swtch() shortly */
/* already in swtch(), force another */
siron();
}
return;
}
if (getpil() >= DISP_LEVEL) {
/*
* We can't preempt this thread if it is at
* a PIL >= DISP_LEVEL since it may be holding
* a spin lock (like sched_lock).
*/
siron(); /* check back later */
return;
}
if (asyncspl != KPREEMPT_SYNC)
else
cur_thread->t_preempt++;
preempt();
cur_thread->t_preempt--;
} while (CPU->cpu_kprunrun);
}
/*
* Print out debugging info.
*/
static void
{
int s;
s = spl7();
if (u.u_comm[0])
if (type < TRAP_TYPES)
else
switch (type) {
case T_SYSCALL:
printf("Syscall Trap:\n");
break;
case T_AST:
printf("AST\n");
break;
default:
break;
}
printf("Bad %s fault at addr=0x%lx\n",
} else if (addr) {
}
printf("pid=%d, pc=0x%lx, sp=0x%lx, eflags=0x%lx\n",
#if defined(__lint)
/*
* this clause can be deleted when lint bug 4870403 is fixed
* (lint thinks that bit 32 is illegal in a %b format string)
*/
printf("cr0: %x cr4: %b\n",
#else
printf("cr0: %b cr4: %b\n",
#endif
#if defined(__amd64)
#endif
splx(s);
}
static void
{
#if defined(__amd64)
const char fmt[] = "\t%3s: %16lx %3s: %16lx %3s: %16lx\n";
const char fmt[] = "\t%3s: %8lx %3s: %8lx %3s: %8lx %3s: %8lx\n";
printf("\t%3s: %8lx %3s: %8lx %3s: %8lx\n",
#endif /* __i386 */
}
/*
* Handle #gp faults in kernel mode.
*
* One legitimate way this can happen is if we attempt to update segment
* registers to naughty values on the way out of the kernel.
*
* This can happen in a couple of ways: someone - either accidentally or
* on purpose - creates (setcontext(2), lwp_create(2)) or modifies
* (signal(2)) a ucontext that contains silly segment register values.
* Or someone - either accidentally or on purpose - modifies the prgregset_t
* of a subject process via /proc to contain silly segment register values.
*
* (The unfortunate part is that we can end up discovering the bad segment
* register value in the middle of an 'iret' after we've popped most of the
* stack. So it becomes quite difficult to associate an accurate ucontext
* with the lwp, because the act of taking the #gp trap overwrites most of
* what we were going to send the lwp.)
*
* OTOH if it turns out that's -not- the problem, and we're -not- an lwp
* trying to return to user mode and we get a #gp fault, then we need
* to die() -- which will happen if we return non-zero from this routine.
*/
static int
{
int v;
#if defined(__amd64)
extern void _update_sregs(), _update_sregs_done();
/*
* Note carefully the appallingly awful dependency between
* the instruction sequence used in __SEGREGS_POP and these
* instructions encoded here.
*
* XX64 Add some commentary to locore.s/privregs.h to document this.
*/
#endif
/*
* if we're not an lwp, or the pc range is outside _sys_rtt, then
* we should immediately be die()ing horribly
*/
return (1);
/*
* So at least we're in the right part of the kernel.
*
* Disassemble the instruction at the faulting pc.
* Once we know what it is, we carefully reconstruct the stack
* based on the order in which the stack is deconstructed in
* _sys_rtt. Ew.
*/
#if defined(__amd64)
/*
* We took the #gp while trying to perform the iretq.
* This means that either %cs or %ss are bad.
* All we know for sure is that most of the general
* registers have been restored, including the
* segment registers, and all we have left on the
* topmost part of the lwp's stack are the
* registers that the iretq was unable to consume.
*
* All the rest of the state was crushed by the #gp
* which pushed -its- registers atop our old save area
* (because we had to decrement the stack pointer, sigh) so
* all that we can try and do is to reconstruct the
* crushed frame from the #gp trap frame itself.
*/
/*
* Validate simple math
*/
/*
* This is the common case -- we're trying to load
* a bad segment register value in the only section
* of kernel code that ever loads segment registers.
*
* We don't need to do anything at this point because
* the pcb contains all the pending segment register
* state, and the regs are still intact because we
* didn't adjust the stack pointer yet. Given the fidelity
* of all this, we could conceivably send a signal
* to the lwp, rather than core-ing.
*/
}
/*
* We took the #gp while trying to perform the iret.
* This means that either %cs or %ss are bad.
* All we know for sure is that most of the general
* registers have been restored, including the
* segment registers, and all we have left on the
* topmost part of the lwp's stack are the registers that
* the iret was unable to consume.
*
* All the rest of the state was crushed by the #gp
* which pushed -its- registers atop our old save area
* (because we had to decrement the stack pointer, sigh) so
* all that we can try and do is to reconstruct the
* crushed frame from the #gp trap frame itself.
*/
} else {
/*
* Segment registers are reloaded in _sys_rtt
* via the following sequence:
*
* movw 0(%esp), %gs
* movw 4(%esp), %fs
* movw 8(%esp), %es
* movw 12(%esp), %ds
* addl $16, %esp
*
* Thus if any of them fault, we know the user
* registers are left unharmed on the stack.
*/
}
#endif /* __amd64 */
return (1);
/*
* If we get to here, we're reasonably confident that we've
* correctly decoded what happened on the way out of the kernel.
* Rewrite the lwp's registers so that we can create a core dump
* the (at least vaguely) represents the mcontext we were
* being asked to restore when things went so terribly wrong.
*/
/*
* Make sure that we have a meaningful %trapno and %err.
*/
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
/*
* Terminate all LWPs but don't discard them. If another lwp beat us to
* the punch by calling exit(), evaporate now.
*/
proc_is_exiting(p);
if (exitlwps(1) != 0) {
mutex_enter(&p->p_lock);
lwp_exit();
}
#ifdef C2_AUDIT
if (audit_active) /* audit core dump */
#endif
#ifdef C2_AUDIT
if (audit_active) /* audit core dump */
#endif
return (0);
}
/*
* dump_tss() - Display the TSS structure
*/
#if defined(__amd64)
static void
dump_tss(void)
{
}
static void
dump_tss(void)
{
}
#endif /* __amd64 */
#if defined(TRAPTRACE)
int ttrace_nrec = 0; /* number of records to dump out */
/*
* Dump out the last ttrace_nrec traptrace records on each CPU
*/
static void
dump_ttrace(void)
{
int i, j, k;
int n = NCPU;
#if defined(__amd64)
const char banner[] =
"\ncpu address timestamp "
"type vc handler pc\n";
const char fmt1[] = "%3d %016lx %12llx ";
const char banner[] =
"\ncpu address timestamp type vc handler pc\n";
const char fmt1[] = "%3d %08lx %12llx ";
#endif
const char fmt2[] = "%4s %3x ";
const char fmt3[] = "%8s ";
if (ttrace_nrec == 0)
return;
for (i = 0; i < n; i++) {
ttc = &trap_trace_ctl[i];
continue;
for (j = 0; j < ttrace_nrec; j++) {
int type;
current =
continue;
break;
switch (rec->ttr_marker) {
case TT_SYSCALL:
case TT_SYSENTER:
case TT_SYSC:
case TT_SYSC64:
#if defined(__amd64)
switch (rec->ttr_marker) {
case TT_SYSC64:
/*FALLTHROUGH*/
switch (rec->ttr_marker) {
case TT_SYSC64:
#endif
case TT_SYSC:
break;
case TT_SYSCALL:
break;
case TT_SYSENTER:
break;
default:
break;
}
&off);
else
} else {
printf("unknown ");
}
break;
case TT_INTERRUPT:
else
} else {
printf("unknown ");
}
break;
case TT_TRAP:
break;
default:
break;
}
else
if (ttrace_dump_nregs-- > 0) {
int s;
"\t\tipl %x spl %x pri %x\n",
(void *)rec->ttr_curthread);
/*
* print out the pc stack that we recorded
* at trap time (if any)
*/
for (s = 0; s < rec->ttr_sdepth; s++) {
if (s >= TTR_STACK_DEPTH) {
printf("ttr_sdepth corrupt\n");
break;
}
printf("-> %s+0x%lx()\n",
else
}
printf("\n");
}
current -= sizeof (trap_trace_rec_t);
}
}
}
#endif /* TRAPTRACE */
void
{
#if defined(TRAPTRACE)
dump_ttrace();
#endif /* TRAPTRACE */
dump_tss();
}
void
{
}