module.h 22 KB

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