2009-07-20 Joe Auricchio <jauricchio@gmail.com>
[grub2/phcoder.git] / include / grub / dl.h
blobe24b832d02efddf2fb248e5993e769a4d476b8bb
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.
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/>.
20 #ifndef GRUB_DL_H
21 #define GRUB_DL_H 1
23 #include <grub/symbol.h>
24 #include <grub/err.h>
25 #include <grub/types.h>
26 #include <grub/elf.h>
28 #define GRUB_MOD_INIT(name) \
29 static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
30 void grub_##name##_init (void); \
31 void \
32 grub_##name##_init (void) { grub_mod_init (0); } \
33 static void \
34 grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
36 #define GRUB_MOD_FINI(name) \
37 static void grub_mod_fini (void) __attribute__ ((used)); \
38 void grub_##name##_fini (void); \
39 void \
40 grub_##name##_fini (void) { grub_mod_fini (); } \
41 static void \
42 grub_mod_fini (void)
44 #ifdef APPLE_CC
45 #define GRUB_MOD_NAME(name) \
46 static char grub_modname[] __attribute__ ((section ("_modname, _modname"), used)) = #name;
48 #define GRUB_MOD_DEP(name) \
49 __asm__ (".section _moddeps, _moddeps\n.asciz \"" #name "\"\n")
50 #else
51 #define GRUB_MOD_NAME(name) \
52 __asm__ (".section .modname\n.asciz \"" #name "\"\n")
54 #define GRUB_MOD_DEP(name) \
55 __asm__ (".section .moddeps\n.asciz \"" #name "\"\n")
56 #endif
58 struct grub_dl_segment
60 struct grub_dl_segment *next;
61 void *addr;
62 grub_size_t size;
63 unsigned section;
65 typedef struct grub_dl_segment *grub_dl_segment_t;
67 struct grub_dl;
69 struct grub_dl_dep
71 struct grub_dl_dep *next;
72 struct grub_dl *mod;
74 typedef struct grub_dl_dep *grub_dl_dep_t;
76 struct grub_dl
78 char *name;
79 int ref_count;
80 grub_dl_dep_t dep;
81 grub_dl_segment_t segment;
82 Elf_Sym *symtab;
83 void (*init) (struct grub_dl *mod);
84 void (*fini) (void);
86 typedef struct grub_dl *grub_dl_t;
88 grub_err_t EXPORT_FUNC(grub_dl_check_header) (void *ehdr, grub_size_t size);
89 grub_dl_t EXPORT_FUNC(grub_dl_load_file) (const char *filename);
90 grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name);
91 grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
92 int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod);
93 void grub_dl_unload_unneeded (void);
94 void grub_dl_unload_all (void);
95 #ifdef GRUB_UTIL
96 static inline int
97 grub_dl_ref (grub_dl_t mod)
99 (void) mod;
100 return 0;
102 static inline int
103 grub_dl_unref (grub_dl_t mod)
105 (void) mod;
106 return 0;
108 #else
109 int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
110 int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
111 #endif
112 void EXPORT_FUNC(grub_dl_iterate) (int (*hook) (grub_dl_t mod));
113 grub_dl_t EXPORT_FUNC(grub_dl_get) (const char *name);
114 grub_err_t EXPORT_FUNC(grub_dl_register_symbol) (const char *name, void *addr,
115 grub_dl_t mod);
117 grub_err_t grub_arch_dl_check_header (void *ehdr);
118 grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr);
120 #endif /* ! GRUB_DL_H */