sysent.h revision 273707
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 273707 2014-10-26 19:42:44Z mjg $ 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 79273707Smjg#ifdef KLD_MODULE 80273707Smjg#define SY_THR_STATIC_KLD 0 81273707Smjg#else 82273707Smjg#define SY_THR_STATIC_KLD SY_THR_STATIC 83273707Smjg#endif 84273707Smjg 8510905Sbdestruct image_params; 8655152Sbdestruct __sigset; 87208453Skibstruct syscall_args; 8814331Speterstruct trapframe; 8950791Smarcelstruct vnode; 9010905Sbde 912255Ssosstruct sysentvec { 922255Ssos int sv_size; /* number of entries */ 932255Ssos struct sysent *sv_table; /* pointer to sysent */ 9414917Sbde u_int sv_mask; /* optional mask to index */ 953472Ssos int sv_sigsize; /* size of signal translation table */ 963472Ssos int *sv_sigtbl; /* signal translation table */ 9715036Ssmpatel int sv_errsize; /* size of errno translation table */ 983472Ssos int *sv_errtbl; /* errno translation table */ 9992719Salfred int (*sv_transtrap)(int, int); 10035496Seivind /* translate trap-to-signal mapping */ 10192719Salfred int (*sv_fixup)(register_t **, struct image_params *); 10210905Sbde /* stack fixup function */ 103151316Sdavidxu void (*sv_sendsig)(void (*)(int), struct ksiginfo *, struct __sigset *); 104151316Sdavidxu /* send signal */ 10514331Speter char *sv_sigcode; /* start of sigtramp code */ 10614331Speter int *sv_szsigcode; /* size of sigtramp code */ 10793008Sbde void (*sv_prepsyscall)(struct trapframe *, int *, u_int *, 10893008Sbde caddr_t *); 10916474Sdyson char *sv_name; /* name of binary type */ 110204552Salfred int (*sv_coredump)(struct thread *, struct vnode *, off_t, int); 11139154Sjdp /* function to dump core, or NULL */ 11292719Salfred int (*sv_imgact_try)(struct image_params *); 11368520Smarcel int sv_minsigstksz; /* minimum signal stack size */ 114102808Sjake int sv_pagesize; /* pagesize */ 115102808Sjake vm_offset_t sv_minuser; /* VM_MIN_ADDRESS */ 116102808Sjake vm_offset_t sv_maxuser; /* VM_MAXUSER_ADDRESS */ 117102808Sjake vm_offset_t sv_usrstack; /* USRSTACK */ 118102808Sjake vm_offset_t sv_psstrings; /* PS_STRINGS */ 119102808Sjake int sv_stackprot; /* vm protection for stack */ 120100384Speter register_t *(*sv_copyout_strings)(struct image_params *); 121205642Snwhitehorn void (*sv_setregs)(struct thread *, struct image_params *, 122205642Snwhitehorn u_long); 123169565Sjhb void (*sv_fixlimit)(struct rlimit *, int); 124171410Sjhb u_long *sv_maxssiz; 125185169Skib u_int sv_flags; 126208453Skib void (*sv_set_syscall_retval)(struct thread *, int); 127208453Skib int (*sv_fetch_syscall_args)(struct thread *, struct 128208453Skib syscall_args *); 129208453Skib const char **sv_syscallnames; 130217151Skib vm_offset_t sv_shared_page_base; 131217151Skib vm_offset_t sv_shared_page_len; 132217151Skib vm_offset_t sv_sigcode_base; 133237433Skib vm_offset_t sv_timekeep_base; 134237433Skib int sv_timekeep_off; 135237433Skib int sv_timekeep_curr; 136237433Skib uint32_t sv_timekeep_gen; 137217151Skib void *sv_shared_page_obj; 138219405Sdchagin void (*sv_schedtail)(struct thread *); 1392255Ssos}; 1402255Ssos 141185169Skib#define SV_ILP32 0x000100 142185169Skib#define SV_LP64 0x000200 143185169Skib#define SV_IA32 0x004000 144185169Skib#define SV_AOUT 0x008000 145217151Skib#define SV_SHP 0x010000 146185169Skib 147185169Skib#define SV_ABI_MASK 0xff 148217896Sdchagin#define SV_PROC_FLAG(p, x) ((p)->p_sysent->sv_flags & (x)) 149217896Sdchagin#define SV_PROC_ABI(p) ((p)->p_sysent->sv_flags & SV_ABI_MASK) 150217896Sdchagin#define SV_CURPROC_FLAG(x) SV_PROC_FLAG(curproc, x) 151217896Sdchagin#define SV_CURPROC_ABI() SV_PROC_ABI(curproc) 152185169Skib/* same as ELFOSABI_XXX, to prevent header pollution */ 153185169Skib#define SV_ABI_LINUX 3 154185169Skib#define SV_ABI_FREEBSD 9 155185169Skib#define SV_ABI_UNDEF 255 156185169Skib 15755205Speter#ifdef _KERNEL 1587090Sbdeextern struct sysentvec aout_sysvec; 15968356Sobrienextern struct sysentvec elf_freebsd_sysvec; 160102808Sjakeextern struct sysentvec null_sysvec; 1612255Ssosextern struct sysent sysent[]; 162208453Skibextern const char *syscallnames[]; 1632255Ssos 164268351Smarcel#if defined(__amd64__) 165226388Skibextern int i386_read_exec; 166226388Skib#endif 167226388Skib 168183159Sjhb#define NO_SYSCALL (-1) 16942433Sdfr 17042433Sdfrstruct module; 17142433Sdfr 17242433Sdfrstruct syscall_module_data { 173183159Sjhb int (*chainevh)(struct module *, int, void *); /* next handler */ 174183159Sjhb void *chainarg; /* arg for next event handler */ 175183159Sjhb int *offset; /* offset into sysent */ 176183159Sjhb struct sysent *new_sysent; /* new sysent */ 177183159Sjhb struct sysent old_sysent; /* old sysent */ 17842433Sdfr}; 17942433Sdfr 180183159Sjhb#define MAKE_SYSENT(syscallname) \ 181183159Sjhbstatic struct sysent syscallname##_sysent = { \ 182209587Skib (sizeof(struct syscallname ## _args ) \ 183183159Sjhb / sizeof(register_t)), \ 184225617Skmacy (sy_call_t *)& sys_##syscallname, \ 185225617Skmacy SYS_AUE_##syscallname \ 186225617Skmacy} 187225617Skmacy 188225617Skmacy#define MAKE_SYSENT_COMPAT(syscallname) \ 189225617Skmacystatic struct sysent syscallname##_sysent = { \ 190225617Skmacy (sizeof(struct syscallname ## _args ) \ 191225617Skmacy / sizeof(register_t)), \ 192209587Skib (sy_call_t *)& syscallname, \ 193209587Skib SYS_AUE_##syscallname \ 194168268Sjhb} 195183159Sjhb 196183159Sjhb#define SYSCALL_MODULE(name, offset, new_sysent, evh, arg) \ 197183159Sjhbstatic struct syscall_module_data name##_syscall_mod = { \ 198183159Sjhb evh, arg, offset, new_sysent, { 0, NULL, AUE_NULL } \ 199183159Sjhb}; \ 200183159Sjhb \ 201183159Sjhbstatic moduledata_t name##_mod = { \ 202205320Skib "sys/" #name, \ 203183159Sjhb syscall_module_handler, \ 204183159Sjhb &name##_syscall_mod \ 205183159Sjhb}; \ 206160882SjhbDECLARE_MODULE(name, name##_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE) 20742433Sdfr 208183159Sjhb#define SYSCALL_MODULE_HELPER(syscallname) \ 209183159Sjhbstatic int syscallname##_syscall = SYS_##syscallname; \ 210183159SjhbMAKE_SYSENT(syscallname); \ 211183159SjhbSYSCALL_MODULE(syscallname, \ 212183159Sjhb & syscallname##_syscall, & syscallname##_sysent, \ 213183159Sjhb NULL, NULL) 21469449Salfred 215183159Sjhb#define SYSCALL_MODULE_PRESENT(syscallname) \ 216183159Sjhb (sysent[SYS_##syscallname].sy_call != (sy_call_t *)lkmnosys && \ 217183159Sjhb sysent[SYS_##syscallname].sy_call != (sy_call_t *)lkmressys) 218165402Sjkim 219205321Skib/* 220205321Skib * Syscall registration helpers with resource allocation handling. 221205321Skib */ 222205321Skibstruct syscall_helper_data { 223205321Skib struct sysent new_sysent; 224205321Skib struct sysent old_sysent; 225205321Skib int syscall_no; 226205321Skib int registered; 227205321Skib}; 228205321Skib#define SYSCALL_INIT_HELPER(syscallname) { \ 229205321Skib .new_sysent = { \ 230205321Skib .sy_narg = (sizeof(struct syscallname ## _args ) \ 231205321Skib / sizeof(register_t)), \ 232225617Skmacy .sy_call = (sy_call_t *)& sys_ ## syscallname, \ 233225617Skmacy .sy_auevent = SYS_AUE_##syscallname \ 234225617Skmacy }, \ 235225617Skmacy .syscall_no = SYS_##syscallname \ 236225617Skmacy} 237225617Skmacy#define SYSCALL_INIT_HELPER_COMPAT(syscallname) { \ 238225617Skmacy .new_sysent = { \ 239225617Skmacy .sy_narg = (sizeof(struct syscallname ## _args ) \ 240225617Skmacy / sizeof(register_t)), \ 241205321Skib .sy_call = (sy_call_t *)& syscallname, \ 242205321Skib .sy_auevent = SYS_AUE_##syscallname \ 243205321Skib }, \ 244205321Skib .syscall_no = SYS_##syscallname \ 245205321Skib} 246205321Skib#define SYSCALL_INIT_LAST { \ 247205321Skib .syscall_no = NO_SYSCALL \ 248205321Skib} 249205321Skib 250183159Sjhbint syscall_register(int *offset, struct sysent *new_sysent, 251273707Smjg struct sysent *old_sysent, int flags); 252183159Sjhbint syscall_deregister(int *offset, struct sysent *old_sysent); 253183159Sjhbint syscall_module_handler(struct module *mod, int what, void *arg); 254273707Smjgint syscall_helper_register(struct syscall_helper_data *sd, int flags); 255205321Skibint syscall_helper_unregister(struct syscall_helper_data *sd); 25642433Sdfr 257208566Skibstruct proc; 258208566Skibconst char *syscallname(struct proc *p, u_int code); 259208566Skib 260183361Sjhb/* Special purpose system call functions. */ 261183361Sjhbstruct nosys_args; 262183361Sjhb 263183361Sjhbint lkmnosys(struct thread *, struct nosys_args *); 264183361Sjhbint lkmressys(struct thread *, struct nosys_args *); 265183361Sjhb 266209579Skibint syscall_thread_enter(struct thread *td, struct sysent *se); 267209579Skibvoid syscall_thread_exit(struct thread *td, struct sysent *se); 268209579Skib 269237431Skibint shared_page_alloc(int size, int align); 270237431Skibint shared_page_fill(int size, int align, const void *data); 271237431Skibvoid shared_page_write(int base, int size, const void *data); 272217151Skibvoid exec_sysvec_init(void *param); 273217151Skib 274217151Skib#define INIT_SYSENTVEC(name, sv) \ 275217151Skib SYSINIT(name, SI_SUB_EXEC, SI_ORDER_ANY, \ 276217151Skib (sysinit_cfunc_t)exec_sysvec_init, sv); 277217151Skib 27855205Speter#endif /* _KERNEL */ 27942433Sdfr 28014917Sbde#endif /* !_SYS_SYSENT_H_ */ 281