sysent.h revision 205642
12255Ssos/*-
22255Ssos * Copyright (c) 1982, 1988, 1991 The Regents of the University of California.
32255Ssos * All rights reserved.
42255Ssos *
52255Ssos * Redistribution and use in source and binary forms, with or without
62255Ssos * modification, are permitted provided that the following conditions
72255Ssos * are met:
82255Ssos * 1. Redistributions of source code must retain the above copyright
92255Ssos *    notice, this list of conditions and the following disclaimer.
102255Ssos * 2. Redistributions in binary form must reproduce the above copyright
112255Ssos *    notice, this list of conditions and the following disclaimer in the
122255Ssos *    documentation and/or other materials provided with the distribution.
132255Ssos * 4. Neither the name of the University nor the names of its contributors
142255Ssos *    may be used to endorse or promote products derived from this software
152255Ssos *    without specific prior written permission.
162255Ssos *
172255Ssos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
182255Ssos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
192255Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
202255Ssos * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
212255Ssos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222255Ssos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
232255Ssos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
242255Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
252255Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
262255Ssos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
272255Ssos * SUCH DAMAGE.
282255Ssos *
2950477Speter * $FreeBSD: head/sys/sys/sysent.h 205642 2010-03-25 14:24:00Z nwhitehorn $
302255Ssos */
312255Ssos
322255Ssos#ifndef _SYS_SYSENT_H_
3314917Sbde#define	_SYS_SYSENT_H_
342255Ssos
35146782Srwatson#include <bsm/audit.h>
36146782Srwatson
37169565Sjhbstruct rlimit;
38160941Sjbstruct sysent;
3983366Sjulianstruct thread;
40151316Sdavidxustruct ksiginfo;
4133054Sbde
4292719Salfredtypedef	int	sy_call_t(struct thread *, void *);
4310905Sbde
44160941Sjb/* Used by the machine dependent syscall() code. */
45160941Sjbtypedef	void (*systrace_probe_func_t)(u_int32_t, int, struct sysent *, void *);
46160941Sjb
47160941Sjb/*
48160941Sjb * Used by loaded syscalls to convert arguments to a DTrace array
49160941Sjb * of 64-bit arguments.
50160941Sjb */
51184698Srodrigctypedef	void (*systrace_args_func_t)(int, void *, u_int64_t *, int *);
52160941Sjb
53160941Sjbextern systrace_probe_func_t	systrace_probe_func;
54160941Sjb
55183159Sjhbstruct sysent {			/* system call table */
562255Ssos	int	sy_narg;	/* number of arguments */
5710905Sbde	sy_call_t *sy_call;	/* implementing function */
58146782Srwatson	au_event_t sy_auevent;	/* audit event associated with syscall */
59160941Sjb	systrace_args_func_t sy_systrace_args_func;
60160941Sjb				/* optional argument conversion function. */
61183159Sjhb	u_int32_t sy_entry;	/* DTrace entry ID for systrace. */
62183159Sjhb	u_int32_t sy_return;	/* DTrace return ID for systrace. */
63193234Srwatson	u_int32_t sy_flags;	/* General flags for system calls. */
642255Ssos};
6558717Sdillon
6610905Sbdestruct image_params;
6755152Sbdestruct __sigset;
6814331Speterstruct trapframe;
6950791Smarcelstruct vnode;
7010905Sbde
712255Ssosstruct sysentvec {
722255Ssos	int		sv_size;	/* number of entries */
732255Ssos	struct sysent	*sv_table;	/* pointer to sysent */
7414917Sbde	u_int		sv_mask;	/* optional mask to index */
753472Ssos	int		sv_sigsize;	/* size of signal translation table */
763472Ssos	int		*sv_sigtbl;	/* signal translation table */
7715036Ssmpatel	int		sv_errsize;	/* size of errno translation table */
783472Ssos	int 		*sv_errtbl;	/* errno translation table */
7992719Salfred	int		(*sv_transtrap)(int, int);
8035496Seivind					/* translate trap-to-signal mapping */
8192719Salfred	int		(*sv_fixup)(register_t **, struct image_params *);
8210905Sbde					/* stack fixup function */
83151316Sdavidxu	void		(*sv_sendsig)(void (*)(int), struct ksiginfo *, struct __sigset *);
84151316Sdavidxu			    		/* send signal */
8514331Speter	char 		*sv_sigcode;	/* start of sigtramp code */
8614331Speter	int 		*sv_szsigcode;	/* size of sigtramp code */
8793008Sbde	void		(*sv_prepsyscall)(struct trapframe *, int *, u_int *,
8893008Sbde			    caddr_t *);
8916474Sdyson	char		*sv_name;	/* name of binary type */
90204552Salfred	int		(*sv_coredump)(struct thread *, struct vnode *, off_t, int);
9139154Sjdp					/* function to dump core, or NULL */
9292719Salfred	int		(*sv_imgact_try)(struct image_params *);
9368520Smarcel	int		sv_minsigstksz;	/* minimum signal stack size */
94102808Sjake	int		sv_pagesize;	/* pagesize */
95102808Sjake	vm_offset_t	sv_minuser;	/* VM_MIN_ADDRESS */
96102808Sjake	vm_offset_t	sv_maxuser;	/* VM_MAXUSER_ADDRESS */
97102808Sjake	vm_offset_t	sv_usrstack;	/* USRSTACK */
98102808Sjake	vm_offset_t	sv_psstrings;	/* PS_STRINGS */
99102808Sjake	int		sv_stackprot;	/* vm protection for stack */
100100384Speter	register_t	*(*sv_copyout_strings)(struct image_params *);
101205642Snwhitehorn	void		(*sv_setregs)(struct thread *, struct image_params *,
102205642Snwhitehorn			    u_long);
103169565Sjhb	void		(*sv_fixlimit)(struct rlimit *, int);
104171410Sjhb	u_long		*sv_maxssiz;
105185169Skib	u_int		sv_flags;
1062255Ssos};
1072255Ssos
108185169Skib#define	SV_ILP32	0x000100
109185169Skib#define	SV_LP64		0x000200
110185169Skib#define	SV_IA32		0x004000
111185169Skib#define	SV_AOUT		0x008000
112185169Skib
113185169Skib#define	SV_ABI_MASK	0xff
114185169Skib#define	SV_CURPROC_FLAG(x) (curproc->p_sysent->sv_flags & (x))
115185169Skib#define	SV_CURPROC_ABI() (curproc->p_sysent->sv_flags & SV_ABI_MASK)
116185169Skib/* same as ELFOSABI_XXX, to prevent header pollution */
117185169Skib#define	SV_ABI_LINUX	3
118185169Skib#define	SV_ABI_FREEBSD 	9
119185169Skib#define	SV_ABI_UNDEF	255
120185169Skib
12155205Speter#ifdef _KERNEL
1227090Sbdeextern struct sysentvec aout_sysvec;
12368356Sobrienextern struct sysentvec elf_freebsd_sysvec;
124102808Sjakeextern struct sysentvec null_sysvec;
1252255Ssosextern struct sysent sysent[];
1262255Ssos
127183159Sjhb#define	NO_SYSCALL (-1)
12842433Sdfr
12942433Sdfrstruct module;
13042433Sdfr
13142433Sdfrstruct syscall_module_data {
132183159Sjhb	int	(*chainevh)(struct module *, int, void *); /* next handler */
133183159Sjhb	void	*chainarg;		/* arg for next event handler */
134183159Sjhb	int	*offset;		/* offset into sysent */
135183159Sjhb	struct sysent *new_sysent;	/* new sysent */
136183159Sjhb	struct sysent old_sysent;	/* old sysent */
13742433Sdfr};
13842433Sdfr
139183159Sjhb#define	MAKE_SYSENT(syscallname)				\
140183159Sjhbstatic struct sysent syscallname##_sysent = {			\
141183159Sjhb	(sizeof(struct syscallname ## _args )			\
142183159Sjhb	    / sizeof(register_t)),				\
143183159Sjhb	(sy_call_t *)& syscallname,				\
144183159Sjhb	SYS_AUE_##syscallname					\
145168268Sjhb}
146183159Sjhb
147183159Sjhb#define SYSCALL_MODULE(name, offset, new_sysent, evh, arg)	\
148183159Sjhbstatic struct syscall_module_data name##_syscall_mod = {	\
149183159Sjhb	evh, arg, offset, new_sysent, { 0, NULL, AUE_NULL }	\
150183159Sjhb};								\
151183159Sjhb								\
152183159Sjhbstatic moduledata_t name##_mod = {				\
153205320Skib	"sys/" #name,						\
154183159Sjhb	syscall_module_handler,					\
155183159Sjhb	&name##_syscall_mod					\
156183159Sjhb};								\
157160882SjhbDECLARE_MODULE(name, name##_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE)
15842433Sdfr
159183159Sjhb#define	SYSCALL_MODULE_HELPER(syscallname)			\
160183159Sjhbstatic int syscallname##_syscall = SYS_##syscallname;		\
161183159SjhbMAKE_SYSENT(syscallname);					\
162183159SjhbSYSCALL_MODULE(syscallname,					\
163183159Sjhb    & syscallname##_syscall, & syscallname##_sysent,		\
164183159Sjhb    NULL, NULL)
16569449Salfred
166183159Sjhb#define	SYSCALL_MODULE_PRESENT(syscallname)				\
167183159Sjhb	(sysent[SYS_##syscallname].sy_call != (sy_call_t *)lkmnosys &&	\
168183159Sjhb	sysent[SYS_##syscallname].sy_call != (sy_call_t *)lkmressys)
169165402Sjkim
170205321Skib/*
171205321Skib * Syscall registration helpers with resource allocation handling.
172205321Skib */
173205321Skibstruct syscall_helper_data {
174205321Skib	struct sysent new_sysent;
175205321Skib	struct sysent old_sysent;
176205321Skib	int syscall_no;
177205321Skib	int registered;
178205321Skib};
179205321Skib#define SYSCALL_INIT_HELPER(syscallname) {			\
180205321Skib    .new_sysent = {						\
181205321Skib	.sy_narg = (sizeof(struct syscallname ## _args )	\
182205321Skib	    / sizeof(register_t)),				\
183205321Skib	.sy_call = (sy_call_t *)& syscallname,			\
184205321Skib	.sy_auevent = SYS_AUE_##syscallname			\
185205321Skib    },								\
186205321Skib    .syscall_no = SYS_##syscallname				\
187205321Skib}
188205321Skib#define SYSCALL_INIT_LAST {					\
189205321Skib    .syscall_no = NO_SYSCALL					\
190205321Skib}
191205321Skib
192183159Sjhbint	syscall_register(int *offset, struct sysent *new_sysent,
19393008Sbde	    struct sysent *old_sysent);
194183159Sjhbint	syscall_deregister(int *offset, struct sysent *old_sysent);
195183159Sjhbint	syscall_module_handler(struct module *mod, int what, void *arg);
196205321Skibint	syscall_helper_register(struct syscall_helper_data *sd);
197205321Skibint	syscall_helper_unregister(struct syscall_helper_data *sd);
19842433Sdfr
199183361Sjhb/* Special purpose system call functions. */
200183361Sjhbstruct nosys_args;
201183361Sjhb
202183361Sjhbint	lkmnosys(struct thread *, struct nosys_args *);
203183361Sjhbint	lkmressys(struct thread *, struct nosys_args *);
204183361Sjhb
20555205Speter#endif /* _KERNEL */
20642433Sdfr
20714917Sbde#endif /* !_SYS_SYSENT_H_ */
208