Sun Aug 7 20:44:39 2022 UTC ()
module(9): Call callbacks in topological order on load.

They are called in reverse topological order on unload.

dtrace_sdt will rely on this soon to ensure provider definitions are
processed before their uses.

ok chs@


(riastradh)
diff -r1.154 -r1.155 src/sys/kern/kern_module.c

cvs diff -r1.154 -r1.155 src/sys/kern/kern_module.c (expand / switch to unified diff)

--- src/sys/kern/kern_module.c 2022/05/07 04:30:41 1.154
+++ src/sys/kern/kern_module.c 2022/08/07 20:44:39 1.155
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_module.c,v 1.154 2022/05/07 04:30:41 rin Exp $ */ 1/* $NetBSD: kern_module.c,v 1.155 2022/08/07 20:44:39 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software developed for The NetBSD Foundation 7 * This code is derived from software developed for The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Kernel module support. 33 * Kernel module support.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.154 2022/05/07 04:30:41 rin Exp $"); 37__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.155 2022/08/07 20:44:39 riastradh Exp $");
38 38
39#define _MODULE_INTERNAL 39#define _MODULE_INTERNAL
40 40
41#ifdef _KERNEL_OPT 41#ifdef _KERNEL_OPT
42#include "opt_ddb.h" 42#include "opt_ddb.h"
43#include "opt_modular.h" 43#include "opt_modular.h"
44#endif 44#endif
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/systm.h> 47#include <sys/systm.h>
48#include <sys/kernel.h> 48#include <sys/kernel.h>
49#include <sys/proc.h> 49#include <sys/proc.h>
50#include <sys/lwp.h> 50#include <sys/lwp.h>
@@ -1879,27 +1879,27 @@ module_setspecific(module_t *mod, specif @@ -1879,27 +1879,27 @@ module_setspecific(module_t *mod, specif
1879void * 1879void *
1880module_register_callbacks(void (*load)(struct module *), 1880module_register_callbacks(void (*load)(struct module *),
1881 void (*unload)(struct module *)) 1881 void (*unload)(struct module *))
1882{ 1882{
1883 struct module_callbacks *modcb; 1883 struct module_callbacks *modcb;
1884 struct module *mod; 1884 struct module *mod;
1885 1885
1886 modcb = kmem_alloc(sizeof(*modcb), KM_SLEEP); 1886 modcb = kmem_alloc(sizeof(*modcb), KM_SLEEP);
1887 modcb->modcb_load = load; 1887 modcb->modcb_load = load;
1888 modcb->modcb_unload = unload; 1888 modcb->modcb_unload = unload;
1889 1889
1890 kernconfig_lock(); 1890 kernconfig_lock();
1891 TAILQ_INSERT_TAIL(&modcblist, modcb, modcb_list); 1891 TAILQ_INSERT_TAIL(&modcblist, modcb, modcb_list);
1892 TAILQ_FOREACH(mod, &module_list, mod_chain) 1892 TAILQ_FOREACH_REVERSE(mod, &module_list, modlist, mod_chain)
1893 load(mod); 1893 load(mod);
1894 kernconfig_unlock(); 1894 kernconfig_unlock();
1895 1895
1896 return modcb; 1896 return modcb;
1897} 1897}
1898 1898
1899/* 1899/*
1900 * module_unregister_callbacks: 1900 * module_unregister_callbacks:
1901 * 1901 *
1902 * Unregister a previously-registered set of module load/unload callbacks. 1902 * Unregister a previously-registered set of module load/unload callbacks.
1903 * Call the unload callback on each existing module. 1903 * Call the unload callback on each existing module.
1904 */ 1904 */
1905void 1905void