subr_syscall.c revision 5837
1/*-
2 * Copyright (C) 1994, David Greenman
3 * Copyright (c) 1990, 1993
4 *	The Regents of the University of California.  All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * the University of Utah, and William Jolitz.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
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.
24 *
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
35 * SUCH DAMAGE.
36 *
37 *	from: @(#)trap.c	7.4 (Berkeley) 5/13/91
38 *	$Id: trap.c,v 1.44 1995/01/14 13:20:10 bde Exp $
39 */
40
41/*
42 * 386 Trap and System call handling
43 */
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/proc.h>
48#include <sys/user.h>
49#include <sys/acct.h>
50#include <sys/kernel.h>
51#include <sys/syscall.h>
52#include <sys/sysent.h>
53#ifdef KTRACE
54#include <sys/ktrace.h>
55#endif
56
57#include <vm/vm_param.h>
58#include <vm/pmap.h>
59#include <vm/vm_map.h>
60#include <vm/vm_page.h>
61
62#include <machine/cpu.h>
63#include <machine/psl.h>
64#include <machine/reg.h>
65#include <machine/trap.h>
66#include <machine/../isa/isa_device.h>
67
68#include "isa.h"
69#include "npx.h"
70
71int	trap_pfault	__P((struct trapframe *, int));
72void	trap_fatal	__P((struct trapframe *));
73
74#define MAX_TRAP_MSG		27
75char *trap_msg[] = {
76	"",					/*  0 unused */
77	"privileged instruction fault",		/*  1 T_PRIVINFLT */
78	"",					/*  2 unused */
79	"breakpoint instruction fault",		/*  3 T_BPTFLT */
80	"",					/*  4 unused */
81	"",					/*  5 unused */
82	"arithmetic trap",			/*  6 T_ARITHTRAP */
83	"system forced exception",		/*  7 T_ASTFLT */
84	"",					/*  8 unused */
85	"general protection fault",		/*  9 T_PROTFLT */
86	"trace trap",				/* 10 T_TRCTRAP */
87	"",					/* 11 unused */
88	"page fault",				/* 12 T_PAGEFLT */
89	"",					/* 13 unused */
90	"alignment fault",			/* 14 T_ALIGNFLT */
91	"",					/* 15 unused */
92	"",					/* 16 unused */
93	"",					/* 17 unused */
94	"integer divide fault",			/* 18 T_DIVIDE */
95	"non-maskable interrupt trap",		/* 19 T_NMI */
96	"overflow trap",			/* 20 T_OFLOW */
97	"FPU bounds check fault",		/* 21 T_BOUND */
98	"FPU device not available",		/* 22 T_DNA */
99	"double fault",				/* 23 T_DOUBLEFLT */
100	"FPU operand fetch fault",		/* 24 T_FPOPFLT */
101	"invalid TSS fault",			/* 25 T_TSSFLT */
102	"segment not present fault",		/* 26 T_SEGNPFLT */
103	"stack fault",				/* 27 T_STKFLT */
104};
105
106static inline void
107userret(p, frame, oticks)
108	struct proc *p;
109	struct trapframe *frame;
110	u_quad_t oticks;
111{
112	int sig, s;
113
114	while ((sig = CURSIG(p)) != 0)
115		postsig(sig);
116	p->p_priority = p->p_usrpri;
117	if (want_resched) {
118		/*
119		 * Since we are curproc, clock will normally just change
120		 * our priority without moving us from one queue to another
121		 * (since the running process is not on a queue.)
122		 * If that happened after we setrunqueue ourselves but before we
123		 * mi_switch()'ed, we might not be on the queue indicated by
124		 * our priority.
125		 */
126		s = splclock();
127		setrunqueue(p);
128		p->p_stats->p_ru.ru_nivcsw++;
129		mi_switch();
130		splx(s);
131		while ((sig = CURSIG(p)) != 0)
132			postsig(sig);
133	}
134	if (p->p_stats->p_prof.pr_scale) {
135		u_quad_t ticks = p->p_sticks - oticks;
136
137		if (ticks) {
138#ifdef PROFTIMER
139			extern int profscale;
140			addupc(frame->tf_eip, &p->p_stats->p_prof,
141			    ticks * profscale);
142#else
143			addupc(frame->tf_eip, &p->p_stats->p_prof, ticks);
144#endif
145		}
146	}
147	curpriority = p->p_priority;
148}
149
150/*
151 * trap(frame):
152 *	Exception, fault, and trap interface to the FreeBSD kernel.
153 * This common code is called from assembly language IDT gate entry
154 * routines that prepare a suitable stack frame, and restore this
155 * frame after the exception has been processed.
156 */
157
158/*ARGSUSED*/
159void
160trap(frame)
161	struct trapframe frame;
162{
163	struct proc *p = curproc;
164	u_quad_t sticks = 0;
165	int i = 0, ucode = 0, type, code;
166#ifdef DIAGNOSTIC
167	u_long eva;
168#endif
169
170	type = frame.tf_trapno;
171	code = frame.tf_err;
172
173	if (ISPL(frame.tf_cs) == SEL_UPL) {
174		/* user trap */
175
176		sticks = p->p_sticks;
177		p->p_md.md_regs = (int *)&frame;
178
179		switch (type) {
180		case T_PRIVINFLT:	/* privileged instruction fault */
181			ucode = type;
182			i = SIGILL;
183			break;
184
185		case T_BPTFLT:		/* bpt instruction fault */
186		case T_TRCTRAP:		/* trace trap */
187			frame.tf_eflags &= ~PSL_T;
188			i = SIGTRAP;
189			break;
190
191		case T_ARITHTRAP:	/* arithmetic trap */
192			ucode = code;
193			i = SIGFPE;
194			break;
195
196		case T_ASTFLT:		/* Allow process switch */
197			astoff();
198			cnt.v_soft++;
199			if ((p->p_flag & P_OWEUPC) && p->p_stats->p_prof.pr_scale) {
200				addupc(frame.tf_eip, &p->p_stats->p_prof, 1);
201				p->p_flag &= ~P_OWEUPC;
202			}
203			goto out;
204
205		case T_PROTFLT:		/* general protection fault */
206		case T_SEGNPFLT:	/* segment not present fault */
207		case T_STKFLT:		/* stack fault */
208		case T_TSSFLT:		/* invalid TSS fault */
209		case T_DOUBLEFLT:	/* double fault */
210		default:
211			ucode = code + BUS_SEGM_FAULT ;
212			i = SIGBUS;
213			break;
214
215		case T_PAGEFLT:		/* page fault */
216			i = trap_pfault(&frame, TRUE);
217			if (i == -1)
218				return;
219			if (i == 0)
220				goto out;
221
222			ucode = T_PAGEFLT;
223			break;
224
225		case T_DIVIDE:		/* integer divide fault */
226			ucode = FPE_INTDIV_TRAP;
227			i = SIGFPE;
228			break;
229
230#if NISA > 0
231		case T_NMI:
232#ifdef DDB
233			/* NMI can be hooked up to a pushbutton for debugging */
234			printf ("NMI ... going to debugger\n");
235			if (kdb_trap (type, 0, &frame))
236				return;
237#endif
238			/* machine/parity/power fail/"kitchen sink" faults */
239			if (isa_nmi(code) == 0) return;
240			panic("NMI indicates hardware failure");
241#endif
242
243		case T_OFLOW:		/* integer overflow fault */
244			ucode = FPE_INTOVF_TRAP;
245			i = SIGFPE;
246			break;
247
248		case T_BOUND:		/* bounds check fault */
249			ucode = FPE_SUBRNG_TRAP;
250			i = SIGFPE;
251			break;
252
253		case T_DNA:
254#if NNPX > 0
255			/* if a transparent fault (due to context switch "late") */
256			if (npxdna())
257				return;
258#endif	/* NNPX > 0 */
259
260#if defined(MATH_EMULATE) || defined(GPL_MATH_EMULATE)
261			i = math_emulate(&frame);
262			if (i == 0) {
263				if (!(frame.tf_eflags & PSL_T))
264					return;
265				frame.tf_eflags &= ~PSL_T;
266				i = SIGTRAP;
267			}
268			/* else ucode = emulator_only_knows() XXX */
269#else	/* MATH_EMULATE || GPL_MATH_EMULATE */
270			i = SIGFPE;
271			ucode = FPE_FPU_NP_TRAP;
272#endif	/* MATH_EMULATE || GPL_MATH_EMULATE */
273			break;
274
275		case T_FPOPFLT:		/* FPU operand fetch fault */
276			ucode = T_FPOPFLT;
277			i = SIGILL;
278			break;
279		}
280	} else {
281		/* kernel trap */
282
283		switch (type) {
284		case T_PAGEFLT:			/* page fault */
285			(void) trap_pfault(&frame, FALSE);
286			return;
287
288		case T_PROTFLT:		/* general protection fault */
289		case T_SEGNPFLT:	/* segment not present fault */
290			/*
291			 * Invalid segment selectors and out of bounds
292			 * %eip's and %esp's can be set up in user mode.
293			 * This causes a fault in kernel mode when the
294			 * kernel tries to return to user mode.  We want
295			 * to get this fault so that we can fix the
296			 * problem here and not have to check all the
297			 * selectors and pointers when the user changes
298			 * them.
299			 */
300#define	MAYBE_DORETI_FAULT(where, whereto)				\
301	do {								\
302		extern void where(void) __asm(__STRING(where));		\
303		extern void whereto(void) __asm(__STRING(whereto));	\
304		if (frame.tf_eip == (int)where) {			\
305			frame.tf_eip = (int)whereto;			\
306			return;						\
307		}							\
308	} while (0)
309
310			if (intr_nesting_level == 0) {
311				MAYBE_DORETI_FAULT(doreti_iret,
312						   doreti_iret_fault);
313				MAYBE_DORETI_FAULT(doreti_popl_ds,
314						   doreti_popl_ds_fault);
315				MAYBE_DORETI_FAULT(doreti_popl_es,
316						   doreti_popl_es_fault);
317			}
318			if (curpcb && curpcb->pcb_onfault) {
319				frame.tf_eip = (int)curpcb->pcb_onfault;
320				return;
321			}
322			break;
323
324		case T_TSSFLT:
325			/*
326			 * PSL_NT can be set in user mode and isn't cleared
327			 * automatically when the kernel is entered.  This
328			 * causes a TSS fault when the kernel attempts to
329			 * `iret' because the TSS link is uninitialized.  We
330			 * want to get this fault so that we can fix the
331			 * problem here and not every time the kernel is
332			 * entered.
333			 */
334			if (frame.tf_eflags & PSL_NT) {
335				frame.tf_eflags &= ~PSL_NT;
336				return;
337			}
338			break;
339
340#ifdef DDB
341		case T_BPTFLT:
342		case T_TRCTRAP:
343			if (kdb_trap (type, 0, &frame))
344				return;
345			break;
346#else
347		case T_TRCTRAP:	 /* trace trap -- someone single stepping lcall's */
348			/* Q: how do we turn it on again? */
349			frame.tf_eflags &= ~PSL_T;
350			return;
351#endif
352
353#if NISA > 0
354		case T_NMI:
355#ifdef DDB
356			/* NMI can be hooked up to a pushbutton for debugging */
357			printf ("NMI ... going to debugger\n");
358			if (kdb_trap (type, 0, &frame))
359				return;
360#endif
361			/* machine/parity/power fail/"kitchen sink" faults */
362			if (isa_nmi(code) == 0) return;
363			/* FALL THROUGH */
364#endif
365		}
366
367		trap_fatal(&frame);
368		return;
369	}
370
371	trapsignal(p, i, ucode);
372
373#ifdef DIAGNOSTIC
374	eva = rcr2();
375	if (type <= MAX_TRAP_MSG) {
376		uprintf("fatal process exception: %s",
377			trap_msg[type]);
378		if ((type == T_PAGEFLT) || (type == T_PROTFLT))
379			uprintf(", fault VA = 0x%x", eva);
380		uprintf("\n");
381	}
382#endif
383
384out:
385	userret(p, &frame, sticks);
386}
387
388int
389trap_pfault(frame, usermode)
390	struct trapframe *frame;
391	int usermode;
392{
393	vm_offset_t va;
394	struct vmspace *vm = NULL;
395	vm_map_t map = 0;
396	int rv = 0;
397	vm_prot_t ftype;
398	extern vm_map_t kernel_map;
399	int eva;
400	struct proc *p = curproc;
401
402	eva = rcr2();
403	va = trunc_page((vm_offset_t)eva);
404
405	if (va >= KERNBASE) {
406		/*
407		 * Don't allow user-mode faults in kernel address space.
408		 */
409		if (usermode)
410			goto nogo;
411
412		map = kernel_map;
413	} else {
414		/*
415		 * This is a fault on non-kernel virtual memory.
416		 * vm is initialized above to NULL. If curproc is NULL
417		 * or curproc->p_vmspace is NULL the fault is fatal.
418		 */
419		if (p != NULL)
420			vm = p->p_vmspace;
421
422		if (vm == NULL)
423			goto nogo;
424
425		map = &vm->vm_map;
426	}
427
428	if (frame->tf_err & PGEX_W)
429		ftype = VM_PROT_READ | VM_PROT_WRITE;
430	else
431		ftype = VM_PROT_READ;
432
433	if (map != kernel_map) {
434		vm_offset_t v = (vm_offset_t) vtopte(va);
435		vm_page_t ptepg;
436
437		/*
438		 * Keep swapout from messing with us during this
439		 *	critical time.
440		 */
441		++p->p_lock;
442
443		/*
444		 * Grow the stack if necessary
445		 */
446		if ((caddr_t)va > vm->vm_maxsaddr
447		    && (caddr_t)va < (caddr_t)USRSTACK) {
448			if (!grow(p, va)) {
449				rv = KERN_FAILURE;
450				--p->p_lock;
451				goto nogo;
452			}
453		}
454
455		/*
456		 * Check if page table is mapped, if not,
457		 *	fault it first
458		 */
459
460		/* Fault the pte only if needed: */
461		*(volatile char *)v += 0;
462
463		pmap_use_pt( vm_map_pmap(map), va);
464
465		/* Fault in the user page: */
466		rv = vm_fault(map, va, ftype, FALSE);
467
468		pmap_unuse_pt( vm_map_pmap(map), va);
469
470		--p->p_lock;
471	} else {
472		/*
473		 * Since we know that kernel virtual address addresses
474		 * always have pte pages mapped, we just have to fault
475		 * the page.
476		 */
477		rv = vm_fault(map, va, ftype, FALSE);
478	}
479
480	if (rv == KERN_SUCCESS)
481		return (0);
482nogo:
483	if (!usermode) {
484		if (curpcb && curpcb->pcb_onfault) {
485			frame->tf_eip = (int)curpcb->pcb_onfault;
486			return (0);
487		}
488		trap_fatal(frame);
489		return (-1);
490	}
491
492	/* kludge to pass faulting virtual address to sendsig */
493	frame->tf_err = eva;
494
495	return((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV);
496}
497
498void
499trap_fatal(frame)
500	struct trapframe *frame;
501{
502	int code, type, eva;
503	struct soft_segment_descriptor softseg;
504
505	code = frame->tf_err;
506	type = frame->tf_trapno;
507	eva = rcr2();
508	sdtossd(&gdt[IDXSEL(frame->tf_cs & 0xffff)].sd, &softseg);
509
510	if (type <= MAX_TRAP_MSG)
511		printf("\n\nFatal trap %d: %s while in %s mode\n",
512			type, trap_msg[type],
513			ISPL(frame->tf_cs) == SEL_UPL ? "user" : "kernel");
514	if (type == T_PAGEFLT) {
515		printf("fault virtual address	= 0x%x\n", eva);
516		printf("fault code		= %s %s, %s\n",
517			code & PGEX_U ? "user" : "supervisor",
518			code & PGEX_W ? "write" : "read",
519			code & PGEX_P ? "protection violation" : "page not present");
520	}
521	printf("instruction pointer	= 0x%x:0x%x\n", frame->tf_cs & 0xffff, frame->tf_eip);
522	printf("code segment		= base 0x%x, limit 0x%x, type 0x%x\n",
523	    softseg.ssd_base, softseg.ssd_limit, softseg.ssd_type);
524	printf("			= DPL %d, pres %d, def32 %d, gran %d\n",
525	    softseg.ssd_dpl, softseg.ssd_p, softseg.ssd_def32, softseg.ssd_gran);
526	printf("processor eflags	= ");
527	if (frame->tf_eflags & PSL_T)
528		printf("trace/trap, ");
529	if (frame->tf_eflags & PSL_I)
530		printf("interrupt enabled, ");
531	if (frame->tf_eflags & PSL_NT)
532		printf("nested task, ");
533	if (frame->tf_eflags & PSL_RF)
534		printf("resume, ");
535	if (frame->tf_eflags & PSL_VM)
536		printf("vm86, ");
537	printf("IOPL = %d\n", (frame->tf_eflags & PSL_IOPL) >> 12);
538	printf("current process		= ");
539	if (curproc) {
540		printf("%lu (%s)\n",
541		    (u_long)curproc->p_pid, curproc->p_comm ?
542		    curproc->p_comm : "");
543	} else {
544		printf("Idle\n");
545	}
546	printf("interrupt mask		= ");
547	if ((cpl & net_imask) == net_imask)
548		printf("net ");
549	if ((cpl & tty_imask) == tty_imask)
550		printf("tty ");
551	if ((cpl & bio_imask) == bio_imask)
552		printf("bio ");
553	if (cpl == 0)
554		printf("none");
555	printf("\n");
556
557#ifdef KDB
558	if (kdb_trap(&psl))
559		return;
560#endif
561#ifdef DDB
562	if (kdb_trap (type, 0, frame))
563		return;
564#endif
565	if (type <= MAX_TRAP_MSG)
566		panic(trap_msg[type]);
567	else
568		panic("unknown/reserved trap");
569}
570
571/*
572 * Compensate for 386 brain damage (missing URKR).
573 * This is a little simpler than the pagefault handler in trap() because
574 * it the page tables have already been faulted in and high addresses
575 * are thrown out early for other reasons.
576 */
577int trapwrite(addr)
578	unsigned addr;
579{
580	struct proc *p;
581	vm_offset_t va, v;
582	struct vmspace *vm;
583	int rv;
584
585	va = trunc_page((vm_offset_t)addr);
586	/*
587	 * XXX - MAX is END.  Changed > to >= for temp. fix.
588	 */
589	if (va >= VM_MAXUSER_ADDRESS)
590		return (1);
591
592	p = curproc;
593	vm = p->p_vmspace;
594
595	++p->p_lock;
596
597	if ((caddr_t)va >= vm->vm_maxsaddr
598	    && (caddr_t)va < (caddr_t)USRSTACK) {
599		if (!grow(p, va)) {
600			--p->p_lock;
601			return (1);
602		}
603	}
604
605	v = trunc_page(vtopte(va));
606
607	/*
608	 * wire the pte page
609	 */
610	if (va < USRSTACK) {
611		vm_map_pageable(&vm->vm_map, v, round_page(v+1), FALSE);
612	}
613
614	/*
615	 * fault the data page
616	 */
617	rv = vm_fault(&vm->vm_map, va, VM_PROT_READ|VM_PROT_WRITE, FALSE);
618
619	/*
620	 * unwire the pte page
621	 */
622	if (va < USRSTACK) {
623		vm_map_pageable(&vm->vm_map, v, round_page(v+1), TRUE);
624	}
625
626	--p->p_lock;
627
628	if (rv != KERN_SUCCESS)
629		return 1;
630
631	return (0);
632}
633
634/*
635 * syscall(frame):
636 *	System call request from POSIX system call gate interface to kernel.
637 * Like trap(), argument is call by reference.
638 */
639/*ARGSUSED*/
640void
641syscall(frame)
642	struct trapframe frame;
643{
644	caddr_t params;
645	int i;
646	struct sysent *callp;
647	struct proc *p = curproc;
648	u_quad_t sticks;
649	int error, opc;
650	int args[8], rval[2];
651	u_int code;
652
653	sticks = p->p_sticks;
654	if (ISPL(frame.tf_cs) != SEL_UPL)
655		panic("syscall");
656
657	code = frame.tf_eax;
658	p->p_md.md_regs = (int *)&frame;
659	params = (caddr_t)frame.tf_esp + sizeof (int) ;
660
661	/*
662	 * Reconstruct pc, assuming lcall $X,y is 7 bytes, as it is always.
663	 */
664	opc = frame.tf_eip - 7;
665	/*
666	 * Need to check if this is a 32 bit or 64 bit syscall.
667	 */
668	if (code == SYS_syscall) {
669		/*
670		 * Code is first argument, followed by actual args.
671		 */
672		code = fuword(params);
673		params += sizeof (int);
674	} else if (code == SYS___syscall) {
675		/*
676		 * Like syscall, but code is a quad, so as to maintain
677		 * quad alignment for the rest of the arguments.
678		 */
679		code = fuword(params + _QUAD_LOWWORD * sizeof(int));
680		params += sizeof(quad_t);
681	}
682
683 	if (p->p_sysent->sv_mask)
684 		code = code & p->p_sysent->sv_mask;
685
686 	if (code >= p->p_sysent->sv_size)
687 		callp = &p->p_sysent->sv_table[0];
688  	else
689 		callp = &p->p_sysent->sv_table[code];
690
691	if ((i = callp->sy_narg * sizeof (int)) &&
692	    (error = copyin(params, (caddr_t)args, (u_int)i))) {
693#ifdef KTRACE
694		if (KTRPOINT(p, KTR_SYSCALL))
695			ktrsyscall(p->p_tracep, code, callp->sy_narg, args);
696#endif
697		goto bad;
698	}
699#ifdef KTRACE
700	if (KTRPOINT(p, KTR_SYSCALL))
701		ktrsyscall(p->p_tracep, code, callp->sy_narg, args);
702#endif
703	rval[0] = 0;
704	rval[1] = frame.tf_edx;
705
706	error = (*callp->sy_call)(p, args, rval);
707
708	switch (error) {
709
710	case 0:
711		/*
712		 * Reinitialize proc pointer `p' as it may be different
713		 * if this is a child returning from fork syscall.
714		 */
715		p = curproc;
716		frame.tf_eax = rval[0];
717		frame.tf_edx = rval[1];
718		frame.tf_eflags &= ~PSL_C;	/* carry bit */
719		break;
720
721	case ERESTART:
722		frame.tf_eip = opc;
723		break;
724
725	case EJUSTRETURN:
726		break;
727
728	default:
729	bad:
730 		if (p->p_sysent->sv_errsize)
731 			if (error >= p->p_sysent->sv_errsize)
732  				error = -1;	/* XXX */
733   			else
734  				error = p->p_sysent->sv_errtbl[error];
735		frame.tf_eax = error;
736		frame.tf_eflags |= PSL_C;	/* carry bit */
737		break;
738	}
739
740	userret(p, &frame, sticks);
741
742#ifdef KTRACE
743	if (KTRPOINT(p, KTR_SYSRET))
744		ktrsysret(p->p_tracep, code, error, rval[0]);
745#endif
746}
747