sysent.h revision 160882
1285890Sbapt/*-
2285890Sbapt * Copyright (c) 1982, 1988, 1991 The Regents of the University of California.
3285923Sdelphij * All rights reserved.
4285890Sbapt *
5285890Sbapt * Redistribution and use in source and binary forms, with or without
6285890Sbapt * modification, are permitted provided that the following conditions
7285890Sbapt * are met:
8285890Sbapt * 1. Redistributions of source code must retain the above copyright
9285890Sbapt *    notice, this list of conditions and the following disclaimer.
10285890Sbapt * 2. Redistributions in binary form must reproduce the above copyright
11285890Sbapt *    notice, this list of conditions and the following disclaimer in the
12285890Sbapt *    documentation and/or other materials provided with the distribution.
13285890Sbapt * 4. Neither the name of the University nor the names of its contributors
14285890Sbapt *    may be used to endorse or promote products derived from this software
15285890Sbapt *    without specific prior written permission.
16285890Sbapt *
17285890Sbapt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18285890Sbapt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19285890Sbapt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20285890Sbapt * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21285890Sbapt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22285890Sbapt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23285890Sbapt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24285890Sbapt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25285890Sbapt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26285890Sbapt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27285890Sbapt * SUCH DAMAGE.
28285890Sbapt *
29285890Sbapt * $FreeBSD: head/sys/sys/sysent.h 160882 2006-08-01 16:32:20Z jhb $
30285890Sbapt */
31285890Sbapt
32285890Sbapt#ifndef _SYS_SYSENT_H_
33285890Sbapt#define	_SYS_SYSENT_H_
34285890Sbapt
35285890Sbapt#include <bsm/audit.h>
36285890Sbapt
37285890Sbaptstruct proc;
38285890Sbaptstruct thread;
39285890Sbaptstruct ksiginfo;
40285890Sbapt
41285890Sbapttypedef	int	sy_call_t(struct thread *, void *);
42285923Sdelphij
43285923Sdelphijstruct sysent {		/* system call table */
44285923Sdelphij	int	sy_narg;	/* number of arguments */
45285923Sdelphij	sy_call_t *sy_call;	/* implementing function */
46285923Sdelphij	au_event_t sy_auevent;	/* audit event associated with syscall */
47285923Sdelphij};
48285923Sdelphij
49285923Sdelphijstruct image_params;
50285923Sdelphijstruct __sigset;
51285890Sbaptstruct trapframe;
52285890Sbaptstruct vnode;
53285890Sbapt
54285890Sbaptstruct sysentvec {
55285890Sbapt	int		sv_size;	/* number of entries */
56285890Sbapt	struct sysent	*sv_table;	/* pointer to sysent */
57285923Sdelphij	u_int		sv_mask;	/* optional mask to index */
58285923Sdelphij	int		sv_sigsize;	/* size of signal translation table */
59285890Sbapt	int		*sv_sigtbl;	/* signal translation table */
60285890Sbapt	int		sv_errsize;	/* size of errno translation table */
61285890Sbapt	int 		*sv_errtbl;	/* errno translation table */
62285890Sbapt	int		(*sv_transtrap)(int, int);
63285890Sbapt					/* translate trap-to-signal mapping */
64285890Sbapt	int		(*sv_fixup)(register_t **, struct image_params *);
65285890Sbapt					/* stack fixup function */
66285890Sbapt	void		(*sv_sendsig)(void (*)(int), struct ksiginfo *, struct __sigset *);
67285890Sbapt			    		/* send signal */
68285923Sdelphij	char 		*sv_sigcode;	/* start of sigtramp code */
69285923Sdelphij	int 		*sv_szsigcode;	/* size of sigtramp code */
70285923Sdelphij	void		(*sv_prepsyscall)(struct trapframe *, int *, u_int *,
71285923Sdelphij			    caddr_t *);
72285923Sdelphij	char		*sv_name;	/* name of binary type */
73285923Sdelphij	int		(*sv_coredump)(struct thread *, struct vnode *, off_t);
74285923Sdelphij					/* function to dump core, or NULL */
75285923Sdelphij	int		(*sv_imgact_try)(struct image_params *);
76285923Sdelphij	int		sv_minsigstksz;	/* minimum signal stack size */
77285923Sdelphij	int		sv_pagesize;	/* pagesize */
78285923Sdelphij	vm_offset_t	sv_minuser;	/* VM_MIN_ADDRESS */
79285923Sdelphij	vm_offset_t	sv_maxuser;	/* VM_MAXUSER_ADDRESS */
80285923Sdelphij	vm_offset_t	sv_usrstack;	/* USRSTACK */
81285923Sdelphij	vm_offset_t	sv_psstrings;	/* PS_STRINGS */
82285923Sdelphij	int		sv_stackprot;	/* vm protection for stack */
83285923Sdelphij	register_t	*(*sv_copyout_strings)(struct image_params *);
84285923Sdelphij	void		(*sv_setregs)(struct thread *, u_long, u_long, u_long);
85285923Sdelphij	void		(*sv_fixlimits)(struct proc *);
86285923Sdelphij};
87285923Sdelphij
88285923Sdelphij#ifdef _KERNEL
89285923Sdelphijextern struct sysentvec aout_sysvec;
90285923Sdelphijextern struct sysentvec elf_freebsd_sysvec;
91285923Sdelphijextern struct sysentvec null_sysvec;
92285923Sdelphijextern struct sysent sysent[];
93285923Sdelphij
94285923Sdelphij#define NO_SYSCALL (-1)
95285923Sdelphij
96285923Sdelphijstruct module;
97285923Sdelphij
98285923Sdelphijstruct syscall_module_data {
99285923Sdelphij       int     (*chainevh)(struct module *, int, void *); /* next handler */
100285923Sdelphij       void    *chainarg;      /* arg for next event handler */
101285923Sdelphij       int     *offset;         /* offset into sysent */
102285923Sdelphij       struct  sysent *new_sysent; /* new sysent */
103285923Sdelphij       struct  sysent old_sysent; /* old sysent */
104285923Sdelphij};
105285923Sdelphij
106285923Sdelphij#define SYSCALL_MODULE(name, offset, new_sysent, evh, arg)     \
107285923Sdelphijstatic struct syscall_module_data name##_syscall_mod = {       \
108285923Sdelphij       evh, arg, offset, new_sysent, { 0, NULL }               \
109285923Sdelphij};                                                             \
110285923Sdelphij                                                               \
111285923Sdelphijstatic moduledata_t name##_mod = {                             \
112285923Sdelphij       #name,                                                  \
113285923Sdelphij       syscall_module_handler,                                 \
114285923Sdelphij       &name##_syscall_mod                                     \
115285923Sdelphij};                                                             \
116285923SdelphijDECLARE_MODULE(name, name##_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE)
117285923Sdelphij
118285923Sdelphij#define SYSCALL_MODULE_HELPER(syscallname)              \
119285923Sdelphijstatic int syscallname##_syscall = SYS_##syscallname;   \
120285923Sdelphijstatic struct sysent syscallname##_sysent = {           \
121285923Sdelphij    (sizeof(struct syscallname ## _args )               \
122285923Sdelphij     / sizeof(register_t)),                             \
123285923Sdelphij    (sy_call_t *)& syscallname                          \
124285923Sdelphij};                                                      \
125285923SdelphijSYSCALL_MODULE(syscallname,                             \
126285923Sdelphij    & syscallname##_syscall, & syscallname##_sysent,    \
127285923Sdelphij    NULL, NULL);
128285923Sdelphij
129285923Sdelphijint    syscall_register(int *offset, struct sysent *new_sysent,
130285923Sdelphij	    struct sysent *old_sysent);
131285923Sdelphijint    syscall_deregister(int *offset, struct sysent *old_sysent);
132285923Sdelphijint    syscall_module_handler(struct module *mod, int what, void *arg);
133285923Sdelphij
134285923Sdelphij#endif /* _KERNEL */
135285923Sdelphij
136285923Sdelphij#endif /* !_SYS_SYSENT_H_ */
137285923Sdelphij