1 /* dl.h - types and prototypes for loadable module support */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2002,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
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.
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.
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/>.
23 #include <grub/symbol.h>
26 #include <grub/types.h>
28 #include <grub/list.h>
29 #include <grub/misc.h>
33 * Macros GRUB_MOD_INIT and GRUB_MOD_FINI are also used by build rules
34 * to collect module names, so we define them only when they are not
41 #if !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_KERNEL)
43 #define GRUB_MOD_INIT(name) \
44 static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
46 grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
48 #define GRUB_MOD_FINI(name) \
49 static void grub_mod_fini (void) __attribute__ ((used)); \
53 #elif defined (GRUB_KERNEL)
55 #define GRUB_MOD_INIT(name) \
56 static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
58 grub_##name##_init (void) { grub_mod_init (0); } \
60 grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
62 #define GRUB_MOD_FINI(name) \
63 static void grub_mod_fini (void) __attribute__ ((used)); \
65 grub_##name##_fini (void) { grub_mod_fini (); } \
71 #define GRUB_MOD_INIT(name) \
72 static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
73 void grub_##name##_init (void); \
75 grub_##name##_init (void) { grub_mod_init (0); } \
77 grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
79 #define GRUB_MOD_FINI(name) \
80 static void grub_mod_fini (void) __attribute__ ((used)); \
81 void grub_##name##_fini (void); \
83 grub_##name##_fini (void) { grub_mod_fini (); } \
95 #define GRUB_MOD_SECTION(x) "_" #x ", _" #x ""
97 #define GRUB_MOD_SECTION(x) "." #x
101 #define GRUB_MOD_SECTION(x) _ ## x , _ ##x
103 #define GRUB_MOD_SECTION(x) . ## x
107 /* Me, Vladimir Serbinenko, hereby I add this module check as per new
108 GNU module policy. Note that this license check is informative only.
109 Modules have to be licensed under GPLv3 or GPLv3+ (optionally
110 multi-licensed under other licences as well) independently of the
111 presence of this check and solely by linking (module loading in GRUB
112 constitutes linking) and GRUB core being licensed under GPLv3+.
113 Be sure to understand your license obligations.
116 #if GNUC_PREREQ (3,2)
117 #define ATTRIBUTE_USED __used__
119 #define ATTRIBUTE_USED __unused__
121 #define GRUB_MOD_LICENSE(license) \
122 static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), ATTRIBUTE_USED)) = "LICENSE=" license;
123 #define GRUB_MOD_DEP(name) \
124 static const char grub_module_depend_##name[] \
125 __attribute__((section(GRUB_MOD_SECTION(moddeps)), ATTRIBUTE_USED)) = #name
126 #define GRUB_MOD_NAME(name) \
127 static const char grub_module_name_##name[] \
128 __attribute__((section(GRUB_MOD_SECTION(modname)), __used__)) = #name
131 .macro GRUB_MOD_LICENSE
132 .section
GRUB_MOD_SECTION(module_license
)
138 .macro GRUB_MOD_LICENSE license
139 .section
GRUB_MOD_SECTION(module_license
), "a"
147 /* Under GPL license obligations you have to distribute your module
148 under GPLv3(+). However, you can also distribute the same code under
149 another license as long as GPLv3(+) version is provided.
151 #define GRUB_MOD_DUAL_LICENSE(x)
155 struct grub_dl_segment
157 struct grub_dl_segment
*next
;
162 typedef struct grub_dl_segment
*grub_dl_segment_t
;
168 struct grub_dl_dep
*next
;
171 typedef struct grub_dl_dep
*grub_dl_dep_t
;
179 grub_dl_segment_t segment
;
182 void (*init
) (struct grub_dl
*mod
);
184 #if !defined (__i386__) && !defined (__x86_64__)
191 grub_uint32_t
*reginfo
;
195 struct grub_dl
*next
;
198 typedef struct grub_dl
*grub_dl_t
;
200 grub_dl_t
grub_dl_load_file (const char *filename
);
201 grub_dl_t
EXPORT_FUNC(grub_dl_load
) (const char *name
);
202 grub_dl_t
grub_dl_load_core (void *addr
, grub_size_t size
);
203 grub_dl_t
EXPORT_FUNC(grub_dl_load_core_noinit
) (void *addr
, grub_size_t size
);
204 int EXPORT_FUNC(grub_dl_unload
) (grub_dl_t mod
);
205 void grub_dl_unload_unneeded (void);
206 int EXPORT_FUNC(grub_dl_ref
) (grub_dl_t mod
);
207 int EXPORT_FUNC(grub_dl_unref
) (grub_dl_t mod
);
208 extern grub_dl_t
EXPORT_VAR(grub_dl_head
);
212 #define FOR_DL_MODULES(var) FOR_LIST_ELEMENTS ((var), (grub_dl_head))
214 #ifdef GRUB_MACHINE_EMU
216 grub_osdep_dl_memalign (grub_size_t align
, grub_size_t size
);
218 grub_dl_osdep_dl_free (void *ptr
);
222 grub_dl_init (grub_dl_t mod
)
227 mod
->next
= grub_dl_head
;
231 static inline grub_dl_t
232 grub_dl_get (const char *name
)
237 if (grub_strcmp (name
, l
->name
) == 0)
245 grub_err_t
grub_dl_register_symbol (const char *name
, void *addr
,
246 int isfunc
, grub_dl_t mod
);
248 grub_err_t
grub_arch_dl_check_header (void *ehdr
);
251 grub_arch_dl_relocate_symbols (grub_dl_t mod
, void *ehdr
,
252 Elf_Shdr
*s
, grub_dl_segment_t seg
);
256 #define GRUB_LINKER_HAVE_INIT 1
257 void grub_arch_dl_init_linker (void);
260 #define GRUB_IA64_DL_TRAMP_ALIGN 16
261 #define GRUB_IA64_DL_GOT_ALIGN 16
264 grub_ia64_dl_get_tramp_got_size (const void *ehdr
, grub_size_t
*tramp
,
267 #if defined (__ia64__)
268 #define GRUB_ARCH_DL_TRAMP_ALIGN GRUB_IA64_DL_TRAMP_ALIGN
269 #define GRUB_ARCH_DL_GOT_ALIGN GRUB_IA64_DL_GOT_ALIGN
270 #define grub_arch_dl_get_tramp_got_size grub_ia64_dl_get_tramp_got_size
273 grub_arch_dl_get_tramp_got_size (const void *ehdr
, grub_size_t
*tramp
,
277 #if defined (__powerpc__) || defined (__mips__) || defined (__arm__)
278 #define GRUB_ARCH_DL_TRAMP_ALIGN 4
279 #define GRUB_ARCH_DL_GOT_ALIGN 4
282 #if defined (__aarch64__) || defined (__sparc__)
283 #define GRUB_ARCH_DL_TRAMP_ALIGN 8
284 #define GRUB_ARCH_DL_GOT_ALIGN 8
289 #endif /* ! GRUB_DL_H */