include/linux/module.h
15529 /*
15530 * Dynamic loading of modules into the kernel.
15531 *
15532 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
15533 */
15534
15535 #ifndef _LINUX_MODULE_H
15536 #define _LINUX_MODULE_H
15537
15538 #include <linux/config.h>
15539
15540 #ifdef __GENKSYMS__
15541 # define _set_ver(sym) sym
15542 # undef MODVERSIONS
15543 # define MODVERSIONS
15544 #else /* ! __GENKSYMS__ */
15545 # if !defined(MODVERSIONS) && defined(EXPORT_SYMTAB)
15546 # define _set_ver(sym) sym
15547 # include <linux/modversions.h>
15548 # endif
15549 #endif /* __GENKSYMS__ */
15550
15551 #include <asm/atomic.h>
15552
15553 /* Don't need to bring in all of uaccess.h just for this
15554 decl. */
15555 struct exception_table_entry;
15556
15557 /* Used by get_kernel_syms, which is obsolete. */
15558 struct kernel_sym
15559 {
15560 unsigned long value;
15561 /* should have been 64-sizeof(long); oh well */
15562 char name[60];
15563 };
15564
15565 struct module_symbol
15566 {
15567 unsigned long value;
15568 const char *name;
15569 };
15570
15571 struct module_ref
15572 {
15573 struct module *dep; /* "parent" pointer */
15574 struct module *ref; /* "child" pointer */
15575 struct module_ref *next_ref;
15576 };
15577
15578 /* TBD */
15579 struct module_persist;
15580
15581 struct module
15582 {
15583 unsigned long size_of_struct; /* == sizeof(module) */
15584 struct module *next;
15585 const char *name;
15586 unsigned long size;
15587
15588 union
15589 {
15590 atomic_t usecount;
15591 long pad;
15592 } uc; /* Needs to keep its size - so says rth */
15593
15594 unsigned long flags; /* AUTOCLEAN et al */
15595
15596 unsigned nsyms;
15597 unsigned ndeps;
15598
15599 struct module_symbol *syms;
15600 struct module_ref *deps;
15601 struct module_ref *refs;
15602 int (*init)(void);
15603 void (*cleanup)(void);
15604 const struct exception_table_entry *ex_table_start;
15605 const struct exception_table_entry *ex_table_end;
15606 #ifdef __alpha__
15607 unsigned long gp;
15608 #endif
15609 /* Members past this point are extensions to the basic
15610 module support and are optional. Use
15611 mod_opt_member() to examine them. */
15612 const struct module_persist *persist_start;
15613 const struct module_persist *persist_end;
15614 int (*can_unload)(void);
15615 };
15616
15617 struct module_info
15618 {
15619 unsigned long addr;
15620 unsigned long size;
15621 unsigned long flags;
15622 long usecount;
15623 };
15624
15625 /* Bits of module.flags. */
15626
15627 #define MOD_UNINITIALIZED 0
15628 #define MOD_RUNNING 1
15629 #define MOD_DELETED 2
15630 #define MOD_AUTOCLEAN 4
15631 #define MOD_VISITED 8
15632 #define MOD_USED_ONCE 16
15633 #define MOD_JUST_FREED 32
15634
15635 /* Values for query_module's which. */
15636
15637 #define QM_MODULES 1
15638 #define QM_DEPS 2
15639 #define QM_REFS 3
15640 #define QM_SYMBOLS 4
15641 #define QM_INFO 5
15642
15643 /* When struct module is extended, we must test whether
15644 the new member is present in the header received from
15645 insmod before we can use it. This function returns
15646 true if the member is present. */
15647
15648 #define mod_member_present(mod,member) \
15649 ((unsigned long)(&((struct module *)0L)->member + 1) \
15650 <= (mod)->size_of_struct)
15651
15652 /* Backwards compatibility definition. */
15653
15654 #define GET_USE_COUNT(module) \
15655 (atomic_read(&(module)->uc.usecount))
15656
15657 /* Poke the use count of a module. */
15658
15659 #define __MOD_INC_USE_COUNT(mod) \
15660 (atomic_inc(&(mod)->uc.usecount), \
15661 (mod)->flags |= MOD_VISITED|MOD_USED_ONCE)
15662 #define __MOD_DEC_USE_COUNT(mod) \
15663 (atomic_dec(&(mod)->uc.usecount), \
15664 (mod)->flags |= MOD_VISITED)
15665 #define __MOD_IN_USE(mod) \
15666 (mod_member_present((mod), can_unload) \
15667 && (mod)->can_unload \
15668 ? (mod)->can_unload() \
15669 : atomic_read(&(mod)->uc.usecount))
15670
15671 /* Indirect stringification. */
15672
15673 #define __MODULE_STRING_1(x) #x
15674 #define __MODULE_STRING(x) __MODULE_STRING_1(x)
15675
15676 /* Find a symbol exported by the kernel or another
15677 * module */
15678 extern unsigned long get_module_symbol(char *, char *);
15679
15680 #if defined(MODULE) && !defined(__GENKSYMS__)
15681
15682 /* Embedded module documentation macros. */
15683
15684 /* For documentation purposes only. */
15685
15686 #define MODULE_AUTHOR(name) \
15687 const char __module_author[] \
15688 __attribute__((section(".modinfo"))) = "author=" name
15689
15690 #define MODULE_DESCRIPTION(desc) \
15691 const char __module_description[] \
15692 __attribute__((section(".modinfo"))) = \
15693 "description=" desc
15694
15695 /* Could potentially be used by kmod... */
15696
15697 #define MODULE_SUPPORTED_DEVICE(dev) \
15698 const char __module_device[] \
15699 __attribute__((section(".modinfo"))) = "device=" dev
15700
15701 /* Used to verify parameters given to the module. The
15702 TYPE arg should be a string in the following format:
15703 [min[-max]]{b,h,i,l,s}
15704
15705 The MIN and MAX specifiers delimit the length of the
15706 array. If MAX is omitted, it defaults to MIN; if both
15707 are omitted, the default is 1. The final character is
15708 a type specifier:
15709
15710 b byte
15711 h short
15712 i int
15713 l long
15714 s string */
15715
15716 #define MODULE_PARM(var,type) \
15717 const char __module_parm_##var[] \
15718 __attribute__((section(".modinfo"))) = \
15719 "parm_" __MODULE_STRING(var) "=" type
15720
15721 #define MODULE_PARM_DESC(var,desc) \
15722 const char __module_parm_desc_##var[] \
15723 __attribute__((section(".modinfo"))) = \
15724 "parm_desc_" __MODULE_STRING(var) "=" desc
15725
15726 /* The attributes of a section are set the first time the
15727 * section is seen; we want .modinfo to not be allocated.
15728 */
15729
15730 __asm__(".section .modinfo\n\t.previous");
15731
15732 /* Define the module variable, and usage macros. */
15733 extern struct module __this_module;
15734
15735 #define MOD_INC_USE_COUNT \
15736 __MOD_INC_USE_COUNT(&__this_module)
15737 #define MOD_DEC_USE_COUNT \
15738 __MOD_DEC_USE_COUNT(&__this_module)
15739 #define MOD_IN_USE \
15740 __MOD_IN_USE(&__this_module)
15741
15742 #ifndef __NO_VERSION__
15743 #include <linux/version.h>
15744 const char __module_kernel_version[]
15745 __attribute__((section(".modinfo"))) =
15746 "kernel_version=" UTS_RELEASE;
15747 #ifdef MODVERSIONS
15748 const char __module_using_checksums[]
15749 __attribute__((section(".modinfo"))) =
15750 "using_checksums=1";
15751 #endif
15752 #endif
15753
15754 #else /* MODULE */
15755
15756 #define MODULE_AUTHOR(name)
15757 #define MODULE_DESCRIPTION(desc)
15758 #define MODULE_SUPPORTED_DEVICE(name)
15759 #define MODULE_PARM(var,type)
15760 #define MODULE_PARM_DESC(var,desc)
15761
15762 #ifndef __GENKSYMS__
15763
15764 #define MOD_INC_USE_COUNT do { } while (0)
15765 #define MOD_DEC_USE_COUNT do { } while (0)
15766 #define MOD_IN_USE 1
15767
15768 extern struct module *module_list;
15769
15770 #endif /* !__GENKSYMS__ */
15771
15772 #endif /* MODULE */
15773
15774 /* Export a symbol either from the kernel or a module.
15775
15776 In the kernel, the symbol is added to the kernel's
15777 global symbol table.
15778
15779 In a module, it controls which variables are exported.
15780 If no variables are explicitly exported, the action is
15781 controled by the insmod -[xX] flags. Otherwise, only
15782 the variables listed are exported. This obviates the
15783 need for the old register_symtab() function. */
15784
15785 #if defined(__GENKSYMS__)
15786
15787 /* We want the EXPORT_SYMBOL tag left intact for
15788 recognition. */
15789
15790 #elif !defined(AUTOCONF_INCLUDED)
15791
15792 #define __EXPORT_SYMBOL(sym,str) \
15793 error config_must_be_included_before_module
15794 #define EXPORT_SYMBOL(var) \
15795 error config_must_be_included_before_module
15796 #define EXPORT_SYMBOL_NOVERS(var) \
15797 error config_must_be_included_before_module
15798
15799 #elif !defined(CONFIG_MODULES)
15800
15801 #define __EXPORT_SYMBOL(sym,str)
15802 #define EXPORT_SYMBOL(var)
15803 #define EXPORT_SYMBOL_NOVERS(var)
15804
15805 #elif !defined(EXPORT_SYMTAB)
15806
15807 /* If things weren't set up in the Makefiles to get
15808 EXPORT_SYMTAB defined, then they weren't set up to run
15809 genksyms properly so MODVERSIONS breaks. */
15810 #define __EXPORT_SYMBOL(sym,str) \
15811 error EXPORT_SYMTAB_not_defined
15812 #define EXPORT_SYMBOL(var) \
15813 error EXPORT_SYMTAB_not_defined
15814 #define EXPORT_SYMBOL_NOVERS(var) \
15815 error EXPORT_SYMTAB_not_defined
15816
15817 #else
15818
15819 #define __EXPORT_SYMBOL(sym, str) \
15820 const char __kstrtab_##sym[] \
15821 __attribute__((section(".kstrtab"))) = str; \
15822 const struct module_symbol __ksymtab_##sym \
15823 __attribute__((section("__ksymtab"))) = \
15824 { (unsigned long)&sym, __kstrtab_##sym }
15825
15826 #if defined(MODVERSIONS) || !defined(CONFIG_MODVERSIONS)
15827 #define EXPORT_SYMBOL(var) \
15828 __EXPORT_SYMBOL(var, __MODULE_STRING(var))
15829 #else
15830 #define EXPORT_SYMBOL(var) \
15831 __EXPORT_SYMBOL(var, \
15832 __MODULE_STRING(__VERSIONED_SYMBOL(var)))
15833 #endif
15834
15835 #define EXPORT_SYMBOL_NOVERS(var) \
15836 __EXPORT_SYMBOL(var, __MODULE_STRING(var))
15837
15838 #endif /* __GENKSYMS__ */
15839
15840 #ifdef MODULE
15841 /* Force a module to export no symbols. */
15842 #define EXPORT_NO_SYMBOLS \
15843 __asm__(".section __ksymtab\n.previous")
15844 #else
15845 #define EXPORT_NO_SYMBOLS
15846 #endif /* MODULE */
15847
15848 #endif /* _LINUX_MODULE_H */
Сайт управляется системой
uCoz