xref: /minix3/sys/sys/syscallvar.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: syscallvar.h,v 1.11 2015/09/24 14:34:22 christos Exp $	*/
26c8f7fc3SBen Gras 
36c8f7fc3SBen Gras /*-
46c8f7fc3SBen Gras  * Copyright (c) 2008 The NetBSD Foundation, Inc.
56c8f7fc3SBen Gras  * All rights reserved.
66c8f7fc3SBen Gras  *
76c8f7fc3SBen Gras  * This code is derived from software developed for The NetBSD Foundation
86c8f7fc3SBen Gras  * by Andrew Doran.
96c8f7fc3SBen Gras  *
106c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
116c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
126c8f7fc3SBen Gras  * are met:
136c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
146c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
156c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
166c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
176c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
186c8f7fc3SBen Gras  *
196c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
206c8f7fc3SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
216c8f7fc3SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
226c8f7fc3SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
236c8f7fc3SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
246c8f7fc3SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
256c8f7fc3SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
266c8f7fc3SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
276c8f7fc3SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
286c8f7fc3SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
296c8f7fc3SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
306c8f7fc3SBen Gras  */
316c8f7fc3SBen Gras 
326c8f7fc3SBen Gras #ifndef _SYS_SYSCALLVAR_H_
336c8f7fc3SBen Gras #define	_SYS_SYSCALLVAR_H_
346c8f7fc3SBen Gras 
356c8f7fc3SBen Gras #ifndef _KERNEL
366c8f7fc3SBen Gras #error nothing of interest to userspace here
376c8f7fc3SBen Gras #endif
386c8f7fc3SBen Gras 
39*0a6a1f1dSLionel Sambuc #if defined(_KERNEL) && defined(_KERNEL_OPT)
40*0a6a1f1dSLionel Sambuc #include "opt_dtrace.h"
41*0a6a1f1dSLionel Sambuc #endif
42*0a6a1f1dSLionel Sambuc 
436c8f7fc3SBen Gras #include <sys/systm.h>
446c8f7fc3SBen Gras #include <sys/proc.h>
456c8f7fc3SBen Gras 
466c8f7fc3SBen Gras extern struct emul emul_netbsd;
476c8f7fc3SBen Gras 
486c8f7fc3SBen Gras struct syscall_package {
496c8f7fc3SBen Gras 	u_short		sp_code;
506c8f7fc3SBen Gras 	u_short		sp_flags;
516c8f7fc3SBen Gras 	sy_call_t	*sp_call;
526c8f7fc3SBen Gras };
536c8f7fc3SBen Gras 
546c8f7fc3SBen Gras void	syscall_init(void);
556c8f7fc3SBen Gras int	syscall_establish(const struct emul *, const struct syscall_package *);
566c8f7fc3SBen Gras int	syscall_disestablish(const struct emul *, const struct syscall_package *);
576c8f7fc3SBen Gras 
586c8f7fc3SBen Gras static inline int
sy_call(const struct sysent * sy,struct lwp * l,const void * uap,register_t * rval)596c8f7fc3SBen Gras sy_call(const struct sysent *sy, struct lwp *l, const void *uap,
606c8f7fc3SBen Gras 	register_t *rval)
616c8f7fc3SBen Gras {
626c8f7fc3SBen Gras 	int error;
636c8f7fc3SBen Gras 
646c8f7fc3SBen Gras 	l->l_sysent = sy;
656c8f7fc3SBen Gras 	error = (*sy->sy_call)(l, uap, rval);
666c8f7fc3SBen Gras 	l->l_sysent = NULL;
676c8f7fc3SBen Gras 
686c8f7fc3SBen Gras 	return error;
696c8f7fc3SBen Gras }
706c8f7fc3SBen Gras 
7184d9c625SLionel Sambuc static inline int
sy_invoke(const struct sysent * sy,struct lwp * l,const void * uap,register_t * rval,int code)7284d9c625SLionel Sambuc sy_invoke(const struct sysent *sy, struct lwp *l, const void *uap,
7384d9c625SLionel Sambuc 	register_t *rval, int code)
7484d9c625SLionel Sambuc {
7584d9c625SLionel Sambuc 	const bool do_trace = l->l_proc->p_trace_enabled &&
7684d9c625SLionel Sambuc 	    (sy->sy_flags & SYCALL_INDIRECT) == 0;
7784d9c625SLionel Sambuc 	int error;
7884d9c625SLionel Sambuc 
79*0a6a1f1dSLionel Sambuc #ifdef KDTRACE_HOOKS
80*0a6a1f1dSLionel Sambuc #define KDTRACE_ENTRY(a)	(a)
81*0a6a1f1dSLionel Sambuc #else
82*0a6a1f1dSLionel Sambuc #define KDTRACE_ENTRY(a)	(0)
83*0a6a1f1dSLionel Sambuc #endif
84*0a6a1f1dSLionel Sambuc 	if (__predict_true(!(do_trace || KDTRACE_ENTRY(sy->sy_entry)))
85*0a6a1f1dSLionel Sambuc 	    || (error = trace_enter(code, sy, uap)) == 0) {
8684d9c625SLionel Sambuc 		rval[0] = 0;
87*0a6a1f1dSLionel Sambuc #if !defined(__mips__) && !defined(__m68k__)
8884d9c625SLionel Sambuc 		/*
8984d9c625SLionel Sambuc 		 * Due to the mips userland code for SYS_break needing v1 to be
9084d9c625SLionel Sambuc 		 * preserved, we can't clear this on mips.
9184d9c625SLionel Sambuc 		 */
9284d9c625SLionel Sambuc 		rval[1] = 0;
9384d9c625SLionel Sambuc #endif
9484d9c625SLionel Sambuc 		error = sy_call(sy, l, uap, rval);
9584d9c625SLionel Sambuc 	}
9684d9c625SLionel Sambuc 
97*0a6a1f1dSLionel Sambuc 	if (__predict_false(do_trace || KDTRACE_ENTRY(sy->sy_return))) {
98*0a6a1f1dSLionel Sambuc 		trace_exit(code, sy, uap, rval, error);
9984d9c625SLionel Sambuc 	}
10084d9c625SLionel Sambuc 	return error;
10184d9c625SLionel Sambuc }
10284d9c625SLionel Sambuc 
1036c8f7fc3SBen Gras /* inclusion in the kernel currently depends on SYSCALL_DEBUG */
1046c8f7fc3SBen Gras extern const char * const syscallnames[];
105*0a6a1f1dSLionel Sambuc extern const char * const altsyscallnames[];
1066c8f7fc3SBen Gras 
1076c8f7fc3SBen Gras #endif	/* _SYS_SYSCALLVAR_H_ */
108