sysent.h revision 219405
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 219405 2011-03-08 19:01:45Z dchagin $ 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. */ 45211608Srpaulotypedef void (*systrace_probe_func_t)(u_int32_t, int, struct sysent *, void *, 46211608Srpaulo int); 47160941Sjb 48160941Sjb/* 49160941Sjb * Used by loaded syscalls to convert arguments to a DTrace array 50160941Sjb * of 64-bit arguments. 51160941Sjb */ 52184698Srodrigctypedef void (*systrace_args_func_t)(int, void *, u_int64_t *, int *); 53160941Sjb 54160941Sjbextern systrace_probe_func_t systrace_probe_func; 55160941Sjb 56183159Sjhbstruct sysent { /* system call table */ 572255Ssos int sy_narg; /* number of arguments */ 5810905Sbde sy_call_t *sy_call; /* implementing function */ 59146782Srwatson au_event_t sy_auevent; /* audit event associated with syscall */ 60160941Sjb systrace_args_func_t sy_systrace_args_func; 61160941Sjb /* optional argument conversion function. */ 62183159Sjhb u_int32_t sy_entry; /* DTrace entry ID for systrace. */ 63183159Sjhb u_int32_t sy_return; /* DTrace return ID for systrace. */ 64193234Srwatson u_int32_t sy_flags; /* General flags for system calls. */ 65209579Skib u_int32_t sy_thrcnt; 662255Ssos}; 6758717Sdillon 68219131Srwatson/* 69219131Srwatson * A system call is permitted in capability mode. 70219131Srwatson */ 71219131Srwatson#define SYF_CAPENABLED 0x00000001 72219131Srwatson 73209579Skib#define SY_THR_FLAGMASK 0x7 74209579Skib#define SY_THR_STATIC 0x1 75209579Skib#define SY_THR_DRAINING 0x2 76209579Skib#define SY_THR_ABSENT 0x4 77209579Skib#define SY_THR_INCR 0x8 78209579Skib 7910905Sbdestruct image_params; 8055152Sbdestruct __sigset; 81208453Skibstruct syscall_args; 8214331Speterstruct trapframe; 8350791Smarcelstruct vnode; 8410905Sbde 852255Ssosstruct sysentvec { 862255Ssos int sv_size; /* number of entries */ 872255Ssos struct sysent *sv_table; /* pointer to sysent */ 8814917Sbde u_int sv_mask; /* optional mask to index */ 893472Ssos int sv_sigsize; /* size of signal translation table */ 903472Ssos int *sv_sigtbl; /* signal translation table */ 9115036Ssmpatel int sv_errsize; /* size of errno translation table */ 923472Ssos int *sv_errtbl; /* errno translation table */ 9392719Salfred int (*sv_transtrap)(int, int); 9435496Seivind /* translate trap-to-signal mapping */ 9592719Salfred int (*sv_fixup)(register_t **, struct image_params *); 9610905Sbde /* stack fixup function */ 97151316Sdavidxu void (*sv_sendsig)(void (*)(int), struct ksiginfo *, struct __sigset *); 98151316Sdavidxu /* send signal */ 9914331Speter char *sv_sigcode; /* start of sigtramp code */ 10014331Speter int *sv_szsigcode; /* size of sigtramp code */ 10193008Sbde void (*sv_prepsyscall)(struct trapframe *, int *, u_int *, 10293008Sbde caddr_t *); 10316474Sdyson char *sv_name; /* name of binary type */ 104204552Salfred int (*sv_coredump)(struct thread *, struct vnode *, off_t, int); 10539154Sjdp /* function to dump core, or NULL */ 10692719Salfred int (*sv_imgact_try)(struct image_params *); 10768520Smarcel int sv_minsigstksz; /* minimum signal stack size */ 108102808Sjake int sv_pagesize; /* pagesize */ 109102808Sjake vm_offset_t sv_minuser; /* VM_MIN_ADDRESS */ 110102808Sjake vm_offset_t sv_maxuser; /* VM_MAXUSER_ADDRESS */ 111102808Sjake vm_offset_t sv_usrstack; /* USRSTACK */ 112102808Sjake vm_offset_t sv_psstrings; /* PS_STRINGS */ 113102808Sjake int sv_stackprot; /* vm protection for stack */ 114100384Speter register_t *(*sv_copyout_strings)(struct image_params *); 115205642Snwhitehorn void (*sv_setregs)(struct thread *, struct image_params *, 116205642Snwhitehorn u_long); 117169565Sjhb void (*sv_fixlimit)(struct rlimit *, int); 118171410Sjhb u_long *sv_maxssiz; 119185169Skib u_int sv_flags; 120208453Skib void (*sv_set_syscall_retval)(struct thread *, int); 121208453Skib int (*sv_fetch_syscall_args)(struct thread *, struct 122208453Skib syscall_args *); 123208453Skib const char **sv_syscallnames; 124217151Skib vm_offset_t sv_shared_page_base; 125217151Skib vm_offset_t sv_shared_page_len; 126217151Skib vm_offset_t sv_sigcode_base; 127217151Skib void *sv_shared_page_obj; 128219405Sdchagin void (*sv_schedtail)(struct thread *); 1292255Ssos}; 1302255Ssos 131185169Skib#define SV_ILP32 0x000100 132185169Skib#define SV_LP64 0x000200 133185169Skib#define SV_IA32 0x004000 134185169Skib#define SV_AOUT 0x008000 135217151Skib#define SV_SHP 0x010000 136185169Skib 137185169Skib#define SV_ABI_MASK 0xff 138217896Sdchagin#define SV_PROC_FLAG(p, x) ((p)->p_sysent->sv_flags & (x)) 139217896Sdchagin#define SV_PROC_ABI(p) ((p)->p_sysent->sv_flags & SV_ABI_MASK) 140217896Sdchagin#define SV_CURPROC_FLAG(x) SV_PROC_FLAG(curproc, x) 141217896Sdchagin#define SV_CURPROC_ABI() SV_PROC_ABI(curproc) 142185169Skib/* same as ELFOSABI_XXX, to prevent header pollution */ 143185169Skib#define SV_ABI_LINUX 3 144185169Skib#define SV_ABI_FREEBSD 9 145185169Skib#define SV_ABI_UNDEF 255 146185169Skib 14755205Speter#ifdef _KERNEL 1487090Sbdeextern struct sysentvec aout_sysvec; 14968356Sobrienextern struct sysentvec elf_freebsd_sysvec; 150102808Sjakeextern struct sysentvec null_sysvec; 1512255Ssosextern struct sysent sysent[]; 152208453Skibextern const char *syscallnames[]; 1532255Ssos 154183159Sjhb#define NO_SYSCALL (-1) 15542433Sdfr 15642433Sdfrstruct module; 15742433Sdfr 15842433Sdfrstruct syscall_module_data { 159183159Sjhb int (*chainevh)(struct module *, int, void *); /* next handler */ 160183159Sjhb void *chainarg; /* arg for next event handler */ 161183159Sjhb int *offset; /* offset into sysent */ 162183159Sjhb struct sysent *new_sysent; /* new sysent */ 163183159Sjhb struct sysent old_sysent; /* old sysent */ 16442433Sdfr}; 16542433Sdfr 166183159Sjhb#define MAKE_SYSENT(syscallname) \ 167183159Sjhbstatic struct sysent syscallname##_sysent = { \ 168209587Skib (sizeof(struct syscallname ## _args ) \ 169183159Sjhb / sizeof(register_t)), \ 170209587Skib (sy_call_t *)& syscallname, \ 171209587Skib SYS_AUE_##syscallname \ 172168268Sjhb} 173183159Sjhb 174183159Sjhb#define SYSCALL_MODULE(name, offset, new_sysent, evh, arg) \ 175183159Sjhbstatic struct syscall_module_data name##_syscall_mod = { \ 176183159Sjhb evh, arg, offset, new_sysent, { 0, NULL, AUE_NULL } \ 177183159Sjhb}; \ 178183159Sjhb \ 179183159Sjhbstatic moduledata_t name##_mod = { \ 180205320Skib "sys/" #name, \ 181183159Sjhb syscall_module_handler, \ 182183159Sjhb &name##_syscall_mod \ 183183159Sjhb}; \ 184160882SjhbDECLARE_MODULE(name, name##_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE) 18542433Sdfr 186183159Sjhb#define SYSCALL_MODULE_HELPER(syscallname) \ 187183159Sjhbstatic int syscallname##_syscall = SYS_##syscallname; \ 188183159SjhbMAKE_SYSENT(syscallname); \ 189183159SjhbSYSCALL_MODULE(syscallname, \ 190183159Sjhb & syscallname##_syscall, & syscallname##_sysent, \ 191183159Sjhb NULL, NULL) 19269449Salfred 193183159Sjhb#define SYSCALL_MODULE_PRESENT(syscallname) \ 194183159Sjhb (sysent[SYS_##syscallname].sy_call != (sy_call_t *)lkmnosys && \ 195183159Sjhb sysent[SYS_##syscallname].sy_call != (sy_call_t *)lkmressys) 196165402Sjkim 197205321Skib/* 198205321Skib * Syscall registration helpers with resource allocation handling. 199205321Skib */ 200205321Skibstruct syscall_helper_data { 201205321Skib struct sysent new_sysent; 202205321Skib struct sysent old_sysent; 203205321Skib int syscall_no; 204205321Skib int registered; 205205321Skib}; 206205321Skib#define SYSCALL_INIT_HELPER(syscallname) { \ 207205321Skib .new_sysent = { \ 208205321Skib .sy_narg = (sizeof(struct syscallname ## _args ) \ 209205321Skib / sizeof(register_t)), \ 210205321Skib .sy_call = (sy_call_t *)& syscallname, \ 211205321Skib .sy_auevent = SYS_AUE_##syscallname \ 212205321Skib }, \ 213205321Skib .syscall_no = SYS_##syscallname \ 214205321Skib} 215205321Skib#define SYSCALL_INIT_LAST { \ 216205321Skib .syscall_no = NO_SYSCALL \ 217205321Skib} 218205321Skib 219183159Sjhbint syscall_register(int *offset, struct sysent *new_sysent, 22093008Sbde struct sysent *old_sysent); 221183159Sjhbint syscall_deregister(int *offset, struct sysent *old_sysent); 222183159Sjhbint syscall_module_handler(struct module *mod, int what, void *arg); 223205321Skibint syscall_helper_register(struct syscall_helper_data *sd); 224205321Skibint syscall_helper_unregister(struct syscall_helper_data *sd); 22542433Sdfr 226208566Skibstruct proc; 227208566Skibconst char *syscallname(struct proc *p, u_int code); 228208566Skib 229183361Sjhb/* Special purpose system call functions. */ 230183361Sjhbstruct nosys_args; 231183361Sjhb 232183361Sjhbint lkmnosys(struct thread *, struct nosys_args *); 233183361Sjhbint lkmressys(struct thread *, struct nosys_args *); 234183361Sjhb 235209579Skibint syscall_thread_enter(struct thread *td, struct sysent *se); 236209579Skibvoid syscall_thread_exit(struct thread *td, struct sysent *se); 237209579Skib 238217151Skibint shared_page_fill(int size, int align, const char *data); 239217151Skibvoid exec_sysvec_init(void *param); 240217151Skib 241217151Skib#define INIT_SYSENTVEC(name, sv) \ 242217151Skib SYSINIT(name, SI_SUB_EXEC, SI_ORDER_ANY, \ 243217151Skib (sysinit_cfunc_t)exec_sysvec_init, sv); 244217151Skib 24555205Speter#endif /* _KERNEL */ 24642433Sdfr 24714917Sbde#endif /* !_SYS_SYSENT_H_ */ 248