module.h 23 KB

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