module.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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/list.h>
  10. #include <linux/stat.h>
  11. #include <linux/compiler.h>
  12. #include <linux/cache.h>
  13. #include <linux/kmod.h>
  14. #include <linux/init.h>
  15. #include <linux/elf.h>
  16. #include <linux/stringify.h>
  17. #include <linux/kobject.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/jump_label.h>
  20. #include <linux/export.h>
  21. #include <linux/rbtree_latch.h>
  22. #include <linux/percpu.h>
  23. #include <asm/module.h>
  24. /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
  25. #define MODULE_SIG_STRING "~Module signature appended~\n"
  26. /* Not Yet Implemented */
  27. #define MODULE_SUPPORTED_DEVICE(name)
  28. #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
  29. struct modversion_info {
  30. unsigned long crc;
  31. char name[MODULE_NAME_LEN];
  32. };
  33. struct module;
  34. struct module_kobject {
  35. struct kobject kobj;
  36. struct module *mod;
  37. struct kobject *drivers_dir;
  38. struct module_param_attrs *mp;
  39. struct completion *kobj_completion;
  40. };
  41. struct module_attribute {
  42. struct attribute attr;
  43. ssize_t (*show)(struct module_attribute *, struct module_kobject *,
  44. char *);
  45. ssize_t (*store)(struct module_attribute *, struct module_kobject *,
  46. const char *, size_t count);
  47. void (*setup)(struct module *, const char *);
  48. int (*test)(struct module *);
  49. void (*free)(struct module *);
  50. };
  51. struct module_version_attribute {
  52. struct module_attribute mattr;
  53. const char *module_name;
  54. const char *version;
  55. } __attribute__ ((__aligned__(sizeof(void *))));
  56. extern ssize_t __modver_version_show(struct module_attribute *,
  57. struct module_kobject *, char *);
  58. extern struct module_attribute module_uevent;
  59. /* These are either module local, or the kernel's dummy ones. */
  60. extern int init_module(void);
  61. extern void cleanup_module(void);
  62. #ifndef MODULE
  63. /**
  64. * module_init() - driver initialization entry point
  65. * @x: function to be run at kernel boot time or module insertion
  66. *
  67. * module_init() will either be called during do_initcalls() (if
  68. * builtin) or at module insertion time (if a module). There can only
  69. * be one per module.
  70. */
  71. #define module_init(x) __initcall(x);
  72. /**
  73. * module_exit() - driver exit entry point
  74. * @x: function to be run when driver is removed
  75. *
  76. * module_exit() will wrap the driver clean-up code
  77. * with cleanup_module() when used with rmmod when
  78. * the driver is a module. If the driver is statically
  79. * compiled into the kernel, module_exit() has no effect.
  80. * There can only be one per module.
  81. */
  82. #define module_exit(x) __exitcall(x);
  83. #else /* MODULE */
  84. /*
  85. * In most cases loadable modules do not need custom
  86. * initcall levels. There are still some valid cases where
  87. * a driver may be needed early if built in, and does not
  88. * matter when built as a loadable module. Like bus
  89. * snooping debug drivers.
  90. */
  91. #define early_initcall(fn) module_init(fn)
  92. #define core_initcall(fn) module_init(fn)
  93. #define core_initcall_sync(fn) module_init(fn)
  94. #define postcore_initcall(fn) module_init(fn)
  95. #define postcore_initcall_sync(fn) module_init(fn)
  96. #define arch_initcall(fn) module_init(fn)
  97. #define subsys_initcall(fn) module_init(fn)
  98. #define subsys_initcall_sync(fn) module_init(fn)
  99. #define fs_initcall(fn) module_init(fn)
  100. #define fs_initcall_sync(fn) module_init(fn)
  101. #define rootfs_initcall(fn) module_init(fn)
  102. #define device_initcall(fn) module_init(fn)
  103. #define device_initcall_sync(fn) module_init(fn)
  104. #define late_initcall(fn) module_init(fn)
  105. #define late_initcall_sync(fn) module_init(fn)
  106. #define console_initcall(fn) module_init(fn)
  107. #define security_initcall(fn) module_init(fn)
  108. /* Each module must use one module_init(). */
  109. #define module_init(initfn) \
  110. static inline initcall_t __inittest(void) \
  111. { return initfn; } \
  112. int init_module(void) __attribute__((alias(#initfn)));
  113. /* This is only required if you want to be unloadable. */
  114. #define module_exit(exitfn) \
  115. static inline exitcall_t __exittest(void) \
  116. { return exitfn; } \
  117. void cleanup_module(void) __attribute__((alias(#exitfn)));
  118. #endif
  119. /* This means "can be init if no module support, otherwise module load
  120. may call it." */
  121. #ifdef CONFIG_MODULES
  122. #define __init_or_module
  123. #define __initdata_or_module
  124. #define __initconst_or_module
  125. #define __INIT_OR_MODULE .text
  126. #define __INITDATA_OR_MODULE .data
  127. #define __INITRODATA_OR_MODULE .section ".rodata","a",%progbits
  128. #else
  129. #define __init_or_module __init
  130. #define __initdata_or_module __initdata
  131. #define __initconst_or_module __initconst
  132. #define __INIT_OR_MODULE __INIT
  133. #define __INITDATA_OR_MODULE __INITDATA
  134. #define __INITRODATA_OR_MODULE __INITRODATA
  135. #endif /*CONFIG_MODULES*/
  136. /* Archs provide a method of finding the correct exception table. */
  137. struct exception_table_entry;
  138. const struct exception_table_entry *
  139. search_extable(const struct exception_table_entry *first,
  140. const struct exception_table_entry *last,
  141. unsigned long value);
  142. void sort_extable(struct exception_table_entry *start,
  143. struct exception_table_entry *finish);
  144. void sort_main_extable(void);
  145. void trim_init_extable(struct module *m);
  146. /* Generic info of form tag = "info" */
  147. #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
  148. /* For userspace: you can also call me... */
  149. #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
  150. /* Soft module dependencies. See man modprobe.d for details.
  151. * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz")
  152. */
  153. #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
  154. /*
  155. * The following license idents are currently accepted as indicating free
  156. * software modules
  157. *
  158. * "GPL" [GNU Public License v2 or later]
  159. * "GPL v2" [GNU Public License v2]
  160. * "GPL and additional rights" [GNU Public License v2 rights and more]
  161. * "Dual BSD/GPL" [GNU Public License v2
  162. * or BSD license choice]
  163. * "Dual MIT/GPL" [GNU Public License v2
  164. * or MIT license choice]
  165. * "Dual MPL/GPL" [GNU Public License v2
  166. * or Mozilla license choice]
  167. *
  168. * The following other idents are available
  169. *
  170. * "Proprietary" [Non free products]
  171. *
  172. * There are dual licensed components, but when running with Linux it is the
  173. * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
  174. * is a GPL combined work.
  175. *
  176. * This exists for several reasons
  177. * 1. So modinfo can show license info for users wanting to vet their setup
  178. * is free
  179. * 2. So the community can ignore bug reports including proprietary modules
  180. * 3. So vendors can do likewise based on their own policies
  181. */
  182. #define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
  183. /*
  184. * Author(s), use "Name <email>" or just "Name", for multiple
  185. * authors use multiple MODULE_AUTHOR() statements/lines.
  186. */
  187. #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
  188. /* What your module does. */
  189. #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
  190. #ifdef MODULE
  191. /* Creates an alias so file2alias.c can find device table. */
  192. #define MODULE_DEVICE_TABLE(type, name) \
  193. extern const typeof(name) __mod_##type##__##name##_device_table \
  194. __attribute__ ((unused, alias(__stringify(name))))
  195. #else /* !MODULE */
  196. #define MODULE_DEVICE_TABLE(type, name)
  197. #endif
  198. /* Version of form [<epoch>:]<version>[-<extra-version>].
  199. * Or for CVS/RCS ID version, everything but the number is stripped.
  200. * <epoch>: A (small) unsigned integer which allows you to start versions
  201. * anew. If not mentioned, it's zero. eg. "2:1.0" is after
  202. * "1:2.0".
  203. * <version>: The <version> may contain only alphanumerics and the
  204. * character `.'. Ordered by numeric sort for numeric parts,
  205. * ascii sort for ascii parts (as per RPM or DEB algorithm).
  206. * <extraversion>: Like <version>, but inserted for local
  207. * customizations, eg "rh3" or "rusty1".
  208. * Using this automatically adds a checksum of the .c files and the
  209. * local headers in "srcversion".
  210. */
  211. #if defined(MODULE) || !defined(CONFIG_SYSFS)
  212. #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
  213. #else
  214. #define MODULE_VERSION(_version) \
  215. static struct module_version_attribute ___modver_attr = { \
  216. .mattr = { \
  217. .attr = { \
  218. .name = "version", \
  219. .mode = S_IRUGO, \
  220. }, \
  221. .show = __modver_version_show, \
  222. }, \
  223. .module_name = KBUILD_MODNAME, \
  224. .version = _version, \
  225. }; \
  226. static const struct module_version_attribute \
  227. __used __attribute__ ((__section__ ("__modver"))) \
  228. * __moduleparam_const __modver_attr = &___modver_attr
  229. #endif
  230. /* Optional firmware file (or files) needed by the module
  231. * format is simply firmware file name. Multiple firmware
  232. * files require multiple MODULE_FIRMWARE() specifiers */
  233. #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
  234. /* Given an address, look for it in the exception tables */
  235. const struct exception_table_entry *search_exception_tables(unsigned long add);
  236. struct notifier_block;
  237. #ifdef CONFIG_MODULES
  238. extern int modules_disabled; /* for sysctl */
  239. /* Get/put a kernel symbol (calls must be symmetric) */
  240. void *__symbol_get(const char *symbol);
  241. void *__symbol_get_gpl(const char *symbol);
  242. #define symbol_get(x) ((typeof(&x))(__symbol_get(VMLINUX_SYMBOL_STR(x))))
  243. /* modules using other modules: kdb wants to see this. */
  244. struct module_use {
  245. struct list_head source_list;
  246. struct list_head target_list;
  247. struct module *source, *target;
  248. };
  249. enum module_state {
  250. MODULE_STATE_LIVE, /* Normal state. */
  251. MODULE_STATE_COMING, /* Full formed, running module_init. */
  252. MODULE_STATE_GOING, /* Going away. */
  253. MODULE_STATE_UNFORMED, /* Still setting it up. */
  254. };
  255. struct module;
  256. struct mod_tree_node {
  257. struct module *mod;
  258. struct latch_tree_node node;
  259. };
  260. struct module_layout {
  261. /* The actual code + data. */
  262. void *base;
  263. /* Total size. */
  264. unsigned int size;
  265. /* The size of the executable code. */
  266. unsigned int text_size;
  267. /* Size of RO section of the module (text+rodata) */
  268. unsigned int ro_size;
  269. #ifdef CONFIG_MODULES_TREE_LOOKUP
  270. struct mod_tree_node mtn;
  271. #endif
  272. };
  273. #ifdef CONFIG_MODULES_TREE_LOOKUP
  274. /* Only touch one cacheline for common rbtree-for-core-layout case. */
  275. #define __module_layout_align ____cacheline_aligned
  276. #else
  277. #define __module_layout_align
  278. #endif
  279. struct module {
  280. enum module_state state;
  281. /* Member of list of modules */
  282. struct list_head list;
  283. /* Unique handle for this module */
  284. char name[MODULE_NAME_LEN];
  285. /* Sysfs stuff. */
  286. struct module_kobject mkobj;
  287. struct module_attribute *modinfo_attrs;
  288. const char *version;
  289. const char *srcversion;
  290. struct kobject *holders_dir;
  291. /* Exported symbols */
  292. const struct kernel_symbol *syms;
  293. const unsigned long *crcs;
  294. unsigned int num_syms;
  295. /* Kernel parameters. */
  296. #ifdef CONFIG_SYSFS
  297. struct mutex param_lock;
  298. #endif
  299. struct kernel_param *kp;
  300. unsigned int num_kp;
  301. /* GPL-only exported symbols. */
  302. unsigned int num_gpl_syms;
  303. const struct kernel_symbol *gpl_syms;
  304. const unsigned long *gpl_crcs;
  305. #ifdef CONFIG_UNUSED_SYMBOLS
  306. /* unused exported symbols. */
  307. const struct kernel_symbol *unused_syms;
  308. const unsigned long *unused_crcs;
  309. unsigned int num_unused_syms;
  310. /* GPL-only, unused exported symbols. */
  311. unsigned int num_unused_gpl_syms;
  312. const struct kernel_symbol *unused_gpl_syms;
  313. const unsigned long *unused_gpl_crcs;
  314. #endif
  315. #ifdef CONFIG_MODULE_SIG
  316. /* Signature was verified. */
  317. bool sig_ok;
  318. #endif
  319. bool async_probe_requested;
  320. /* symbols that will be GPL-only in the near future. */
  321. const struct kernel_symbol *gpl_future_syms;
  322. const unsigned long *gpl_future_crcs;
  323. unsigned int num_gpl_future_syms;
  324. /* Exception table */
  325. unsigned int num_exentries;
  326. struct exception_table_entry *extable;
  327. /* Startup function. */
  328. int (*init)(void);
  329. /* Core layout: rbtree is accessed frequently, so keep together. */
  330. struct module_layout core_layout __module_layout_align;
  331. struct module_layout init_layout;
  332. /* Arch-specific module values */
  333. struct mod_arch_specific arch;
  334. unsigned int taints; /* same bits as kernel:tainted */
  335. #ifdef CONFIG_GENERIC_BUG
  336. /* Support for BUG */
  337. unsigned num_bugs;
  338. struct list_head bug_list;
  339. struct bug_entry *bug_table;
  340. #endif
  341. #ifdef CONFIG_KALLSYMS
  342. /*
  343. * We keep the symbol and string tables for kallsyms.
  344. * The core_* fields below are temporary, loader-only (they
  345. * could really be discarded after module init).
  346. */
  347. Elf_Sym *symtab, *core_symtab;
  348. unsigned int num_symtab, core_num_syms;
  349. char *strtab, *core_strtab;
  350. /* Section attributes */
  351. struct module_sect_attrs *sect_attrs;
  352. /* Notes attributes */
  353. struct module_notes_attrs *notes_attrs;
  354. #endif
  355. /* The command line arguments (may be mangled). People like
  356. keeping pointers to this stuff */
  357. char *args;
  358. #ifdef CONFIG_SMP
  359. /* Per-cpu data. */
  360. void __percpu *percpu;
  361. unsigned int percpu_size;
  362. #endif
  363. #ifdef CONFIG_TRACEPOINTS
  364. unsigned int num_tracepoints;
  365. struct tracepoint * const *tracepoints_ptrs;
  366. #endif
  367. #ifdef HAVE_JUMP_LABEL
  368. struct jump_entry *jump_entries;
  369. unsigned int num_jump_entries;
  370. #endif
  371. #ifdef CONFIG_TRACING
  372. unsigned int num_trace_bprintk_fmt;
  373. const char **trace_bprintk_fmt_start;
  374. #endif
  375. #ifdef CONFIG_EVENT_TRACING
  376. struct trace_event_call **trace_events;
  377. unsigned int num_trace_events;
  378. struct trace_enum_map **trace_enums;
  379. unsigned int num_trace_enums;
  380. #endif
  381. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  382. unsigned int num_ftrace_callsites;
  383. unsigned long *ftrace_callsites;
  384. #endif
  385. #ifdef CONFIG_LIVEPATCH
  386. bool klp_alive;
  387. #endif
  388. #ifdef CONFIG_MODULE_UNLOAD
  389. /* What modules depend on me? */
  390. struct list_head source_list;
  391. /* What modules do I depend on? */
  392. struct list_head target_list;
  393. /* Destruction function. */
  394. void (*exit)(void);
  395. atomic_t refcnt;
  396. #endif
  397. #ifdef CONFIG_CONSTRUCTORS
  398. /* Constructor functions. */
  399. ctor_fn_t *ctors;
  400. unsigned int num_ctors;
  401. #endif
  402. } ____cacheline_aligned;
  403. #ifndef MODULE_ARCH_INIT
  404. #define MODULE_ARCH_INIT {}
  405. #endif
  406. extern struct mutex module_mutex;
  407. /* FIXME: It'd be nice to isolate modules during init, too, so they
  408. aren't used before they (may) fail. But presently too much code
  409. (IDE & SCSI) require entry into the module during init.*/
  410. static inline int module_is_live(struct module *mod)
  411. {
  412. return mod->state != MODULE_STATE_GOING;
  413. }
  414. struct module *__module_text_address(unsigned long addr);
  415. struct module *__module_address(unsigned long addr);
  416. bool is_module_address(unsigned long addr);
  417. bool is_module_percpu_address(unsigned long addr);
  418. bool is_module_text_address(unsigned long addr);
  419. static inline bool within_module_core(unsigned long addr,
  420. const struct module *mod)
  421. {
  422. return (unsigned long)mod->core_layout.base <= addr &&
  423. addr < (unsigned long)mod->core_layout.base + mod->core_layout.size;
  424. }
  425. static inline bool within_module_init(unsigned long addr,
  426. const struct module *mod)
  427. {
  428. return (unsigned long)mod->init_layout.base <= addr &&
  429. addr < (unsigned long)mod->init_layout.base + mod->init_layout.size;
  430. }
  431. static inline bool within_module(unsigned long addr, const struct module *mod)
  432. {
  433. return within_module_init(addr, mod) || within_module_core(addr, mod);
  434. }
  435. /* Search for module by name: must hold module_mutex. */
  436. struct module *find_module(const char *name);
  437. struct symsearch {
  438. const struct kernel_symbol *start, *stop;
  439. const unsigned long *crcs;
  440. enum {
  441. NOT_GPL_ONLY,
  442. GPL_ONLY,
  443. WILL_BE_GPL_ONLY,
  444. } licence;
  445. bool unused;
  446. };
  447. /*
  448. * Search for an exported symbol by name.
  449. *
  450. * Must be called with module_mutex held or preemption disabled.
  451. */
  452. const struct kernel_symbol *find_symbol(const char *name,
  453. struct module **owner,
  454. const unsigned long **crc,
  455. bool gplok,
  456. bool warn);
  457. /*
  458. * Walk the exported symbol table
  459. *
  460. * Must be called with module_mutex held or preemption disabled.
  461. */
  462. bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
  463. struct module *owner,
  464. void *data), void *data);
  465. /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
  466. symnum out of range. */
  467. int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
  468. char *name, char *module_name, int *exported);
  469. /* Look for this name: can be of form module:name. */
  470. unsigned long module_kallsyms_lookup_name(const char *name);
  471. int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
  472. struct module *, unsigned long),
  473. void *data);
  474. extern void __module_put_and_exit(struct module *mod, long code)
  475. __attribute__((noreturn));
  476. #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code)
  477. #ifdef CONFIG_MODULE_UNLOAD
  478. int module_refcount(struct module *mod);
  479. void __symbol_put(const char *symbol);
  480. #define symbol_put(x) __symbol_put(VMLINUX_SYMBOL_STR(x))
  481. void symbol_put_addr(void *addr);
  482. /* Sometimes we know we already have a refcount, and it's easier not
  483. to handle the error case (which only happens with rmmod --wait). */
  484. extern void __module_get(struct module *module);
  485. /* This is the Right Way to get a module: if it fails, it's being removed,
  486. * so pretend it's not there. */
  487. extern bool try_module_get(struct module *module);
  488. extern void module_put(struct module *module);
  489. #else /*!CONFIG_MODULE_UNLOAD*/
  490. static inline int try_module_get(struct module *module)
  491. {
  492. return !module || module_is_live(module);
  493. }
  494. static inline void module_put(struct module *module)
  495. {
  496. }
  497. static inline void __module_get(struct module *module)
  498. {
  499. }
  500. #define symbol_put(x) do { } while (0)
  501. #define symbol_put_addr(p) do { } while (0)
  502. #endif /* CONFIG_MODULE_UNLOAD */
  503. int ref_module(struct module *a, struct module *b);
  504. /* This is a #define so the string doesn't get put in every .o file */
  505. #define module_name(mod) \
  506. ({ \
  507. struct module *__mod = (mod); \
  508. __mod ? __mod->name : "kernel"; \
  509. })
  510. /* For kallsyms to ask for address resolution. namebuf should be at
  511. * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
  512. * found, otherwise NULL. */
  513. const char *module_address_lookup(unsigned long addr,
  514. unsigned long *symbolsize,
  515. unsigned long *offset,
  516. char **modname,
  517. char *namebuf);
  518. int lookup_module_symbol_name(unsigned long addr, char *symname);
  519. int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
  520. /* For extable.c to search modules' exception tables. */
  521. const struct exception_table_entry *search_module_extables(unsigned long addr);
  522. int register_module_notifier(struct notifier_block *nb);
  523. int unregister_module_notifier(struct notifier_block *nb);
  524. extern void print_modules(void);
  525. static inline bool module_requested_async_probing(struct module *module)
  526. {
  527. return module && module->async_probe_requested;
  528. }
  529. #else /* !CONFIG_MODULES... */
  530. /* Given an address, look for it in the exception tables. */
  531. static inline const struct exception_table_entry *
  532. search_module_extables(unsigned long addr)
  533. {
  534. return NULL;
  535. }
  536. static inline struct module *__module_address(unsigned long addr)
  537. {
  538. return NULL;
  539. }
  540. static inline struct module *__module_text_address(unsigned long addr)
  541. {
  542. return NULL;
  543. }
  544. static inline bool is_module_address(unsigned long addr)
  545. {
  546. return false;
  547. }
  548. static inline bool is_module_percpu_address(unsigned long addr)
  549. {
  550. return false;
  551. }
  552. static inline bool is_module_text_address(unsigned long addr)
  553. {
  554. return false;
  555. }
  556. /* Get/put a kernel symbol (calls should be symmetric) */
  557. #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
  558. #define symbol_put(x) do { } while (0)
  559. #define symbol_put_addr(x) do { } while (0)
  560. static inline void __module_get(struct module *module)
  561. {
  562. }
  563. static inline int try_module_get(struct module *module)
  564. {
  565. return 1;
  566. }
  567. static inline void module_put(struct module *module)
  568. {
  569. }
  570. #define module_name(mod) "kernel"
  571. /* For kallsyms to ask for address resolution. NULL means not found. */
  572. static inline const char *module_address_lookup(unsigned long addr,
  573. unsigned long *symbolsize,
  574. unsigned long *offset,
  575. char **modname,
  576. char *namebuf)
  577. {
  578. return NULL;
  579. }
  580. static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
  581. {
  582. return -ERANGE;
  583. }
  584. static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
  585. {
  586. return -ERANGE;
  587. }
  588. static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
  589. char *type, char *name,
  590. char *module_name, int *exported)
  591. {
  592. return -ERANGE;
  593. }
  594. static inline unsigned long module_kallsyms_lookup_name(const char *name)
  595. {
  596. return 0;
  597. }
  598. static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
  599. struct module *,
  600. unsigned long),
  601. void *data)
  602. {
  603. return 0;
  604. }
  605. static inline int register_module_notifier(struct notifier_block *nb)
  606. {
  607. /* no events will happen anyway, so this can always succeed */
  608. return 0;
  609. }
  610. static inline int unregister_module_notifier(struct notifier_block *nb)
  611. {
  612. return 0;
  613. }
  614. #define module_put_and_exit(code) do_exit(code)
  615. static inline void print_modules(void)
  616. {
  617. }
  618. static inline bool module_requested_async_probing(struct module *module)
  619. {
  620. return false;
  621. }
  622. #endif /* CONFIG_MODULES */
  623. #ifdef CONFIG_SYSFS
  624. extern struct kset *module_kset;
  625. extern struct kobj_type module_ktype;
  626. extern int module_sysfs_initialized;
  627. #endif /* CONFIG_SYSFS */
  628. #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
  629. /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
  630. #define __MODULE_STRING(x) __stringify(x)
  631. #ifdef CONFIG_DEBUG_SET_MODULE_RONX
  632. extern void set_all_modules_text_rw(void);
  633. extern void set_all_modules_text_ro(void);
  634. #else
  635. static inline void set_all_modules_text_rw(void) { }
  636. static inline void set_all_modules_text_ro(void) { }
  637. #endif
  638. #ifdef CONFIG_GENERIC_BUG
  639. void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
  640. struct module *);
  641. void module_bug_cleanup(struct module *);
  642. #else /* !CONFIG_GENERIC_BUG */
  643. static inline void module_bug_finalize(const Elf_Ehdr *hdr,
  644. const Elf_Shdr *sechdrs,
  645. struct module *mod)
  646. {
  647. }
  648. static inline void module_bug_cleanup(struct module *mod) {}
  649. #endif /* CONFIG_GENERIC_BUG */
  650. #ifdef CONFIG_MODULE_SIG
  651. static inline bool module_sig_ok(struct module *module)
  652. {
  653. return module->sig_ok;
  654. }
  655. #else /* !CONFIG_MODULE_SIG */
  656. static inline bool module_sig_ok(struct module *module)
  657. {
  658. return true;
  659. }
  660. #endif /* CONFIG_MODULE_SIG */
  661. #endif /* _LINUX_MODULE_H */