linux/include/linux/module.h
<<
>>
Prefs
   1#ifndef _LINUX_MODULE_H
   2#define _LINUX_MODULE_H
   3/*
   4 * Dynamic loading of modules into the kernel.
   5 *
   6 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
   7 * Rewritten again by Rusty Russell, 2002
   8 */
   9#include <linux/config.h>
  10#include <linux/sched.h>
  11#include <linux/spinlock.h>
  12#include <linux/list.h>
  13#include <linux/stat.h>
  14#include <linux/compiler.h>
  15#include <linux/cache.h>
  16#include <linux/kmod.h>
  17#include <linux/elf.h>
  18#include <linux/stringify.h>
  19#include <linux/kobject.h>
  20#include <linux/moduleparam.h>
  21#include <asm/local.h>
  22
  23#include <asm/module.h>
  24
  25/* Not Yet Implemented */
  26#define MODULE_SUPPORTED_DEVICE(name)
  27
  28/* v850 toolchain uses a `_' prefix for all user symbols */
  29#ifndef MODULE_SYMBOL_PREFIX
  30#define MODULE_SYMBOL_PREFIX ""
  31#endif
  32
  33#define MODULE_NAME_LEN (64 - sizeof(unsigned long))
  34
  35struct kernel_symbol
  36{
  37        unsigned long value;
  38        const char *name;
  39};
  40
  41struct modversion_info
  42{
  43        unsigned long crc;
  44        char name[MODULE_NAME_LEN];
  45};
  46
  47struct module;
  48
  49struct module_attribute {
  50        struct attribute attr;
  51        ssize_t (*show)(struct module_attribute *, struct module *, char *);
  52        ssize_t (*store)(struct module_attribute *, struct module *,
  53                         const char *, size_t count);
  54};
  55
  56struct module_kobject
  57{
  58        struct kobject kobj;
  59        struct module *mod;
  60};
  61
  62/* These are either module local, or the kernel's dummy ones. */
  63extern int init_module(void);
  64extern void cleanup_module(void);
  65
  66/* Archs provide a method of finding the correct exception table. */
  67struct exception_table_entry;
  68
  69const struct exception_table_entry *
  70search_extable(const struct exception_table_entry *first,
  71               const struct exception_table_entry *last,
  72               unsigned long value);
  73void sort_extable(struct exception_table_entry *start,
  74                  struct exception_table_entry *finish);
  75void sort_main_extable(void);
  76
  77extern struct subsystem module_subsys;
  78
  79#ifdef MODULE
  80#define ___module_cat(a,b) __mod_ ## a ## b
  81#define __module_cat(a,b) ___module_cat(a,b)
  82#define __MODULE_INFO(tag, name, info)                                    \
  83static const char __module_cat(name,__LINE__)[]                           \
  84  __attribute_used__                                                      \
  85  __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info
  86
  87#define MODULE_GENERIC_TABLE(gtype,name)                        \
  88extern const struct gtype##_id __mod_##gtype##_table            \
  89  __attribute__ ((unused, alias(__stringify(name))))
  90
  91extern struct module __this_module;
  92#define THIS_MODULE (&__this_module)
  93
  94#else  /* !MODULE */
  95
  96#define MODULE_GENERIC_TABLE(gtype,name)
  97#define __MODULE_INFO(tag, name, info)
  98#define THIS_MODULE ((struct module *)0)
  99#endif
 100
 101/* Generic info of form tag = "info" */
 102#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
 103
 104/* For userspace: you can also call me... */
 105#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
 106
 107/*
 108 * The following license idents are currently accepted as indicating free
 109 * software modules
 110 *
 111 *      "GPL"                           [GNU Public License v2 or later]
 112 *      "GPL v2"                        [GNU Public License v2]
 113 *      "GPL and additional rights"     [GNU Public License v2 rights and more]
 114 *      "Dual BSD/GPL"                  [GNU Public License v2
 115 *                                       or BSD license choice]
 116 *      "Dual MPL/GPL"                  [GNU Public License v2
 117 *                                       or Mozilla license choice]
 118 *
 119 * The following other idents are available
 120 *
 121 *      "Proprietary"                   [Non free products]
 122 *
 123 * There are dual licensed components, but when running with Linux it is the
 124 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
 125 * is a GPL combined work.
 126 *
 127 * This exists for several reasons
 128 * 1.   So modinfo can show license info for users wanting to vet their setup 
 129 *      is free
 130 * 2.   So the community can ignore bug reports including proprietary modules
 131 * 3.   So vendors can do likewise based on their own policies
 132 */
 133#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
 134
 135/* Author, ideally of form NAME <EMAIL>[, NAME <EMAIL>]*[ and NAME <EMAIL>] */
 136#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
 137  
 138/* What your module does. */
 139#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
 140
 141/* One for each parameter, describing how to use it.  Some files do
 142   multiple of these per line, so can't just use MODULE_INFO. */
 143#define MODULE_PARM_DESC(_parm, desc) \
 144        __MODULE_INFO(parm, _parm, #_parm ":" desc)
 145
 146#define MODULE_DEVICE_TABLE(type,name)          \
 147  MODULE_GENERIC_TABLE(type##_device,name)
 148
 149/* Version of form [<epoch>:]<version>[-<extra-version>].
 150   Or for CVS/RCS ID version, everything but the number is stripped.
 151  <epoch>: A (small) unsigned integer which allows you to start versions
 152           anew. If not mentioned, it's zero.  eg. "2:1.0" is after
 153           "1:2.0".
 154  <version>: The <version> may contain only alphanumerics and the
 155           character `.'.  Ordered by numeric sort for numeric parts,
 156           ascii sort for ascii parts (as per RPM or DEB algorithm).
 157  <extraversion>: Like <version>, but inserted for local
 158           customizations, eg "rh3" or "rusty1".
 159
 160  Using this automatically adds a checksum of the .c files and the
 161  local headers in "srcversion".
 162*/
 163#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
 164
 165/* Given an address, look for it in the exception tables */
 166const struct exception_table_entry *search_exception_tables(unsigned long add);
 167
 168struct notifier_block;
 169
 170#ifdef CONFIG_MODULES
 171
 172/* Get/put a kernel symbol (calls must be symmetric) */
 173void *__symbol_get(const char *symbol);
 174void *__symbol_get_gpl(const char *symbol);
 175#define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
 176
 177#ifndef __GENKSYMS__
 178#ifdef CONFIG_MODVERSIONS
 179/* Mark the CRC weak since genksyms apparently decides not to
 180 * generate a checksums for some symbols */
 181#define __CRC_SYMBOL(sym, sec)                                  \
 182        extern void *__crc_##sym __attribute__((weak));         \
 183        static const unsigned long __kcrctab_##sym              \
 184        __attribute_used__                                      \
 185        __attribute__((section("__kcrctab" sec), unused))       \
 186        = (unsigned long) &__crc_##sym;
 187#else
 188#define __CRC_SYMBOL(sym, sec)
 189#endif
 190
 191/* For every exported symbol, place a struct in the __ksymtab section */
 192#define __EXPORT_SYMBOL(sym, sec)                               \
 193        __CRC_SYMBOL(sym, sec)                                  \
 194        static const char __kstrtab_##sym[]                     \
 195        __attribute__((section("__ksymtab_strings")))           \
 196        = MODULE_SYMBOL_PREFIX #sym;                            \
 197        static const struct kernel_symbol __ksymtab_##sym       \
 198        __attribute_used__                                      \
 199        __attribute__((section("__ksymtab" sec), unused))       \
 200        = { (unsigned long)&sym, __kstrtab_##sym }
 201
 202#define EXPORT_SYMBOL(sym)                                      \
 203        __EXPORT_SYMBOL(sym, "")
 204
 205#define EXPORT_SYMBOL_GPL(sym)                                  \
 206        __EXPORT_SYMBOL(sym, "_gpl")
 207
 208#endif
 209
 210struct module_ref
 211{
 212        local_t count;
 213} ____cacheline_aligned;
 214
 215enum module_state
 216{
 217        MODULE_STATE_LIVE,
 218        MODULE_STATE_COMING,
 219        MODULE_STATE_GOING,
 220};
 221
 222/* Similar stuff for section attributes. */
 223#define MODULE_SECT_NAME_LEN 32
 224struct module_sect_attr
 225{
 226        struct module_attribute mattr;
 227        char name[MODULE_SECT_NAME_LEN];
 228        unsigned long address;
 229};
 230
 231struct module_sect_attrs
 232{
 233        struct attribute_group grp;
 234        struct module_sect_attr attrs[0];
 235};
 236
 237struct module_param_attrs;
 238
 239struct module
 240{
 241        enum module_state state;
 242
 243        /* Member of list of modules */
 244        struct list_head list;
 245
 246        /* Unique handle for this module */
 247        char name[MODULE_NAME_LEN];
 248
 249        /* Sysfs stuff. */
 250        struct module_kobject mkobj;
 251        struct module_param_attrs *param_attrs;
 252
 253        /* Exported symbols */
 254        const struct kernel_symbol *syms;
 255        unsigned int num_syms;
 256        const unsigned long *crcs;
 257
 258        /* GPL-only exported symbols. */
 259        const struct kernel_symbol *gpl_syms;
 260        unsigned int num_gpl_syms;
 261        const unsigned long *gpl_crcs;
 262
 263        /* Exception table */
 264        unsigned int num_exentries;
 265        const struct exception_table_entry *extable;
 266
 267        /* Startup function. */
 268        int (*init)(void);
 269
 270        /* If this is non-NULL, vfree after init() returns */
 271        void *module_init;
 272
 273        /* Here is the actual code + data, vfree'd on unload. */
 274        void *module_core;
 275
 276        /* Here are the sizes of the init and core sections */
 277        unsigned long init_size, core_size;
 278
 279        /* The size of the executable code in each section.  */
 280        unsigned long init_text_size, core_text_size;
 281
 282        /* Arch-specific module values */
 283        struct mod_arch_specific arch;
 284
 285        /* Am I unsafe to unload? */
 286        int unsafe;
 287
 288        /* Am I GPL-compatible */
 289        int license_gplok;
 290
 291#ifdef CONFIG_MODULE_UNLOAD
 292        /* Reference counts */
 293        struct module_ref ref[NR_CPUS];
 294
 295        /* What modules depend on me? */
 296        struct list_head modules_which_use_me;
 297
 298        /* Who is waiting for us to be unloaded */
 299        struct task_struct *waiter;
 300
 301        /* Destruction function. */
 302        void (*exit)(void);
 303#endif
 304
 305#ifdef CONFIG_KALLSYMS
 306        /* We keep the symbol and string tables for kallsyms. */
 307        Elf_Sym *symtab;
 308        unsigned long num_symtab;
 309        char *strtab;
 310
 311        /* Section attributes */
 312        struct module_sect_attrs *sect_attrs;
 313#endif
 314
 315        /* Per-cpu data. */
 316        void *percpu;
 317
 318        /* The command line arguments (may be mangled).  People like
 319           keeping pointers to this stuff */
 320        char *args;
 321};
 322
 323/* FIXME: It'd be nice to isolate modules during init, too, so they
 324   aren't used before they (may) fail.  But presently too much code
 325   (IDE & SCSI) require entry into the module during init.*/
 326static inline int module_is_live(struct module *mod)
 327{
 328        return mod->state != MODULE_STATE_GOING;
 329}
 330
 331/* Is this address in a module? (second is with no locks, for oops) */
 332struct module *module_text_address(unsigned long addr);
 333struct module *__module_text_address(unsigned long addr);
 334
 335/* Returns module and fills in value, defined and namebuf, or NULL if
 336   symnum out of range. */
 337struct module *module_get_kallsym(unsigned int symnum,
 338                                  unsigned long *value,
 339                                  char *type,
 340                                  char namebuf[128]);
 341
 342/* Look for this name: can be of form module:name. */
 343unsigned long module_kallsyms_lookup_name(const char *name);
 344
 345int is_exported(const char *name, const struct module *mod);
 346
 347extern void __module_put_and_exit(struct module *mod, long code)
 348        __attribute__((noreturn));
 349#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
 350
 351#ifdef CONFIG_MODULE_UNLOAD
 352unsigned int module_refcount(struct module *mod);
 353void __symbol_put(const char *symbol);
 354#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
 355void symbol_put_addr(void *addr);
 356
 357/* Sometimes we know we already have a refcount, and it's easier not
 358   to handle the error case (which only happens with rmmod --wait). */
 359static inline void __module_get(struct module *module)
 360{
 361        if (module) {
 362                BUG_ON(module_refcount(module) == 0);
 363                local_inc(&module->ref[get_cpu()].count);
 364                put_cpu();
 365        }
 366}
 367
 368static inline int try_module_get(struct module *module)
 369{
 370        int ret = 1;
 371
 372        if (module) {
 373                unsigned int cpu = get_cpu();
 374                if (likely(module_is_live(module)))
 375                        local_inc(&module->ref[cpu].count);
 376                else
 377                        ret = 0;
 378                put_cpu();
 379        }
 380        return ret;
 381}
 382
 383static inline void module_put(struct module *module)
 384{
 385        if (module) {
 386                unsigned int cpu = get_cpu();
 387                local_dec(&module->ref[cpu].count);
 388                /* Maybe they're waiting for us to drop reference? */
 389                if (unlikely(!module_is_live(module)))
 390                        wake_up_process(module->waiter);
 391                put_cpu();
 392        }
 393}
 394
 395#else /*!CONFIG_MODULE_UNLOAD*/
 396static inline int try_module_get(struct module *module)
 397{
 398        return !module || module_is_live(module);
 399}
 400static inline void module_put(struct module *module)
 401{
 402}
 403static inline void __module_get(struct module *module)
 404{
 405}
 406#define symbol_put(x) do { } while(0)
 407#define symbol_put_addr(p) do { } while(0)
 408
 409#endif /* CONFIG_MODULE_UNLOAD */
 410
 411/* This is a #define so the string doesn't get put in every .o file */
 412#define module_name(mod)                        \
 413({                                              \
 414        struct module *__mod = (mod);           \
 415        __mod ? __mod->name : "kernel";         \
 416})
 417
 418#define __unsafe(mod)                                                        \
 419do {                                                                         \
 420        if (mod && !(mod)->unsafe) {                                         \
 421                printk(KERN_WARNING                                          \
 422                       "Module %s cannot be unloaded due to unsafe usage in" \
 423                       " %s:%u\n", (mod)->name, __FILE__, __LINE__);         \
 424                (mod)->unsafe = 1;                                           \
 425        }                                                                    \
 426} while(0)
 427
 428/* For kallsyms to ask for address resolution.  NULL means not found. */
 429const char *module_address_lookup(unsigned long addr,
 430                                  unsigned long *symbolsize,
 431                                  unsigned long *offset,
 432                                  char **modname);
 433
 434/* For extable.c to search modules' exception tables. */
 435const struct exception_table_entry *search_module_extables(unsigned long addr);
 436
 437int register_module_notifier(struct notifier_block * nb);
 438int unregister_module_notifier(struct notifier_block * nb);
 439
 440extern void print_modules(void);
 441
 442struct device_driver;
 443void module_add_driver(struct module *, struct device_driver *);
 444void module_remove_driver(struct device_driver *);
 445
 446#else /* !CONFIG_MODULES... */
 447#define EXPORT_SYMBOL(sym)
 448#define EXPORT_SYMBOL_GPL(sym)
 449
 450/* Given an address, look for it in the exception tables. */
 451static inline const struct exception_table_entry *
 452search_module_extables(unsigned long addr)
 453{
 454        return NULL;
 455}
 456
 457/* Is this address in a module? */
 458static inline struct module *module_text_address(unsigned long addr)
 459{
 460        return NULL;
 461}
 462
 463/* Is this address in a module? (don't take a lock, we're oopsing) */
 464static inline struct module *__module_text_address(unsigned long addr)
 465{
 466        return NULL;
 467}
 468
 469/* Get/put a kernel symbol (calls should be symmetric) */
 470#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
 471#define symbol_put(x) do { } while(0)
 472#define symbol_put_addr(x) do { } while(0)
 473
 474static inline void __module_get(struct module *module)
 475{
 476}
 477
 478static inline int try_module_get(struct module *module)
 479{
 480        return 1;
 481}
 482
 483static inline void module_put(struct module *module)
 484{
 485}
 486
 487#define module_name(mod) "kernel"
 488
 489#define __unsafe(mod)
 490
 491/* For kallsyms to ask for address resolution.  NULL means not found. */
 492static inline const char *module_address_lookup(unsigned long addr,
 493                                                unsigned long *symbolsize,
 494                                                unsigned long *offset,
 495                                                char **modname)
 496{
 497        return NULL;
 498}
 499
 500static inline struct module *module_get_kallsym(unsigned int symnum,
 501                                                unsigned long *value,
 502                                                char *type,
 503                                                char namebuf[128])
 504{
 505        return NULL;
 506}
 507
 508static inline unsigned long module_kallsyms_lookup_name(const char *name)
 509{
 510        return 0;
 511}
 512
 513static inline int is_exported(const char *name, const struct module *mod)
 514{
 515        return 0;
 516}
 517
 518static inline int register_module_notifier(struct notifier_block * nb)
 519{
 520        /* no events will happen anyway, so this can always succeed */
 521        return 0;
 522}
 523
 524static inline int unregister_module_notifier(struct notifier_block * nb)
 525{
 526        return 0;
 527}
 528
 529#define module_put_and_exit(code) do_exit(code)
 530
 531static inline void print_modules(void)
 532{
 533}
 534
 535struct device_driver;
 536struct module;
 537
 538static inline void module_add_driver(struct module *module, struct device_driver *driver)
 539{
 540}
 541
 542static inline void module_remove_driver(struct device_driver *driver)
 543{
 544}
 545
 546#endif /* CONFIG_MODULES */
 547
 548#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
 549
 550/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
 551
 552struct obsolete_modparm {
 553        char name[64];
 554        char type[64-sizeof(void *)];
 555        void *addr;
 556};
 557
 558static inline void MODULE_PARM_(void) { }
 559#ifdef MODULE
 560/* DEPRECATED: Do not use. */
 561#define MODULE_PARM(var,type)                                               \
 562struct obsolete_modparm __parm_##var __attribute__((section("__obsparm"))) = \
 563{ __stringify(var), type, &MODULE_PARM_ };
 564#else
 565#define MODULE_PARM(var,type) static void __attribute__((__unused__)) *__parm_##var = &MODULE_PARM_;
 566#endif
 567
 568#define __MODULE_STRING(x) __stringify(x)
 569
 570/* Use symbol_get and symbol_put instead.  You'll thank me. */
 571#define HAVE_INTER_MODULE
 572extern void __deprecated inter_module_register(const char *,
 573                struct module *, const void *);
 574extern void __deprecated inter_module_unregister(const char *);
 575extern const void * __deprecated inter_module_get(const char *);
 576extern const void * __deprecated inter_module_get_request(const char *,
 577                const char *);
 578extern void __deprecated inter_module_put(const char *);
 579
 580#endif /* _LINUX_MODULE_H */
 581
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.