moduleloader.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef _LINUX_MODULELOADER_H
  2. #define _LINUX_MODULELOADER_H
  3. /* The stuff needed for archs to support modules. */
  4. #include <linux/module.h>
  5. #include <linux/elf.h>
  6. /* These may be implemented by architectures that need to hook into the
  7. * module loader code. Architectures that don't need to do anything special
  8. * can just rely on the 'weak' default hooks defined in kernel/module.c.
  9. * Note, however, that at least one of apply_relocate or apply_relocate_add
  10. * must be implemented by each architecture.
  11. */
  12. /* Adjust arch-specific sections. Return 0 on success. */
  13. int module_frob_arch_sections(Elf_Ehdr *hdr,
  14. Elf_Shdr *sechdrs,
  15. char *secstrings,
  16. struct module *mod);
  17. /* Additional bytes needed by arch in front of individual sections */
  18. unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
  19. /* Allocator used for allocating struct module, core sections and init
  20. sections. Returns NULL on failure. */
  21. void *module_alloc(unsigned long size);
  22. /* Free memory returned from module_alloc. */
  23. void module_memfree(void *module_region);
  24. /*
  25. * Apply the given relocation to the (simplified) ELF. Return -error
  26. * or 0.
  27. */
  28. #ifdef CONFIG_MODULES_USE_ELF_REL
  29. int apply_relocate(Elf_Shdr *sechdrs,
  30. const char *strtab,
  31. unsigned int symindex,
  32. unsigned int relsec,
  33. struct module *mod);
  34. #else
  35. static inline int apply_relocate(Elf_Shdr *sechdrs,
  36. const char *strtab,
  37. unsigned int symindex,
  38. unsigned int relsec,
  39. struct module *me)
  40. {
  41. printk(KERN_ERR "module %s: REL relocation unsupported\n",
  42. module_name(me));
  43. return -ENOEXEC;
  44. }
  45. #endif
  46. /*
  47. * Apply the given add relocation to the (simplified) ELF. Return
  48. * -error or 0
  49. */
  50. #ifdef CONFIG_MODULES_USE_ELF_RELA
  51. int apply_relocate_add(Elf_Shdr *sechdrs,
  52. const char *strtab,
  53. unsigned int symindex,
  54. unsigned int relsec,
  55. struct module *mod);
  56. #else
  57. static inline int apply_relocate_add(Elf_Shdr *sechdrs,
  58. const char *strtab,
  59. unsigned int symindex,
  60. unsigned int relsec,
  61. struct module *me)
  62. {
  63. printk(KERN_ERR "module %s: REL relocation unsupported\n",
  64. module_name(me));
  65. return -ENOEXEC;
  66. }
  67. #endif
  68. /* Any final processing of module before access. Return -error or 0. */
  69. int module_finalize(const Elf_Ehdr *hdr,
  70. const Elf_Shdr *sechdrs,
  71. struct module *mod);
  72. /* Any cleanup needed when module leaves. */
  73. void module_arch_cleanup(struct module *mod);
  74. /* Any cleanup before freeing mod->module_init */
  75. void module_arch_freeing_init(struct module *mod);
  76. #ifdef CONFIG_KASAN
  77. #include <linux/kasan.h>
  78. #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
  79. #else
  80. #define MODULE_ALIGN PAGE_SIZE
  81. #endif
  82. #endif