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"
54 #include <sys/param.h>
56 #include <sys/systm.h>
58 #include <sys/pioctl.h>
59 #include <sys/ptrace.h>
61 #include <sys/kernel.h>
64 #include <sys/mutex.h>
65 #include <sys/resourcevar.h>
66 #include <sys/signalvar.h>
67 #include <sys/syscall.h>
68 #include <sys/sysctl.h>
69 #include <sys/sysent.h>
71 #include <sys/vmmeter.h>
73 #include <sys/pmckern.h>
77 #include <vm/vm_param.h>
79 #include <vm/vm_kern.h>
80 #include <vm/vm_map.h>
81 #include <vm/vm_page.h>
82 #include <vm/vm_extern.h>
84 #include <machine/cpu.h>
85 #include <machine/intr_machdep.h>
87 #include <machine/md_var.h>
88 #include <machine/pcb.h>
90 #include <machine/smp.h>
92 #include <machine/tss.h>
95 #include <sys/dtrace_bsd.h>
98 * This is a hook which is initialised by the dtrace module
99 * to handle traps which might occur during DTrace probe
102 dtrace_trap_func_t dtrace_trap_func;
104 dtrace_doubletrap_func_t dtrace_doubletrap_func;
107 * This is a hook which is initialised by the systrace module
108 * when it is loaded. This keeps the DTrace syscall provider
109 * implementation opaque.
111 systrace_probe_func_t systrace_probe_func;
114 * These hooks are necessary for the pid, usdt and fasttrap providers.
116 dtrace_fasttrap_probe_ptr_t dtrace_fasttrap_probe_ptr;
117 dtrace_pid_probe_ptr_t dtrace_pid_probe_ptr;
118 dtrace_return_probe_ptr_t dtrace_return_probe_ptr;
121 extern void trap(struct trapframe *frame);
122 extern void syscall(struct trapframe *frame);
123 void dblfault_handler(struct trapframe *frame);
125 static int trap_pfault(struct trapframe *, int);
126 static void trap_fatal(struct trapframe *, vm_offset_t);
128 #define MAX_TRAP_MSG 33
129 static char *trap_msg[] = {
131 "privileged instruction fault", /* 1 T_PRIVINFLT */
133 "breakpoint instruction fault", /* 3 T_BPTFLT */
136 "arithmetic trap", /* 6 T_ARITHTRAP */
139 "general protection fault", /* 9 T_PROTFLT */
140 "trace trap", /* 10 T_TRCTRAP */
142 "page fault", /* 12 T_PAGEFLT */
144 "alignment fault", /* 14 T_ALIGNFLT */
148 "integer divide fault", /* 18 T_DIVIDE */
149 "non-maskable interrupt trap", /* 19 T_NMI */
150 "overflow trap", /* 20 T_OFLOW */
151 "FPU bounds check fault", /* 21 T_BOUND */
152 "FPU device not available", /* 22 T_DNA */
153 "double fault", /* 23 T_DOUBLEFLT */
154 "FPU operand fetch fault", /* 24 T_FPOPFLT */
155 "invalid TSS fault", /* 25 T_TSSFLT */
156 "segment not present fault", /* 26 T_SEGNPFLT */
157 "stack fault", /* 27 T_STKFLT */
158 "machine check trap", /* 28 T_MCHK */
159 "SIMD floating-point exception", /* 29 T_XMMFLT */
160 "reserved (unknown) fault", /* 30 T_RESERVED */
161 "", /* 31 unused (reserved) */
162 "DTrace pid return trap", /* 32 T_DTRACE_RET */
163 "DTrace fasttrap probe trap", /* 33 T_DTRACE_PROBE */
167 static int kdb_on_nmi = 1;
168 SYSCTL_INT(_machdep, OID_AUTO, kdb_on_nmi, CTLFLAG_RW,
169 &kdb_on_nmi, 0, "Go to KDB on NMI");
170 TUNABLE_INT("machdep.kdb_on_nmi", &kdb_on_nmi);
172 static int panic_on_nmi = 1;
173 SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RW,
174 &panic_on_nmi, 0, "Panic on NMI");
175 TUNABLE_INT("machdep.panic_on_nmi", &panic_on_nmi);
176 static int prot_fault_translation = 0;
177 SYSCTL_INT(_machdep, OID_AUTO, prot_fault_translation, CTLFLAG_RW,
178 &prot_fault_translation, 0, "Select signal to deliver on protection fault");
181 * Exception, fault, and trap interface to the FreeBSD kernel.
182 * This common code is called from assembly language IDT gate entry
183 * routines that prepare a suitable stack frame, and restore this
184 * frame after the exception has been processed.
188 trap(struct trapframe *frame)
190 struct thread *td = curthread;
191 struct proc *p = td->td_proc;
192 int i = 0, ucode = 0, code;
197 PCPU_INC(cnt.v_trap);
198 type = frame->tf_trapno;
201 /* Handler for NMI IPIs used for stopping CPUs. */
203 if (ipi_nmi_handler() == 0)
215 if (type == T_RESERVED) {
216 trap_fatal(frame, 0);
222 * CPU PMCs interrupt using an NMI. If the PMC module is
223 * active, pass the 'rip' value to the PMC module's interrupt
224 * handler. A return value of '1' from the handler means that
225 * the NMI was handled by it and we can return immediately.
227 if (type == T_NMI && pmc_intr &&
228 (*pmc_intr)(PCPU_GET(cpuid), frame))
232 if (type == T_MCHK) {
239 * A trap can occur while DTrace executes a probe. Before
240 * executing the probe, DTrace blocks re-scheduling and sets
241 * a flag in it's per-cpu flags to indicate that it doesn't
242 * want to fault. On returning from the probe, the no-fault
243 * flag is cleared and finally re-scheduling is enabled.
245 * If the DTrace kernel module has registered a trap handler,
246 * call it and if it returns non-zero, assume that it has
247 * handled the trap and modified the trap frame so that this
248 * function can return normally.
250 if (type == T_DTRACE_PROBE || type == T_DTRACE_RET ||
254 fill_frame_regs(frame, ®s);
255 if (type == T_DTRACE_PROBE &&
256 dtrace_fasttrap_probe_ptr != NULL &&
257 dtrace_fasttrap_probe_ptr(®s) == 0)
259 else if (type == T_BPTFLT &&
260 dtrace_pid_probe_ptr != NULL &&
261 dtrace_pid_probe_ptr(®s) == 0)
263 else if (type == T_DTRACE_RET &&
264 dtrace_return_probe_ptr != NULL &&
265 dtrace_return_probe_ptr(®s) == 0)
268 if (dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type))
272 if ((frame->tf_rflags & PSL_I) == 0) {
274 * Buggy application or kernel code has disabled
275 * interrupts and then trapped. Enabling interrupts
276 * now is wrong, but it is better than running with
277 * interrupts disabled until they are accidentally
280 if (ISPL(frame->tf_cs) == SEL_UPL)
282 "pid %ld (%s): trap %d with interrupts disabled\n",
283 (long)curproc->p_pid, curthread->td_name, type);
284 else if (type != T_NMI && type != T_BPTFLT &&
287 * XXX not quite right, since this may be for a
288 * multiple fault in user mode.
290 printf("kernel trap %d with interrupts disabled\n",
294 * We shouldn't enable interrupts while holding a
297 if (td->td_md.md_spinlock_count == 0)
302 code = frame->tf_err;
304 if (ISPL(frame->tf_cs) == SEL_UPL) {
308 td->td_frame = frame;
309 addr = frame->tf_rip;
310 if (td->td_ucred != p->p_ucred)
311 cred_update_thread(td);
314 case T_PRIVINFLT: /* privileged instruction fault */
319 case T_BPTFLT: /* bpt instruction fault */
320 case T_TRCTRAP: /* trace trap */
322 frame->tf_rflags &= ~PSL_T;
324 ucode = (type == T_TRCTRAP ? TRAP_TRACE : TRAP_BRKPT);
327 case T_ARITHTRAP: /* arithmetic trap */
334 case T_PROTFLT: /* general protection fault */
338 case T_STKFLT: /* stack fault */
339 case T_SEGNPFLT: /* segment not present fault */
343 case T_TSSFLT: /* invalid TSS fault */
347 case T_DOUBLEFLT: /* double fault */
353 case T_PAGEFLT: /* page fault */
354 addr = frame->tf_addr;
355 i = trap_pfault(frame, TRUE);
364 if (prot_fault_translation == 0) {
367 * This check also covers the images
368 * without the ABI-tag ELF note.
370 if (SV_CURPROC_ABI() == SV_ABI_FREEBSD
371 && p->p_osrel >= P_OSREL_SIGSEGV) {
376 ucode = BUS_PAGE_FAULT;
378 } else if (prot_fault_translation == 1) {
380 * Always compat mode.
383 ucode = BUS_PAGE_FAULT;
386 * Always SIGSEGV mode.
394 case T_DIVIDE: /* integer divide fault */
401 /* machine/parity/power fail/"kitchen sink" faults */
402 if (isa_nmi(code) == 0) {
405 * NMI can be hooked up to a pushbutton
409 printf ("NMI ... going to debugger\n");
410 kdb_trap(type, 0, frame);
414 } else if (panic_on_nmi)
415 panic("NMI indicates hardware failure");
419 case T_OFLOW: /* integer overflow fault */
424 case T_BOUND: /* bounds check fault */
430 /* transparent fault (due to context switch "late") */
431 KASSERT(PCB_USER_FPU(td->td_pcb),
432 ("kernel FPU ctx has leaked"));
436 case T_FPOPFLT: /* FPU operand fetch fault */
441 case T_XMMFLT: /* SIMD floating-point exception */
449 KASSERT(cold || td->td_ucred != NULL,
450 ("kernel trap doesn't have ucred"));
452 case T_PAGEFLT: /* page fault */
453 (void) trap_pfault(frame, FALSE);
457 KASSERT(!PCB_USER_FPU(td->td_pcb),
458 ("Unregistered use of FPU in kernel"));
462 case T_ARITHTRAP: /* arithmetic trap */
463 case T_XMMFLT: /* SIMD floating-point exception */
464 case T_FPOPFLT: /* FPU operand fetch fault */
466 * XXXKIB for now disable any FPU traps in kernel
467 * handler registration seems to be overkill
469 trap_fatal(frame, 0);
472 case T_STKFLT: /* stack fault */
475 case T_PROTFLT: /* general protection fault */
476 case T_SEGNPFLT: /* segment not present fault */
477 if (td->td_intr_nesting_level != 0)
481 * Invalid segment selectors and out of bounds
482 * %rip's and %rsp's can be set up in user mode.
483 * This causes a fault in kernel mode when the
484 * kernel tries to return to user mode. We want
485 * to get this fault so that we can fix the
486 * problem here and not have to check all the
487 * selectors and pointers when the user changes
490 if (frame->tf_rip == (long)doreti_iret) {
491 frame->tf_rip = (long)doreti_iret_fault;
494 if (frame->tf_rip == (long)ld_ds) {
495 frame->tf_rip = (long)ds_load_fault;
498 if (frame->tf_rip == (long)ld_es) {
499 frame->tf_rip = (long)es_load_fault;
502 if (frame->tf_rip == (long)ld_fs) {
503 frame->tf_rip = (long)fs_load_fault;
506 if (frame->tf_rip == (long)ld_gs) {
507 frame->tf_rip = (long)gs_load_fault;
510 if (frame->tf_rip == (long)ld_gsbase) {
511 frame->tf_rip = (long)gsbase_load_fault;
514 if (frame->tf_rip == (long)ld_fsbase) {
515 frame->tf_rip = (long)fsbase_load_fault;
518 if (PCPU_GET(curpcb)->pcb_onfault != NULL) {
520 (long)PCPU_GET(curpcb)->pcb_onfault;
527 * PSL_NT can be set in user mode and isn't cleared
528 * automatically when the kernel is entered. This
529 * causes a TSS fault when the kernel attempts to
530 * `iret' because the TSS link is uninitialized. We
531 * want to get this fault so that we can fix the
532 * problem here and not every time the kernel is
535 if (frame->tf_rflags & PSL_NT) {
536 frame->tf_rflags &= ~PSL_NT;
541 case T_TRCTRAP: /* trace trap */
543 * Ignore debug register trace traps due to
544 * accesses in the user's address space, which
545 * can happen under several conditions such as
546 * if a user sets a watchpoint on a buffer and
547 * then passes that buffer to a system call.
548 * We still want to get TRCTRAPS for addresses
549 * in kernel space because that is useful when
550 * debugging the kernel.
552 if (user_dbreg_trap()) {
554 * Reset breakpoint bits because the
557 /* XXX check upper bits here */
558 load_dr6(rdr6() & 0xfffffff0);
562 * FALLTHROUGH (TRCTRAP kernel mode, kernel address)
566 * If KDB is enabled, let it handle the debugger trap.
567 * Otherwise, debugger traps "can't happen".
570 if (kdb_trap(type, 0, frame))
577 /* machine/parity/power fail/"kitchen sink" faults */
578 if (isa_nmi(code) == 0) {
581 * NMI can be hooked up to a pushbutton
585 printf ("NMI ... going to debugger\n");
586 kdb_trap(type, 0, frame);
590 } else if (panic_on_nmi == 0)
596 trap_fatal(frame, 0);
600 /* Translate fault for emulators (e.g. Linux) */
601 if (*p->p_sysent->sv_transtrap)
602 i = (*p->p_sysent->sv_transtrap)(i, type);
604 ksiginfo_init_trap(&ksi);
606 ksi.ksi_code = ucode;
607 ksi.ksi_trapno = type;
608 ksi.ksi_addr = (void *)addr;
609 trapsignal(td, &ksi);
613 mtx_assert(&Giant, MA_NOTOWNED);
614 KASSERT(PCB_USER_FPU(td->td_pcb),
615 ("Return from trap with kernel FPU ctx leaked"));
622 trap_pfault(frame, usermode)
623 struct trapframe *frame;
627 struct vmspace *vm = NULL;
631 struct thread *td = curthread;
632 struct proc *p = td->td_proc;
633 vm_offset_t eva = frame->tf_addr;
635 if (__predict_false((td->td_pflags & TDP_NOFAULTING) != 0)) {
637 * Due to both processor errata and lazy TLB invalidation when
638 * access restrictions are removed from virtual pages, memory
639 * accesses that are allowed by the physical mapping layer may
640 * nonetheless cause one spurious page fault per virtual page.
641 * When the thread is executing a "no faulting" section that
642 * is bracketed by vm_fault_{disable,enable}_pagefaults(),
643 * every page fault is treated as a spurious page fault,
644 * unless it accesses the same virtual address as the most
645 * recent page fault within the same "no faulting" section.
647 if (td->td_md.md_spurflt_addr != eva ||
648 (td->td_pflags & TDP_RESETSPUR) != 0) {
650 * Do nothing to the TLB. A stale TLB entry is
651 * flushed automatically by a page fault.
653 td->td_md.md_spurflt_addr = eva;
654 td->td_pflags &= ~TDP_RESETSPUR;
659 * If we get a page fault while in a critical section, then
660 * it is most likely a fatal kernel page fault. The kernel
661 * is already going to panic trying to get a sleep lock to
662 * do the VM lookup, so just consider it a fatal trap so the
663 * kernel can print out a useful trap message and even get
666 * If we get a page fault while holding a non-sleepable
667 * lock, then it is most likely a fatal kernel page fault.
668 * If WITNESS is enabled, then it's going to whine about
669 * bogus LORs with various VM locks, so just skip to the
670 * fatal trap handling directly.
672 if (td->td_critnest != 0 ||
673 WITNESS_CHECK(WARN_SLEEPOK | WARN_GIANTOK, NULL,
674 "Kernel page fault") != 0) {
675 trap_fatal(frame, eva);
679 va = trunc_page(eva);
680 if (va >= VM_MIN_KERNEL_ADDRESS) {
682 * Don't allow user-mode faults in kernel address space.
690 * This is a fault on non-kernel virtual memory.
691 * vm is initialized above to NULL. If curproc is NULL
692 * or curproc->p_vmspace is NULL the fault is fatal.
703 * When accessing a usermode address, kernel must be
704 * ready to accept the page fault, and provide a
705 * handling routine. Since accessing the address
706 * without the handler is a bug, do not try to handle
707 * it normally, and panic immediately.
709 if (!usermode && (td->td_intr_nesting_level != 0 ||
710 PCPU_GET(curpcb)->pcb_onfault == NULL)) {
711 trap_fatal(frame, eva);
717 * PGEX_I is defined only if the execute disable bit capability is
718 * supported and enabled.
720 if (frame->tf_err & PGEX_W)
721 ftype = VM_PROT_WRITE;
722 else if ((frame->tf_err & PGEX_I) && pg_nx != 0)
723 ftype = VM_PROT_EXECUTE;
725 ftype = VM_PROT_READ;
727 if (map != kernel_map) {
729 * Keep swapout from messing with us during this
736 /* Fault in the user page: */
737 rv = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
744 * Don't have to worry about process locking or stacks in the
747 rv = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
749 if (rv == KERN_SUCCESS)
753 if (td->td_intr_nesting_level == 0 &&
754 PCPU_GET(curpcb)->pcb_onfault != NULL) {
755 frame->tf_rip = (long)PCPU_GET(curpcb)->pcb_onfault;
758 trap_fatal(frame, eva);
762 return((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV);
766 trap_fatal(frame, eva)
767 struct trapframe *frame;
773 struct soft_segment_descriptor softseg;
776 code = frame->tf_err;
777 type = frame->tf_trapno;
778 sdtossd(&gdt[NGDT * PCPU_GET(cpuid) + IDXSEL(frame->tf_cs & 0xffff)],
781 if (type <= MAX_TRAP_MSG)
782 msg = trap_msg[type];
785 printf("\n\nFatal trap %d: %s while in %s mode\n", type, msg,
786 ISPL(frame->tf_cs) == SEL_UPL ? "user" : "kernel");
788 /* two separate prints in case of a trap on an unmapped page */
789 printf("cpuid = %d; ", PCPU_GET(cpuid));
790 printf("apic id = %02x\n", PCPU_GET(apic_id));
792 if (type == T_PAGEFLT) {
793 printf("fault virtual address = 0x%lx\n", eva);
794 printf("fault code = %s %s %s, %s\n",
795 code & PGEX_U ? "user" : "supervisor",
796 code & PGEX_W ? "write" : "read",
797 code & PGEX_I ? "instruction" : "data",
798 code & PGEX_P ? "protection violation" : "page not present");
800 printf("instruction pointer = 0x%lx:0x%lx\n",
801 frame->tf_cs & 0xffff, frame->tf_rip);
802 if (ISPL(frame->tf_cs) == SEL_UPL) {
803 ss = frame->tf_ss & 0xffff;
806 ss = GSEL(GDATA_SEL, SEL_KPL);
807 esp = (long)&frame->tf_rsp;
809 printf("stack pointer = 0x%x:0x%lx\n", ss, esp);
810 printf("frame pointer = 0x%x:0x%lx\n", ss, frame->tf_rbp);
811 printf("code segment = base 0x%lx, limit 0x%lx, type 0x%x\n",
812 softseg.ssd_base, softseg.ssd_limit, softseg.ssd_type);
813 printf(" = DPL %d, pres %d, long %d, def32 %d, gran %d\n",
814 softseg.ssd_dpl, softseg.ssd_p, softseg.ssd_long, softseg.ssd_def32,
816 printf("processor eflags = ");
817 if (frame->tf_rflags & PSL_T)
818 printf("trace trap, ");
819 if (frame->tf_rflags & PSL_I)
820 printf("interrupt enabled, ");
821 if (frame->tf_rflags & PSL_NT)
822 printf("nested task, ");
823 if (frame->tf_rflags & PSL_RF)
825 printf("IOPL = %ld\n", (frame->tf_rflags & PSL_IOPL) >> 12);
826 printf("current process = ");
829 (u_long)curproc->p_pid, curthread->td_name ?
830 curthread->td_name : "");
836 if (debugger_on_panic || kdb_active)
837 if (kdb_trap(type, 0, frame))
840 printf("trap number = %d\n", type);
841 if (type <= MAX_TRAP_MSG)
842 panic("%s", trap_msg[type]);
844 panic("unknown/reserved trap");
848 * Double fault handler. Called when a fault occurs while writing
849 * a frame for a trap/exception onto the stack. This usually occurs
850 * when the stack overflows (such is the case with infinite recursion,
854 dblfault_handler(struct trapframe *frame)
857 if (dtrace_doubletrap_func != NULL)
858 (*dtrace_doubletrap_func)();
860 printf("\nFatal double fault\n");
861 printf("rip = 0x%lx\n", frame->tf_rip);
862 printf("rsp = 0x%lx\n", frame->tf_rsp);
863 printf("rbp = 0x%lx\n", frame->tf_rbp);
865 /* two separate prints in case of a trap on an unmapped page */
866 printf("cpuid = %d; ", PCPU_GET(cpuid));
867 printf("apic id = %02x\n", PCPU_GET(apic_id));
869 panic("double fault");
873 cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
876 struct trapframe *frame;
879 int reg, regcnt, error;
882 frame = td->td_frame;
886 params = (caddr_t)frame->tf_rsp + sizeof(register_t);
887 sa->code = frame->tf_rax;
889 if (sa->code == SYS_syscall || sa->code == SYS___syscall) {
890 sa->code = frame->tf_rdi;
894 if (p->p_sysent->sv_mask)
895 sa->code &= p->p_sysent->sv_mask;
897 if (sa->code >= p->p_sysent->sv_size)
898 sa->callp = &p->p_sysent->sv_table[0];
900 sa->callp = &p->p_sysent->sv_table[sa->code];
902 sa->narg = sa->callp->sy_narg;
903 KASSERT(sa->narg <= sizeof(sa->args) / sizeof(sa->args[0]),
904 ("Too many syscall arguments!"));
906 argp = &frame->tf_rdi;
908 bcopy(argp, sa->args, sizeof(sa->args[0]) * regcnt);
909 if (sa->narg > regcnt) {
910 KASSERT(params != NULL, ("copyin args with no params!"));
911 error = copyin(params, &sa->args[regcnt],
912 (sa->narg - regcnt) * sizeof(sa->args[0]));
916 td->td_retval[0] = 0;
917 td->td_retval[1] = frame->tf_rdx;
923 #include "../../kern/subr_syscall.c"
926 * System call handler for native binaries. The trap frame is already
927 * set up by the assembler trampoline and a pointer to it is saved in
931 amd64_syscall(struct thread *td, int traced)
933 struct syscall_args sa;
938 if (ISPL(td->td_frame->tf_cs) != SEL_UPL) {
943 error = syscallenter(td, &sa);
948 if (__predict_false(traced)) {
949 td->td_frame->tf_rflags &= ~PSL_T;
950 ksiginfo_init_trap(&ksi);
951 ksi.ksi_signo = SIGTRAP;
952 ksi.ksi_code = TRAP_TRACE;
953 ksi.ksi_addr = (void *)td->td_frame->tf_rip;
954 trapsignal(td, &ksi);
957 KASSERT(PCB_USER_FPU(td->td_pcb),
958 ("System call %s returing with kernel FPU ctx leaked",
959 syscallname(td->td_proc, sa.code)));
960 KASSERT(td->td_pcb->pcb_save == get_pcb_user_save_td(td),
961 ("System call %s returning with mangled pcb_save",
962 syscallname(td->td_proc, sa.code)));
964 syscallret(td, error, &sa);