moduleloader.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_free(struct module *mod, 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", me->name);
  42. return -ENOEXEC;
  43. }
  44. #endif
  45. /*
  46. * Apply the given add relocation to the (simplified) ELF. Return
  47. * -error or 0
  48. */
  49. #ifdef CONFIG_MODULES_USE_ELF_RELA
  50. int apply_relocate_add(Elf_Shdr *sechdrs,
  51. const char *strtab,
  52. unsigned int symindex,
  53. unsigned int relsec,
  54. struct module *mod);
  55. #else
  56. static inline int apply_relocate_add(Elf_Shdr *sechdrs,
  57. const char *strtab,
  58. unsigned int symindex,
  59. unsigned int relsec,
  60. struct module *me)
  61. {
  62. printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
  63. return -ENOEXEC;
  64. }
  65. #endif
  66. /* Any final processing of module before access. Return -error or 0. */
  67. int module_finalize(const Elf_Ehdr *hdr,
  68. const Elf_Shdr *sechdrs,
  69. struct module *mod);
  70. /* Any cleanup needed when module leaves. */
  71. void module_arch_cleanup(struct module *mod);
  72. #endif