Let the linker keep track of pseudo-devices needing initialization and
authorGarrett Wollman <wollman@FreeBSD.org>
Mon, 20 Dec 1993 19:31:42 +0000 (19:31 +0000)
committerGarrett Wollman <wollman@FreeBSD.org>
Mon, 20 Dec 1993 19:31:42 +0000 (19:31 +0000)
image activators, rather than listing them inline in the code.

sys/kern/imgact_aout.c
sys/kern/imgact_shell.c
sys/kern/init_main.c
sys/kern/kern_execve.c
sys/kern/sysv_shm.c
sys/net/if_loop.c
sys/net/if_ppp.c
sys/net/if_sl.c
sys/sys/imgact.h
sys/sys/kernel.h

index 55d61eb..4fe4946 100644 (file)
@@ -28,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $Id: aout_imgact.c,v 1.2 1993/12/19 00:51:14 wollman Exp $
+ *     $Id: imgact_aout.c,v 1.1 1993/12/20 16:16:45 wollman Exp $
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -37,6 +37,7 @@
 #include "exec.h"
 #include "mman.h"
 #include "imgact.h"
 #include "exec.h"
 #include "mman.h"
 #include "imgact.h"
+#include "kernel.h"
 
 #include "vm/vm.h"
 
 
 #include "vm/vm.h"
 
@@ -179,3 +180,12 @@ exec_aout_imgact(iparams)
        
        return (0);
 }
        
        return (0);
 }
+
+/*
+ * Tell kern_execve.c about it, with a little help from the linker.
+ * Since `const' objects end up in the text segment, TEXT_SET is the
+ * correct directive to use.
+ */
+static const struct execsw aout_execsw = { exec_aout_imgact };
+TEXT_SET(execsw_set, aout_execsw);
+
index 50e3d7c..42b3297 100644 (file)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $Id: shell_imgact.c,v 1.1 1993/12/12 12:23:20 davidg Exp $
+ *     $Id: imgact_shell.c,v 1.1 1993/12/20 16:16:46 wollman Exp $
  */
 
 #include "param.h"
 #include "systm.h"
 #include "resourcevar.h"
 #include "imgact.h"
  */
 
 #include "param.h"
 #include "systm.h"
 #include "resourcevar.h"
 #include "imgact.h"
+#include "kernel.h"
+#include "machine/endian.h"
 
 
+#if BYTE_ORDER == LITTLE_ENDIAN
 #define SHELLMAGIC     0x2123 /* #! */
 #define SHELLMAGIC     0x2123 /* #! */
+#else
+#define SHELLMAGIC     0x2321
+#endif
+
 #define MAXSHELLCMDLEN 64
 
 /*
 #define MAXSHELLCMDLEN 64
 
 /*
@@ -127,3 +134,11 @@ exec_shell_imgact(iparams)
 
        return(0);
 }
 
        return(0);
 }
+
+/*
+ * Tell kern_execve.c about it, with a little help from the linker.
+ * Since `const' objects end up in the text segment, TEXT_SET is the
+ * correct directive to use.
+ */
+static const struct execsw shell_execsw = { exec_shell_imgact };
+TEXT_SET(execsw_set, shell_execsw);
index 842f908..8f9b730 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *     from: @(#)init_main.c   7.41 (Berkeley) 5/15/91
  * SUCH DAMAGE.
  *
  *     from: @(#)init_main.c   7.41 (Berkeley) 5/15/91
- *     $Id: init_main.c,v 1.10 1993/11/25 13:16:07 davidg Exp $
+ *     $Id: init_main.c,v 1.11 1993/12/19 00:51:18 wollman Exp $
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -57,7 +57,7 @@
 
 #include "vm/vm.h"
 
 
 #include "vm/vm.h"
 
-char   copyright[] =
+const char     copyright[] =
 "Copyright (c) 1989,1990,1991,1992 William F. Jolitz. All rights reserved.\n\
 Copyright (c) 1982,1986,1989,1991 The Regents of the University\n\
 of California.  All rights reserved.\n\n";
 "Copyright (c) 1989,1990,1991,1992 William F. Jolitz. All rights reserved.\n\
 Copyright (c) 1982,1986,1989,1991 The Regents of the University\n\
 of California.  All rights reserved.\n\n";
@@ -92,6 +92,15 @@ struct       proc *updateproc;
 void __main() {}
 #endif
 
 void __main() {}
 #endif
 
+/*
+ * This table is filled in by the linker with functions that need to be
+ * called to initialize various pseudo-devices and whatnot.
+ */
+typedef void (*pseudo_func_t)(void);
+extern const struct linker_set pseudo_set;
+static const pseudo_func_t *pseudos = 
+  (const pseudo_func_t *)&pseudo_set.ls_items[0];
+
 /*
  * System startup; initialize the world, create process 0,
  * mount root filesystem, and fork to create init and pagedaemon.
 /*
  * System startup; initialize the world, create process 0,
  * mount root filesystem, and fork to create init and pagedaemon.
@@ -223,21 +232,11 @@ main()
         * Initialize tables, protocols, and set up well-known inodes.
         */
        mbinit();
         * Initialize tables, protocols, and set up well-known inodes.
         */
        mbinit();
-#ifdef SYSVSHM
-       shminit();
-#endif
-#include "sl.h"
-#if NSL > 0
-       slattach();                     /* XXX */
-#endif
-#include "ppp.h"
-#if NPPP > 0
-       pppattach();                    /* XXX */
-#endif
-#include "loop.h"
-#if NLOOP > 0
-       loattach();                     /* XXX */
-#endif
+
+       while(*pseudos) {
+               (**pseudos)();
+       }
+
        /*
         * Block reception of incoming packets
         * until protocols have been initialized.
        /*
         * Block reception of incoming packets
         * until protocols have been initialized.
index 56240a6..524c07b 100644 (file)
@@ -28,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $Id: kern_execve.c,v 1.10 1993/12/12 12:23:19 davidg Exp $
+ *     $Id: kern_execve.c,v 1.11 1993/12/19 00:51:23 wollman Exp $
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -36,6 +36,7 @@
 #include "signalvar.h"
 #include "resourcevar.h"
 #include "imgact.h"
 #include "signalvar.h"
 #include "resourcevar.h"
 #include "imgact.h"
+#include "kernel.h"
 #include "mount.h"
 #include "file.h"
 #include "acct.h"
 #include "mount.h"
 #include "file.h"
 #include "acct.h"
 int exec_extract_strings __P((struct image_params *));
 caddr_t exec_copyout_strings __P((struct image_params *));
 
 int exec_extract_strings __P((struct image_params *));
 caddr_t exec_copyout_strings __P((struct image_params *));
 
-int exec_aout_imgact __P((struct image_params *));
-int exec_shell_imgact __P((struct image_params *));
-
-struct execsw {
-       int (*imgact) __P((struct image_params *));
-};
-
-struct execsw execsw[] = {
-       { exec_aout_imgact },
-       { exec_shell_imgact },
-       { NULL },
-       { NULL },
-       { NULL },
-       { NULL },
-       { NULL },
-       { NULL },
-};
+/*
+ * execsw_set is constructed for us by the linker.  Each of the items
+ * is a pointer to a `const struct execsw', hence the double pointer here.
+ */
+extern const struct linker_set execsw_set;
+const struct execsw **execsw = (const struct execsw **)&execsw_set.ls_items[0];
 
 /*
  * execve() system call.
  */
 
 /*
  * execve() system call.
  */
-
 int
 execve(p, uap, retval)
        struct proc *p;
 int
 execve(p, uap, retval)
        struct proc *p;
@@ -203,9 +192,9 @@ interpret:
         *      image is interpreted, loop back up and try activating
         *      the interpreter.
         */
         *      image is interpreted, loop back up and try activating
         *      the interpreter.
         */
-       for (i = 0; i < sizeof(execsw)/sizeof(execsw[0]); ++i) {
-               if (execsw[i].imgact)
-                       error = (*execsw[i].imgact)(iparams);
+       for (i = 0; execsw[i]; ++i) {
+               if (execsw[i]->ex_imgact)
+                       error = (*execsw[i]->ex_imgact)(iparams);
                else
                        continue;
 
                else
                        continue;
 
index b9d50f1..8a521b1 100644 (file)
@@ -37,7 +37,7 @@
  *
  *     from: Utah $Hdr: uipc_shm.c 1.9 89/08/14$
  *     from: @(#)sysv_shm.c    7.15 (Berkeley) 5/13/91
  *
  *     from: Utah $Hdr: uipc_shm.c 1.9 89/08/14$
  *     from: @(#)sysv_shm.c    7.15 (Berkeley) 5/13/91
- *     $Id: sysv_shm.c,v 1.6 1993/11/25 01:33:24 wollman Exp $
+ *     $Id: sysv_shm.c,v 1.7 1993/12/19 00:51:37 wollman Exp $
  */
 
 /*
  */
 
 /*
@@ -114,6 +114,8 @@ shminit()
        }
 }
 
        }
 }
 
+TEXT_SET(pseudo_set, shminit);
+
 /*
  * Entry point for all SHM calls
  */
 /*
  * Entry point for all SHM calls
  */
index df561d1..fee81ac 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *     from: @(#)if_loop.c     7.13 (Berkeley) 4/26/91
  * SUCH DAMAGE.
  *
  *     from: @(#)if_loop.c     7.13 (Berkeley) 4/26/91
- *     $Id: if_loop.c,v 1.4 1993/11/15 20:45:58 wollman Exp $
+ *     $Id: if_loop.c,v 1.5 1993/11/25 01:34:03 wollman Exp $
  */
 
 /*
  */
 
 /*
@@ -44,6 +44,7 @@
 #include "socket.h"
 #include "errno.h"
 #include "ioctl.h"
 #include "socket.h"
 #include "errno.h"
 #include "ioctl.h"
+#include "kernel.h"
 
 #include "../net/if.h"
 #include "../net/if_types.h"
 
 #include "../net/if.h"
 #include "../net/if_types.h"
@@ -71,8 +72,8 @@
 
 #include "bpfilter.h"
 #if NBPFILTER > 0
 
 #include "bpfilter.h"
 #if NBPFILTER > 0
-#include <sys/time.h>
-#include <net/bpf.h>
+#include "sys/time.h"
+#include "net/bpf.h"
 static caddr_t lo_bpf;
 #endif
 
 static caddr_t lo_bpf;
 #endif
 
@@ -106,6 +107,8 @@ loattach(void)
 #endif
 }
 
 #endif
 }
 
+TEXT_SET(pseudo_set, loattach);
+
 int
 looutput(ifp, m, dst, rt)
        struct ifnet *ifp;
 int
 looutput(ifp, m, dst, rt)
        struct ifnet *ifp;
index 6320eee..786a858 100644 (file)
@@ -70,7 +70,7 @@
  */
 
 /*
  */
 
 /*
- *     $Id: if_ppp.c,v 1.5 1993/11/25 01:34:04 wollman Exp $
+ *     $Id: if_ppp.c,v 1.6 1993/12/19 00:52:03 wollman Exp $
  *     From: if_ppp.c,v 1.22 1993/08/31 23:20:40 paulus Exp
  *     From: if_ppp.c,v 1.21 1993/08/29 11:22:37 paulus Exp
  *     From: if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp 
  *     From: if_ppp.c,v 1.22 1993/08/31 23:20:40 paulus Exp
  *     From: if_ppp.c,v 1.21 1993/08/29 11:22:37 paulus Exp
  *     From: if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp 
 #include "systm.h"
 #include "proc.h"
 #include "mbuf.h"
 #include "systm.h"
 #include "proc.h"
 #include "mbuf.h"
-#include "buf.h"
-#include "dkstat.h"
 #include "socket.h"
 #include "ioctl.h"
 #include "file.h"
 #include "tty.h"
 #include "kernel.h"
 #include "conf.h"
 #include "socket.h"
 #include "ioctl.h"
 #include "file.h"
 #include "tty.h"
 #include "kernel.h"
 #include "conf.h"
+#include "dkstat.h"
 
 #include "if.h"
 #include "if_types.h"
 
 #include "if.h"
 #include "if_types.h"
@@ -223,6 +222,8 @@ pppattach()
     }
 }
 
     }
 }
 
+TEXT_SET(pseudo_set, pppattach);
+
 /*
  * Line specific open routine.
  * Attach the given tty to the first available ppp unit.
 /*
  * Line specific open routine.
  * Attach the given tty to the first available ppp unit.
index 8bdcd74..358c2a0 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *     from: @(#)if_sl.c       7.22 (Berkeley) 4/20/91
  * SUCH DAMAGE.
  *
  *     from: @(#)if_sl.c       7.22 (Berkeley) 4/20/91
- *     $Id: if_sl.c,v 1.5 1993/11/16 02:47:24 wollman Exp $
+ *     $Id: if_sl.c,v 1.6 1993/11/25 01:34:06 wollman Exp $
  */
 
 /*
  */
 
 /*
@@ -65,7 +65,7 @@
  * interrupts and network activity; thus, splimp must be >= spltty.
  */
 
  * interrupts and network activity; thus, splimp must be >= spltty.
  */
 
-/* $Id: if_sl.c,v 1.5 1993/11/16 02:47:24 wollman Exp $ */
+/* $Id: if_sl.c,v 1.6 1993/11/25 01:34:06 wollman Exp $ */
 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
 
 #include "sl.h"
 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
 
 #include "sl.h"
@@ -95,7 +95,7 @@
 #include "netinet/in_var.h"
 #include "netinet/ip.h"
 #else
 #include "netinet/in_var.h"
 #include "netinet/ip.h"
 #else
-Huh? Slip without inet?
+#error "Huh? Slip without inet?"
 #endif
 
 #include "machine/mtpr.h"
 #endif
 
 #include "machine/mtpr.h"
@@ -106,8 +106,8 @@ Huh? Slip without inet?
 
 #include "bpfilter.h"
 #if NBPFILTER > 0
 
 #include "bpfilter.h"
 #if NBPFILTER > 0
-#include <sys/time.h>
-#include <net/bpf.h>
+#include "sys/time.h"
+#include "net/bpf.h"
 #endif
 
 /*
 #endif
 
 /*
@@ -262,6 +262,8 @@ slattach(void)
        }
 }
 
        }
 }
 
+TEXT_SET(pseudo_set, slattach);
+
 static int
 slinit(sc)
        register struct sl_softc *sc;
 static int
 slinit(sc)
        register struct sl_softc *sc;
index 9818796..8cba997 100644 (file)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $Id: imgact.h,v 1.2 1993/12/11 06:56:02 davidg Exp davidg $
+ *     $Id: imgact.h,v 1.1 1993/12/12 12:31:40 davidg Exp $
  */
 
  */
 
+#ifndef __h_imgact
+#define __h_imgact 1
+
 #include "proc.h"
 #include "namei.h"
 #include "vnode.h"
 #include "proc.h"
 #include "namei.h"
 #include "vnode.h"
@@ -58,3 +61,11 @@ struct image_params {
        char interpreted;       /* flag - this executable is interpreted */
        char interpreter_name[64]; /* name of the interpreter */
 };
        char interpreted;       /* flag - this executable is interpreted */
        char interpreter_name[64]; /* name of the interpreter */
 };
+
+struct execsw {
+       int (*ex_imgact)(struct image_params *);
+};
+
+extern const struct execsw **execsw;
+
+#endif /* __h_imgact */
index c363f5d..d0ad820 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *     from: @(#)kernel.h      7.4 (Berkeley) 2/15/91
  * SUCH DAMAGE.
  *
  *     from: @(#)kernel.h      7.4 (Berkeley) 2/15/91
- *     $Id: kernel.h,v 1.6 1993/12/19 00:55:17 wollman Exp $
+ *     $Id: kernel.h,v 1.7 1993/12/20 16:13:05 wollman Exp $
  */
 
 #ifndef _SYS_KERNEL_H_
  */
 
 #ifndef _SYS_KERNEL_H_
@@ -70,8 +70,8 @@ extern char *s_lowpc;
 #endif
 
 extern const char *panicstr;   /* panic message */
 #endif
 
 extern const char *panicstr;   /* panic message */
-extern char version[];         /* system version */
-extern char copyright[];       /* system copyright */
+extern const char version[];   /* system version */
+extern const char copyright[]; /* system copyright */
 
 extern int nblkdev;            /* number of entries in bdevsw */
 extern int nchrdev;            /* number of entries in cdevsw */
 
 extern int nblkdev;            /* number of entries in bdevsw */
 extern int nchrdev;            /* number of entries in cdevsw */