Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Niels Provos systrace work, ported to NetBSD by kit...
details: https://anonhg.NetBSD.org/src/rev/7249e983fbab
branches: trunk
changeset: 532888:7249e983fbab
user: christos <christos%NetBSD.org@localhost>
date: Mon Jun 17 16:22:50 2002 +0000
description:
Niels Provos systrace work, ported to NetBSD by kittenz and reworked...
diffstat:
sys/kern/init_main.c | 11 +-
sys/kern/kern_exit.c | 10 +-
sys/kern/kern_fork.c | 175 +++--
sys/kern/kern_ktrace.c | 7 +-
sys/kern/kern_subr.c | 50 +-
sys/kern/kern_systrace.c | 1374 ++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 1533 insertions(+), 94 deletions(-)
diffs (truncated from 1803 to 300 lines):
diff -r 0a50c16fb523 -r 7249e983fbab sys/kern/init_main.c
--- a/sys/kern/init_main.c Mon Jun 17 16:21:03 2002 +0000
+++ b/sys/kern/init_main.c Mon Jun 17 16:22:50 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init_main.c,v 1.200 2002/05/27 13:46:45 itojun Exp $ */
+/* $NetBSD: init_main.c,v 1.201 2002/06/17 16:22:50 christos Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou. All rights reserved.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.200 2002/05/27 13:46:45 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.201 2002/06/17 16:22:50 christos Exp $");
#include "fs_nfs.h"
#include "opt_nfsserver.h"
@@ -51,6 +51,7 @@
#include "opt_multiprocessor.h"
#include "opt_pipe.h"
#include "opt_syscall_debug.h"
+#include "opt_systrace.h"
#include "rnd.h"
@@ -90,6 +91,9 @@
#ifdef SYSVMSG
#include <sys/msg.h>
#endif
+#ifdef SYSTRACE
+#include <sys/systrace.h>
+#endif
#include <sys/domain.h>
#include <sys/mbuf.h>
#include <sys/namei.h>
@@ -385,6 +389,9 @@
/* Initialize system accouting. */
acct_init();
+#ifdef SYSTRACE
+ systrace_init();
+#endif
/*
* Initialize signal-related data structures, and signal state
* for proc0.
diff -r 0a50c16fb523 -r 7249e983fbab sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c Mon Jun 17 16:21:03 2002 +0000
+++ b/sys/kern/kern_exit.c Mon Jun 17 16:22:50 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exit.c,v 1.93 2002/03/17 23:41:30 christos Exp $ */
+/* $NetBSD: kern_exit.c,v 1.94 2002/06/17 16:22:50 christos Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -78,9 +78,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.93 2002/03/17 23:41:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.94 2002/06/17 16:22:50 christos Exp $");
#include "opt_ktrace.h"
+#include "opt_systrace.h"
#include "opt_sysv.h"
#include <sys/param.h>
@@ -109,11 +110,13 @@
#include <sys/sched.h>
#include <sys/mount.h>
#include <sys/syscallargs.h>
+#include <sys/systrace.h>
#include <machine/cpu.h>
#include <uvm/uvm_extern.h>
+
/*
* exit --
* Death of process.
@@ -214,6 +217,9 @@
*/
ktrderef(p);
#endif
+#ifdef SYSTRACE
+ systrace_sys_exit(p);
+#endif
/*
* NOTE: WE ARE NO LONGER ALLOWED TO SLEEP!
*/
diff -r 0a50c16fb523 -r 7249e983fbab sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c Mon Jun 17 16:21:03 2002 +0000
+++ b/sys/kern/kern_fork.c Mon Jun 17 16:22:50 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_fork.c,v 1.88 2001/12/08 00:35:30 thorpej Exp $ */
+/* $NetBSD: kern_fork.c,v 1.89 2002/06/17 16:22:50 christos Exp $ */
/*-
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -78,9 +78,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.88 2001/12/08 00:35:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.89 2002/06/17 16:22:50 christos Exp $");
#include "opt_ktrace.h"
+#include "opt_systrace.h"
#include "opt_multiprocessor.h"
#include <sys/param.h>
@@ -100,11 +101,13 @@
#include <sys/vmmeter.h>
#include <sys/sched.h>
#include <sys/signalvar.h>
+#include <sys/systrace.h>
#include <sys/syscallargs.h>
#include <uvm/uvm_extern.h>
+
int nprocs = 1; /* process 0 */
/*ARGSUSED*/
@@ -251,6 +254,85 @@
p2 = pool_get(&proc_pool, PR_WAITOK);
/*
+ * BEGIN PID ALLOCATION.
+ */
+ s = proclist_lock_write();
+
+ /*
+ * Find an unused process ID. We remember a range of unused IDs
+ * ready to use (from nextpid+1 through pidchecked-1).
+ */
+ nextpid++;
+ retry:
+ /*
+ * If the process ID prototype has wrapped around,
+ * restart somewhat above 0, as the low-numbered procs
+ * tend to include daemons that don't exit.
+ */
+ if (nextpid >= PID_MAX) {
+ nextpid = 500;
+ pidchecked = 0;
+ }
+ if (nextpid >= pidchecked) {
+ const struct proclist_desc *pd;
+
+ pidchecked = PID_MAX;
+ /*
+ * Scan the process lists to check whether this pid
+ * is in use. Remember the lowest pid that's greater
+ * than nextpid, so we can avoid checking for a while.
+ */
+ pd = proclists;
+ again:
+ LIST_FOREACH(tp, pd->pd_list, p_list) {
+ while (tp->p_pid == nextpid ||
+ tp->p_pgrp->pg_id == nextpid ||
+ tp->p_session->s_sid == nextpid) {
+ nextpid++;
+ if (nextpid >= pidchecked)
+ goto retry;
+ }
+ if (tp->p_pid > nextpid && pidchecked > tp->p_pid)
+ pidchecked = tp->p_pid;
+
+ if (tp->p_pgrp->pg_id > nextpid &&
+ pidchecked > tp->p_pgrp->pg_id)
+ pidchecked = tp->p_pgrp->pg_id;
+
+ if (tp->p_session->s_sid > nextpid &&
+ pidchecked > tp->p_session->s_sid)
+ pidchecked = tp->p_session->s_sid;
+ }
+
+ /*
+ * If there's another list, scan it. If we have checked
+ * them all, we've found one!
+ */
+ pd++;
+ if (pd->pd_list != NULL)
+ goto again;
+ }
+
+ /*
+ * Put the proc on allproc before unlocking PID allocation
+ * so that waiters won't grab it as soon as we unlock.
+ */
+
+ p2->p_stat = SIDL; /* protect against others */
+ p2->p_pid = nextpid;
+ p2->p_exitsig = exitsig; /* signal for parent on exit */
+ p2->p_forw = p2->p_back = NULL; /* shouldn't be necessary */
+
+ LIST_INSERT_HEAD(&allproc, p2, p_list);
+
+ LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
+
+ /*
+ * END PID ALLOCATION.
+ */
+ proclist_unlock_write(s);
+
+ /*
* Make a proc table entry for the new process.
* Start by zeroing the section of proc that is zero-initialized,
* then copy the section that is copied directly from the parent.
@@ -343,6 +425,12 @@
ktradref(p2);
}
#endif
+#ifdef SYSTRACE
+ /* Tell systrace what's happening. */
+ if (ISSET(p1->p_flag, P_SYSTRACE))
+ systrace_sys_fork(p1, p2);
+#endif
+
#ifdef __HAVE_SYSCALL_INTERN
(*p2->p_emul->e_syscall_intern)(p2);
@@ -378,89 +466,6 @@
(arg != NULL) ? arg : p2);
/*
- * BEGIN PID ALLOCATION.
- */
- s = proclist_lock_write();
-
- /*
- * Find an unused process ID. We remember a range of unused IDs
- * ready to use (from nextpid+1 through pidchecked-1).
- */
- nextpid++;
- retry:
- /*
- * If the process ID prototype has wrapped around,
- * restart somewhat above 0, as the low-numbered procs
- * tend to include daemons that don't exit.
- */
- if (nextpid >= PID_MAX) {
- nextpid = 500;
- pidchecked = 0;
- }
- if (nextpid >= pidchecked) {
- const struct proclist_desc *pd;
-
- pidchecked = PID_MAX;
- /*
- * Scan the process lists to check whether this pid
- * is in use. Remember the lowest pid that's greater
- * than nextpid, so we can avoid checking for a while.
- */
- pd = proclists;
- again:
- LIST_FOREACH(tp, pd->pd_list, p_list) {
- while (tp->p_pid == nextpid ||
- tp->p_pgrp->pg_id == nextpid ||
- tp->p_session->s_sid == nextpid) {
- nextpid++;
- if (nextpid >= pidchecked)
- goto retry;
- }
- if (tp->p_pid > nextpid && pidchecked > tp->p_pid)
- pidchecked = tp->p_pid;
-
- if (tp->p_pgrp->pg_id > nextpid &&
- pidchecked > tp->p_pgrp->pg_id)
- pidchecked = tp->p_pgrp->pg_id;
-
- if (tp->p_session->s_sid > nextpid &&
- pidchecked > tp->p_session->s_sid)
- pidchecked = tp->p_session->s_sid;
- }
-
- /*
- * If there's another list, scan it. If we have checked
- * them all, we've found one!
- */
- pd++;
- if (pd->pd_list != NULL)
- goto again;
- }
-
- /* Record the pid we've allocated. */
- p2->p_pid = nextpid;
-
- /* Record the signal to be delivered to the parent on exit. */
- p2->p_exitsig = exitsig;
-
- /*
- * Put the proc on allproc before unlocking PID allocation
- * so that waiters won't grab it as soon as we unlock.
- */
-
- p2->p_stat = SIDL; /* protect against others */
Home |
Main Index |
Thread Index |
Old Index