subr_syscall.c revision 5603
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.43 1995/01/09 16:04:39 davidg 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		ptepg = (vm_page_t) pmap_pte_vm_page(vm_map_pmap(map), v);
464		vm_page_hold(ptepg);
465
466		/* Fault in the user page: */
467		rv = vm_fault(map, va, ftype, FALSE);
468
469		vm_page_unhold(ptepg);
470
471		/*
472		 * page table pages don't need to be kept if they
473		 * are not held
474		 */
475		if( ptepg->hold_count == 0 && ptepg->wire_count == 0) {
476			pmap_page_protect( VM_PAGE_TO_PHYS(ptepg),
477				VM_PROT_NONE);
478			vm_page_free(ptepg);
479		}
480
481		--p->p_lock;
482	} else {
483		/*
484		 * Since we know that kernel virtual address addresses
485		 * always have pte pages mapped, we just have to fault
486		 * the page.
487		 */
488		rv = vm_fault(map, va, ftype, FALSE);
489	}
490
491	if (rv == KERN_SUCCESS)
492		return (0);
493nogo:
494	if (!usermode) {
495		if (curpcb && curpcb->pcb_onfault) {
496			frame->tf_eip = (int)curpcb->pcb_onfault;
497			return (0);
498		}
499		trap_fatal(frame);
500		return (-1);
501	}
502
503	/* kludge to pass faulting virtual address to sendsig */
504	frame->tf_err = eva;
505
506	return((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV);
507}
508
509void
510trap_fatal(frame)
511	struct trapframe *frame;
512{
513	int code, type, eva;
514	struct soft_segment_descriptor softseg;
515
516	code = frame->tf_err;
517	type = frame->tf_trapno;
518	eva = rcr2();
519	sdtossd(&gdt[IDXSEL(frame->tf_cs & 0xffff)].sd, &softseg);
520
521	if (type <= MAX_TRAP_MSG)
522		printf("\n\nFatal trap %d: %s while in %s mode\n",
523			type, trap_msg[type],
524			ISPL(frame->tf_cs) == SEL_UPL ? "user" : "kernel");
525	if (type == T_PAGEFLT) {
526		printf("fault virtual address	= 0x%x\n", eva);
527		printf("fault code		= %s %s, %s\n",
528			code & PGEX_U ? "user" : "supervisor",
529			code & PGEX_W ? "write" : "read",
530			code & PGEX_P ? "protection violation" : "page not present");
531	}
532	printf("instruction pointer	= 0x%x:0x%x\n", frame->tf_cs & 0xffff, frame->tf_eip);
533	printf("code segment		= base 0x%x, limit 0x%x, type 0x%x\n",
534	    softseg.ssd_base, softseg.ssd_limit, softseg.ssd_type);
535	printf("			= DPL %d, pres %d, def32 %d, gran %d\n",
536	    softseg.ssd_dpl, softseg.ssd_p, softseg.ssd_def32, softseg.ssd_gran);
537	printf("processor eflags	= ");
538	if (frame->tf_eflags & PSL_T)
539		printf("trace/trap, ");
540	if (frame->tf_eflags & PSL_I)
541		printf("interrupt enabled, ");
542	if (frame->tf_eflags & PSL_NT)
543		printf("nested task, ");
544	if (frame->tf_eflags & PSL_RF)
545		printf("resume, ");
546	if (frame->tf_eflags & PSL_VM)
547		printf("vm86, ");
548	printf("IOPL = %d\n", (frame->tf_eflags & PSL_IOPL) >> 12);
549	printf("current process		= ");
550	if (curproc) {
551		printf("%lu (%s)\n",
552		    (u_long)curproc->p_pid, curproc->p_comm ?
553		    curproc->p_comm : "");
554	} else {
555		printf("Idle\n");
556	}
557	printf("interrupt mask		= ");
558	if ((cpl & net_imask) == net_imask)
559		printf("net ");
560	if ((cpl & tty_imask) == tty_imask)
561		printf("tty ");
562	if ((cpl & bio_imask) == bio_imask)
563		printf("bio ");
564	if (cpl == 0)
565		printf("none");
566	printf("\n");
567
568#ifdef KDB
569	if (kdb_trap(&psl))
570		return;
571#endif
572#ifdef DDB
573	if (kdb_trap (type, 0, frame))
574		return;
575#endif
576	if (type <= MAX_TRAP_MSG)
577		panic(trap_msg[type]);
578	else
579		panic("unknown/reserved trap");
580}
581
582/*
583 * Compensate for 386 brain damage (missing URKR).
584 * This is a little simpler than the pagefault handler in trap() because
585 * it the page tables have already been faulted in and high addresses
586 * are thrown out early for other reasons.
587 */
588int trapwrite(addr)
589	unsigned addr;
590{
591	struct proc *p;
592	vm_offset_t va, v;
593	struct vmspace *vm;
594	int rv;
595
596	va = trunc_page((vm_offset_t)addr);
597	/*
598	 * XXX - MAX is END.  Changed > to >= for temp. fix.
599	 */
600	if (va >= VM_MAXUSER_ADDRESS)
601		return (1);
602
603	p = curproc;
604	vm = p->p_vmspace;
605
606	++p->p_lock;
607
608	if ((caddr_t)va >= vm->vm_maxsaddr
609	    && (caddr_t)va < (caddr_t)USRSTACK) {
610		if (!grow(p, va)) {
611			--p->p_lock;
612			return (1);
613		}
614	}
615
616	v = trunc_page(vtopte(va));
617
618	/*
619	 * wire the pte page
620	 */
621	if (va < USRSTACK) {
622		vm_map_pageable(&vm->vm_map, v, round_page(v+1), FALSE);
623	}
624
625	/*
626	 * fault the data page
627	 */
628	rv = vm_fault(&vm->vm_map, va, VM_PROT_READ|VM_PROT_WRITE, FALSE);
629
630	/*
631	 * unwire the pte page
632	 */
633	if (va < USRSTACK) {
634		vm_map_pageable(&vm->vm_map, v, round_page(v+1), TRUE);
635	}
636
637	--p->p_lock;
638
639	if (rv != KERN_SUCCESS)
640		return 1;
641
642	return (0);
643}
644
645/*
646 * syscall(frame):
647 *	System call request from POSIX system call gate interface to kernel.
648 * Like trap(), argument is call by reference.
649 */
650/*ARGSUSED*/
651void
652syscall(frame)
653	struct trapframe frame;
654{
655	caddr_t params;
656	int i;
657	struct sysent *callp;
658	struct proc *p = curproc;
659	u_quad_t sticks;
660	int error, opc;
661	int args[8], rval[2];
662	u_int code;
663
664	sticks = p->p_sticks;
665	if (ISPL(frame.tf_cs) != SEL_UPL)
666		panic("syscall");
667
668	code = frame.tf_eax;
669	p->p_md.md_regs = (int *)&frame;
670	params = (caddr_t)frame.tf_esp + sizeof (int) ;
671
672	/*
673	 * Reconstruct pc, assuming lcall $X,y is 7 bytes, as it is always.
674	 */
675	opc = frame.tf_eip - 7;
676	/*
677	 * Need to check if this is a 32 bit or 64 bit syscall.
678	 */
679	if (code == SYS_syscall) {
680		/*
681		 * Code is first argument, followed by actual args.
682		 */
683		code = fuword(params);
684		params += sizeof (int);
685	} else if (code == SYS___syscall) {
686		/*
687		 * Like syscall, but code is a quad, so as to maintain
688		 * quad alignment for the rest of the arguments.
689		 */
690		code = fuword(params + _QUAD_LOWWORD * sizeof(int));
691		params += sizeof(quad_t);
692	}
693
694 	if (p->p_sysent->sv_mask)
695 		code = code & p->p_sysent->sv_mask;
696
697 	if (code >= p->p_sysent->sv_size)
698 		callp = &p->p_sysent->sv_table[0];
699  	else
700 		callp = &p->p_sysent->sv_table[code];
701
702	if ((i = callp->sy_narg * sizeof (int)) &&
703	    (error = copyin(params, (caddr_t)args, (u_int)i))) {
704#ifdef KTRACE
705		if (KTRPOINT(p, KTR_SYSCALL))
706			ktrsyscall(p->p_tracep, code, callp->sy_narg, args);
707#endif
708		goto bad;
709	}
710#ifdef KTRACE
711	if (KTRPOINT(p, KTR_SYSCALL))
712		ktrsyscall(p->p_tracep, code, callp->sy_narg, args);
713#endif
714	rval[0] = 0;
715	rval[1] = frame.tf_edx;
716
717	error = (*callp->sy_call)(p, args, rval);
718
719	switch (error) {
720
721	case 0:
722		/*
723		 * Reinitialize proc pointer `p' as it may be different
724		 * if this is a child returning from fork syscall.
725		 */
726		p = curproc;
727		frame.tf_eax = rval[0];
728		frame.tf_edx = rval[1];
729		frame.tf_eflags &= ~PSL_C;	/* carry bit */
730		break;
731
732	case ERESTART:
733		frame.tf_eip = opc;
734		break;
735
736	case EJUSTRETURN:
737		break;
738
739	default:
740	bad:
741 		if (p->p_sysent->sv_errsize)
742 			if (error >= p->p_sysent->sv_errsize)
743  				error = -1;	/* XXX */
744   			else
745  				error = p->p_sysent->sv_errtbl[error];
746		frame.tf_eax = error;
747		frame.tf_eflags |= PSL_C;	/* carry bit */
748		break;
749	}
750
751	userret(p, &frame, sticks);
752
753#ifdef KTRACE
754	if (KTRPOINT(p, KTR_SYSRET))
755		ktrsysret(p->p_tracep, code, error, rval[0]);
756#endif
757}
758