module.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Kernel module help for x86.
  2. Copyright (C) 2001 Rusty Russell.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #include <linux/moduleloader.h>
  16. #include <linux/elf.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/fs.h>
  19. #include <linux/string.h>
  20. #include <linux/kernel.h>
  21. #include <linux/bug.h>
  22. #include <linux/mm.h>
  23. #include <asm/system.h>
  24. #include <asm/page.h>
  25. #include <asm/pgtable.h>
  26. #if 0
  27. #define DEBUGP printk
  28. #else
  29. #define DEBUGP(fmt...)
  30. #endif
  31. /* Free memory returned from module_alloc */
  32. void module_free(struct module *mod, void *module_region)
  33. {
  34. vfree(module_region);
  35. /* FIXME: If module_region == mod->init_region, trim exception
  36. table entries. */
  37. }
  38. /* We don't need anything special. */
  39. int module_frob_arch_sections(Elf_Ehdr *hdr,
  40. Elf_Shdr *sechdrs,
  41. char *secstrings,
  42. struct module *mod)
  43. {
  44. return 0;
  45. }
  46. int module_finalize(const Elf_Ehdr *hdr,
  47. const Elf_Shdr *sechdrs,
  48. struct module *me)
  49. {
  50. const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL,
  51. *para = NULL;
  52. char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
  53. for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
  54. if (!strcmp(".text", secstrings + s->sh_name))
  55. text = s;
  56. if (!strcmp(".altinstructions", secstrings + s->sh_name))
  57. alt = s;
  58. if (!strcmp(".smp_locks", secstrings + s->sh_name))
  59. locks = s;
  60. if (!strcmp(".parainstructions", secstrings + s->sh_name))
  61. para = s;
  62. }
  63. if (alt) {
  64. /* patch .altinstructions */
  65. void *aseg = (void *)alt->sh_addr;
  66. apply_alternatives(aseg, aseg + alt->sh_size);
  67. }
  68. if (locks && text) {
  69. void *lseg = (void *)locks->sh_addr;
  70. void *tseg = (void *)text->sh_addr;
  71. alternatives_smp_module_add(me, me->name,
  72. lseg, lseg + locks->sh_size,
  73. tseg, tseg + text->sh_size);
  74. }
  75. if (para) {
  76. void *pseg = (void *)para->sh_addr;
  77. apply_paravirt(pseg, pseg + para->sh_size);
  78. }
  79. return module_bug_finalize(hdr, sechdrs, me);
  80. }
  81. void module_arch_cleanup(struct module *mod)
  82. {
  83. alternatives_smp_module_del(mod);
  84. module_bug_cleanup(mod);
  85. }