The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/module.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: module.h,v 1.10 2008/10/22 11:16:29 ad Exp $   */
    2 
    3 /*-
    4  * Copyright (c) 2008 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   26  * POSSIBILITY OF SUCH DAMAGE.
   27  */
   28 
   29 #ifndef _SYS_MODULE_H_
   30 #define _SYS_MODULE_H_
   31 
   32 #include <sys/types.h>
   33 #include <sys/param.h>
   34 #include <sys/cdefs.h>
   35 #include <sys/queue.h>
   36 #include <sys/uio.h>
   37 
   38 #define MAXMODNAME      32
   39 #define MAXMODDEPS      10
   40 
   41 /* Module classes, provided only for system boot and cosmetic purposes. */
   42 typedef enum modclass {
   43         MODULE_CLASS_ANY,
   44         MODULE_CLASS_MISC,
   45         MODULE_CLASS_VFS,
   46         MODULE_CLASS_DRIVER,
   47         MODULE_CLASS_EXEC
   48 } modclass_t;
   49 
   50 /* Module sources: where did it come from? */
   51 typedef enum modsrc {
   52         MODULE_SOURCE_KERNEL,
   53         MODULE_SOURCE_BOOT,
   54         MODULE_SOURCE_FILESYS
   55 } modsrc_t;
   56 
   57 /* Commands passed to module control routine. */
   58 typedef enum modcmd {
   59         MODULE_CMD_INIT,
   60         MODULE_CMD_FINI,
   61         MODULE_CMD_STAT
   62 } modcmd_t;
   63 
   64 /* Module header structure. */
   65 typedef struct modinfo {
   66         u_int           mi_version;
   67         modclass_t      mi_class;
   68         int             (*mi_modcmd)(modcmd_t, void *);
   69         const char      *mi_name;
   70         const char      *mi_required;
   71 } const modinfo_t;
   72 
   73 /* Per module information, maintained by kern_module.c */ 
   74 typedef struct module {
   75         u_int                   mod_refcnt;
   76         const modinfo_t         *mod_info;
   77         struct kobj             *mod_kobj;
   78         TAILQ_ENTRY(module)     mod_chain;
   79         struct module           *mod_required[MAXMODDEPS];
   80         u_int                   mod_nrequired;
   81         modsrc_t                mod_source;
   82 } module_t;
   83 
   84 #ifdef _KERNEL
   85 
   86 #include <sys/mutex.h>
   87 
   88 #include <prop/proplib.h>
   89 
   90 /*
   91  * Per-module linkage.  Loadable modules have a `link_set_modules' section
   92  * containing only one entry, pointing to the module's modinfo_t record.
   93  * For the kernel, `link_set_modules' can contain multiple entries and
   94  * records all modules built into the kernel at link time.
   95  */
   96 #define MODULE(class, name, required)                           \
   97 static int name##_modcmd(modcmd_t, void *);                     \
   98 static const modinfo_t name##_modinfo = {                       \
   99         .mi_version = __NetBSD_Version__,                       \
  100         .mi_class = (class),                                    \
  101         .mi_modcmd = name##_modcmd,                             \
  102         .mi_name = #name,                                       \
  103         .mi_required = (required)                               \
  104 };                                                              \
  105 __link_set_add_rodata(modules, name##_modinfo);
  106 
  107 TAILQ_HEAD(modlist, module);
  108 
  109 extern struct vm_map    *module_map;
  110 extern kmutex_t         module_lock;
  111 extern u_int            module_count;
  112 extern struct modlist   module_list;
  113 
  114 void    module_init(void);
  115 void    module_init_md(void);
  116 void    module_init_class(modclass_t);
  117 int     module_prime(void *, size_t);
  118 
  119 bool    module_compatible(int, int);
  120 int     module_load(const char *, int, prop_dictionary_t, modclass_t);
  121 int     module_autoload(const char *, modclass_t);
  122 int     module_unload(const char *);
  123 int     module_hold(const char *);
  124 void    module_rele(const char *);
  125 int     module_find_section(const char *, void **, size_t *);
  126 
  127 #else   /* _KERNEL */
  128 
  129 #include <stdint.h>
  130 
  131 #endif  /* _KERNEL */
  132 
  133 typedef struct modctl_load {
  134         const char *ml_filename;
  135 
  136 #define MODCTL_LOAD_FORCE 1
  137         int ml_flags;
  138 
  139         const char *ml_props;
  140         size_t ml_propslen;
  141 } modctl_load_t;
  142 
  143 typedef enum modctl {
  144         MODCTL_LOAD,            /* modctl_load_t *ml */
  145         MODCTL_UNLOAD,          /* char *name */
  146         MODCTL_STAT             /* struct iovec *buffer */
  147 } modctl_t;
  148 
  149 /*
  150  * This structure intentionally has the same layout for 32 and 64
  151  * bit builds.
  152  */
  153 typedef struct modstat {
  154         char            ms_name[MAXMODNAME];
  155         char            ms_required[MAXMODNAME * MAXMODDEPS];
  156         uint64_t        ms_addr;
  157         modsrc_t        ms_source;
  158         modclass_t      ms_class;
  159         u_int           ms_size;
  160         u_int           ms_refcnt;
  161         u_int           ms_reserved[4];
  162 } modstat_t;
  163 
  164 int     modctl(int, void *);
  165 
  166 #endif  /* !_SYS_MODULE_H_ */

Cache object: a114c24bcdecdfbe8475768b52c7dbee


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.