dl.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* dl.h - types and prototypes for loadable module support */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2002,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef GRUB_DL_H
  20. #define GRUB_DL_H 1
  21. #include <grub/symbol.h>
  22. #include <grub/err.h>
  23. #include <grub/types.h>
  24. #include <grub/elf.h>
  25. #define GRUB_MOD_INIT(name) \
  26. static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
  27. void grub_##name##_init (void); \
  28. void \
  29. grub_##name##_init (void) { grub_mod_init (0); } \
  30. static void \
  31. grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
  32. #define GRUB_MOD_FINI(name) \
  33. static void grub_mod_fini (void) __attribute__ ((used)); \
  34. void grub_##name##_fini (void); \
  35. void \
  36. grub_##name##_fini (void) { grub_mod_fini (); } \
  37. static void \
  38. grub_mod_fini (void)
  39. #ifdef APPLE_CC
  40. #define GRUB_MOD_NAME(name) \
  41. static char grub_modname[] __attribute__ ((section ("_modname, _modname"), used)) = #name;
  42. #define GRUB_MOD_DEP(name) \
  43. __asm__ (".section _moddeps, _moddeps\n.asciz \"" #name "\"\n")
  44. #elif defined(__MINGW32__) || defined(__CYGWIN__)
  45. #define GRUB_MOD_NAME(name) \
  46. __asm__ (".section .modname\n.asciz \"" #name "\"\n")
  47. #define GRUB_MOD_DEP(name) \
  48. __asm__ (".section .moddeps\n.asciz \"" #name "\"\n")
  49. #else
  50. #define GRUB_MOD_NAME(name) \
  51. __asm__ (".section \".modname\"\n.asciz \"" #name "\"\n")
  52. #define GRUB_MOD_DEP(name) \
  53. __asm__ (".section \".moddeps\"\n.asciz \"" #name "\"\n")
  54. #endif
  55. struct grub_dl_segment
  56. {
  57. struct grub_dl_segment *next;
  58. void *addr;
  59. grub_size_t size;
  60. unsigned section;
  61. };
  62. typedef struct grub_dl_segment *grub_dl_segment_t;
  63. struct grub_dl;
  64. struct grub_dl_dep
  65. {
  66. struct grub_dl_dep *next;
  67. struct grub_dl *mod;
  68. };
  69. typedef struct grub_dl_dep *grub_dl_dep_t;
  70. struct grub_dl
  71. {
  72. char *name;
  73. int ref_count;
  74. grub_dl_dep_t dep;
  75. grub_dl_segment_t segment;
  76. Elf_Sym *symtab;
  77. void (*init) (struct grub_dl *mod);
  78. void (*fini) (void);
  79. };
  80. typedef struct grub_dl *grub_dl_t;
  81. grub_dl_t grub_dl_load_file (const char *filename);
  82. grub_dl_t grub_dl_load (const char *name);
  83. grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
  84. int grub_dl_unload (grub_dl_t mod);
  85. void grub_dl_unload_unneeded (void);
  86. void grub_dl_unload_all (void);
  87. #if defined (GRUB_UTIL) || defined (GRUB_TARGET_NO_MODULES)
  88. #define GRUB_NO_MODULES 1
  89. #else
  90. #define GRUB_NO_MODULES 0
  91. #endif
  92. #if GRUB_NO_MODULES
  93. static inline int
  94. grub_dl_ref (grub_dl_t mod)
  95. {
  96. (void) mod;
  97. return 0;
  98. }
  99. static inline int
  100. grub_dl_unref (grub_dl_t mod)
  101. {
  102. (void) mod;
  103. return 0;
  104. }
  105. #else
  106. int grub_dl_ref (grub_dl_t mod);
  107. int grub_dl_unref (grub_dl_t mod);
  108. #endif
  109. void grub_dl_iterate (int (*hook) (grub_dl_t mod));
  110. grub_dl_t grub_dl_get (const char *name);
  111. grub_err_t grub_dl_register_symbol (const char *name, void *addr,
  112. grub_dl_t mod);
  113. grub_err_t grub_arch_dl_check_header (void *ehdr);
  114. grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr);
  115. grub_err_t grub_dl_add (grub_dl_t mod);
  116. grub_err_t grub_dl_resolve_dependencies (grub_dl_t mod, char *name);
  117. #if defined (_mips) && ! GRUB_NO_MODULES
  118. #define GRUB_LINKER_HAVE_INIT 1
  119. void grub_arch_dl_init_linker (void);
  120. #endif
  121. #endif /* ! GRUB_DL_H */