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