Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Add an exec hook mechanism, where kernel subsystem ...



details:   https://anonhg.NetBSD.org/src/rev/8568551bd259
branches:  trunk
changeset: 481224:8568551bd259
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Tue Jan 25 01:15:14 2000 +0000

description:
Add an exec hook mechanism, where kernel subsystem can register to
execute certain functions when a process does an exec(). Currently
uses a global list. Could possibly be done using a per-process list,
but this needs more thought.

diffstat:

 sys/kern/kern_exec.c |   4 ++-
 sys/kern/kern_subr.c |  68 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 70 insertions(+), 2 deletions(-)

diffs (100 lines):

diff -r 444d763db5eb -r 8568551bd259 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Tue Jan 25 01:15:06 2000 +0000
+++ b/sys/kern/kern_exec.c      Tue Jan 25 01:15:14 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.106 2000/01/05 08:11:31 mrg Exp $      */
+/*     $NetBSD: kern_exec.c,v 1.107 2000/01/25 01:15:14 fvdl Exp $     */
 
 /*-
  * Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou
@@ -472,6 +472,8 @@
        p->p_cred->p_svuid = p->p_ucred->cr_uid;
        p->p_cred->p_svgid = p->p_ucred->cr_gid;
 
+       doexechooks(p);
+
        uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
 
        FREE(nid.ni_cnd.cn_pnbuf, M_NAMEI);
diff -r 444d763db5eb -r 8568551bd259 sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c      Tue Jan 25 01:15:06 2000 +0000
+++ b/sys/kern/kern_subr.c      Tue Jan 25 01:15:14 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_subr.c,v 1.52 1999/06/26 08:25:25 augustss Exp $  */
+/*     $NetBSD: kern_subr.c,v 1.53 2000/01/25 01:15:14 fvdl Exp $      */
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -456,6 +456,72 @@
 }
 
 /*
+ * Exec hook code.
+ */
+
+struct exechook_desc {
+       LIST_ENTRY(exechook_desc) ehk_list;
+       void    (*ehk_fn) __P((struct proc *, void *));
+       void    *ehk_arg;
+};
+
+LIST_HEAD(, exechook_desc) exechook_list;
+
+void *
+exechook_establish(fn, arg)
+       void (*fn) __P((struct proc *, void *));
+       void *arg;
+{
+       struct exechook_desc *edp;
+
+       edp = (struct exechook_desc *)
+           malloc(sizeof(*edp), M_DEVBUF, M_NOWAIT);
+       if (edp == NULL)
+               return NULL;
+
+       edp->ehk_fn = fn;
+       edp->ehk_arg = arg;
+       LIST_INSERT_HEAD(&exechook_list, edp, ehk_list);
+
+       return (edp);
+}
+
+void
+exechook_disestablish(vhook)
+       void *vhook;
+{
+#ifdef DIAGNOSTIC
+       struct exechook_desc *edp;
+
+       for (edp = exechook_list.lh_first; edp != NULL;
+           edp = edp->ehk_list.le_next)
+                if (edp == vhook)
+                       break;
+       if (edp == NULL)
+               panic("exechook_disestablish: hook not established");
+#endif
+
+       LIST_REMOVE((struct exechook_desc *)vhook, ehk_list);
+       free(vhook, M_DEVBUF);
+}
+
+/*
+ * Run exec hooks.
+ */
+void
+doexechooks(p)
+       struct proc *p;
+{
+       struct exechook_desc *edp;
+
+       for (edp = LIST_FIRST(&exechook_list); 
+            edp != NULL; 
+            edp = LIST_NEXT(edp, ehk_list)) {
+               (*edp->ehk_fn)(p, edp->ehk_arg);
+       }
+}
+
+/*
  * Determine the root device and, if instructed to, the root file system.
  */
 



Home | Main Index | Thread Index | Old Index