2012-05-05 23:44:02 +04:00
|
|
|
/* $NetBSD: sys_syscall.c,v 1.10 2012/05/05 19:44:02 christos Exp $ */
|
2007-11-09 17:50:51 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by David Laight.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2012-05-05 23:44:02 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sys_syscall.c,v 1.10 2012/05/05 19:44:02 christos Exp $");
|
2007-11-09 17:50:51 +03:00
|
|
|
|
|
|
|
#include <sys/syscall_stats.h>
|
2012-05-05 23:44:02 +04:00
|
|
|
#include <sys/syscallvar.h>
|
2007-11-09 17:50:51 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MI indirect system call support.
|
|
|
|
* Included from sys_indirect.c and compat/netbsd32/netbsd32_indirect.c
|
|
|
|
*
|
|
|
|
* SYS_SYSCALL is set to the required function name.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CONCAT(a,b) __CONCAT(a,b)
|
|
|
|
|
|
|
|
int
|
2007-12-22 14:38:54 +03:00
|
|
|
SYS_SYSCALL(struct lwp *l, const struct CONCAT(SYS_SYSCALL, _args) *uap,
|
|
|
|
register_t *rval)
|
2007-11-09 17:50:51 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-11-09 17:50:51 +03:00
|
|
|
syscallarg(int) code;
|
|
|
|
syscallarg(register_t) args[SYS_MAXSYSARGS];
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-11-09 17:50:51 +03:00
|
|
|
const struct sysent *callp;
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
int code;
|
|
|
|
int error;
|
2008-02-07 01:12:39 +03:00
|
|
|
int narg;
|
2007-11-09 17:50:51 +03:00
|
|
|
#ifdef NETBSD32_SYSCALL
|
|
|
|
register_t args64[SYS_MAXSYSARGS];
|
2008-02-07 01:12:39 +03:00
|
|
|
int i;
|
2007-11-09 17:50:51 +03:00
|
|
|
#define TRACE_ARGS args64
|
|
|
|
#else
|
2007-12-22 19:19:34 +03:00
|
|
|
#define TRACE_ARGS &SCARG(uap, args[0])
|
2007-11-09 17:50:51 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
callp = p->p_emul->e_sysent;
|
|
|
|
|
|
|
|
code = SCARG(uap, code) & (SYS_NSYSENT - 1);
|
|
|
|
SYSCALL_COUNT(syscall_counts, code);
|
|
|
|
callp += code;
|
|
|
|
|
|
|
|
if (__predict_false(callp->sy_flags & SYCALL_INDIRECT))
|
|
|
|
return ENOSYS;
|
|
|
|
|
|
|
|
if (__predict_true(!p->p_trace_enabled))
|
2012-05-05 23:44:02 +04:00
|
|
|
return sy_call(callp, l, &uap->args, rval);
|
2007-11-09 17:50:51 +03:00
|
|
|
|
2008-02-07 01:12:39 +03:00
|
|
|
narg = callp->sy_narg;
|
2007-11-09 17:50:51 +03:00
|
|
|
#ifdef NETBSD32_SYSCALL
|
|
|
|
for (i = 0; i < narg; i++)
|
|
|
|
args64[i] = SCARG(uap, args[i]);
|
|
|
|
#endif
|
|
|
|
|
2008-02-07 01:12:39 +03:00
|
|
|
error = trace_enter(code, TRACE_ARGS, narg);
|
2007-11-09 17:50:51 +03:00
|
|
|
if (__predict_false(error != 0))
|
|
|
|
return error;
|
2012-05-05 23:44:02 +04:00
|
|
|
error = sy_call(callp, l, &uap->args, rval);
|
2008-02-07 01:12:39 +03:00
|
|
|
trace_exit(code, rval, error);
|
2007-11-09 17:50:51 +03:00
|
|
|
return error;
|
|
|
|
|
|
|
|
#undef TRACE_ARGS
|
|
|
|
}
|