#Fork with a Random PID - This current version DOESN'T work!!! #Aaron Linville # #Index: bsd/kern/bsd_init.c #=================================================================== #RCS file: /cvs/Darwin/xnu/bsd/kern/bsd_init.c,v #retrieving revision 1.1.1.20.6.2 #diff -u -d -b -w -r1.1.1.20.6.2 bsd_init.c --- bsd/kern/bsd_init.c 4 Mar 2002 18:51:31 -0000 1.1.1.20.6.2 +++ bsd/kern/bsd_init.c 17 Apr 2002 19:43:47 -0000 @@ -524,6 +524,8 @@ bsd_utaskbootstrap(); + randompid = 1; + (void) thread_funnel_set(kernel_flock, FALSE); } #Index: bsd/kern/kern_fork.c #=================================================================== #RCS file: /cvs/Darwin/xnu/bsd/kern/kern_fork.c,v #retrieving revision 1.1.1.13 #diff -u -d -b -w -r1.1.1.13 kern_fork.c --- bsd/kern/kern_fork.c 7 Sep 2001 22:19:37 -0000 1.1.1.13 +++ bsd/kern/kern_fork.c 17 Apr 2002 19:43:47 -0000 @@ -86,6 +86,8 @@ #define DOVFORK 0x2 /* vfork() system call */ static int fork1(struct proc *, long, register_t *); +int randompid; /* when set to 1, pid's go random */ + /* * fork system call. */ @@ -394,6 +396,8 @@ * ready to use (from nextpid+1 through pidchecked-1). */ nextpid++; + if(randompid) + nextpid = PID_MAX; retry: /* * If the process ID prototype has wrapped around, @@ -401,7 +405,7 @@ * tend to include daemons that don't exit. */ if (nextpid >= PID_MAX) { - nextpid = 100; + nextpid = random() % PID_MAX; pidchecked = 0; } if (nextpid >= pidchecked) { #=================================================================== #RCS file: /cvs/Darwin/xnu/bsd/sys/proc.h,v #retrieving revision 1.1.1.13 #diff -u -d -b -w -r1.1.1.13 proc.h --- bsd/sys/proc.h 7 Sep 2001 22:20:50 -0000 1.1.1.13 +++ bsd/sys/proc.h 17 Apr 2002 19:43:54 -0000 @@ -349,6 +349,7 @@ extern u_long pgrphash; extern int nprocs, maxproc; /* Current and max number of procs. */ +extern int randompid; /* fork() should create random pid's */ LIST_HEAD(proclist, proc); extern struct proclist allproc; /* List of all processes. */