From a38686d5023d3624e24ad022d13fcbaae8ba2973 Mon Sep 17 00:00:00 2001 From: pooka Date: Sun, 4 Jan 2015 22:11:40 +0000 Subject: [PATCH] Extend RUMP_USE_CTOR to SYSCTL_SETUP(), similar to what is already done in MODULE(). The sysctl tree nodes from all components which were loaded when rump_init() was called now get created -- mimics the monolithic kernel. No change to the monolithic kernel. --- sys/rump/librump/rumpkern/rump.c | 30 +++++++++++++++++++++++++---- sys/sys/sysctl.h | 33 +++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/sys/rump/librump/rumpkern/rump.c b/sys/rump/librump/rumpkern/rump.c index f7df5a722b9b..3be7f69ae029 100644 --- a/sys/rump/librump/rumpkern/rump.c +++ b/sys/rump/librump/rumpkern/rump.c @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.313 2015/01/03 17:23:51 pooka Exp $ */ +/* $NetBSD: rump.c,v 1.314 2015/01/04 22:11:40 pooka Exp $ */ /* * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.313 2015/01/03 17:23:51 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.314 2015/01/04 22:11:40 pooka Exp $"); #include #define ELFSIZE ARCH_ELFSIZE @@ -182,7 +182,15 @@ rump_daemonize_done(int error) return rumpuser_daemonize_done(error); } -#ifndef RUMP_USE_CTOR +#ifdef RUMP_USE_CTOR + +/* sysctl bootstrap handling */ +struct sysctl_boot_chain sysctl_boot_chain \ + = LIST_HEAD_INITIALIZER(sysctl_boot_chain); +__link_set_add_text(sysctl_funcs,voidop); /* ensure linkset is non-empty */ + +#else /* RUMP_USE_CTOR */ + RUMP_COMPONENT(RUMP_COMPONENT_POSTINIT) { __link_set_decl(rump_components, struct rump_component); @@ -194,7 +202,8 @@ RUMP_COMPONENT(RUMP_COMPONENT_POSTINIT) asm("" :: "r"(__start_link_set_rump_components)); asm("" :: "r"(__stop_link_set_rump_components)); } -#endif + +#endif /* RUMP_USE_CTOR */ int rump_init(void) @@ -284,6 +293,19 @@ rump_init(void) secmodel_init(); sysctl_init(); + /* + * The above call to sysctl_init() only initializes sysctl nodes + * from link sets. Initialize sysctls in case we used ctors. + */ +#ifdef RUMP_USE_CTOR + { + struct sysctl_setup_chain *ssc; + + LIST_FOREACH(ssc, &sysctl_boot_chain, ssc_entries) { + ssc->ssc_func(NULL); + } + } +#endif /* RUMP_USE_CTOR */ rnd_init(); cprng_init(); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 347c90419e5d..7694d09842d5 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $NetBSD: sysctl.h,v 1.214 2014/09/05 05:42:50 matt Exp $ */ +/* $NetBSD: sysctl.h,v 1.215 2015/01/04 22:11:40 pooka Exp $ */ /* * Copyright (c) 1989, 1993 @@ -1087,6 +1087,29 @@ extern struct ctldebug debug15, debug16, debug17, debug18, debug19; oldlenp, newp, newlen, \ oname, l, node +#ifdef RUMP_USE_CTOR +struct sysctl_setup_chain { + void (*ssc_func)(struct sysctllog **); + LIST_ENTRY(sysctl_setup_chain) ssc_entries; +}; +LIST_HEAD(sysctl_boot_chain, sysctl_setup_chain); +#define _SYSCTL_REGISTER(name) \ +static void sysctlctor_##name(void) __attribute__((constructor)); \ +static void sysctlctor_##name(void) \ +{ \ + static struct sysctl_setup_chain ssc = { \ + .ssc_func = name, \ + }; \ + extern struct sysctl_boot_chain sysctl_boot_chain; \ + LIST_INSERT_HEAD(&sysctl_boot_chain, &ssc, ssc_entries); \ +} + +#else /* RUMP_USE_CTOR */ + +#define _SYSCTL_REGISTER(name) __link_set_add_text(sysctl_funcs, name); + +#endif /* RUMP_USE_CTOR */ + #ifdef _MODULE #define SYSCTL_SETUP_PROTO(name) \ @@ -1098,12 +1121,12 @@ extern struct ctldebug debug15, debug16, debug17, debug18, debug19; void name(struct sysctllog **clog) { \ printf("%s\n", desc); \ __CONCAT(___,name)(clog); } \ - __link_set_add_text(sysctl_funcs, name); \ + _SYSCTL_REGISTER(name); \ static void __CONCAT(___,name)(struct sysctllog **clog) #else /* !SYSCTL_DEBUG_SETUP */ #define SYSCTL_SETUP(name, desc) \ SYSCTL_SETUP_PROTO(name); \ - __link_set_add_text(sysctl_funcs, name); \ + _SYSCTL_REGISTER(name); \ void name(struct sysctllog **clog) #endif /* !SYSCTL_DEBUG_SETUP */ @@ -1116,12 +1139,12 @@ extern struct ctldebug debug15, debug16, debug17, debug18, debug19; static void name(struct sysctllog **clog) { \ printf("%s\n", desc); \ __CONCAT(___,name)(clog); } \ - __link_set_add_text(sysctl_funcs, name); \ + _SYSCTL_REGISTER(name); \ static void __CONCAT(___,name)(struct sysctllog **clog) #else /* !SYSCTL_DEBUG_SETUP */ #define SYSCTL_SETUP(name, desc) \ static void name(struct sysctllog **); \ - __link_set_add_text(sysctl_funcs, name); \ + _SYSCTL_REGISTER(name); \ static void name(struct sysctllog **clog) #endif /* !SYSCTL_DEBUG_SETUP */