#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/syscall.h>
#include <sys/syscall_mi.h>
#include <uvm/uvm_extern.h>
#include <machine/syscall.h>
static __inline struct trapframe *
process_frame(struct proc *p)
{
return p->p_addr->u_pcb.pcb_tf;
}
void
svc_handler(trapframe_t *frame)
{
struct proc *p = curproc;
const struct sysent *callp = sysent;
int code, error = ENOSYS;
register_t *args, rval[2];
atomic_inc_int(&uvmexp.syscalls);
code = frame->tf_t[0];
if (code <= 0 || code >= SYS_MAXSYSCALL)
goto bad;
callp += code;
args = &frame->tf_a[0];
rval[0] = 0;
rval[1] = 0;
error = mi_syscall(p, code, callp, args, rval);
switch (error) {
case 0:
frame->tf_a[0] = rval[0];
frame->tf_t[0] = 0;
break;
case ERESTART:
frame->tf_sepc -= 4;
break;
case EJUSTRETURN:
break;
default:
bad:
frame->tf_a[0] = error;
frame->tf_t[0] = 1;
break;
}
mi_syscall_return(p, code, error, rval);
}
void
child_return(void *arg)
{
struct proc *p = arg;
struct trapframe *frame = process_frame(p);
frame->tf_a[0] = 0;
frame->tf_t[0] = 0;
KERNEL_UNLOCK();
mi_child_return(p);
}