Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys In sysv_sem.c, defer establishment of exithook so we can...
details: https://anonhg.NetBSD.org/src/rev/f4483825fd01
branches: trunk
changeset: 811572:f4483825fd01
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Fri Nov 06 02:26:42 2015 +0000
description:
In sysv_sem.c, defer establishment of exithook so we can initialize the
module code from module_init() rather than waiting until after calling
exec_init(). Use a RUN_ONCE routine at entry to each sys_sem* syscall
to establish the exithook, and no longer KASSERT that the hook has
been set before removing it. (A manually loaded module can be unloaded
before any syscalls have been invoked.)
Remove the conditional calls to the various xxx_init() routines from
init_main.c - we now rely on module_init() to handle initialization.
Let each sub-component's xxx_init() routine handle its own sysctl
sub-tree initialization; this removes another set of #ifdef ugliness.
Tested both built-in and loadable versions and verified that atf
test kernel/t_sysv passes.
diffstat:
sys/kern/init_main.c | 28 +-------------------------
sys/kern/sysv_ipc.c | 54 +++++++++++++++++++++++----------------------------
sys/kern/sysv_msg.c | 13 ++++++++---
sys/kern/sysv_sem.c | 38 ++++++++++++++++++++++++++++-------
sys/kern/sysv_shm.c | 13 ++++++++---
sys/sys/msg.h | 4 +-
sys/sys/sem.h | 4 +-
sys/sys/shm.h | 4 +-
8 files changed, 80 insertions(+), 78 deletions(-)
diffs (truncated from 456 to 300 lines):
diff -r bddd08e78210 -r f4483825fd01 sys/kern/init_main.c
--- a/sys/kern/init_main.c Fri Nov 06 01:17:08 2015 +0000
+++ b/sys/kern/init_main.c Fri Nov 06 02:26:42 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init_main.c,v 1.472 2015/10/29 00:27:08 mrg Exp $ */
+/* $NetBSD: init_main.c,v 1.473 2015/11/06 02:26:42 pgoyette Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.472 2015/10/29 00:27:08 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.473 2015/11/06 02:26:42 pgoyette Exp $");
#include "opt_ddb.h"
#include "opt_ipsec.h"
@@ -179,15 +179,6 @@
#ifdef IPSEC
#include <netipsec/ipsec.h>
#endif
-#ifdef SYSVSHM
-#include <sys/shm.h>
-#endif
-#ifdef SYSVSEM
-#include <sys/sem.h>
-#endif
-#ifdef SYSVMSG
-#include <sys/msg.h>
-#endif
#include <sys/domain.h>
#include <sys/namei.h>
#include <sys/rnd.h>
@@ -525,26 +516,11 @@
kprintf_init_callout();
#endif
-#ifdef SYSVSHM
- /* Initialize System V style shared memory. */
- shminit();
-#endif
-
vmem_rehash_start(); /* must be before exec_init */
/* Initialize exec structures */
exec_init(1); /* seminit calls exithook_establish() */
-#ifdef SYSVSEM
- /* Initialize System V style semaphores. */
- seminit();
-#endif
-
-#ifdef SYSVMSG
- /* Initialize System V style message queues. */
- msginit();
-#endif
-
#if NVERIEXEC > 0
/*
* Initialise the Veriexec subsystem.
diff -r bddd08e78210 -r f4483825fd01 sys/kern/sysv_ipc.c
--- a/sys/kern/sysv_ipc.c Fri Nov 06 01:17:08 2015 +0000
+++ b/sys/kern/sysv_ipc.c Fri Nov 06 02:26:42 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysv_ipc.c,v 1.29 2015/11/06 01:00:41 pgoyette Exp $ */
+/* $NetBSD: sysv_ipc.c,v 1.30 2015/11/06 02:26:42 pgoyette Exp $ */
/*-
* Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_ipc.c,v 1.29 2015/11/06 01:00:41 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_ipc.c,v 1.30 2015/11/06 02:26:42 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "opt_sysv.h"
@@ -127,14 +127,9 @@
MODULE(MODULE_CLASS_EXEC, sysv_ipc, NULL);
-#ifdef _MODULE
SYSCTL_SETUP_PROTO(sysctl_ipc_setup);
-SYSCTL_SETUP_PROTO(sysctl_ipc_shm_setup);
-SYSCTL_SETUP_PROTO(sysctl_ipc_sem_setup);
-SYSCTL_SETUP_PROTO(sysctl_ipc_msg_setup);
static struct sysctllog *sysctl_sysvipc_clog = NULL;
-#endif
static const struct syscall_package sysvipc_syscalls[] = {
#ifdef SYSVSHM
@@ -165,35 +160,35 @@
switch (cmd) {
case MODULE_CMD_INIT:
+ /* Set up the kauth listener */
+ sysvipcinit();
+
+#ifdef _MODULE
+ /* Set up the common sysctl tree */
+ sysctl_ipc_setup(&sysctl_sysvipc_clog);
+#endif
+
/* Link the system calls */
error = syscall_establish(NULL, sysvipc_syscalls);
+ if (error)
+ sysvipcfini();
- /* Initialize all sysctl sub-trees */
-#ifdef _MODULE
- sysctl_ipc_setup(&sysctl_sysvipc_clog);
-#ifdef SYSVMSG
- sysctl_ipc_msg_setup(&sysctl_sysvipc_clog);
-#endif
-#ifdef SYSVSHM
- sysctl_ipc_shm_setup(&sysctl_sysvipc_clog);
-#endif
-#ifdef SYSVSEM
- sysctl_ipc_sem_setup(&sysctl_sysvipc_clog);
-#endif
/* Assume no compat sysctl routine for now */
kern_sysvipc50_sysctl_p = NULL;
- /* Initialize each sub-component */
+ /*
+ * Initialize each sub-component, including their
+ * sysctl data
+ */
#ifdef SYSVSHM
- shminit();
+ shminit(&sysctl_sysvipc_clog);
#endif
#ifdef SYSVSEM
- seminit();
+ seminit(&sysctl_sysvipc_clog);
#endif
#ifdef SYSVMSG
- msginit();
+ msginit(&sysctl_sysvipc_clog);
#endif
-#endif /* _MODULE */
break;
case MODULE_CMD_FINI:
/*
@@ -212,7 +207,7 @@
#ifdef SYSVSEM
if (semfini()) {
#ifdef SYSVSHM
- shminit();
+ shminit(NULL);
#endif
return EBUSY;
}
@@ -220,10 +215,10 @@
#ifdef SYSVMSG
if (msgfini()) {
#ifdef SYSVSEM
- seminit();
+ seminit(NULL);
#endif
#ifdef SYSVSHM
- shminit();
+ shminit(NULL);
#endif
return EBUSY;
}
@@ -237,7 +232,7 @@
#ifdef _MODULE
/* Remove the sysctl sub-trees */
sysctl_teardown(&sysctl_sysvipc_clog);
-#endif
+#endif
/* Remove the kauth listener */
sysvipcfini();
@@ -345,8 +340,7 @@
sysvipcinit(void)
{
- if (sysvipc_listener != NULL)
- return;
+ KASSERT(sysvipc_listener == NULL);
sysvipc_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM,
sysvipc_listener_cb, NULL);
diff -r bddd08e78210 -r f4483825fd01 sys/kern/sysv_msg.c
--- a/sys/kern/sysv_msg.c Fri Nov 06 01:17:08 2015 +0000
+++ b/sys/kern/sysv_msg.c Fri Nov 06 02:26:42 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysv_msg.c,v 1.69 2015/05/13 01:16:15 pgoyette Exp $ */
+/* $NetBSD: sysv_msg.c,v 1.70 2015/11/06 02:26:42 pgoyette Exp $ */
/*-
* Copyright (c) 1999, 2006, 2007 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_msg.c,v 1.69 2015/05/13 01:16:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_msg.c,v 1.70 2015/11/06 02:26:42 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "opt_sysv.h"
@@ -91,8 +91,10 @@
extern int kern_has_sysvmsg;
+SYSCTL_SETUP_PROTO(sysctl_ipc_msg_setup);
+
void
-msginit(void)
+msginit(struct sysctllog **clog)
{
int i, sz;
vaddr_t v;
@@ -161,7 +163,10 @@
kern_has_sysvmsg = 1;
- sysvipcinit();
+#ifdef _MODULE
+ if (clog)
+ sysctl_ipc_msg_setup(clog);
+#endif
}
int
diff -r bddd08e78210 -r f4483825fd01 sys/kern/sysv_sem.c
--- a/sys/kern/sysv_sem.c Fri Nov 06 01:17:08 2015 +0000
+++ b/sys/kern/sysv_sem.c Fri Nov 06 02:26:42 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysv_sem.c,v 1.94 2015/05/13 01:16:15 pgoyette Exp $ */
+/* $NetBSD: sysv_sem.c,v 1.95 2015/11/06 02:26:42 pgoyette Exp $ */
/*-
* Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_sem.c,v 1.94 2015/05/13 01:16:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_sem.c,v 1.95 2015/11/06 02:26:42 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "opt_sysv.h"
@@ -53,6 +53,7 @@
#include <sys/mount.h> /* XXX for <sys/syscallargs.h> */
#include <sys/syscallargs.h>
#include <sys/kauth.h>
+#include <sys/once.h>
/*
* Memory areas:
@@ -91,12 +92,17 @@
extern int kern_has_sysvsem;
+SYSCTL_SETUP_PROTO(sysctl_ipc_sem_setup);
+
struct sem_undo *semu_alloc(struct proc *);
int semundo_adjust(struct proc *, struct sem_undo **, int, int, int);
void semundo_clear(int, int);
+static ONCE_DECL(exithook_control);
+static int seminit_exithook(void);
+
void
-seminit(void)
+seminit(struct sysctllog **clog)
{
int i, sz;
vaddr_t v;
@@ -134,13 +140,21 @@
suptr->un_proc = NULL;
}
semu_list = NULL;
- hook = exithook_establish(semexit, NULL);
kern_has_sysvsem = 1;
- kern_has_sysvsem = 1;
+#ifdef _MODULE
+ if (clog)
+ sysctl_ipc_sem_setup(clog);
+#endif
+}
- sysvipcinit();
+static int
+seminit_exithook(void)
+{
+
+ hook = exithook_establish(semexit, NULL);
+ return 0;
}
int
Home |
Main Index |
Thread Index |
Old Index