/* dl.c - loadable module support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
/* Force native word size */
#include <config.h>
/* Platforms where modules are in a readonly area of memory. */
#if defined(GRUB_MACHINE_QEMU)
#define GRUB_MODULES_MACHINE_READONLY
#endif
#ifdef GRUB_MACHINE_EMU
#endif
static grub_err_t
{
return grub_error (GRUB_ERR_BAD_MODULE,
grub_dl_head = mod;
return GRUB_ERR_NONE;
}
static void
{
grub_dl_t *p, q;
for (p = &grub_dl_head, q = *p; q; p = &q->next, q = *p)
if (q == mod)
{
*p = q->next;
return;
}
}
{
grub_dl_t l;
for (l = grub_dl_head; l; l = l->next)
return l;
return 0;
}
struct grub_symbol
{
const char *name;
void *addr;
int isfunc;
};
/* The size of the symbol table. */
/* The symbol table (using an open-hash). */
/* Simple hash function. */
static unsigned
grub_symbol_hash (const char *s)
{
unsigned key = 0;
while (*s)
}
/* Resolve the symbol name NAME and return the address.
Return NULL, if not found. */
static grub_symbol_t
{
return sym;
return 0;
}
/* Register a symbol with the name NAME and the address ADDR. */
{
unsigned k;
if (! sym)
return grub_errno;
if (mod)
{
{
return grub_errno;
}
}
else
k = grub_symbol_hash (name);
grub_symtab[k] = sym;
return GRUB_ERR_NONE;
}
/* Unregister all the symbols defined in the module MOD. */
static void
{
unsigned i;
if (! mod)
grub_fatal ("core symbols cannot be unregistered");
for (i = 0; i < GRUB_SYMTAB_SIZE; i++)
{
{
{
*p = q;
}
else
}
}
}
/* Return the address of a section whose index is N. */
static void *
{
return 0;
}
/* Check if EHDR is a valid ELF header. */
static grub_err_t
{
/* Check the header size. */
/* Check the magic numbers. */
|| e->e_version != EV_CURRENT)
return GRUB_ERR_NONE;
}
/* Load all segments from memory specified by E. */
static grub_err_t
{
unsigned i;
Elf_Shdr *s;
#if defined (__ia64__) || defined (__powerpc__)
#endif
char *ptr;
i < e->e_shnum;
i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize))
{
if (talign < s->sh_addralign)
talign = s->sh_addralign;
}
#if defined (__ia64__) || defined (__powerpc__)
got *= sizeof (grub_uint64_t);
if (talign < GRUB_ARCH_DL_TRAMP_ALIGN)
if (talign < GRUB_ARCH_DL_GOT_ALIGN)
#endif
#ifdef GRUB_MACHINE_EMU
#endif
return grub_errno;
#ifdef GRUB_MACHINE_EMU
#endif
i < e->e_shnum;
i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize))
{
{
if (! seg)
return grub_errno;
if (s->sh_size)
{
void *addr;
switch (s->sh_type)
{
case SHT_PROGBITS:
break;
case SHT_NOBITS:
break;
}
}
else
}
}
#if defined (__ia64__) || defined (__powerpc__)
#endif
return GRUB_ERR_NONE;
}
static grub_err_t
{
unsigned i;
Elf_Shdr *s;
const char *str;
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
if (i == e->e_shnum)
#else
#endif
entsize = s->sh_entsize;
for (i = 0;
{
switch (type)
{
case STT_NOTYPE:
case STT_OBJECT:
/* Resolve a global symbol. */
{
if (! nsym)
return grub_error (GRUB_ERR_BAD_MODULE,
"symbol not found: `%s'", name);
}
else
{
return grub_errno;
}
break;
case STT_FUNC:
#ifdef __ia64__
{
/* FIXME: free descriptor once it's not used anymore. */
char **desc;
if (!desc)
return grub_errno;
}
#endif
return grub_errno;
break;
case STT_SECTION:
break;
case STT_FILE:
break;
default:
return grub_error (GRUB_ERR_BAD_MODULE,
"unknown symbol type `%d'", (int) type);
}
}
return GRUB_ERR_NONE;
}
static void
{
}
/* Me, Vladimir Serbinenko, hereby I add this module check as per new
GNU module policy. Note that this license check is informative only.
Modules have to be licensed under GPLv3 or GPLv3+ (optionally
multi-licensed under other licences as well) independently of the
presence of this check and solely by linking (module loading in GRUB
constitutes linking) and GRUB core being licensed under GPLv3+.
Be sure to understand your license obligations.
*/
static grub_err_t
{
Elf_Shdr *s;
const char *str;
unsigned i;
char *licensep = 0;
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
{
return GRUB_ERR_NONE;
}
return grub_error (GRUB_ERR_BAD_MODULE, "incompatible license (%s) for module %s", licensep ? : "(none present)", modname);
}
static grub_err_t
{
Elf_Shdr *s;
const char *str;
unsigned i;
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
{
return grub_errno;
break;
}
if (i == e->e_shnum)
return GRUB_ERR_NONE;
}
static grub_err_t
{
Elf_Shdr *s;
const char *str;
unsigned i;
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
{
{
grub_dl_t m;
m = grub_dl_load (name);
if (! m)
return grub_errno;
grub_dl_ref (m);
if (! dep)
return grub_errno;
}
}
return GRUB_ERR_NONE;
}
int
{
if (!mod)
return 0;
}
int
{
if (!mod)
return 0;
}
static void
{
}
/* Load a module from core memory. */
{
Elf_Ehdr *e;
(unsigned long) size);
e = addr;
if (grub_dl_check_header (e, size))
return 0;
{
return 0;
}
/* Make sure that every section is within the core. */
{
return 0;
}
if (! mod)
return 0;
/* Me, Vladimir Serbinenko, hereby I add this module check as per new
GNU module policy. Note that this license check is informative only.
Modules have to be licensed under GPLv3 or GPLv3+ (optionally
multi-licensed under other licences as well) independently of the
presence of this check and solely by linking (module loading in GRUB
constitutes linking) and GRUB core being licensed under GPLv3+.
Be sure to understand your license obligations.
*/
if (grub_dl_resolve_name (mod, e)
|| grub_dl_resolve_dependencies (mod, e)
|| grub_dl_load_segments (mod, e)
|| grub_dl_resolve_symbols (mod, e)
|| grub_arch_dl_relocate_symbols (mod, e))
{
return 0;
}
if (grub_dl_add (mod))
{
return 0;
}
return mod;
}
/* Load a module from the file FILENAME. */
{
void *core = 0;
if (! file)
return 0;
if (! core)
{
return 0;
}
{
return 0;
}
/* We must close this before we try to process dependencies.
Some disk backends do not handle gracefully multiple concurrent
opens of the same device. */
if (! mod)
return 0;
return mod;
}
/* Load a module using a symbolic name. */
{
char *filename;
if (mod)
return mod;
if (! grub_dl_dir) {
return 0;
}
if (! filename)
return 0;
if (! mod)
return 0;
return mod;
}
/* Unload the module MOD. */
int
{
return 0;
{
}
#endif
return 1;
}
/* Unload unneeded modules. */
void
grub_dl_unload_unneeded (void)
{
/* Because grub_dl_remove modifies the list of modules, this
implementation is tricky. */
grub_dl_t p = grub_dl_head;
while (p)
{
if (grub_dl_unload (p))
{
p = grub_dl_head;
continue;
}
p = p->next;
}
}