2012-07-27 13:09:05 +04:00
|
|
|
/* $NetBSD: rumpuser_dl.c,v 1.8 2012/07/27 09:09:05 pooka Exp $ */
|
2009-09-25 01:30:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2009-11-26 12:50:38 +03:00
|
|
|
* Load all module link sets and feed symbol table to the kernel.
|
|
|
|
* Called during rump bootstrap.
|
2009-09-25 01:30:42 +04:00
|
|
|
*/
|
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
#include "rumpuser_port.h"
|
|
|
|
|
|
|
|
#if !defined(lint)
|
|
|
|
__RCSID("$NetBSD: rumpuser_dl.c,v 1.8 2012/07/27 09:09:05 pooka Exp $");
|
|
|
|
#endif /* !lint */
|
2009-09-25 01:30:42 +04:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <assert.h>
|
2012-07-27 13:09:05 +04:00
|
|
|
|
2009-09-25 01:30:42 +04:00
|
|
|
#include <dlfcn.h>
|
2009-11-26 12:50:38 +03:00
|
|
|
#include <elf.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2009-11-23 17:39:35 +03:00
|
|
|
#include <link.h>
|
2009-09-25 01:30:42 +04:00
|
|
|
#include <stdio.h>
|
2009-11-26 12:50:38 +03:00
|
|
|
#include <stdlib.h>
|
2009-09-25 01:30:42 +04:00
|
|
|
#include <string.h>
|
2009-11-26 12:50:38 +03:00
|
|
|
#include <unistd.h>
|
2009-09-25 01:30:42 +04:00
|
|
|
|
|
|
|
#include <rump/rumpuser.h>
|
|
|
|
|
2009-11-23 17:39:35 +03:00
|
|
|
#if defined(__ELF__) && (defined(__NetBSD__) || defined(__FreeBSD__) \
|
2012-07-27 13:09:05 +04:00
|
|
|
|| (defined(__sun__) && defined(__svr4__))) || defined(__linux__)
|
2009-11-26 12:50:38 +03:00
|
|
|
static size_t symtabsize = 0, strtabsize = 0;
|
|
|
|
static size_t symtaboff = 0, strtaboff = 0;
|
|
|
|
static uint8_t *symtab = NULL;
|
|
|
|
static char *strtab = NULL;
|
|
|
|
static unsigned char eident;
|
|
|
|
|
2011-03-23 01:27:33 +03:00
|
|
|
/* nb5 compat */
|
|
|
|
#ifndef Elf_Symindx
|
|
|
|
#define Elf_Symindx uint32_t
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
/*
|
|
|
|
* Linux ld.so requires a valid handle for dlinfo(), so use the main
|
|
|
|
* handle. We initialize this variable in rumpuser_dl_bootstrap()
|
|
|
|
*/
|
|
|
|
static void *mainhandle;
|
|
|
|
|
2009-11-26 12:50:38 +03:00
|
|
|
static void *
|
|
|
|
reservespace(void *store, size_t *storesize,
|
2009-11-26 13:57:26 +03:00
|
|
|
size_t storeoff, size_t required)
|
2009-11-26 12:50:38 +03:00
|
|
|
{
|
|
|
|
size_t chunk, newsize;
|
|
|
|
|
|
|
|
assert(storeoff <= *storesize);
|
|
|
|
chunk = *storesize - storeoff;
|
|
|
|
|
|
|
|
if (chunk >= required)
|
|
|
|
return store;
|
|
|
|
|
|
|
|
newsize = *storesize + ((size_t)required - chunk);
|
|
|
|
store = realloc(store, newsize);
|
|
|
|
if (store == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*((uint8_t *)store + storeoff) = '\0';
|
|
|
|
*storesize = newsize;
|
|
|
|
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros to make handling elf32/64 in the code a little saner.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DYNn_GETMEMBER(base, n, thevar, result) \
|
|
|
|
do { \
|
|
|
|
if (eident == ELFCLASS32) { \
|
|
|
|
Elf32_Dyn *dyn = base; \
|
|
|
|
/*LINTED*/ \
|
|
|
|
result = dyn[n].thevar; \
|
|
|
|
} else { \
|
|
|
|
Elf64_Dyn *dyn = base; \
|
|
|
|
/*LINTED*/ \
|
|
|
|
result = dyn[n].thevar; \
|
|
|
|
} \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
|
|
|
#define SYMn_GETMEMBER(base, n, thevar, result) \
|
|
|
|
do { \
|
|
|
|
if (eident == ELFCLASS32) { \
|
2010-06-08 19:32:55 +04:00
|
|
|
const Elf32_Sym *sym = base; \
|
2009-11-26 12:50:38 +03:00
|
|
|
/*LINTED*/ \
|
|
|
|
result = sym[n].thevar; \
|
|
|
|
} else { \
|
2010-06-08 19:32:55 +04:00
|
|
|
const Elf64_Sym *sym = base; \
|
2009-11-26 12:50:38 +03:00
|
|
|
/*LINTED*/ \
|
|
|
|
result = sym[n].thevar; \
|
|
|
|
} \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
|
|
|
#define SYMn_SETMEMBER(base, n, thevar, value) \
|
|
|
|
do { \
|
|
|
|
if (eident == ELFCLASS32) { \
|
|
|
|
Elf32_Sym *sym = base; \
|
|
|
|
/*LINTED*/ \
|
|
|
|
sym[n].thevar = value; \
|
|
|
|
} else { \
|
|
|
|
Elf64_Sym *sym = base; \
|
|
|
|
/*LINTED*/ \
|
|
|
|
sym[n].thevar = value; \
|
|
|
|
} \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
|
|
|
#define SYM_GETSIZE() ((eident==ELFCLASS32)?sizeof(Elf32_Sym):sizeof(Elf64_Sym))
|
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
/*
|
|
|
|
* On NetBSD, the dynamic section pointer values seem to be relative to
|
|
|
|
* the address the dso is mapped at. On Linux, they seem to contain
|
|
|
|
* the absolute address. I couldn't find anything definite from a quick
|
|
|
|
* read of the standard and therefore I will not go and figure beyond ifdef.
|
|
|
|
*/
|
|
|
|
#ifdef __linux__
|
|
|
|
#define adjptr(_map_, _ptr_) ((void *)(_ptr_))
|
|
|
|
#else
|
|
|
|
#define adjptr(_map_, _ptr_) ((void *)(_map_->l_addr + (_ptr_)))
|
|
|
|
#endif
|
|
|
|
|
2009-11-26 12:50:38 +03:00
|
|
|
static int
|
|
|
|
getsymbols(struct link_map *map)
|
|
|
|
{
|
|
|
|
char *str_base;
|
|
|
|
void *syms_base = NULL; /* XXXgcc */
|
2010-06-08 19:32:55 +04:00
|
|
|
size_t curstrsize;
|
2009-11-26 12:50:38 +03:00
|
|
|
void *ed_base;
|
|
|
|
uint64_t ed_tag;
|
2010-06-08 19:32:55 +04:00
|
|
|
size_t cursymcount;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if (map->l_addr) {
|
2012-07-27 13:09:05 +04:00
|
|
|
if (memcmp((void *)map->l_addr, ELFMAG, SELFMAG) != 0)
|
2010-06-08 19:32:55 +04:00
|
|
|
return ENOEXEC;
|
|
|
|
eident = *(unsigned char *)(map->l_addr + EI_CLASS);
|
|
|
|
if (eident != ELFCLASS32 && eident != ELFCLASS64)
|
|
|
|
return ENOEXEC;
|
2009-11-26 12:50:38 +03:00
|
|
|
}
|
|
|
|
|
2010-06-08 19:32:55 +04:00
|
|
|
/*
|
|
|
|
* ok, we probably have only the main object. instead of going
|
|
|
|
* to disk and reading the ehdr, just try to guess the size.
|
|
|
|
*/
|
|
|
|
if (eident == 0) {
|
|
|
|
if (/*CONSTCOND*/sizeof(void *) == 4)
|
|
|
|
eident = ELFCLASS32;
|
|
|
|
else
|
|
|
|
eident = ELFCLASS64;
|
2009-11-26 12:50:38 +03:00
|
|
|
}
|
|
|
|
|
2010-06-08 19:32:55 +04:00
|
|
|
/*
|
|
|
|
* Find symtab and strtab and their sizes.
|
|
|
|
*/
|
2009-11-26 12:50:38 +03:00
|
|
|
str_base = NULL;
|
2010-06-08 19:32:55 +04:00
|
|
|
curstrsize = 0;
|
|
|
|
cursymcount = 0;
|
2009-11-26 12:50:38 +03:00
|
|
|
ed_base = map->l_ld;
|
2010-06-08 19:32:55 +04:00
|
|
|
DYNn_GETMEMBER(ed_base, 0, d_tag, ed_tag);
|
|
|
|
for (i = 0; ed_tag != DT_NULL;) {
|
2009-11-26 12:50:38 +03:00
|
|
|
uintptr_t edptr;
|
2009-11-26 13:57:26 +03:00
|
|
|
size_t edval;
|
2011-03-16 14:44:01 +03:00
|
|
|
Elf_Symindx *hashtab;
|
2009-11-26 12:50:38 +03:00
|
|
|
|
|
|
|
switch (ed_tag) {
|
|
|
|
case DT_SYMTAB:
|
|
|
|
DYNn_GETMEMBER(ed_base, i, d_un.d_ptr, edptr);
|
2012-07-27 13:09:05 +04:00
|
|
|
syms_base = adjptr(map, edptr);
|
2009-11-26 12:50:38 +03:00
|
|
|
break;
|
|
|
|
case DT_STRTAB:
|
|
|
|
DYNn_GETMEMBER(ed_base, i, d_un.d_ptr, edptr);
|
2012-07-27 13:09:05 +04:00
|
|
|
str_base = adjptr(map, edptr);
|
2009-11-26 12:50:38 +03:00
|
|
|
break;
|
|
|
|
case DT_STRSZ:
|
|
|
|
DYNn_GETMEMBER(ed_base, i, d_un.d_val, edval);
|
|
|
|
curstrsize = edval;
|
|
|
|
break;
|
2010-06-08 19:32:55 +04:00
|
|
|
case DT_HASH:
|
|
|
|
DYNn_GETMEMBER(ed_base, i, d_un.d_ptr, edptr);
|
2012-07-27 13:09:05 +04:00
|
|
|
hashtab = (Elf_Symindx *)adjptr(map, edptr);
|
2011-03-16 14:44:01 +03:00
|
|
|
cursymcount = hashtab[1];
|
2010-06-08 19:32:55 +04:00
|
|
|
break;
|
|
|
|
case DT_SYMENT:
|
|
|
|
DYNn_GETMEMBER(ed_base, i, d_un.d_val, edval);
|
|
|
|
assert(edval == SYM_GETSIZE());
|
|
|
|
break;
|
2009-11-26 12:50:38 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
DYNn_GETMEMBER(ed_base, i, d_tag, ed_tag);
|
2010-06-08 19:32:55 +04:00
|
|
|
}
|
2009-11-26 12:50:38 +03:00
|
|
|
|
2010-06-08 19:32:55 +04:00
|
|
|
if (str_base == NULL || syms_base == NULL ||
|
|
|
|
curstrsize == 0 || cursymcount == 0) {
|
|
|
|
fprintf(stderr, "could not find strtab, symtab or their sizes "
|
2009-11-26 12:50:38 +03:00
|
|
|
"in %s\n", map->l_name);
|
|
|
|
return ENOEXEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we have enough space for the contents of the symbol
|
|
|
|
* and string tables we are currently processing. The total used
|
|
|
|
* space will be smaller due to undefined symbols we are not
|
|
|
|
* interested in.
|
|
|
|
*/
|
2010-06-08 19:32:55 +04:00
|
|
|
symtab = reservespace(symtab, &symtabsize,
|
|
|
|
symtaboff, cursymcount * SYM_GETSIZE());
|
2009-11-26 12:50:38 +03:00
|
|
|
strtab = reservespace(strtab, &strtabsize, strtaboff, curstrsize);
|
|
|
|
if (symtab == NULL || strtab == NULL) {
|
|
|
|
fprintf(stderr, "failed to reserve memory");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iterate over all symbols in current symtab */
|
2010-06-08 19:32:55 +04:00
|
|
|
for (i = 0; i < cursymcount; i++) {
|
|
|
|
const char *cursymname;
|
2009-11-26 12:50:38 +03:00
|
|
|
int shndx, name;
|
|
|
|
uintptr_t value;
|
|
|
|
void *csym;
|
|
|
|
|
|
|
|
SYMn_GETMEMBER(syms_base, i, st_shndx, shndx);
|
|
|
|
SYMn_GETMEMBER(syms_base, i, st_value, value);
|
|
|
|
if (shndx == SHN_UNDEF || value == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* get symbol name */
|
|
|
|
SYMn_GETMEMBER(syms_base, i, st_name, name);
|
|
|
|
cursymname = name + str_base;
|
2010-06-08 19:32:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only accept symbols which are decidedly in
|
|
|
|
* the rump kernel namespace.
|
|
|
|
* XXX: quirks, but they wouldn't matter here
|
|
|
|
*/
|
|
|
|
if (strncmp(cursymname, "rump", 4) != 0 &&
|
|
|
|
strncmp(cursymname, "RUMP", 4) != 0 &&
|
|
|
|
strncmp(cursymname, "__", 2) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-11-26 12:50:38 +03:00
|
|
|
memcpy(symtab + symtaboff,
|
2010-06-08 19:32:55 +04:00
|
|
|
(const uint8_t *)syms_base + i*SYM_GETSIZE(),SYM_GETSIZE());
|
2009-11-26 12:50:38 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* set name to point at new strtab, offset symbol value
|
|
|
|
* with lib base address.
|
|
|
|
*/
|
|
|
|
csym = symtab + symtaboff;
|
|
|
|
SYMn_SETMEMBER(csym, 0, st_name, strtaboff);
|
|
|
|
SYMn_GETMEMBER(csym, 0, st_value, value);
|
|
|
|
SYMn_SETMEMBER(csym, 0, st_value,(intptr_t)(value+map->l_addr));
|
|
|
|
symtaboff += SYM_GETSIZE();
|
|
|
|
|
|
|
|
strcpy(strtab + strtaboff, cursymname);
|
|
|
|
strtaboff += strlen(cursymname)+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-05 21:47:49 +03:00
|
|
|
static void
|
2009-10-24 15:36:59 +04:00
|
|
|
process(const char *soname, rump_modinit_fn domodinit)
|
2009-09-25 01:30:42 +04:00
|
|
|
{
|
|
|
|
void *handle;
|
2010-03-05 21:47:49 +03:00
|
|
|
const struct modinfo *const *mi_start, *const *mi_end;
|
2009-09-25 01:30:42 +04:00
|
|
|
|
|
|
|
if (strstr(soname, "librump") == NULL)
|
2010-03-05 21:47:49 +03:00
|
|
|
return;
|
2009-09-25 01:30:42 +04:00
|
|
|
|
|
|
|
handle = dlopen(soname, RTLD_LAZY);
|
|
|
|
if (handle == NULL)
|
2010-03-05 21:47:49 +03:00
|
|
|
return;
|
2009-09-25 01:30:42 +04:00
|
|
|
|
2010-03-05 21:47:49 +03:00
|
|
|
mi_start = dlsym(handle, "__start_link_set_modules");
|
|
|
|
if (!mi_start)
|
2009-10-08 04:34:54 +04:00
|
|
|
goto out;
|
2009-09-25 01:30:42 +04:00
|
|
|
mi_end = dlsym(handle, "__stop_link_set_modules");
|
|
|
|
if (!mi_end)
|
2009-10-08 04:34:54 +04:00
|
|
|
goto out;
|
2009-09-25 01:30:42 +04:00
|
|
|
|
2010-03-05 21:47:49 +03:00
|
|
|
domodinit(mi_start, (size_t)(mi_end-mi_start));
|
2009-09-25 01:30:42 +04:00
|
|
|
|
2009-10-08 04:34:54 +04:00
|
|
|
out:
|
2009-09-25 01:30:42 +04:00
|
|
|
dlclose(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the linkmap from the dynlinker. Try to load kernel modules
|
|
|
|
* from all objects in the linkmap.
|
|
|
|
*/
|
|
|
|
void
|
2010-02-26 18:23:20 +03:00
|
|
|
rumpuser_dl_bootstrap(rump_modinit_fn domodinit,
|
2009-11-26 12:50:38 +03:00
|
|
|
rump_symload_fn symload)
|
2009-09-25 01:30:42 +04:00
|
|
|
{
|
2009-11-05 17:13:03 +03:00
|
|
|
struct link_map *map, *origmap;
|
2009-11-26 12:50:38 +03:00
|
|
|
int error;
|
2009-09-25 01:30:42 +04:00
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
mainhandle = dlopen(NULL, RTLD_NOW);
|
|
|
|
if (dlinfo(mainhandle, RTLD_DI_LINKMAP, &origmap) == -1) {
|
2009-09-25 01:30:42 +04:00
|
|
|
fprintf(stderr, "warning: rumpuser module bootstrap "
|
|
|
|
"failed: %s\n", dlerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
2009-11-05 17:13:03 +03:00
|
|
|
* Process last->first because that's the most probable
|
|
|
|
* order for dependencies
|
2009-09-25 01:30:42 +04:00
|
|
|
*/
|
2009-11-05 17:13:03 +03:00
|
|
|
for (; origmap->l_next; origmap = origmap->l_next)
|
2009-09-25 01:30:42 +04:00
|
|
|
continue;
|
2009-11-05 17:13:03 +03:00
|
|
|
|
2009-11-26 12:50:38 +03:00
|
|
|
/*
|
|
|
|
* Build symbol table to hand to the rump kernel. Do this by
|
|
|
|
* iterating over all rump libraries and collecting symbol
|
|
|
|
* addresses and relocation info.
|
|
|
|
*/
|
|
|
|
error = 0;
|
|
|
|
for (map = origmap; map && !error; map = map->l_prev) {
|
|
|
|
if (strstr(map->l_name, "librump") != NULL)
|
|
|
|
error = getsymbols(map);
|
2010-06-08 19:32:55 +04:00
|
|
|
/* this should be the main object */
|
2012-07-27 13:09:05 +04:00
|
|
|
else if (!map->l_addr && map->l_prev == NULL)
|
2010-06-08 19:32:55 +04:00
|
|
|
error = getsymbols(map);
|
2009-11-26 12:50:38 +03:00
|
|
|
}
|
2009-11-26 18:44:26 +03:00
|
|
|
|
|
|
|
if (error == 0) {
|
|
|
|
void *trimmedsym, *trimmedstr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate optimum-sized memory for storing tables
|
|
|
|
* and feed to kernel. If memory allocation fails,
|
|
|
|
* just give the ones with extra context (although
|
|
|
|
* I'm pretty sure we'll die moments later due to
|
|
|
|
* memory running out).
|
|
|
|
*/
|
|
|
|
if ((trimmedsym = malloc(symtaboff)) != NULL) {
|
|
|
|
memcpy(trimmedsym, symtab, symtaboff);
|
|
|
|
} else {
|
|
|
|
trimmedsym = symtab;
|
|
|
|
symtab = NULL;
|
|
|
|
}
|
|
|
|
if ((trimmedstr = malloc(strtaboff)) != NULL) {
|
|
|
|
memcpy(trimmedstr, strtab, strtaboff);
|
|
|
|
} else {
|
|
|
|
trimmedstr = strtab;
|
|
|
|
strtab = NULL;
|
|
|
|
}
|
|
|
|
symload(trimmedsym, symtaboff, trimmedstr, strtaboff);
|
|
|
|
}
|
|
|
|
free(symtab);
|
|
|
|
free(strtab);
|
2009-11-26 12:50:38 +03:00
|
|
|
|
2009-12-07 20:38:16 +03:00
|
|
|
/*
|
|
|
|
* Next, load modules from dynlibs.
|
|
|
|
*/
|
2010-03-05 21:47:49 +03:00
|
|
|
for (map = origmap; map; map = map->l_prev)
|
|
|
|
process(map->l_name, domodinit);
|
2009-09-25 01:30:42 +04:00
|
|
|
}
|
2010-03-01 16:12:19 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_dl_component_init(int type, rump_component_init_fn compinit)
|
|
|
|
{
|
|
|
|
struct link_map *map;
|
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
if (dlinfo(mainhandle, RTLD_DI_LINKMAP, &map) == -1) {
|
2010-03-01 16:12:19 +03:00
|
|
|
fprintf(stderr, "warning: rumpuser module bootstrap "
|
|
|
|
"failed: %s\n", dlerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; map->l_next; map = map->l_next)
|
|
|
|
continue;
|
|
|
|
for (; map; map = map->l_prev) {
|
|
|
|
if (strstr(map->l_name, "librump") != NULL) {
|
|
|
|
void *handle;
|
|
|
|
struct rump_component **rc, **rc_end;
|
|
|
|
|
|
|
|
handle = dlopen(map->l_name, RTLD_LAZY);
|
|
|
|
if (handle == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rc = dlsym(handle,
|
|
|
|
"__start_link_set_rump_components");
|
|
|
|
if (!rc)
|
|
|
|
goto loop;
|
|
|
|
rc_end = dlsym(handle,
|
|
|
|
"__stop_link_set_rump_components");
|
|
|
|
if (!rc_end)
|
|
|
|
goto loop;
|
|
|
|
|
|
|
|
for (; rc < rc_end; rc++)
|
|
|
|
compinit(*rc, type);
|
|
|
|
assert(rc == rc_end);
|
|
|
|
loop:
|
|
|
|
dlclose(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-25 01:30:42 +04:00
|
|
|
#else
|
|
|
|
void
|
2010-02-26 18:23:20 +03:00
|
|
|
rumpuser_dl_bootstrap(rump_modinit_fn domodinit,
|
2009-12-08 11:12:49 +03:00
|
|
|
rump_symload_fn symload)
|
2009-09-25 01:30:42 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "Warning, dlinfo() unsupported on host?\n");
|
|
|
|
}
|
2010-03-01 16:12:19 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_dl_component_init(int type, rump_component_init_fn compinit)
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "Warning, dlinfo() unsupported on host?\n");
|
|
|
|
}
|
2009-09-25 01:30:42 +04:00
|
|
|
#endif
|
2010-12-30 18:47:30 +03:00
|
|
|
|
|
|
|
void *
|
|
|
|
rumpuser_dl_globalsym(const char *symname)
|
|
|
|
{
|
|
|
|
|
|
|
|
return dlsym(RTLD_DEFAULT, symname);
|
|
|
|
}
|