tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kernel constructor



Ideally the long hardcoded sequence of init functions in init_main:main() is
converted to a single vector whose order is resolved by modular dependency.
But for the moment such a hardcoded priority should be good enough to improve
modularity.

Question - where to put the declarations (typedef, __link_set_decl())?

Index: sys/kern/init_main.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_main.c,v
retrieving revision 1.460
diff -p -u -r1.460 init_main.c
--- sys/kern/init_main.c	4 Oct 2014 11:15:44 -0000	1.460
+++ sys/kern/init_main.c	9 Nov 2014 07:11:10 -0000
@@ -590,6 +590,7 @@ main(void)
 	/* Initialize system accounting. */
 	acct_init();
 
+#if 0
 #ifndef PIPE_SOCKETPAIR
 	/* Initialize pipes. */
 	pipe_init();
@@ -604,6 +605,15 @@ main(void)
 	/* Initialize ptrace. */
 	ptrace_init();
 #endif /* PTRACE */
+#else
+	typedef void kctors_func(void);
+	__link_set_decl(kctors_9, kctors_func);
+
+	kctors_func * const * func;
+	__link_set_foreach(func, kctors_9) {
+		(*(*func))();
+	}
+#endif
 
 	machdep_init();
 
Index: sys/kern/kern_ktrace.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_ktrace.c,v
retrieving revision 1.165
diff -p -u -r1.165 kern_ktrace.c
--- sys/kern/kern_ktrace.c	21 Sep 2014 17:17:15 -0000	1.165
+++ sys/kern/kern_ktrace.c	9 Nov 2014 07:11:10 -0000
@@ -251,6 +251,12 @@ ktrace_listener_cb(kauth_cred_t cred, ka
 	return result;
 }
 
+#ifdef KTRACE
+typedef void kctors_func(void);
+__link_set_decl(kctors_9, kctors_func);
+__link_set_add_text(kctors_9, ktrinit);
+#endif
+
 /*
  * Initialise the ktrace system.
  */
Index: sys/kern/sys_pipe.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sys_pipe.c,v
retrieving revision 1.140
diff -p -u -r1.140 sys_pipe.c
--- sys/kern/sys_pipe.c	5 Sep 2014 09:20:59 -0000	1.140
+++ sys/kern/sys_pipe.c	9 Nov 2014 07:11:10 -0000
@@ -179,6 +179,12 @@ static void	pipe_loan_free(struct pipe *
 static pool_cache_t	pipe_wr_cache;
 static pool_cache_t	pipe_rd_cache;
 
+#ifndef PIPE_SOCKETPAIR
+typedef void kctors_func(void);
+__link_set_decl(kctors_9, kctors_func);
+__link_set_add_text(kctors_9, pipe_init);
+#endif
+
 void
 pipe_init(void)
 {
Index: sys/kern/sys_process.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sys_process.c,v
retrieving revision 1.164
diff -p -u -r1.164 sys_process.c
--- sys/kern/sys_process.c	21 Sep 2014 17:17:15 -0000	1.164
+++ sys/kern/sys_process.c	9 Nov 2014 07:11:10 -0000
@@ -210,6 +210,12 @@ ptrace_listener_cb(kauth_cred_t cred, ka
 	return result;
 }
 
+#ifdef PTRACE
+typedef void kctors_func(void);
+__link_set_decl(kctors_9, kctors_func);
+__link_set_add_text(kctors_9, ptrace_init);
+#endif
+
 void
 ptrace_init(void)
 {


Home | Main Index | Thread Index | Old Index