Module Name: src Committed By: pooka Date: Thu Sep 24 21:30:42 UTC 2009
Modified Files: src/sys/rump/include/rump: rumpuser.h src/sys/rump/librump/rumpkern: rump.c src/sys/rump/librump/rumpuser: Makefile Added Files: src/sys/rump/librump/rumpuser: rumpuser_dl.c Log Message: Load modules from all components which are linked into a rump binary with -lrumpcomponent. Previously only the first library component containing a module would get loaded automatically. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/sys/rump/include/rump/rumpuser.h cvs rdiff -u -r1.115 -r1.116 src/sys/rump/librump/rumpkern/rump.c cvs rdiff -u -r1.15 -r1.16 src/sys/rump/librump/rumpuser/Makefile cvs rdiff -u -r0 -r1.1 src/sys/rump/librump/rumpuser/rumpuser_dl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/rump/include/rump/rumpuser.h diff -u src/sys/rump/include/rump/rumpuser.h:1.26 src/sys/rump/include/rump/rumpuser.h:1.27 --- src/sys/rump/include/rump/rumpuser.h:1.26 Mon Sep 21 15:29:36 2009 +++ src/sys/rump/include/rump/rumpuser.h Thu Sep 24 21:30:42 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.h,v 1.26 2009/09/21 15:29:36 pooka Exp $ */ +/* $NetBSD: rumpuser.h,v 1.27 2009/09/24 21:30:42 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -185,4 +185,8 @@ enum rumpuser_getnametype, int *); int rumpuser_net_setsockopt(int, int, int, const void *, int, int *); +/* rumpuser dynloader */ + +void rumpuser_dl_module_bootstrap(void); + #endif /* _RUMP_RUMPUSER_H_ */ Index: src/sys/rump/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.115 src/sys/rump/librump/rumpkern/rump.c:1.116 --- src/sys/rump/librump/rumpkern/rump.c:1.115 Wed Sep 16 15:23:05 2009 +++ src/sys/rump/librump/rumpkern/rump.c Thu Sep 24 21:30:42 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.115 2009/09/16 15:23:05 pooka Exp $ */ +/* $NetBSD: rump.c,v 1.116 2009/09/24 21:30:42 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.115 2009/09/16 15:23:05 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.116 2009/09/24 21:30:42 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -284,6 +284,8 @@ vmem_rehash_start(); #endif + rumpuser_dl_module_bootstrap(); + return 0; } Index: src/sys/rump/librump/rumpuser/Makefile diff -u src/sys/rump/librump/rumpuser/Makefile:1.15 src/sys/rump/librump/rumpuser/Makefile:1.16 --- src/sys/rump/librump/rumpuser/Makefile:1.15 Wed Mar 25 14:05:03 2009 +++ src/sys/rump/librump/rumpuser/Makefile Thu Sep 24 21:30:42 2009 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.15 2009/03/25 14:05:03 pooka Exp $ +# $NetBSD: Makefile,v 1.16 2009/09/24 21:30:42 pooka Exp $ # LIB= rumpuser @@ -6,6 +6,7 @@ SRCS= rumpuser.c rumpuser_net.c SRCS+= rumpuser_pth.c +SRCS+= rumpuser_dl.c CPPFLAGS+= -D_REENTRANT Added files: Index: src/sys/rump/librump/rumpuser/rumpuser_dl.c diff -u /dev/null src/sys/rump/librump/rumpuser/rumpuser_dl.c:1.1 --- /dev/null Thu Sep 24 21:30:42 2009 +++ src/sys/rump/librump/rumpuser/rumpuser_dl.c Thu Sep 24 21:30:42 2009 @@ -0,0 +1,110 @@ +/* $NetBSD: rumpuser_dl.c,v 1.1 2009/09/24 21:30:42 pooka Exp $ */ + +/* + * 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. + */ + +/* + * Load all module link sets. Called during rump bootstrap. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: rumpuser_dl.c,v 1.1 2009/09/24 21:30:42 pooka Exp $"); + +#include <sys/types.h> +#include <sys/time.h> + +#include <assert.h> +#include <dlfcn.h> +#include <link_elf.h> +#include <stdio.h> +#include <string.h> + +#include <rump/rump.h> +#include <rump/rumpuser.h> + +#if defined(__NetBSD__) || defined(__FreeBSD__) \ + || (defined(__sun__) && defined(__svr4__)) +static void +process(const char *soname) +{ + void *handle; + struct modinfo **mi, **mi_end; + + if (strstr(soname, "librump") == NULL) + return; + + handle = dlopen(soname, RTLD_LAZY); + if (handle == NULL) + return; + + mi = dlsym(handle, "__start_link_set_modules"); + if (!mi) + return; + mi_end = dlsym(handle, "__stop_link_set_modules"); + if (!mi_end) + return; + + for (; mi < mi_end; mi++) + rump_module_init(*mi, NULL); + assert(mi == mi_end); + + dlclose(handle); +} + +/* + * Get the linkmap from the dynlinker. Try to load kernel modules + * from all objects in the linkmap. + */ +void +rumpuser_dl_module_bootstrap(void) +{ + struct link_map *map; + + if (dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map) == -1) { + fprintf(stderr, "warning: rumpuser module bootstrap " + "failed: %s\n", dlerror()); + return; + } + + /* + * Load starting from last object because of + * possible dependencies. + * XXX: not perfect. this could retry the list until no (or all) + * modules were be loaded? + */ + for (; map->l_next; map = map->l_next) + continue; + for (; map; map = map->l_prev) + process(map->l_name); +} +#else +void +rumpuser_dl_module_bootstrap(void) +{ + + fprintf(stderr, "Warning, dlinfo() unsupported on host?\n"); + fprintf(stderr, "module bootstrap unavailable\n"); +} +#endif