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/lkm.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: lkm.h,v 1.40 2006/09/22 15:17:55 elad Exp $    */
    2 
    3 /*
    4  * Header file used by loadable kernel modules and loadable kernel module
    5  * utilities.
    6  *
    7  * 23 Jan 93    Terry Lambert           Original
    8  *
    9  * Copyright (c) 1992 Terrence R. Lambert.
   10  * All rights reserved.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  * 3. All advertising materials mentioning features or use of this software
   21  *    must display the following acknowledgement:
   22  *      This product includes software developed by Terrence R. Lambert.
   23  * 4. The name Terrence R. Lambert may not be used to endorse or promote
   24  *    products derived from this software without specific prior written
   25  *    permission.
   26  *
   27  * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY
   28  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
   31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   37  * SUCH DAMAGE.
   38  */
   39 
   40 #ifndef _SYS_LKM_H_
   41 #define _SYS_LKM_H_
   42 
   43 #include <sys/queue.h>
   44 
   45 /*
   46  * Supported module types
   47  */
   48 typedef enum loadmod {
   49         LM_SYSCALL,
   50         LM_VFS,
   51         LM_DEV,
   52         LM_STRMOD,
   53         LM_EXEC,
   54         LM_COMPAT,
   55         LM_MISC,
   56         LM_DRV
   57 } MODTYPE;
   58 
   59 #define MODTYPE_NAMES \
   60         "SYSCALL", \
   61         "VFS", \
   62         "DEV", \
   63         "STRMOD", \
   64         "EXEC", \
   65         "COMPAT", \
   66         "MISC", \
   67         "DRV"
   68 
   69 /*
   70  * Version of module interface. Bump if kernel structures or API affecting
   71  * LKM modules change, unless the kernel version is bumped at the
   72  * same time too.
   73  */
   74 #define LKM_VERSION     2
   75 
   76 #define MAXLKMNAME      32
   77 
   78 /****************************************************************************/
   79 
   80 #ifdef _KERNEL
   81 
   82 /*
   83  * Any module (to get type and name info without knowing type)
   84  */
   85 struct lkm_any {
   86         MODTYPE lkm_type;
   87         const char *lkm_name;
   88         u_long  lkm_offset;
   89         u_int   lkm_modver;
   90         u_int   lkm_sysver;
   91         const char *lkm_envver;
   92 };
   93 
   94 
   95 /*
   96  * Loadable system call
   97  */
   98 struct lkm_syscall {
   99         struct lkm_any mod;
  100         struct sysent   *lkm_sysent;
  101         struct sysent   lkm_oldent;     /* save area for unload */
  102 };
  103 
  104 /*
  105  * Loadable file system
  106  */
  107 struct lkm_vfs {
  108         struct lkm_any mod;
  109         struct vfsops   *lkm_vfsops;
  110 };
  111 
  112 /*
  113  * Loadable device driver
  114  */
  115 struct lkm_dev {
  116         struct lkm_any mod;
  117         const char *lkm_devname;
  118         const struct bdevsw     *lkm_bdev;
  119         int lkm_bdevmaj;
  120         const struct cdevsw     *lkm_cdev;
  121         int lkm_cdevmaj;
  122 };
  123 
  124 #ifdef STREAMS
  125 /*
  126  * Loadable streams module
  127  */
  128 struct lkm_strmod {
  129         struct lkm_any mod;
  130         /*
  131          * Removed: future release
  132          */
  133 };
  134 #endif
  135 
  136 /*
  137  * Exec loader
  138  */
  139 struct lkm_exec {
  140         struct lkm_any mod;
  141         struct execsw   *lkm_execsw;
  142         const char *lkm_emul;
  143 };
  144 
  145 /*
  146  * Compat (emulation) loader
  147  */
  148 struct lkm_compat {
  149         struct lkm_any mod;
  150         const struct emul       *lkm_compat;
  151 };
  152 
  153 /*
  154  * Miscellaneous module (complex load/unload, potentially complex stat)
  155  */
  156 struct lkm_misc {
  157         struct lkm_any mod;
  158 };
  159 
  160 /*
  161  * Driver module
  162  */
  163 struct lkm_drv {
  164         struct lkm_any mod;
  165         struct cfdriver **lkm_cd;
  166         const struct cfattachlkminit *lkm_cai;
  167         struct cfdata *lkm_cf;
  168 };
  169 
  170 /*
  171  * Generic reference ala XEvent to allow single entry point in the xxxinit()
  172  * routine.
  173  */
  174 union lkm_generic {
  175         struct lkm_any          *lkm_any;
  176         struct lkm_syscall      *lkm_syscall;
  177         struct lkm_vfs          *lkm_vfs;
  178         struct lkm_dev          *lkm_dev;
  179 #ifdef STREAMS
  180         struct lkm_strmod       *lkm_strmod;
  181 #endif
  182         struct lkm_exec         *lkm_exec;
  183         struct lkm_compat       *lkm_compat;
  184         struct lkm_misc         *lkm_misc;
  185         struct lkm_drv          *lkm_drv;
  186 };
  187 
  188 /*
  189  * Per module information structure
  190  */
  191 struct lkm_table {
  192         char    refcnt;         /* Reference count */
  193         char    forced;         /* Forced load, skipping compatibility check */
  194 
  195         int     (*entry)(struct lkm_table *, int, int);/* entry function */
  196         union lkm_generic       private;        /* module private data */
  197 
  198         u_long  size;
  199         u_long  offset;
  200         u_long  area;
  201 
  202                                 /* ddb support */
  203         u_long  syms;           /* start of symbol table */
  204         u_long  sym_size;       /* size of symbol table (syms+strings) */
  205         u_long  sym_offset;     /* offset of next symbol chunk */
  206         u_long  sym_symsize;    /* size of symbol part only */
  207 
  208         int     id;             /* Identifier */
  209         TAILQ_ENTRY(lkm_table) link;
  210 };
  211 
  212 
  213 #define LKM_E_LOAD      1
  214 #define LKM_E_UNLOAD    2
  215 #define LKM_E_STAT      3
  216 
  217 
  218 #define MOD_SYSCALL(name,callslot,sysentp)      \
  219         static struct lkm_syscall _module = {   \
  220                 { LM_SYSCALL, name, callslot,   \
  221                   LKM_VERSION, __NetBSD_Version__, _LKM_ENV_VERSION },  \
  222                 sysentp                         \
  223         };
  224 
  225 #define MOD_VFS(name,vfsslot,vfsopsp)           \
  226         static struct lkm_vfs _module = {       \
  227                 { LM_VFS, name, (u_long)vfsslot,        \
  228                   LKM_VERSION, __NetBSD_Version__, _LKM_ENV_VERSION },  \
  229                 vfsopsp                         \
  230         };
  231 
  232 #define MOD_DEV(name,devname,bdevp,bdevm,cdevp,cdevm)   \
  233         static struct lkm_dev _module = {       \
  234                 { LM_DEV, name, (u_long)-1,             \
  235                   LKM_VERSION, __NetBSD_Version__, _LKM_ENV_VERSION },  \
  236                 devname,                        \
  237                 bdevp,                          \
  238                 bdevm,                          \
  239                 cdevp,                          \
  240                 cdevm,                          \
  241         };
  242 
  243 #define MOD_COMPAT(name,compatslot,emulp)       \
  244         static struct lkm_compat _module = {    \
  245                 { LM_COMPAT, name, (u_long)compatslot,  \
  246                   LKM_VERSION, __NetBSD_Version__, _LKM_ENV_VERSION },  \
  247                 emulp                           \
  248         };
  249 
  250 #define MOD_EXEC(name,execslot,execsw,emul)     \
  251         static struct lkm_exec _module = {      \
  252                 { LM_EXEC, name, (u_long)execslot,      \
  253                   LKM_VERSION, __NetBSD_Version__, _LKM_ENV_VERSION },  \
  254                 execsw,                         \
  255                 emul                            \
  256         };
  257 
  258 #define MOD_MISC(name)                          \
  259         static struct lkm_misc _module = {      \
  260                 { LM_MISC, name, (u_long)-1,            \
  261                   LKM_VERSION, __NetBSD_Version__, _LKM_ENV_VERSION },  \
  262         };
  263 
  264 #define MOD_DRV(name,drvs,atts,cfdata)  \
  265         static struct lkm_drv _module = {       \
  266                 { LM_DRV, name, (u_long)-1,             \
  267                   LKM_VERSION, __NetBSD_Version__, _LKM_ENV_VERSION },  \
  268                 drvs, atts, cfdata              \
  269         };
  270 
  271 /*
  272  * Environment encoding, for LKM<->kernel compatibility check.
  273  */
  274 #ifdef DEBUG
  275 #define _LKM_E_DEBUG            ",DEBUG"
  276 #else
  277 #define _LKM_E_DEBUG            ""
  278 #endif
  279 
  280 #ifdef LOCKDEBUG
  281 #define _LKM_E_LOCKDEBUG        ",LOCKDEBUG"
  282 #else
  283 #define _LKM_E_LOCKDEBUG        ""
  284 #endif
  285 
  286 #ifdef MULTIPROCESSOR
  287 #define _LKM_E_MULTIPROCESSOR   ",MULTIPROCESSOR"
  288 #else
  289 #define _LKM_E_MULTIPROCESSOR   ""
  290 #endif
  291 
  292 #ifdef MALLOCLOG
  293 #define _LKM_E_MALLOCLOG        ",MALLOCLOG"
  294 #else
  295 #define _LKM_E_MALLOCLOG        ""
  296 #endif
  297 
  298 #define _LKM_ENV_VERSION        \
  299         _LKM_E_DEBUG _LKM_E_LOCKDEBUG \
  300         _LKM_E_MULTIPROCESSOR _LKM_E_MALLOCLOG
  301 
  302 int lkm_nofunc(struct lkm_table *, int);
  303 int lkmexists(struct lkm_table *);
  304 int lkmdispatch(struct lkm_table *, int);
  305 
  306 /*
  307  * LKM_DISPATCH -- body function for use in module entry point function;
  308  * generally, the function body will consist entirely of a single
  309  * LKM_DISPATCH line.
  310  *
  311  * If load/unload/stat are called on each corresponding entry instance.
  312  * If no function is desired for load/stat/unload, lkm_nofunc() should
  313  * be specified.  "cmd" is passed to each function so that a single
  314  * function can be used if desired.
  315  */
  316 #define LKM_DISPATCH(lkmtp, cmd, envdep, load, unload, stat)            \
  317         switch (cmd) {                                                  \
  318         int     error;                                                  \
  319         case LKM_E_LOAD:                                                \
  320                 lkmtp->private.lkm_any = (void *)&_module;              \
  321                 if ((error = lkmdispatch(lkmtp, cmd)) != 0)             \
  322                         return error;                                   \
  323                 if ((error = load(lkmtp, cmd)) != 0)                    \
  324                         (void)lkmdispatch(lkmtp, LKM_E_UNLOAD);         \
  325                 return error;                                           \
  326                 break;                                                  \
  327         case LKM_E_UNLOAD:                                              \
  328                 if ((error = unload(lkmtp, cmd)) != 0)                  \
  329                         return error;                                   \
  330                 return lkmdispatch(lkmtp, cmd);                         \
  331                 break;                                                  \
  332         case LKM_E_STAT:                                                \
  333                 if ((error = stat(lkmtp, cmd)) != 0)                    \
  334                         return error;                                   \
  335                 return lkmdispatch(lkmtp, cmd);                         \
  336                 break;                                                  \
  337         }                                                               \
  338         return (0);
  339 
  340 /* remap the old macro for backward source compatibility */
  341 #define DISPATCH(lkmtp, cmd, ver, att, det, stat)       \
  342         LKM_DISPATCH(lkmtp, cmd, NULL, att, det, stat)
  343 
  344 extern struct vm_map *lkm_map;
  345 
  346 #endif /* _KERNEL */
  347 
  348 /****************************************************************************/
  349 
  350 /*
  351  * IOCTL's recognized by /dev/lkm
  352  */
  353 #define LMLOADBUF       _IOW('K', 1, struct lmc_loadbuf)
  354 #define LMUNRESRV       _IO('K', 2)
  355 #define LMREADY         _IOW('K', 3, u_long)
  356 #define LMRESERV        _IOWR('K', 4, struct lmc_resrv)
  357 
  358 #define LMLOAD          _IOW('K', 9, struct lmc_load)
  359 #define LMUNLOAD        _IOWR('K', 10, struct lmc_unload)
  360 #define LMSTAT          _IOWR('K', 11, struct lmc_stat)
  361 #define LMLOADSYMS      _IOW('K', 12, struct lmc_loadbuf)
  362 #define LMFORCE         _IOW('K', 13, u_long)
  363 
  364 #define MODIOBUF        512             /* # of bytes at a time to loadbuf */
  365 
  366 /*
  367  * IOCTL arguments
  368  */
  369 
  370 
  371 /*
  372  * Reserve a page-aligned block of kernel memory for the module
  373  */
  374 struct lmc_resrv {
  375         u_long  size;           /* IN: size of module to reserve */
  376         char    *name;          /* IN: name (must be provided */
  377         int     slot;           /* OUT: allocated slot (module ID) */
  378         u_long  addr;           /* OUT: Link-to address */
  379                                 /* ddb support */
  380         u_long  xxx_unused1;    /* unused */
  381         u_long  sym_size;       /* IN: total size of symbol table */
  382         u_long  xxx_unused2;    /* unused */
  383         u_long  sym_symsize;    /* IN: size of symbol portion of symtable */
  384         u_long  sym_addr;       /* OUT: address of symbol table */
  385 };
  386 
  387 /*
  388  * Copy a buffer at a time into the allocated area in the kernel; writes
  389  * are assumed to occur contiguously.
  390  */
  391 struct lmc_loadbuf {
  392         int     cnt;            /* IN: # of chars pointed to by data */
  393         char    *data;          /* IN: pointer to data buffer */
  394 };
  395 
  396 
  397 /*
  398  * Load a module (assumes it's been mmapped to address before call)
  399  */
  400 struct lmc_load {
  401         caddr_t address;        /* IN: user space mmap address */
  402         int     status;         /* OUT: status of operation */
  403         int     id;             /* OUT: module ID if loaded */
  404 };
  405 
  406 /*
  407  * Unload a module (by name/id)
  408  */
  409 struct lmc_unload {
  410         int     id;             /* IN: module ID to unload */
  411         char    *name;          /* IN: module name to unload if id -1 */
  412         int     status;         /* OUT: status of operation */
  413 };
  414 
  415 
  416 /*
  417  * Get module information for a given id (or name if id == -1).
  418  */
  419 struct lmc_stat {
  420         int     id;                     /* IN: module ID to unload */
  421         char    name[MAXLKMNAME];       /* IN/OUT: name of module */
  422         u_long  offset;                 /* OUT: target table offset */
  423         MODTYPE type;                   /* OUT: type of module */
  424         u_long  area;                   /* OUT: kernel load addr */
  425         u_long  size;                   /* OUT: module size (pages) */
  426         u_long  private;                /* OUT: module private data */
  427         int     ver;                    /* OUT: lkm compile version */
  428 };
  429 
  430 #define LKM_MAKEMAJOR(b, c)     ((((b) & 0xffff) << 16) | ((c) & 0xffff))
  431 #define LKM_BLOCK_MAJOR(v)      (int)((int16_t)(((uint32_t)(v) >> 16) & 0xffff))
  432 #define LKM_CHAR_MAJOR(v)       (int)((int16_t)((v) & 0xffff))
  433 
  434 #endif  /* !_SYS_LKM_H_ */

Cache object: 65248cd166334ce7176a3c6a1d83aade


[ 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.