2 * Copyright (C) 1994, David Greenman
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
7 * the University of Utah, and William Jolitz.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * from: @(#)trap.c 7.4 (Berkeley) 5/13/91
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
44 * AMD64 Trap and System call handling
47 #include "opt_clock.h"
49 #include "opt_hwpmc_hooks.h"
52 #include "opt_kdtrace.h"
53 #include "opt_ktrace.h"
55 #include <sys/param.h>
57 #include <sys/systm.h>
59 #include <sys/pioctl.h>
60 #include <sys/ptrace.h>
62 #include <sys/kernel.h>
65 #include <sys/mutex.h>
66 #include <sys/resourcevar.h>
67 #include <sys/signalvar.h>
68 #include <sys/syscall.h>
69 #include <sys/sysctl.h>
70 #include <sys/sysent.h>
72 #include <sys/vmmeter.h>
74 #include <sys/ktrace.h>
77 #include <sys/pmckern.h>
79 #include <security/audit/audit.h>
82 #include <vm/vm_param.h>
84 #include <vm/vm_kern.h>
85 #include <vm/vm_map.h>
86 #include <vm/vm_page.h>
87 #include <vm/vm_extern.h>
89 #include <machine/cpu.h>
90 #include <machine/intr_machdep.h>
91 #include <machine/md_var.h>
92 #include <machine/pcb.h>
94 #include <machine/smp.h>
96 #include <machine/tss.h>
99 #include <sys/dtrace_bsd.h>
102 * This is a hook which is initialised by the dtrace module
103 * to handle traps which might occur during DTrace probe
106 dtrace_trap_func_t dtrace_trap_func;
108 dtrace_doubletrap_func_t dtrace_doubletrap_func;
111 * This is a hook which is initialised by the systrace module
112 * when it is loaded. This keeps the DTrace syscall provider
113 * implementation opaque.
115 systrace_probe_func_t systrace_probe_func;
118 extern void trap(struct trapframe *frame);
119 extern void syscall(struct trapframe *frame);
120 void dblfault_handler(struct trapframe *frame);
122 static int trap_pfault(struct trapframe *, int);
123 static void trap_fatal(struct trapframe *, vm_offset_t);
125 #define MAX_TRAP_MSG 30
126 static char *trap_msg[] = {
128 "privileged instruction fault", /* 1 T_PRIVINFLT */
130 "breakpoint instruction fault", /* 3 T_BPTFLT */
133 "arithmetic trap", /* 6 T_ARITHTRAP */
136 "general protection fault", /* 9 T_PROTFLT */
137 "trace trap", /* 10 T_TRCTRAP */
139 "page fault", /* 12 T_PAGEFLT */
141 "alignment fault", /* 14 T_ALIGNFLT */
145 "integer divide fault", /* 18 T_DIVIDE */
146 "non-maskable interrupt trap", /* 19 T_NMI */
147 "overflow trap", /* 20 T_OFLOW */
148 "FPU bounds check fault", /* 21 T_BOUND */
149 "FPU device not available", /* 22 T_DNA */
150 "double fault", /* 23 T_DOUBLEFLT */
151 "FPU operand fetch fault", /* 24 T_FPOPFLT */
152 "invalid TSS fault", /* 25 T_TSSFLT */
153 "segment not present fault", /* 26 T_SEGNPFLT */
154 "stack fault", /* 27 T_STKFLT */
155 "machine check trap", /* 28 T_MCHK */
156 "SIMD floating-point exception", /* 29 T_XMMFLT */
157 "reserved (unknown) fault", /* 30 T_RESERVED */
161 static int kdb_on_nmi = 1;
162 SYSCTL_INT(_machdep, OID_AUTO, kdb_on_nmi, CTLFLAG_RW,
163 &kdb_on_nmi, 0, "Go to KDB on NMI");
165 static int panic_on_nmi = 1;
166 SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RW,
167 &panic_on_nmi, 0, "Panic on NMI");
168 static int prot_fault_translation = 0;
169 SYSCTL_INT(_machdep, OID_AUTO, prot_fault_translation, CTLFLAG_RW,
170 &prot_fault_translation, 0, "Select signal to deliver on protection fault");
172 extern char *syscallnames[];
175 * Exception, fault, and trap interface to the FreeBSD kernel.
176 * This common code is called from assembly language IDT gate entry
177 * routines that prepare a suitable stack frame, and restore this
178 * frame after the exception has been processed.
182 trap(struct trapframe *frame)
184 struct thread *td = curthread;
185 struct proc *p = td->td_proc;
186 int i = 0, ucode = 0, code;
191 PCPU_INC(cnt.v_trap);
192 type = frame->tf_trapno;
196 /* Handler for NMI IPIs used for stopping CPUs. */
198 if (ipi_nmi_handler() == 0)
201 #endif /* STOP_NMI */
213 * CPU PMCs interrupt using an NMI. If the PMC module is
214 * active, pass the 'rip' value to the PMC module's interrupt
215 * handler. A return value of '1' from the handler means that
216 * the NMI was handled by it and we can return immediately.
218 if (type == T_NMI && pmc_intr &&
219 (*pmc_intr)(PCPU_GET(cpuid), (uintptr_t) frame->tf_rip,
220 TRAPF_USERMODE(frame)))
226 * A trap can occur while DTrace executes a probe. Before
227 * executing the probe, DTrace blocks re-scheduling and sets
228 * a flag in it's per-cpu flags to indicate that it doesn't
229 * want to fault. On returning from the the probe, the no-fault
230 * flag is cleared and finally re-scheduling is enabled.
232 * If the DTrace kernel module has registered a trap handler,
233 * call it and if it returns non-zero, assume that it has
234 * handled the trap and modified the trap frame so that this
235 * function can return normally.
237 if (dtrace_trap_func != NULL)
238 if ((*dtrace_trap_func)(frame, type))
242 if ((frame->tf_rflags & PSL_I) == 0) {
244 * Buggy application or kernel code has disabled
245 * interrupts and then trapped. Enabling interrupts
246 * now is wrong, but it is better than running with
247 * interrupts disabled until they are accidentally
250 if (ISPL(frame->tf_cs) == SEL_UPL)
252 "pid %ld (%s): trap %d with interrupts disabled\n",
253 (long)curproc->p_pid, curproc->p_comm, type);
254 else if (type != T_NMI && type != T_BPTFLT &&
257 * XXX not quite right, since this may be for a
258 * multiple fault in user mode.
260 printf("kernel trap %d with interrupts disabled\n",
263 * We shouldn't enable interrupts while holding a
264 * spin lock or servicing an NMI.
266 if (type != T_NMI && td->td_md.md_spinlock_count == 0)
271 code = frame->tf_err;
272 if (type == T_PAGEFLT) {
274 * If we get a page fault while in a critical section, then
275 * it is most likely a fatal kernel page fault. The kernel
276 * is already going to panic trying to get a sleep lock to
277 * do the VM lookup, so just consider it a fatal trap so the
278 * kernel can print out a useful trap message and even get
281 * If we get a page fault while holding a non-sleepable
282 * lock, then it is most likely a fatal kernel page fault.
283 * If WITNESS is enabled, then it's going to whine about
284 * bogus LORs with various VM locks, so just skip to the
285 * fatal trap handling directly.
287 if (td->td_critnest != 0 ||
288 WITNESS_CHECK(WARN_SLEEPOK | WARN_GIANTOK, NULL,
289 "Kernel page fault") != 0)
290 trap_fatal(frame, frame->tf_addr);
293 if (ISPL(frame->tf_cs) == SEL_UPL) {
297 td->td_frame = frame;
298 addr = frame->tf_rip;
299 if (td->td_ucred != p->p_ucred)
300 cred_update_thread(td);
303 case T_PRIVINFLT: /* privileged instruction fault */
308 case T_BPTFLT: /* bpt instruction fault */
309 case T_TRCTRAP: /* trace trap */
311 frame->tf_rflags &= ~PSL_T;
313 ucode = (type == T_TRCTRAP ? TRAP_TRACE : TRAP_BRKPT);
316 case T_ARITHTRAP: /* arithmetic trap */
323 case T_PROTFLT: /* general protection fault */
327 case T_STKFLT: /* stack fault */
328 case T_SEGNPFLT: /* segment not present fault */
332 case T_TSSFLT: /* invalid TSS fault */
336 case T_DOUBLEFLT: /* double fault */
342 case T_PAGEFLT: /* page fault */
343 addr = frame->tf_addr;
345 if (td->td_pflags & TDP_SA)
346 thread_user_enter(td);
348 i = trap_pfault(frame, TRUE);
357 if (prot_fault_translation == 0) {
360 * This check also covers the images
361 * without the ABI-tag ELF note.
363 if (p->p_osrel >= 700004) {
368 ucode = BUS_PAGE_FAULT;
370 } else if (prot_fault_translation == 1) {
372 * Always compat mode.
375 ucode = BUS_PAGE_FAULT;
378 * Always SIGSEGV mode.
386 case T_DIVIDE: /* integer divide fault */
393 /* machine/parity/power fail/"kitchen sink" faults */
395 if (isa_nmi(code) == 0) {
398 * NMI can be hooked up to a pushbutton
402 printf ("NMI ... going to debugger\n");
403 kdb_trap(type, 0, frame);
407 } else if (panic_on_nmi)
408 panic("NMI indicates hardware failure");
412 case T_OFLOW: /* integer overflow fault */
417 case T_BOUND: /* bounds check fault */
423 /* transparent fault (due to context switch "late") */
427 case T_FPOPFLT: /* FPU operand fetch fault */
432 case T_XMMFLT: /* SIMD floating-point exception */
440 KASSERT(cold || td->td_ucred != NULL,
441 ("kernel trap doesn't have ucred"));
443 case T_PAGEFLT: /* page fault */
444 (void) trap_pfault(frame, FALSE);
449 * The kernel is apparently using fpu for copying.
450 * XXX this should be fatal unless the kernel has
451 * registered such use.
454 printf("fpudna in kernel mode!\n");
457 case T_STKFLT: /* stack fault */
460 case T_PROTFLT: /* general protection fault */
461 case T_SEGNPFLT: /* segment not present fault */
462 if (td->td_intr_nesting_level != 0)
466 * Invalid segment selectors and out of bounds
467 * %rip's and %rsp's can be set up in user mode.
468 * This causes a fault in kernel mode when the
469 * kernel tries to return to user mode. We want
470 * to get this fault so that we can fix the
471 * problem here and not have to check all the
472 * selectors and pointers when the user changes
475 if (frame->tf_rip == (long)doreti_iret) {
476 frame->tf_rip = (long)doreti_iret_fault;
479 if (PCPU_GET(curpcb)->pcb_onfault != NULL) {
481 (long)PCPU_GET(curpcb)->pcb_onfault;
488 * PSL_NT can be set in user mode and isn't cleared
489 * automatically when the kernel is entered. This
490 * causes a TSS fault when the kernel attempts to
491 * `iret' because the TSS link is uninitialized. We
492 * want to get this fault so that we can fix the
493 * problem here and not every time the kernel is
496 if (frame->tf_rflags & PSL_NT) {
497 frame->tf_rflags &= ~PSL_NT;
502 case T_TRCTRAP: /* trace trap */
504 * Ignore debug register trace traps due to
505 * accesses in the user's address space, which
506 * can happen under several conditions such as
507 * if a user sets a watchpoint on a buffer and
508 * then passes that buffer to a system call.
509 * We still want to get TRCTRAPS for addresses
510 * in kernel space because that is useful when
511 * debugging the kernel.
513 if (user_dbreg_trap()) {
515 * Reset breakpoint bits because the
518 /* XXX check upper bits here */
519 load_dr6(rdr6() & 0xfffffff0);
523 * FALLTHROUGH (TRCTRAP kernel mode, kernel address)
527 * If KDB is enabled, let it handle the debugger trap.
528 * Otherwise, debugger traps "can't happen".
531 if (kdb_trap(type, 0, frame))
539 /* machine/parity/power fail/"kitchen sink" faults */
540 if (isa_nmi(code) == 0) {
543 * NMI can be hooked up to a pushbutton
547 printf ("NMI ... going to debugger\n");
548 kdb_trap(type, 0, frame);
552 } else if (panic_on_nmi == 0)
558 trap_fatal(frame, 0);
562 /* Translate fault for emulators (e.g. Linux) */
563 if (*p->p_sysent->sv_transtrap)
564 i = (*p->p_sysent->sv_transtrap)(i, type);
566 ksiginfo_init_trap(&ksi);
568 ksi.ksi_code = ucode;
569 ksi.ksi_trapno = type;
570 ksi.ksi_addr = (void *)addr;
571 trapsignal(td, &ksi);
574 if (type <= MAX_TRAP_MSG) {
575 uprintf("fatal process exception: %s",
577 if ((type == T_PAGEFLT) || (type == T_PROTFLT))
578 uprintf(", fault VA = 0x%lx", frame->tf_addr);
585 mtx_assert(&Giant, MA_NOTOWNED);
592 trap_pfault(frame, usermode)
593 struct trapframe *frame;
597 struct vmspace *vm = NULL;
601 struct thread *td = curthread;
602 struct proc *p = td->td_proc;
603 vm_offset_t eva = frame->tf_addr;
605 va = trunc_page(eva);
606 if (va >= VM_MIN_KERNEL_ADDRESS) {
608 * Don't allow user-mode faults in kernel address space.
616 * This is a fault on non-kernel virtual memory.
617 * vm is initialized above to NULL. If curproc is NULL
618 * or curproc->p_vmspace is NULL the fault is fatal.
630 * PGEX_I is defined only if the execute disable bit capability is
631 * supported and enabled.
633 if (frame->tf_err & PGEX_W)
634 ftype = VM_PROT_WRITE;
635 else if ((frame->tf_err & PGEX_I) && pg_nx != 0)
636 ftype = VM_PROT_EXECUTE;
638 ftype = VM_PROT_READ;
640 if (map != kernel_map) {
642 * Keep swapout from messing with us during this
649 /* Fault in the user page: */
650 rv = vm_fault(map, va, ftype,
651 (ftype & VM_PROT_WRITE) ? VM_FAULT_DIRTY
659 * Don't have to worry about process locking or stacks in the
662 rv = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
664 if (rv == KERN_SUCCESS)
668 if (td->td_intr_nesting_level == 0 &&
669 PCPU_GET(curpcb)->pcb_onfault != NULL) {
670 frame->tf_rip = (long)PCPU_GET(curpcb)->pcb_onfault;
673 trap_fatal(frame, eva);
677 return((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV);
681 trap_fatal(frame, eva)
682 struct trapframe *frame;
688 struct soft_segment_descriptor softseg;
691 code = frame->tf_err;
692 type = frame->tf_trapno;
693 sdtossd(&gdt[NGDT * PCPU_GET(cpuid) + IDXSEL(frame->tf_cs & 0xffff)],
696 if (type <= MAX_TRAP_MSG)
697 msg = trap_msg[type];
700 printf("\n\nFatal trap %d: %s while in %s mode\n", type, msg,
701 ISPL(frame->tf_cs) == SEL_UPL ? "user" : "kernel");
703 /* two separate prints in case of a trap on an unmapped page */
704 printf("cpuid = %d; ", PCPU_GET(cpuid));
705 printf("apic id = %02x\n", PCPU_GET(apic_id));
707 if (type == T_PAGEFLT) {
708 printf("fault virtual address = 0x%lx\n", eva);
709 printf("fault code = %s %s %s, %s\n",
710 code & PGEX_U ? "user" : "supervisor",
711 code & PGEX_W ? "write" : "read",
712 code & PGEX_I ? "instruction" : "data",
713 code & PGEX_P ? "protection violation" : "page not present");
715 printf("instruction pointer = 0x%lx:0x%lx\n",
716 frame->tf_cs & 0xffff, frame->tf_rip);
717 if (ISPL(frame->tf_cs) == SEL_UPL) {
718 ss = frame->tf_ss & 0xffff;
721 ss = GSEL(GDATA_SEL, SEL_KPL);
722 esp = (long)&frame->tf_rsp;
724 printf("stack pointer = 0x%x:0x%lx\n", ss, esp);
725 printf("frame pointer = 0x%x:0x%lx\n", ss, frame->tf_rbp);
726 printf("code segment = base 0x%lx, limit 0x%lx, type 0x%x\n",
727 softseg.ssd_base, softseg.ssd_limit, softseg.ssd_type);
728 printf(" = DPL %d, pres %d, long %d, def32 %d, gran %d\n",
729 softseg.ssd_dpl, softseg.ssd_p, softseg.ssd_long, softseg.ssd_def32,
731 printf("processor eflags = ");
732 if (frame->tf_rflags & PSL_T)
733 printf("trace trap, ");
734 if (frame->tf_rflags & PSL_I)
735 printf("interrupt enabled, ");
736 if (frame->tf_rflags & PSL_NT)
737 printf("nested task, ");
738 if (frame->tf_rflags & PSL_RF)
740 printf("IOPL = %ld\n", (frame->tf_rflags & PSL_IOPL) >> 12);
741 printf("current process = ");
744 (u_long)curproc->p_pid, curproc->p_comm ?
745 curproc->p_comm : "");
751 if (debugger_on_panic || kdb_active)
752 if (kdb_trap(type, 0, frame))
755 printf("trap number = %d\n", type);
756 if (type <= MAX_TRAP_MSG)
757 panic("%s", trap_msg[type]);
759 panic("unknown/reserved trap");
763 * Double fault handler. Called when a fault occurs while writing
764 * a frame for a trap/exception onto the stack. This usually occurs
765 * when the stack overflows (such is the case with infinite recursion,
769 dblfault_handler(struct trapframe *frame)
772 if (dtrace_doubletrap_func != NULL)
773 (*dtrace_doubletrap_func)();
775 printf("\nFatal double fault\n");
776 printf("rip = 0x%lx\n", frame->tf_rip);
777 printf("rsp = 0x%lx\n", frame->tf_rsp);
778 printf("rbp = 0x%lx\n", frame->tf_rbp);
780 /* two separate prints in case of a trap on an unmapped page */
781 printf("cpuid = %d; ", PCPU_GET(cpuid));
782 printf("apic id = %02x\n", PCPU_GET(apic_id));
784 panic("double fault");
788 * syscall - system call request C handler
790 * A system call is essentially treated as a trap.
793 syscall(struct trapframe *frame)
796 struct sysent *callp;
797 struct thread *td = curthread;
798 struct proc *p = td->td_proc;
799 register_t orig_tf_rflags;
808 PCPU_INC(cnt.v_syscall);
811 if (ISPL(frame->tf_cs) != SEL_UPL) {
820 td->td_frame = frame;
821 if (td->td_ucred != p->p_ucred)
822 cred_update_thread(td);
824 if (p->p_flag & P_SA)
825 thread_user_enter(td);
827 params = (caddr_t)frame->tf_rsp + sizeof(register_t);
828 code = frame->tf_rax;
829 orig_tf_rflags = frame->tf_rflags;
831 if (p->p_sysent->sv_prepsyscall) {
833 * The prep code is MP aware.
835 (*p->p_sysent->sv_prepsyscall)(frame, (int *)args, &code, ¶ms);
837 if (code == SYS_syscall || code == SYS___syscall) {
838 code = frame->tf_rdi;
844 if (p->p_sysent->sv_mask)
845 code &= p->p_sysent->sv_mask;
847 if (code >= p->p_sysent->sv_size)
848 callp = &p->p_sysent->sv_table[0];
850 callp = &p->p_sysent->sv_table[code];
852 narg = callp->sy_narg;
855 * copyin and the ktrsyscall()/ktrsysret() code is MP-aware
857 KASSERT(narg <= sizeof(args) / sizeof(args[0]),
858 ("Too many syscall arguments!"));
860 argp = &frame->tf_rdi;
862 bcopy(argp, args, sizeof(args[0]) * regcnt);
864 KASSERT(params != NULL, ("copyin args with no params!"));
865 error = copyin(params, &args[regcnt],
866 (narg - regcnt) * sizeof(args[0]));
871 if (KTRPOINT(td, KTR_SYSCALL))
872 ktrsyscall(code, narg, argp);
875 CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td,
876 td->td_proc->p_pid, td->td_proc->p_comm, code);
881 td->td_retval[0] = 0;
882 td->td_retval[1] = frame->tf_rdx;
884 STOPEVENT(p, S_SCE, narg);
886 PTRACESTOP_SC(p, td, S_PT_SCE);
890 * If the systrace module has registered it's probe
891 * callback and if there is a probe active for the
892 * syscall 'entry', process the probe.
894 if (systrace_probe_func != NULL && callp->sy_entry != 0)
895 (*systrace_probe_func)(callp->sy_entry, code, callp,
899 AUDIT_SYSCALL_ENTER(code, td);
900 error = (*callp->sy_call)(td, argp);
901 AUDIT_SYSCALL_EXIT(error, td);
903 /* Save the latest error return value. */
904 td->td_errno = error;
908 * If the systrace module has registered it's probe
909 * callback and if there is a probe active for the
910 * syscall 'return', process the probe.
912 if (systrace_probe_func != NULL && callp->sy_return != 0)
913 (*systrace_probe_func)(callp->sy_return, code, callp,
920 frame->tf_rax = td->td_retval[0];
921 frame->tf_rdx = td->td_retval[1];
922 frame->tf_rflags &= ~PSL_C;
927 * Reconstruct pc, we know that 'syscall' is 2 bytes.
928 * We have to do a full context restore so that %r10
929 * (which was holding the value of %rcx) is restored for
930 * the next iteration.
932 frame->tf_rip -= frame->tf_err;
933 frame->tf_r10 = frame->tf_rcx;
934 td->td_pcb->pcb_flags |= PCB_FULLCTX;
941 if (p->p_sysent->sv_errsize) {
942 if (error >= p->p_sysent->sv_errsize)
943 error = -1; /* XXX */
945 error = p->p_sysent->sv_errtbl[error];
947 frame->tf_rax = error;
948 frame->tf_rflags |= PSL_C;
955 if (orig_tf_rflags & PSL_T) {
956 frame->tf_rflags &= ~PSL_T;
957 ksiginfo_init_trap(&ksi);
958 ksi.ksi_signo = SIGTRAP;
959 ksi.ksi_code = TRAP_TRACE;
960 ksi.ksi_addr = (void *)frame->tf_rip;
961 trapsignal(td, &ksi);
965 * Check for misbehavior.
967 WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning",
968 (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???");
969 KASSERT(td->td_critnest == 0,
970 ("System call %s returning in a critical section",
971 (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"));
972 KASSERT(td->td_locks == 0,
973 ("System call %s returning with %d locks held",
974 (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???",
978 * Handle reschedule and other end-of-syscall issues
982 CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td,
983 td->td_proc->p_pid, td->td_proc->p_comm, code);
986 if (KTRPOINT(td, KTR_SYSRET))
987 ktrsysret(code, error, td->td_retval[0]);
991 * This works because errno is findable through the
992 * register set. If we ever support an emulation where this
993 * is not the case, this code will need to be revisited.
995 STOPEVENT(p, S_SCX, code);
997 PTRACESTOP_SC(p, td, S_PT_SCX);