kern_syscalls.c revision 83366
1/*- 2 * Copyright (c) 1999 Assar Westerlund 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/kern/kern_syscalls.c 83366 2001-09-12 08:38:13Z julian $ 27 */ 28 29#include <sys/param.h> 30#include <sys/sysproto.h> 31#include <sys/sysent.h> 32#include <sys/syscall.h> 33#include <sys/module.h> 34 35/* 36 * Acts like "nosys" but can be identified in sysent for dynamic call 37 * number assignment for a limited number of calls. 38 * 39 * Place holder for system call slots reserved for loadable modules. 40 */ 41int 42lkmnosys(struct thread *td, struct nosys_args *args) 43{ 44 return(nosys(td, args)); 45} 46 47int 48lkmressys(struct thread *td, struct nosys_args *args) 49{ 50 return(nosys(td, args)); 51} 52 53int 54syscall_register(int *offset, struct sysent *new_sysent, 55 struct sysent *old_sysent) 56{ 57 if (*offset == NO_SYSCALL) { 58 int i; 59 60 for (i = 1; i < SYS_MAXSYSCALL; ++i) 61 if (sysent[i].sy_call == (sy_call_t *)lkmnosys) 62 break; 63 if (i == SYS_MAXSYSCALL) 64 return ENFILE; 65 *offset = i; 66 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL) 67 return EINVAL; 68 else if (sysent[*offset].sy_call != (sy_call_t *)lkmnosys && 69 sysent[*offset].sy_call != (sy_call_t *)lkmressys) 70 return EEXIST; 71 72 *old_sysent = sysent[*offset]; 73 sysent[*offset] = *new_sysent; 74 return 0; 75} 76 77int 78syscall_deregister(int *offset, struct sysent *old_sysent) 79{ 80 if (*offset) 81 sysent[*offset] = *old_sysent; 82 return 0; 83} 84 85int 86syscall_module_handler(struct module *mod, int what, void *arg) 87{ 88 struct syscall_module_data *data = (struct syscall_module_data*)arg; 89 modspecific_t ms; 90 int error; 91 92 switch (what) { 93 case MOD_LOAD : 94 error = syscall_register(data->offset, data->new_sysent, 95 &data->old_sysent); 96 if (error) 97 return error; 98 ms.intval = *data->offset; 99 module_setspecific(mod, &ms); 100 if (data->chainevh) 101 error = data->chainevh(mod, what, data->chainarg); 102 return error; 103 104 case MOD_UNLOAD : 105 if (data->chainevh) { 106 error = data->chainevh(mod, what, data->chainarg); 107 if (error) 108 return error; 109 } 110 error = syscall_deregister(data->offset, &data->old_sysent); 111 return error; 112 } 113 114 if (data->chainevh) 115 return data->chainevh(mod, what, data->chainarg); 116 else 117 return 0; 118} 119