Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump Load modules from all components which are linked i...
details: https://anonhg.NetBSD.org/src/rev/0819fe1ad731
branches: trunk
changeset: 747622:0819fe1ad731
user: pooka <pooka%NetBSD.org@localhost>
date: Thu Sep 24 21:30:42 2009 +0000
description:
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.
diffstat:
sys/rump/include/rump/rumpuser.h | 6 +-
sys/rump/librump/rumpkern/rump.c | 6 +-
sys/rump/librump/rumpuser/Makefile | 3 +-
sys/rump/librump/rumpuser/rumpuser_dl.c | 110 ++++++++++++++++++++++++++++++++
4 files changed, 121 insertions(+), 4 deletions(-)
diffs (176 lines):
diff -r 088b8fe55cac -r 0819fe1ad731 sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h Thu Sep 24 21:21:33 2009 +0000
+++ b/sys/rump/include/rump/rumpuser.h Thu Sep 24 21:30:42 2009 +0000
@@ -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_ */
diff -r 088b8fe55cac -r 0819fe1ad731 sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c Thu Sep 24 21:21:33 2009 +0000
+++ b/sys/rump/librump/rumpkern/rump.c Thu Sep 24 21:30:42 2009 +0000
@@ -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;
}
diff -r 088b8fe55cac -r 0819fe1ad731 sys/rump/librump/rumpuser/Makefile
--- a/sys/rump/librump/rumpuser/Makefile Thu Sep 24 21:21:33 2009 +0000
+++ b/sys/rump/librump/rumpuser/Makefile Thu Sep 24 21:30:42 2009 +0000
@@ -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
diff -r 088b8fe55cac -r 0819fe1ad731 sys/rump/librump/rumpuser/rumpuser_dl.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/librump/rumpuser/rumpuser_dl.c Thu Sep 24 21:30:42 2009 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index