#ifndef _LINUX_MODULE_H
#define _LINUX_MODULE_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MODULE_SUPPORTED_DEVICE(name)
#ifndef MODULE_SYMBOL_PREFIX
#define MODULE_SYMBOL_PREFIX ""
#endif
#define MODULE_NAME_LEN (64 - sizeof(unsigned long))
struct kernel_symbol
{
unsigned long value;
const char *name;
};
struct modversion_info
{
unsigned long crc;
char name[MODULE_NAME_LEN];
};
struct module;
struct module_attribute {
struct attribute attr;
ssize_t (*show)(struct module_attribute *, struct module *, char *);
ssize_t (*store)(struct module_attribute *, struct module *,
const char *, size_t count);
void (*setup)(struct module *, const char *);
int (*test)(struct module *);
void (*free)(struct module *);
};
struct module_kobject
{
struct kobject kobj;
struct module *mod;
};
extern int init_module(void);
extern void cleanup_module(void);
struct exception_table_entry;
const struct exception_table_entry *
search_extable(const struct exception_table_entry *first,
const struct exception_table_entry *last,
unsigned long value);
void sort_extable(struct exception_table_entry *start,
struct exception_table_entry *finish);
void sort_main_extable(void);
extern struct subsystem module_subsys;
#ifdef MODULE
#define MODULE_GENERIC_TABLE(gtype,name) \
extern const struct gtype##_id __mod_##gtype##_table \
__attribute__ ((unused, alias(__stringify(name))))
extern struct module __this_module;
#define THIS_MODULE (&__this_module)
#else
#define MODULE_GENERIC_TABLE(gtype,name)
#define THIS_MODULE ((struct module *)0)
#endif
#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
#define MODULE_PARM_DESC(_parm, desc) \
__MODULE_INFO(parm, _parm, #_parm ":" desc)
#define MODULE_DEVICE_TABLE(type,name) \
MODULE_GENERIC_TABLE(type##_device,name)
#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
const struct exception_table_entry *search_exception_tables(unsigned long add);
struct notifier_block;
#ifdef CONFIG_MODULES
void *__symbol_get(const char *symbol);
void *__symbol_get_gpl(const char *symbol);
#define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
#ifndef __GENKSYMS__
#ifdef CONFIG_MODVERSIONS
#define __CRC_SYMBOL(sym, sec) \
extern void *__crc_##sym __attribute__((weak)); \
static const unsigned long __kcrctab_##sym \
__attribute_used__ \
__attribute__((section("__kcrctab" sec), unused)) \
= (unsigned long) &__crc_##sym;
#else
#define __CRC_SYMBOL(sym, sec)
#endif
#define __EXPORT_SYMBOL(sym, sec) \
__CRC_SYMBOL(sym, sec) \
static const char __kstrtab_##sym[] \
__attribute__((section("__ksymtab_strings"))) \
= MODULE_SYMBOL_PREFIX #sym; \
static const struct kernel_symbol __ksymtab_##sym \
__attribute_used__ \
__attribute__((section("__ksymtab" sec), unused)) \
= { (unsigned long)&sym, __kstrtab_##sym }
#define EXPORT_SYMBOL(sym) \
__EXPORT_SYMBOL(sym, "")
#define EXPORT_SYMBOL_GPL(sym) \
__EXPORT_SYMBOL(sym, "_gpl")
#endif
struct module_ref
{
local_t count;
} ____cacheline_aligned;
enum module_state
{
MODULE_STATE_LIVE,
MODULE_STATE_COMING,
MODULE_STATE_GOING,
};
#define MODULE_SECT_NAME_LEN 32
struct module_sect_attr
{
struct module_attribute mattr;
char name[MODULE_SECT_NAME_LEN];
unsigned long address;
};
struct module_sect_attrs
{
struct attribute_group grp;
struct module_sect_attr attrs[0];
};
struct module_param_attrs;
struct module
{
enum module_state state;
struct list_head list;
char name[MODULE_NAME_LEN];
struct module_kobject mkobj;
struct module_param_attrs *param_attrs;
const char *version;
const char *srcversion;
const struct kernel_symbol *syms;
unsigned int num_syms;
const unsigned long *crcs;
const struct kernel_symbol *gpl_syms;
unsigned int num_gpl_syms;
const unsigned long *gpl_crcs;
unsigned int num_exentries;
const struct exception_table_entry *extable;
int (*init)(void);
void *module_init;
void *module_core;
unsigned long init_size, core_size;
unsigned long init_text_size, core_text_size;
struct mod_arch_specific arch;
int unsafe;
int license_gplok;
#ifdef CONFIG_MODULE_UNLOAD
struct module_ref ref[NR_CPUS];
struct list_head modules_which_use_me;
struct task_struct *waiter;
void (*exit)(void);
#endif
#ifdef CONFIG_KALLSYMS
Elf_Sym *symtab;
unsigned long num_symtab;
char *strtab;
struct module_sect_attrs *sect_attrs;
#endif
void *percpu;
char *args;
};
static inline int module_is_live(struct module *mod)
{
return mod->state != MODULE_STATE_GOING;
}
struct module *module_text_address(unsigned long addr);
struct module *__module_text_address(unsigned long addr);
struct module *module_get_kallsym(unsigned int symnum,
unsigned long *value,
char *type,
char namebuf[128]);
unsigned long module_kallsyms_lookup_name(const char *name);
int is_exported(const char *name, const struct module *mod);
extern void __module_put_and_exit(struct module *mod, long code)
__attribute__((noreturn));
#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
#ifdef CONFIG_MODULE_UNLOAD
unsigned int module_refcount(struct module *mod);
void __symbol_put(const char *symbol);
#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
void symbol_put_addr(void *addr);
(which only happens with rmmod --wait). */
static inline void __module_get(struct module *module)
{
if (module) {
BUG_ON(module_refcount(module) == 0);
local_inc(&module->ref[get_cpu()].count);
put_cpu();
}
}
static inline int try_module_get(struct module *module)
{
int ret = 1;
if (module) {
unsigned int cpu = get_cpu();
if (likely(module_is_live(module)))
local_inc(&module->ref[cpu].count);
else
ret = 0;
put_cpu();
}
return ret;
}
static inline void module_put(struct module *module)
{
if (module) {
unsigned int cpu = get_cpu();
local_dec(&module->ref[cpu].count);
if (unlikely(!module_is_live(module)))
wake_up_process(module->waiter);
put_cpu();
}
}
#else
static inline int try_module_get(struct module *module)
{
return !module || module_is_live(module);
}
static inline void module_put(struct module *module)
{
}
static inline void __module_get(struct module *module)
{
}
#define symbol_put(x) do { } while(0)
#define symbol_put_addr(p) do { } while(0)
#endif
#define module_name(mod) \
({ \
struct module *__mod = (mod); \
__mod ? __mod->name : "kernel"; \
})
#define __unsafe(mod) \
do { \
if (mod && !(mod)->unsafe) { \
printk(KERN_WARNING \
"Module %s cannot be unloaded due to unsafe usage in" \
" %s:%u\n", (mod)->name, __FILE__, __LINE__); \
(mod)->unsafe = 1; \
} \
} while(0)
const char *module_address_lookup(unsigned long addr,
unsigned long *symbolsize,
unsigned long *offset,
char **modname);
const struct exception_table_entry *search_module_extables(unsigned long addr);
int register_module_notifier(struct notifier_block * nb);
int unregister_module_notifier(struct notifier_block * nb);
extern void print_modules(void);
struct device_driver;
void module_add_driver(struct module *, struct device_driver *);
void module_remove_driver(struct device_driver *);
#else
#define EXPORT_SYMBOL(sym)
#define EXPORT_SYMBOL_GPL(sym)
static inline const struct exception_table_entry *
search_module_extables(unsigned long addr)
{
return NULL;
}
static inline struct module *module_text_address(unsigned long addr)
{
return NULL;
}
static inline struct module *__module_text_address(unsigned long addr)
{
return NULL;
}
#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
#define symbol_put(x) do { } while(0)
#define symbol_put_addr(x) do { } while(0)
static inline void __module_get(struct module *module)
{
}
static inline int try_module_get(struct module *module)
{
return 1;
}
static inline void module_put(struct module *module)
{
}
#define module_name(mod) "kernel"
#define __unsafe(mod)
static inline const char *module_address_lookup(unsigned long addr,
unsigned long *symbolsize,
unsigned long *offset,
char **modname)
{
return NULL;
}
static inline struct module *module_get_kallsym(unsigned int symnum,
unsigned long *value,
char *type,
char namebuf[128])
{
return NULL;
}
static inline unsigned long module_kallsyms_lookup_name(const char *name)
{
return 0;
}
static inline int is_exported(const char *name, const struct module *mod)
{
return 0;
}
static inline int register_module_notifier(struct notifier_block * nb)
{
return 0;
}
static inline int unregister_module_notifier(struct notifier_block * nb)
{
return 0;
}
#define module_put_and_exit(code) do_exit(code)
static inline void print_modules(void)
{
}
struct device_driver;
struct module;
static inline void module_add_driver(struct module *module, struct device_driver *driver)
{
}
static inline void module_remove_driver(struct device_driver *driver)
{
}
#endif
#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
struct obsolete_modparm {
char name[64];
char type[64-sizeof(void *)];
void *addr;
};
static inline void MODULE_PARM_(void) { }
#ifdef MODULE
#define MODULE_PARM(var,type) \
struct obsolete_modparm __parm_##var __attribute__((section("__obsparm"))) = \
{ __stringify(var), type, &MODULE_PARM_ }; \
__MODULE_PARM_TYPE(var, type);
#else
#define MODULE_PARM(var,type) static void __attribute__((__unused__)) *__parm_##var = &MODULE_PARM_;
#endif
#define __MODULE_STRING(x) __stringify(x)
#define HAVE_INTER_MODULE
extern void __deprecated inter_module_register(const char *,
struct module *, const void *);
extern void __deprecated inter_module_unregister(const char *);
extern const void * __deprecated inter_module_get_request(const char *,
const char *);
extern void __deprecated inter_module_put(const char *);
#endif
|