Index: arch/amd64/amd64/db_disasm.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/amd64/amd64/db_disasm.c,v
retrieving revision 1.8
retrieving revision 1.8.6.1
diff -u -r1.8 -r1.8.6.1
--- arch/amd64/amd64/db_disasm.c	5 Nov 2007 19:23:24 -0000	1.8
+++ arch/amd64/amd64/db_disasm.c	17 Sep 2008 13:37:32 -0000	1.8.6.1
@@ -94,7 +94,7 @@
 #define	Ril	36			/* long register in instruction */
 #define	Iba	37			/* byte immediate, don't print if 0xa */
 
-struct inst {
+struct dinst {
 	char *	i_name;			/* name */
 	short	i_has_modrm;		/* has regmodrm byte */
 	short	i_size;			/* operand size */
@@ -144,7 +144,7 @@
 	"xcrypt-cfb",	"xcrypt-ofb",	"",		""
 };
 
-struct inst db_inst_0f0x[] = {
+struct dinst db_inst_0f0x[] = {
 /*00*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp6 },
 /*01*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp7 },
 /*02*/	{ "lar",   TRUE,  LONG,  op2(E,R),    0 },
@@ -164,7 +164,7 @@
 /*0f*/	{ "",      FALSE, NONE,  0,	      0 },
 };
 
-struct inst	db_inst_0f2x[] = {
+struct dinst	db_inst_0f2x[] = {
 /*20*/	{ "mov",   TRUE,  LONG,  op2(CR,E),   0 }, /* use E for reg */
 /*21*/	{ "mov",   TRUE,  LONG,  op2(DR,E),   0 }, /* since mod == 11 */
 /*22*/	{ "mov",   TRUE,  LONG,  op2(E,CR),   0 },
@@ -184,7 +184,7 @@
 /*2f*/	{ "",      FALSE, NONE,  0,	      0 },
 };
 
-struct inst	db_inst_0f3x[] = {
+struct dinst	db_inst_0f3x[] = {
 /*30*/	{ "wrmsr", FALSE, NONE,  0,           0 },
 /*31*/	{ "rdtsc", FALSE, NONE,  0,           0 },
 /*32*/	{ "rdmsr", FALSE, NONE,  0,           0 },
@@ -204,7 +204,7 @@
 /*3f*/	{ "",      FALSE, NONE,  0,           0 },
 };
 
-struct inst	db_inst_0f8x[] = {
+struct dinst	db_inst_0f8x[] = {
 /*80*/	{ "jo",    FALSE, NONE,  op1(Dl),     0 },
 /*81*/	{ "jno",   FALSE, NONE,  op1(Dl),     0 },
 /*82*/	{ "jb",    FALSE, NONE,  op1(Dl),     0 },
@@ -224,7 +224,7 @@
 /*8f*/	{ "jnle",  FALSE, NONE,  op1(Dl),     0 },
 };
 
-struct inst	db_inst_0f9x[] = {
+struct dinst	db_inst_0f9x[] = {
 /*90*/	{ "seto",  TRUE,  NONE,  op1(Eb),     0 },
 /*91*/	{ "setno", TRUE,  NONE,  op1(Eb),     0 },
 /*92*/	{ "setb",  TRUE,  NONE,  op1(Eb),     0 },
@@ -244,7 +244,7 @@
 /*9f*/	{ "setnle",TRUE,  NONE,  op1(Eb),     0 },
 };
 
-struct inst	db_inst_0fax[] = {
+struct dinst	db_inst_0fax[] = {
 /*a0*/	{ "push",  FALSE, QUAD,  op1(Si),     0 },
 /*a1*/	{ "pop",   FALSE, QUAD,  op1(Si),     0 },
 /*a2*/	{ "cpuid", FALSE, NONE,  0,	      0 },
@@ -264,7 +264,7 @@
 /*af*/	{ "imul",  TRUE,  LONG,  op2(E,R),    0 },
 };
 
-struct inst	db_inst_0fbx[] = {
+struct dinst	db_inst_0fbx[] = {
 /*b0*/	{ "cmpxchg",TRUE, BYTE,	 op2(R, E),   0 },
 /*b1*/	{ "cmpxchg",TRUE, LONG,	 op2(R, E),   0 },
 /*b2*/	{ "lss",   TRUE,  LONG,  op2(E, R),   0 },
@@ -284,7 +284,7 @@
 /*bf*/	{ "movsw", TRUE,  LONG,  op2(Ew, R),  0 },
 };
 
-struct inst	db_inst_0fcx[] = {
+struct dinst	db_inst_0fcx[] = {
 /*c0*/	{ "xadd",  TRUE,  BYTE,	 op2(R, E),   0 },
 /*c1*/	{ "xadd",  TRUE,  LONG,	 op2(R, E),   0 },
 /*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
@@ -304,7 +304,7 @@
 /*cf*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
 };
 
-struct inst *db_inst_0f[] = {
+struct dinst *db_inst_0f[] = {
 	db_inst_0f0x,
 	NULL,
 	db_inst_0f2x,
@@ -479,7 +479,7 @@
 	"sar"
 };
 
-struct inst db_Grp3[] = {
+struct dinst db_Grp3[] = {
 	{ "test",  TRUE, NONE, op2(I,E), 0 },
 	{ "test",  TRUE, NONE, op2(I,E), 0 },
 	{ "not",   TRUE, NONE, op1(E),   0 },
@@ -490,7 +490,7 @@
 	{ "idiv",  TRUE, NONE, op2(E,A), 0 },
 };
 
-struct inst	db_Grp4[] = {
+struct dinst	db_Grp4[] = {
 	{ "inc",   TRUE, BYTE, op1(E),   0 },
 	{ "dec",   TRUE, BYTE, op1(E),   0 },
 	{ "",      TRUE, NONE, 0,	 0 },
@@ -501,7 +501,7 @@
 	{ "",      TRUE, NONE, 0,	 0 }
 };
 
-struct inst	db_Grp5[] = {
+struct dinst	db_Grp5[] = {
 	{ "inc",   TRUE, LONG, op1(E),   0 },
 	{ "dec",   TRUE, LONG, op1(E),   0 },
 	{ "call",  TRUE, QUAD, op1(Eind),0 },
@@ -512,7 +512,7 @@
 	{ "",      TRUE, NONE, 0,	 0 }
 };
 
-struct inst db_inst_table[256] = {
+struct dinst db_inst_table[256] = {
 /*00*/	{ "add",   TRUE,  BYTE,  op2(R, E),  0 },
 /*01*/	{ "add",   TRUE,  LONG,  op2(R, E),  0 },
 /*02*/	{ "add",   TRUE,  BYTE,  op2(E, R),  0 },
@@ -802,7 +802,7 @@
 /*ff*/	{ "",	   TRUE,  NONE,  0,	     db_Grp5 },
 };
 
-struct inst	db_bad_inst =
+struct dinst	db_bad_inst =
 	{ "???",   FALSE, NONE,  0,	      0 }
 ;
 
@@ -1076,7 +1076,7 @@
 	int	size;
 	int	short_addr;
 	char *	seg;
-	struct inst *	ip;
+	struct dinst *	ip;
 	char *	i_name;
 	int	i_size;
 	int	i_mode;
@@ -1208,12 +1208,12 @@
 	    ip->i_extra == db_GrpA || ip->i_extra == db_GrpB) {
 		i_name = ((char **)ip->i_extra)[f_reg(regmodrm, 0)];
 	} else if (ip->i_extra == db_Grp3) {
-		ip = (struct inst *)ip->i_extra;
+		ip = (struct dinst *)ip->i_extra;
 		ip = &ip[f_reg(regmodrm, 0)];
 		i_name = ip->i_name;
 		i_mode = ip->i_mode;
 	} else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
-		ip = (struct inst *)ip->i_extra;
+		ip = (struct dinst *)ip->i_extra;
 		ip = &ip[f_reg(regmodrm, 0)];
 		i_name = ip->i_name;
 		i_mode = ip->i_mode;
Index: arch/arm/arm/db_trace.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/arm/arm/db_trace.c,v
retrieving revision 1.3
retrieving revision 1.3.10.1
diff -u -r1.3 -r1.3.10.1
--- arch/arm/arm/db_trace.c	29 Nov 2006 12:24:17 -0000	1.3
+++ arch/arm/arm/db_trace.c	16 Sep 2008 23:10:37 -0000	1.3.10.1
@@ -105,6 +105,9 @@
 		frame = (u_int32_t *)(DDB_REGS->tf_r11);
 	else {
 		if (trace_thread) {
+			/* FIXME: instances. */
+			(*pr) ("db_trace.c: operation not supported\n");
+#if 0
 			struct proc *p;
 			struct user *u;
 			(*pr) ("trace: pid %d ", (int)addr);
@@ -120,6 +123,7 @@
 			frame = (u_int32_t *)(u->u_pcb.pcb_un.un_32.pcb32_r11);
 #endif
 			(*pr)("at %p\n", frame);
+#endif
 		} else
 			frame = (u_int32_t *)(addr);
 	}
Index: arch/i386/conf/GENERIC
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/i386/conf/GENERIC,v
retrieving revision 1.633
retrieving revision 1.633.4.2
diff -u -r1.633 -r1.633.4.2
--- arch/i386/conf/GENERIC	2 Aug 2008 16:09:29 -0000	1.633
+++ arch/i386/conf/GENERIC	18 Feb 2009 12:43:24 -0000	1.633.4.2
@@ -15,6 +15,8 @@
 
 option		USER_PCICONF	# user-space PCI configuration
 
+makeoptions	DEBUG="-g"
+
 #option		VM86		# Virtual 8086 emulation
 option		KVM86		# Kernel Virtual 8086 emulation
 option		USER_LDT	# user-settable LDT; see i386_set_ldt(2)
@@ -30,7 +32,7 @@
 option		COMPAT_BSDOS	# binary compatibility with BSD/OS
 option		COMPAT_AOUT	# a.out binaries are emulated
 
-option		PROCFS		# /proc
+#option		PROCFS		# /proc
 #option		NTFS		# Experimental NTFS support
 
 # or use		root on nfs swap on nfs
Index: arch/i386/i386/db_disasm.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/i386/i386/db_disasm.c,v
retrieving revision 1.15
retrieving revision 1.15.6.1
diff -u -r1.15 -r1.15.6.1
--- arch/i386/i386/db_disasm.c	1 Sep 2007 11:54:02 -0000	1.15
+++ arch/i386/i386/db_disasm.c	12 Sep 2008 13:58:48 -0000	1.15.6.1
@@ -94,7 +94,7 @@
 #define	Ril	36			/* long register in instruction */
 #define	Iba	37			/* byte immediate, don't print if 0xa */
 
-struct inst {
+struct dinst {
 	char *	i_name;			/* name */
 	short	i_has_modrm;		/* has regmodrm byte */
 	short	i_size;			/* operand size */
@@ -149,7 +149,7 @@
 	"",		"",		"",		""
 };
 
-struct inst db_inst_0f0x[] = {
+struct dinst db_inst_0f0x[] = {
 /*00*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp6 },
 /*01*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp7 },
 /*02*/	{ "lar",   TRUE,  LONG,  op2(E,R),    0 },
@@ -169,7 +169,7 @@
 /*0f*/	{ "",      FALSE, NONE,  0,	      0 },
 };
 
-struct inst	db_inst_0f2x[] = {
+struct dinst	db_inst_0f2x[] = {
 /*20*/	{ "mov",   TRUE,  LONG,  op2(CR,E),   0 }, /* use E for reg */
 /*21*/	{ "mov",   TRUE,  LONG,  op2(DR,E),   0 }, /* since mod == 11 */
 /*22*/	{ "mov",   TRUE,  LONG,  op2(E,CR),   0 },
@@ -189,7 +189,7 @@
 /*2f*/	{ "",      FALSE, NONE,  0,	      0 },
 };
 
-struct inst	db_inst_0f3x[] = {
+struct dinst	db_inst_0f3x[] = {
 /*30*/	{ "wrmsr", FALSE, NONE,  0,           0 },
 /*31*/	{ "rdtsc", FALSE, NONE,  0,           0 },
 /*32*/	{ "rdmsr", FALSE, NONE,  0,           0 },
@@ -209,7 +209,7 @@
 /*3f*/	{ "",      FALSE, NONE,  0,           0 },
 };
 
-struct inst	db_inst_0f8x[] = {
+struct dinst	db_inst_0f8x[] = {
 /*80*/	{ "jo",    FALSE, NONE,  op1(Dl),     0 },
 /*81*/	{ "jno",   FALSE, NONE,  op1(Dl),     0 },
 /*82*/	{ "jb",    FALSE, NONE,  op1(Dl),     0 },
@@ -229,7 +229,7 @@
 /*8f*/	{ "jnle",  FALSE, NONE,  op1(Dl),     0 },
 };
 
-struct inst	db_inst_0f9x[] = {
+struct dinst	db_inst_0f9x[] = {
 /*90*/	{ "seto",  TRUE,  NONE,  op1(Eb),     0 },
 /*91*/	{ "setno", TRUE,  NONE,  op1(Eb),     0 },
 /*92*/	{ "setb",  TRUE,  NONE,  op1(Eb),     0 },
@@ -249,7 +249,7 @@
 /*9f*/	{ "setnle",TRUE,  NONE,  op1(Eb),     0 },
 };
 
-struct inst	db_inst_0fax[] = {
+struct dinst	db_inst_0fax[] = {
 /*a0*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
 /*a1*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
 /*a2*/	{ "cpuid", FALSE, NONE,  0,	      0 },
@@ -269,7 +269,7 @@
 /*af*/	{ "imul",  TRUE,  LONG,  op2(E,R),    0 },
 };
 
-struct inst	db_inst_0fbx[] = {
+struct dinst	db_inst_0fbx[] = {
 /*b0*/	{ "cmpxchg",TRUE, BYTE,	 op2(R, E),   0 },
 /*b1*/	{ "cmpxchg",TRUE, LONG,	 op2(R, E),   0 },
 /*b2*/	{ "lss",   TRUE,  LONG,  op2(E, R),   0 },
@@ -289,7 +289,7 @@
 /*bf*/	{ "movsw", TRUE,  LONG,  op2(Ew, R),  0 },
 };
 
-struct inst	db_inst_0fcx[] = {
+struct dinst	db_inst_0fcx[] = {
 /*c0*/	{ "xadd",  TRUE,  BYTE,	 op2(R, E),   0 },
 /*c1*/	{ "xadd",  TRUE,  LONG,	 op2(R, E),   0 },
 /*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
@@ -309,7 +309,7 @@
 /*cf*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
 };
 
-struct inst *db_inst_0f[] = {
+struct dinst *db_inst_0f[] = {
 	db_inst_0f0x,
 	NULL,
 	db_inst_0f2x,
@@ -484,7 +484,7 @@
 	"sar"
 };
 
-struct inst db_Grp3[] = {
+struct dinst db_Grp3[] = {
 	{ "test",  TRUE, NONE, op2(I,E), 0 },
 	{ "test",  TRUE, NONE, op2(I,E), 0 },
 	{ "not",   TRUE, NONE, op1(E),   0 },
@@ -495,7 +495,7 @@
 	{ "idiv",  TRUE, NONE, op2(E,A), 0 },
 };
 
-struct inst	db_Grp4[] = {
+struct dinst	db_Grp4[] = {
 	{ "inc",   TRUE, BYTE, op1(E),   0 },
 	{ "dec",   TRUE, BYTE, op1(E),   0 },
 	{ "",      TRUE, NONE, 0,	 0 },
@@ -506,7 +506,7 @@
 	{ "",      TRUE, NONE, 0,	 0 }
 };
 
-struct inst	db_Grp5[] = {
+struct dinst	db_Grp5[] = {
 	{ "inc",   TRUE, LONG, op1(E),   0 },
 	{ "dec",   TRUE, LONG, op1(E),   0 },
 	{ "call",  TRUE, NONE, op1(Eind),0 },
@@ -517,7 +517,7 @@
 	{ "",      TRUE, NONE, 0,	 0 }
 };
 
-struct inst db_inst_table[256] = {
+struct dinst db_inst_table[256] = {
 /*00*/	{ "add",   TRUE,  BYTE,  op2(R, E),  0 },
 /*01*/	{ "add",   TRUE,  LONG,  op2(R, E),  0 },
 /*02*/	{ "add",   TRUE,  BYTE,  op2(E, R),  0 },
@@ -807,7 +807,7 @@
 /*ff*/	{ "",	   TRUE,  NONE,  0,	     db_Grp5 },
 };
 
-struct inst	db_bad_inst =
+struct dinst	db_bad_inst =
 	{ "???",   FALSE, NONE,  0,	      0 }
 ;
 
@@ -1077,7 +1077,7 @@
 	int	size;
 	int	short_addr;
 	char *	seg;
-	struct inst *	ip;
+	struct dinst *	ip;
 	char *	i_name;
 	int	i_size;
 	int	i_mode;
@@ -1176,12 +1176,12 @@
 	    ip->i_extra == db_GrpC) {
 		i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
 	} else if (ip->i_extra == db_Grp3) {
-		ip = (struct inst *)ip->i_extra;
+		ip = (struct dinst *)ip->i_extra;
 		ip = &ip[f_reg(regmodrm)];
 		i_name = ip->i_name;
 		i_mode = ip->i_mode;
 	} else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
-		ip = (struct inst *)ip->i_extra;
+		ip = (struct dinst *)ip->i_extra;
 		ip = &ip[f_reg(regmodrm)];
 		i_name = ip->i_name;
 		i_mode = ip->i_mode;
Index: arch/i386/i386/db_trace.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/i386/i386/db_trace.c,v
retrieving revision 1.13
retrieving revision 1.13.10.1
diff -u -r1.13 -r1.13.10.1
--- arch/i386/i386/db_trace.c	28 Nov 2006 18:56:17 -0000	1.13
+++ arch/i386/i386/db_trace.c	16 Sep 2008 23:10:38 -0000	1.13.10.1
@@ -215,6 +215,9 @@
 	} else if (trace_thread) {
 		(*pr) ("db_trace.c: can't trace thread\n");
 	} else if (trace_proc) {
+		/* FIXME: instances. */
+		(*pr) ("db_trace.c: operation not supported\n");
+#if 0
 		struct proc *p = pfind((pid_t)addr);
 		if (p == NULL) {
 			(*pr) ("db_trace.c: process not found\n");
@@ -223,6 +226,7 @@
 		frame = (struct i386_frame *)p->p_addr->u_pcb.pcb_ebp;
 		callpc = (db_addr_t)
 		    db_get_value((int)&frame->f_retaddr, 4, FALSE);
+#endif
 	} else {
 		frame = (struct i386_frame *)addr;
 		callpc = (db_addr_t)
Index: arch/powerpc/powerpc/pmap.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/powerpc/powerpc/pmap.c,v
retrieving revision 1.105
retrieving revision 1.105.4.1
diff -u -r1.105 -r1.105.4.1
--- arch/powerpc/powerpc/pmap.c	14 Jun 2008 10:55:20 -0000	1.105
+++ arch/powerpc/powerpc/pmap.c	16 Sep 2008 23:10:38 -0000	1.105.4.1
@@ -2578,8 +2578,11 @@
 }
 
 
+/* FIXME: is this even used? */
+#if 0
 /* debugger assist function */
 int pmap_prtrans(u_int pid, vaddr_t va);
+#endif
 
 void
 pmap_print_pted(struct pte_desc *pted, int(*print)(const char *, ...))
@@ -2649,6 +2652,8 @@
 	return 0;
 }
 
+/* FIXME: is this used anywhere? */
+#if 0
 int pmap_dump_pmap(u_int pid);
 int
 pmap_dump_pmap(u_int pid)
@@ -2675,7 +2680,10 @@
 
 	return 0;
 }
+#endif
 
+/* FIXME: is this even used? */
+#if 0
 int
 pmap_prtrans(u_int pid, vaddr_t va)
 {
@@ -2716,6 +2724,7 @@
 
 	return 0;
 }
+#endif
 int pmap_show_mappings(paddr_t pa);
 
 int
Index: arch/sh/sh/db_interface.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/sh/sh/db_interface.c,v
retrieving revision 1.2
retrieving revision 1.2.10.3
diff -u -r1.2 -r1.2.10.3
--- arch/sh/sh/db_interface.c	6 Oct 2006 21:16:57 -0000	1.2
+++ arch/sh/sh/db_interface.c	18 Feb 2009 12:43:24 -0000	1.2.10.3
@@ -367,11 +367,14 @@
 __db_procname_by_asid(int asid)
 {
 	static char notfound[] = "---";
+	struct inst *i;
 	struct proc *p;
 
-	LIST_FOREACH(p, &allproc, p_list) {
-		if (p->p_vmspace->vm_map.pmap->pm_asid == asid)
-			return (p->p_comm);
+	LIST_FOREACH(i, &inst_all, inst_list) {
+		LIST_FOREACH(p, &i->inst_proc->allproc, p_list) {
+			if (p->p_vmspace->vm_map.pmap->pm_asid == asid)
+				return (p->p_comm);
+		}
 	}
 
 	return (notfound);
@@ -601,6 +604,7 @@
 		  char *modif)
 {
 	struct proc *p;
+	struct inst *inst;
 	struct user *u;
 	struct pcb *pcb;
 	uint32_t *t32;
@@ -617,27 +621,29 @@
 		  "stack top    max used    frame top     max used"
 		  "  nest\n");
 
-	LIST_FOREACH(p, &allproc, p_list) {
-		u = p->p_addr;
-		pcb = &u->u_pcb;
-		/* stack */
-		t32 = (uint32_t *)(pcb->pcb_sf.sf_r7_bank - MAX_STACK);
-		for (i = 0; *t32++ == 0xa5a5a5a5; i++)
-			continue;
-		i = MAX_STACK - i * sizeof(int);
-
-		/* frame */
-		t8 = (uint8_t *)((vaddr_t)pcb + PAGE_SIZE - MAX_FRAME);
-		for (j = 0; *t8++ == 0x5a; j++)
-			continue;
-		j = MAX_FRAME - j;
-
-		db_printf("%6d 0x%08x %6d (%3d%%) 0x%08lx %6d (%3d%%) %d %s\n",
-		    p->p_lid,
-		    pcb->pcb_sf.sf_r7_bank, i, i * 100 / MAX_STACK,
-		    (vaddr_t)pcb + PAGE_SIZE, j, j * 100 / MAX_FRAME,
-		    j / sizeof(struct trapframe),
-		    p->p_comm);
+	LIST_FOREACH(inst, &inst_all, inst_list) {
+		LIST_FOREACH(p, &inst->inst_proc->allproc, p_list) {
+			u = p->p_addr;
+			pcb = &u->u_pcb;
+			/* stack */
+			t32 = (uint32_t *)(pcb->pcb_sf.sf_r7_bank - MAX_STACK);
+			for (i = 0; *t32++ == 0xa5a5a5a5; i++)
+				continue;
+			i = MAX_STACK - i * sizeof(int);
+	
+			/* frame */
+			t8 = (uint8_t *)((vaddr_t)pcb + PAGE_SIZE - MAX_FRAME);
+			for (j = 0; *t8++ == 0x5a; j++)
+				continue;
+			j = MAX_FRAME - j;
+	
+			db_printf("%6d 0x%08x %6d (%3d%%) 0x%08lx %6d (%3d%%) %d %s\n",
+			    p->p_lid,
+			    pcb->pcb_sf.sf_r7_bank, i, i * 100 / MAX_STACK,
+			    (vaddr_t)pcb + PAGE_SIZE, j, j * 100 / MAX_FRAME,
+			    j / sizeof(struct trapframe),
+			    p->p_comm);
+		}
 	}
 #undef	MAX_STACK
 #undef	MAX_FRAME
Index: arch/sh/sh/pmap.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/sh/sh/pmap.c,v
retrieving revision 1.9
retrieving revision 1.9.4.3
diff -u -r1.9 -r1.9.4.3
--- arch/sh/sh/pmap.c	26 Jun 2008 05:42:13 -0000	1.9
+++ arch/sh/sh/pmap.c	18 Feb 2009 12:43:24 -0000	1.9.4.3
@@ -1035,6 +1035,7 @@
 __pmap_asid_alloc()
 {
 	struct proc *p;
+	struct inst *i;
 	int i, j, k, n, map, asid;
 
 	/* Search free ASID */
@@ -1053,15 +1054,17 @@
 	}
 
 	/* Steal ASID */
-	LIST_FOREACH(p, &allproc, p_list) {
-		if ((asid = p->p_vmspace->vm_map.pmap->pm_asid) > 0) {
-			pmap_t pmap = p->p_vmspace->vm_map.pmap;
-			pmap->pm_asid = -1;
-			__pmap_asid.hint = asid;
-			/* Invalidate all old ASID entry */
-			sh_tlb_invalidate_asid(pmap->pm_asid);
-
-			return (__pmap_asid.hint);
+	LIST_FOREACH(inst, &inst_all, inst_list) {
+		LIST_FOREACH(p, &inst->inst_proc->allproc, p_list) {
+			if ((asid = p->p_vmspace->vm_map.pmap->pm_asid) > 0) {
+				pmap_t pmap = p->p_vmspace->vm_map.pmap;
+				pmap->pm_asid = -1;
+				__pmap_asid.hint = asid;
+				/* Invalidate all old ASID entry */
+				sh_tlb_invalidate_asid(pmap->pm_asid);
+	
+				return (__pmap_asid.hint);
+			}
 		}
 	}
 
Index: arch/sparc/conf/GENERIC
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/sparc/conf/GENERIC,v
retrieving revision 1.90
retrieving revision 1.90.8.1
diff -u -r1.90 -r1.90.8.1
--- arch/sparc/conf/GENERIC	29 May 2007 09:54:03 -0000	1.90
+++ arch/sparc/conf/GENERIC	18 Feb 2009 12:43:24 -0000	1.90.8.1
@@ -28,7 +28,7 @@
 # Options for SPARCstation hardware
 option		COMPAT_SUNOS	# compatibility with SunOS binaries
 option		COMPAT_SVR4	# compatibility with SVR4 binaries
-option		PROCFS		# /proc
+#option		PROCFS		# /proc
 
 option		WSEMUL_SUN	# provide sun terminal emulation; required
 option		WSEMUL_NO_VT100	# do not provide vt100 terminal emulation
Index: arch/sparc64/sparc64/db_interface.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/sparc64/sparc64/db_interface.c,v
retrieving revision 1.26
retrieving revision 1.26.4.3
diff -u -r1.26 -r1.26.4.3
--- arch/sparc64/sparc64/db_interface.c	13 Mar 2008 23:29:46 -0000	1.26
+++ arch/sparc64/sparc64/db_interface.c	18 Feb 2009 12:43:24 -0000	1.26.4.3
@@ -815,18 +815,21 @@
 	char *modif;
 {
 	struct proc *p;
+	struct inst *inst;
 
 	/* XXX LOCKING XXX */
-	LIST_FOREACH(p, &allproc, p_list) {
-		if (p->p_stat) {
-			db_printf("process %p:", p);
-			db_printf("pid:%d pmap:%p ctx:%x tf:%p fpstate %p "
-				"lastcall:%s\n",
-				p->p_pid, p->p_vmspace->vm_map.pmap,
-				p->p_vmspace->vm_map.pmap->pm_ctx,
-				p->p_md.md_tf, p->p_md.md_fpstate,
-				(p->p_addr->u_pcb.lastcall)?
-				p->p_addr->u_pcb.lastcall : "Null");
+	LIST_FOREACH(inst, &inst_all, inst_list) {
+		LIST_FOREACH(p, &inst->inst_proc->allproc, p_list) {
+			if (p->p_stat) {
+				db_printf("process %p:", p);
+				db_printf("inst:%u pid:%d pmap:%p ctx:%x tf:%p fpstate %p "
+					"lastcall:%s\n", p->p_inst->inst_id,
+					p->p_pid, p->p_vmspace->vm_map.pmap,
+					p->p_vmspace->vm_map.pmap->pm_ctx,
+					p->p_md.md_tf, p->p_md.md_fpstate,
+					(p->p_addr->u_pcb.lastcall)?
+					p->p_addr->u_pcb.lastcall : "Null");
+			}
 		}
 	}
 	return;
@@ -886,23 +889,31 @@
 	char *modif;
 {
 	struct proc *p, *pp;
+	struct inst *inst;
 
 	if (!have_addr) {
 		db_printf("What PID do you want to map in?\n");
 		return;
 	}
+	
+	/* 
+	 * FIXME: this doesn't work if multiple procs/same pids can
+	 * co-exist (mult).
+	 */
     
-	LIST_FOREACH(p, &allproc, p_list) {
-		pp = p->p_pptr;
-		if (p->p_stat && p->p_pid == addr) {
-			curproc = p;
-			curpcb = (struct pcb*)p->p_addr;
-			if (p->p_vmspace->vm_map.pmap->pm_ctx) {
-				switchtoctx(p->p_vmspace->vm_map.pmap->pm_ctx);
+	LIST_FOREACH(inst, &inst_all, inst_list) {
+		LIST_FOREACH(p, &inst->inst_proc->allproc, p_list) {
+			pp = p->p_pptr;
+			if (p->p_stat && p->p_pid == addr) {
+				curproc = p;
+				curpcb = (struct pcb*)p->p_addr;
+				if (p->p_vmspace->vm_map.pmap->pm_ctx) {
+					switchtoctx(p->p_vmspace->vm_map.pmap->pm_ctx);
+					return;
+				}
+				db_printf("PID %ld has a null context.\n", addr);
 				return;
 			}
-			db_printf("PID %ld has a null context.\n", addr);
-			return;
 		}
 	}
 	db_printf("PID %ld not found.\n", addr);
Index: arch/sparc64/sparc64/db_trace.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/sparc64/sparc64/db_trace.c,v
retrieving revision 1.9
retrieving revision 1.9.8.1
diff -u -r1.9 -r1.9.8.1
--- arch/sparc64/sparc64/db_trace.c	15 Aug 2007 20:10:08 -0000	1.9
+++ arch/sparc64/sparc64/db_trace.c	16 Sep 2008 23:10:38 -0000	1.9.8.1
@@ -79,6 +79,9 @@
 		frame = (vaddr_t)DDB_TF->tf_out[6];
 	else {
 		if (trace_thread) {
+			/* FIXME: instances */
+			(*pr)("db_trace.c: operation not supported\n");
+#if 0
 			struct proc *p;
 			struct user *u;
 			(*pr)("trace: pid %d ", (int)addr);
@@ -90,6 +93,7 @@
 			u = p->p_addr;
 			frame = (vaddr_t)u->u_pcb.pcb_sp;
 			(*pr)("at %p\n", frame);
+#endif
 		} else {
 			frame = (vaddr_t)addr;
 		}
Index: arch/vax/vax/db_machdep.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/arch/vax/vax/db_machdep.c,v
retrieving revision 1.18
retrieving revision 1.18.4.1
diff -u -r1.18 -r1.18.4.1
--- arch/vax/vax/db_machdep.c	30 Mar 2008 18:24:04 -0000	1.18
+++ arch/vax/vax/db_machdep.c	16 Sep 2008 23:10:38 -0000	1.18.4.1
@@ -347,6 +347,9 @@
 	 * if no address then either current proc or panic
 	 */
 	if (have_addr) {
+		/* FIXME: instances */
+		(*pr) ("db_machdep.c: operation not supported\n");
+#if 0
 		p = pfind((int)addr);
 		/* Try to be helpful by looking at it as if it were decimal */
 		if (p == NULL) {
@@ -368,6 +371,7 @@
 				return;
 			}
 		}
+#endif
 	} else {
 		p = curproc;
 		if (p == NULL) {
Index: compat/hpux/hpux_compat.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/compat/hpux/hpux_compat.c,v
retrieving revision 1.29
retrieving revision 1.29.6.1
diff -u -r1.29 -r1.29.6.1
--- compat/hpux/hpux_compat.c	22 Sep 2007 09:57:40 -0000	1.29
+++ compat/hpux/hpux_compat.c	16 Sep 2008 23:10:38 -0000	1.29.6.1
@@ -519,7 +519,7 @@
 		return (EINVAL);
 	if (SCARG(uap, pid) == 0)
 		p = cp;
-	else if ((p = pfind(SCARG(uap, pid))) == 0)
+	else if ((p = pfind(cp->p_inst->inst_proc, SCARG(uap, pid))) == 0)
 		return (ESRCH);
 	nice = p->p_nice;
 	if (nice < NZERO)
@@ -597,7 +597,7 @@
 		 * has the correct value (the child has already trapped
 		 * into the kernel).
 		 */
-		if ((cp = pfind(SCARG(uap, pid))) == 0)
+		if ((cp = pfind(p->p_inst->inst_proc, SCARG(uap, pid))) == 0)
 			return (ESRCH);
 		SCARG(uap, addr) =
 		    (int *)hpux_to_bsd_uoff(SCARG(uap, addr), &isps, cp);
@@ -961,7 +961,7 @@
 
 	if (SCARG(uap, pid) == 0)
 		SCARG(uap, pid) = cp->p_pid;
-	p = pfind(SCARG(uap, pid));
+	p = pfind(cp->p_inst->inst_proc, SCARG(uap, pid));
 	if (p == 0)
 		return (ESRCH);
 	if (cp->p_ucred->cr_uid && p->p_ucred->cr_uid != cp->p_ucred->cr_uid &&
Index: compat/linux/linux_file.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/compat/linux/linux_file.c,v
retrieving revision 1.23
retrieving revision 1.23.10.2
diff -u -r1.23 -r1.23.10.2
--- compat/linux/linux_file.c	25 Sep 2006 07:12:57 -0000	1.23
+++ compat/linux/linux_file.c	18 Sep 2008 17:21:02 -0000	1.23.10.2
@@ -417,12 +417,12 @@
 		if ((long)arg <= 0) {
 			pgid = -(long)arg;
 		} else {
-			struct proc *p1 = pfind((long)arg);
+			struct proc *p1 = pfind(p->p_inst->inst_proc, (long)arg);
 			if (p1 == 0)
 				return (ESRCH);
 			pgid = (long)p1->p_pgrp->pg_id;
 		}
-		pgrp = pgfind(pgid);
+		pgrp = pgfind(p->p_inst->inst_proc, pgid);
 		if (pgrp == NULL || pgrp->pg_session != p->p_session)
 			return EPERM;
 		tp->t_pgrp = pgrp;
Index: compat/linux/linux_misc.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/compat/linux/linux_misc.c,v
retrieving revision 1.62
retrieving revision 1.62.4.3
diff -u -r1.62 -r1.62.4.3
--- compat/linux/linux_misc.c	26 Jun 2008 05:42:14 -0000	1.62
+++ compat/linux/linux_misc.c	18 Feb 2009 12:43:24 -0000	1.62.4.3
@@ -1226,7 +1226,7 @@
 	struct proc *targp;
 
 	if (SCARG(uap, pid) != 0 && SCARG(uap, pid) != p->p_pid) {
-		if ((targp = pfind(SCARG(uap, pid))) == 0)
+		if ((targp = pfind(p->p_inst->inst_proc, SCARG(uap, pid))) == 0)
 			return ESRCH;
 	}
 	else
@@ -1320,7 +1320,7 @@
 		return 0;
 	}
 
-	p1 = pfind((int)pid);
+	p1 = pfind(p->p_inst->inst_proc, (int)pid);
 	if (p1 == NULL)
 		return ESRCH;
 
Index: compat/linux/linux_sched.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/compat/linux/linux_sched.c,v
retrieving revision 1.6
retrieving revision 1.6.4.1
diff -u -r1.6 -r1.6.4.1
--- compat/linux/linux_sched.c	26 Jun 2008 05:42:14 -0000	1.6
+++ compat/linux/linux_sched.c	16 Sep 2008 23:10:38 -0000	1.6.4.1
@@ -121,7 +121,7 @@
 	if (SCARG(uap, pid) != 0) {
 		struct pcred *pc = cp->p_cred;
 
-		if ((p = pfind(SCARG(uap, pid))) == NULL)
+		if ((p = pfind(cp->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 			return (ESRCH);
 		if (!(cp == p ||
 		      pc->pc_ucred->cr_uid == 0 ||
@@ -158,7 +158,7 @@
 	if (SCARG(uap, pid) != 0) {
 		struct pcred *pc = cp->p_cred;
 
-		if ((p = pfind(SCARG(uap, pid))) == NULL)
+		if ((p = pfind(cp->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 			return (ESRCH);
 		if (!(cp == p ||
 		      pc->pc_ucred->cr_uid == 0 ||
@@ -202,7 +202,7 @@
 	if (SCARG(uap, pid) != 0) {
 		struct pcred *pc = cp->p_cred;
 
-		if ((p = pfind(SCARG(uap, pid))) == NULL)
+		if ((p = pfind(cp->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 			return (ESRCH);
 		if (!(cp == p ||
 		      pc->pc_ucred->cr_uid == 0 ||
@@ -242,7 +242,7 @@
 	if (SCARG(uap, pid) != 0) {
 		struct pcred *pc = cp->p_cred;
 
-		if ((p = pfind(SCARG(uap, pid))) == NULL)
+		if ((p = pfind(cp->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 			return (ESRCH);
 		if (!(cp == p ||
 		      pc->pc_ucred->cr_uid == 0 ||
Index: compat/svr4/svr4_misc.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/compat/svr4/svr4_misc.c,v
retrieving revision 1.49
retrieving revision 1.49.6.3
diff -u -r1.49 -r1.49.6.3
--- compat/svr4/svr4_misc.c	1 Oct 2007 12:10:55 -0000	1.49
+++ compat/svr4/svr4_misc.c	18 Feb 2009 12:43:25 -0000	1.49.6.3
@@ -101,7 +101,7 @@
     struct svr4_statvfs *);
 static void bsd_statfs_to_svr4_statvfs64(const struct statfs *,
     struct svr4_statvfs64 *);
-static struct proc *svr4_pfind(pid_t pid);
+static struct proc *svr4_pfind(struct inst_proc *, pid_t pid);
 
 static int svr4_mknod(struct proc *, register_t *, char *,
 			   svr4_mode_t, svr4_dev_t);
@@ -816,17 +816,18 @@
 
 
 static struct proc *
-svr4_pfind(pid)
+svr4_pfind(ip, pid)
+	struct inst_proc *ip;
 	pid_t pid;
 {
 	struct proc *p;
 
 	/* look in the live processes */
-	if ((p = pfind(pid)) != NULL)
+	if ((p = pfind(ip, pid)) != NULL)
 		return p;
 
 	/* look in the zombies */
-	LIST_FOREACH(p, &zombproc, p_list)
+	LIST_FOREACH(p, &ip->zombproc, p_list)
 		if (p->p_pid == pid)
 			return p;
 
@@ -862,7 +863,7 @@
 
 	case 2:			/* getsid(pid) */
 		if (SCARG(uap, pid) != 0 &&
-		    (p = svr4_pfind(SCARG(uap, pid))) == NULL)
+		    (p = svr4_pfind(p->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 			return ESRCH;
 		/* 
 		 * we return the pid of the session leader for this
@@ -877,7 +878,7 @@
 	case 4:			/* getpgid(pid) */
 
 		if (SCARG(uap, pid) != 0 &&
-		    (p = svr4_pfind(SCARG(uap, pid))) == NULL)
+		    (p = svr4_pfind(p->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 			return ESRCH;
 
 		*retval = (int) p->p_pgrp->pg_id;
@@ -1091,7 +1092,7 @@
 			 * If we got the child via a ptrace 'attach',
 			 * we need to give it back to the old parent.
 			 */
-			if (p->p_oppid && (t = pfind(p->p_oppid))) {
+			if (p->p_oppid && (t = pfind(p->p_inst->inst_proc, p->p_oppid))) {
 				p->p_oppid = 0;
 				proc_reparent(p, t);
 				psignal(t, SIGCHLD);
Index: conf/files
===================================================================
RCS file: /cvs/OpenBSD/src/sys/conf/files,v
retrieving revision 1.438
retrieving revision 1.438.4.1
diff -u -r1.438 -r1.438.4.1
--- conf/files	21 Jul 2008 19:05:21 -0000	1.438
+++ conf/files	12 Sep 2008 13:58:48 -0000	1.438.4.1
@@ -651,6 +651,7 @@
 file kern/kern_exec.c
 file kern/kern_exit.c
 file kern/kern_fork.c
+file kern/kern_inst.c
 file kern/kern_kthread.c
 file kern/kern_ktrace.c			ktrace
 file kern/kern_lock.c
Index: dev/systrace.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/dev/systrace.c,v
retrieving revision 1.47
retrieving revision 1.47.6.1
diff -u -r1.47 -r1.47.6.1
--- dev/systrace.c	5 Jan 2008 07:33:37 -0000	1.47
+++ dev/systrace.c	16 Sep 2008 23:10:38 -0000	1.47.6.1
@@ -149,15 +149,15 @@
 
 /* Needs to be called with fst locked */
 
-int	systrace_attach(struct fsystrace *, pid_t);
-int	systrace_detach(struct str_process *);
+int	systrace_attach(struct inst *, struct fsystrace *, pid_t);
+int	systrace_detach(struct inst *, struct str_process *);
 int	systrace_answer(struct str_process *, struct systrace_answer *);
 int     systrace_setscriptname(struct str_process *,
 	    struct systrace_scriptname *);
 int     systrace_prepinject(struct str_process *, struct systrace_inject *);
 int     systrace_inject(struct str_process *, int);
 int	systrace_io(struct str_process *, struct systrace_io *);
-int	systrace_policy(struct fsystrace *, struct systrace_policy *);
+int	systrace_policy(struct inst *, struct fsystrace *, struct systrace_policy *);
 int	systrace_preprepl(struct str_process *, struct systrace_replace *);
 int	systrace_replace(struct str_process *, size_t, register_t []);
 int	systrace_getcwd(struct fsystrace *, struct str_process *);
@@ -165,8 +165,8 @@
 void	systrace_replacefree(struct str_process *);
 
 int	systrace_processready(struct str_process *);
-struct proc *systrace_find(struct str_process *);
-struct str_process *systrace_findpid(struct fsystrace *fst, pid_t pid);
+struct proc *systrace_find(struct inst *, struct str_process *);
+struct str_process *systrace_findpid(struct inst *, struct fsystrace *fst, pid_t pid);
 void	systrace_wakeup(struct fsystrace *);
 void	systrace_closepolicy(struct fsystrace *, struct str_policy *);
 int	systrace_insert_process(struct fsystrace *, struct proc *);
@@ -335,7 +335,7 @@
 	rw_enter_write(&fst->lock);
 	systrace_unlock();
 	if (pid) {
-		strp = systrace_findpid(fst, pid);
+		strp = systrace_findpid(p->p_inst, fst, pid);
 		if (strp == NULL) {
 			ret = ESRCH;
 			goto unlock;
@@ -348,11 +348,11 @@
 		if (!pid)
 			ret = EINVAL;
 		else
-			ret = systrace_attach(fst, pid);
+			ret = systrace_attach(p->p_inst, fst, pid);
 		DPRINTF(("%s: attach to %u: %d\n", __func__, pid, ret));
 		break;
 	case STRIOCDETACH:
-		ret = systrace_detach(strp);
+		ret = systrace_detach(p->p_inst, strp);
 		break;
 	case STRIOCREPORT:
 		SET(strp->flags, STR_PROC_REPORT);
@@ -371,7 +371,7 @@
 		ret = systrace_prepinject(strp, (struct systrace_inject *)data);
 		break;
 	case STRIOCPOLICY:
-		ret = systrace_policy(fst, (struct systrace_policy *)data);
+		ret = systrace_policy(p->p_inst, fst, (struct systrace_policy *)data);
 		break;
 	case STRIOCREPLACE:
 		ret = systrace_preprepl(strp, (struct systrace_replace *)data);
@@ -471,7 +471,7 @@
 	    strp = TAILQ_FIRST(&fst->processes)) {
 		struct proc *q = strp->proc;
 
-		systrace_detach(strp);
+		systrace_detach(p->p_inst, strp);
 		psignal(q, SIGKILL);
 	}
 
@@ -610,11 +610,11 @@
 }
 
 struct proc *
-systrace_find(struct str_process *strp)
+systrace_find(struct inst *inst, struct str_process *strp)
 {
 	struct proc *proc;
 
-	if ((proc = pfind(strp->pid)) == NULL)
+	if ((proc = pfind(inst->inst_proc, strp->pid)) == NULL)
 		return (NULL);
 
 	if (proc != strp->proc)
@@ -642,7 +642,7 @@
 		/* Insert Exit message */
 		systrace_msg_child(fst, strp, -1);
 
-		systrace_detach(strp);
+		systrace_detach(proc->p_inst, strp);
 		rw_exit_write(&fst->lock);
 	} else
 		systrace_unlock();
@@ -668,7 +668,7 @@
 
 	if (systrace_insert_process(fst, p))
 		goto out;
-	if ((strp = systrace_findpid(fst, p->p_pid)) == NULL)
+	if ((strp = systrace_findpid(p->p_inst, fst, p->p_pid)) == NULL)
 		panic("systrace_fork");
 
 	/* Reference policy */
@@ -1058,7 +1058,7 @@
 }
 
 int
-systrace_policy(struct fsystrace *fst, struct systrace_policy *pol)
+systrace_policy(struct inst *inst, struct fsystrace *fst, struct systrace_policy *pol)
 {
 	struct str_policy *strpol;
 	struct str_process *strp;
@@ -1085,7 +1085,7 @@
 		if (strpol == NULL)
 			return (EINVAL);
 
-		strp = systrace_findpid(fst, pol->strp_pid);
+		strp = systrace_findpid(inst, fst, pol->strp_pid);
 		if (strp == NULL)
 			return (EINVAL);
 
@@ -1216,12 +1216,12 @@
 }
 
 int
-systrace_attach(struct fsystrace *fst, pid_t pid)
+systrace_attach(struct inst *inst, struct fsystrace *fst, pid_t pid)
 {
 	int error = 0;
 	struct proc *proc, *p = curproc;
 
-	if ((proc = pfind(pid)) == NULL) {
+	if ((proc = pfind(inst->inst_proc, pid)) == NULL) {
 		error = ESRCH;
 		goto out;
 	}
@@ -1550,7 +1550,7 @@
 }
 
 struct str_process *
-systrace_findpid(struct fsystrace *fst, pid_t pid)
+systrace_findpid(struct inst *inst, struct fsystrace *fst, pid_t pid)
 {
 	struct str_process *strp;
 	struct proc *proc = NULL;
@@ -1562,13 +1562,13 @@
 	if (strp == NULL)
 		return (NULL);
 
-	proc = systrace_find(strp);
+	proc = systrace_find(inst, strp);
 
 	return (proc ? strp : NULL);
 }
 
 int
-systrace_detach(struct str_process *strp)
+systrace_detach(struct inst *inst, struct str_process *strp)
 {
 	struct proc *proc;
 	struct fsystrace *fst = NULL;
@@ -1576,7 +1576,7 @@
 
 	DPRINTF(("%s: Trying to detach from %d\n", __func__, strp->pid));
 
-	if ((proc = systrace_find(strp)) != NULL) {
+	if ((proc = systrace_find(inst, strp)) != NULL) {
 		atomic_clearbits_int(&proc->p_flag, P_SYSTRACE);
 		proc->p_systrace = NULL;
 	} else
Index: dev/wscons/wsdisplay_compat_usl.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/dev/wscons/wsdisplay_compat_usl.c,v
retrieving revision 1.19
retrieving revision 1.19.10.1
diff -u -r1.19 -r1.19.10.1
--- dev/wscons/wsdisplay_compat_usl.c	14 Feb 2007 01:12:16 -0000	1.19
+++ dev/wscons/wsdisplay_compat_usl.c	16 Sep 2008 23:10:38 -0000	1.19.10.1
@@ -145,7 +145,7 @@
 usl_sync_check(sd)
 	struct usl_syncdata *sd;
 {
-	if (sd->s_proc == pfind(sd->s_pid))
+	if (sd->s_proc == pfind(sd->s_proc->p_inst->inst_proc, sd->s_pid))
 		return (1);
 	DPRINTF(("usl_sync_check: process %d died\n", sd->s_pid));
 	usl_sync_done(sd);
Index: kern/init_main.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/init_main.c,v
retrieving revision 1.150
retrieving revision 1.150.4.10
diff -u -r1.150 -r1.150.4.10
--- kern/init_main.c	9 Jun 2008 07:07:16 -0000	1.150
+++ kern/init_main.c	18 Feb 2009 18:20:20 -0000	1.150.4.10
@@ -217,6 +217,8 @@
 	tty_init();		/* initialise tty's */
 	cpu_startup();
 
+	printf("cpu is started\n");
+
 	/*
 	 * Initialize mbuf's.  Do this now because we might attempt to
 	 * allocate mbufs or mbuf clusters during autoconfiguration.
@@ -227,6 +229,11 @@
 	soinit();
 
 	/*
+	 * Initialise instance structures.
+	 */
+	instinit();
+
+	/*
 	 * Initialize process and pgrp structures.
 	 */
 	procinit();
@@ -252,16 +259,12 @@
 	/*
 	 * Create process 0 (the swapper).
 	 */
-
 	process0.ps_mainproc = p;
 	TAILQ_INIT(&process0.ps_threads);
 	TAILQ_INSERT_TAIL(&process0.ps_threads, p, p_thr_link);
 	p->p_p = &process0;
 
-	LIST_INSERT_HEAD(&allproc, p, p_list);
 	p->p_pgrp = &pgrp0;
-	LIST_INSERT_HEAD(PIDHASH(0), p, p_hash);
-	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
 	LIST_INIT(&pgrp0.pg_members);
 	LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
 
@@ -282,9 +285,23 @@
 	/* Create credentials. */
 	cred0.p_refcnt = 1;
 	p->p_cred = &cred0;
-	p->p_ucred = crget();
+	p->p_ucred = crnew();
 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
 
+	/* 
+	 * FIXME: eventually instances should all be "flat", but for now
+	 * the "main" instance, with id 0,  gets special handling (can't
+	 * be killed).
+	 */
+
+	if (NULL == (p->p_ucred->cr_inst = instknew(0)))
+		panic("couldn't allocate kernel instance");
+
+	p->p_ucred->cr_inst->inst_proc = proc_instinit(p->p_inst);
+
+	pgrp_instadd(p->p_inst->inst_proc, p->p_pgrp);
+	proc_instadd(p->p_inst->inst_proc, p);
+
 	/* Initialize signal state for process 0. */
 	signal_init();
 	p->p_sigacts = &sigacts0;
@@ -422,6 +439,9 @@
 	    &initproc))
 		panic("fork init");
 
+	/* Set "init" process. */
+	p->p_inst->inst_proc->initproc = initproc;
+
 	/*
 	 * Create any kernel threads whose creation was deferred because
 	 * initproc had not yet been created.
@@ -478,7 +498,7 @@
 #else
 	boottime = mono_time = time;	
 #endif
-	LIST_FOREACH(p, &allproc, p_list) {
+	PROCLIST_FOREACH(p, initproc, p_list) {
 		p->p_stats->p_start = boottime;
 		microuptime(&p->p_cpu->ci_schedstate.spc_runtime);
 		p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
Index: kern/init_sysent.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/init_sysent.c,v
retrieving revision 1.103
retrieving revision 1.103.4.3
diff -u -r1.103 -r1.103.4.3
--- kern/init_sysent.c	16 Mar 2008 19:43:41 -0000	1.103
+++ kern/init_sysent.c	13 Feb 2009 09:08:59 -0000	1.103.4.3
@@ -1,10 +1,10 @@
-/*	$OpenBSD$	*/
+/*	\$OpenBSD\$	*/
 
 /*
  * System call switch table.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from;	OpenBSD: syscalls.master,v 1.90 2008/03/16 19:42:57 otto Exp 
+ * created from;	OpenBSD: syscalls.master,v 1.89 2008/01/05 00:36:13 miod Exp 
  */
 
 #include <sys/param.h>
@@ -836,5 +836,11 @@
 	    sys_fstatfs },			/* 308 = fstatfs */
 	{ 2, s(struct sys_fhstatfs_args), 0,
 	    sys_fhstatfs },			/* 309 = fhstatfs */
+	{ 1, s(struct sys_forkinst_args), 0,
+	    sys_forkinst },			/* 310 = forkinst */
+	{ 0, 0, SY_NOLOCK | 0,
+	    sys_getinstid },			/* 311 = getinstid */
+	{ 2, s(struct sys_killinst_args), 0,
+	    sys_killinst },			/* 312 = killinst */
 };
 
Index: kern/kern_descrip.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_descrip.c,v
retrieving revision 1.79
retrieving revision 1.79.4.3
diff -u -r1.79 -r1.79.4.3
--- kern/kern_descrip.c	12 Jun 2008 18:10:06 -0000	1.79
+++ kern/kern_descrip.c	27 Sep 2008 14:09:44 -0000	1.79.4.3
@@ -383,13 +383,14 @@
 
 			so->so_pgid = (long)SCARG(uap, arg);
 			so->so_siguid = p->p_cred->p_ruid;
+			so->so_siginstid = p->p_inst->inst_id;
 			so->so_sigeuid = p->p_ucred->cr_uid;
 			break;
 		}
 		if ((long)SCARG(uap, arg) <= 0) {
 			SCARG(uap, arg) = (void *)(-(long)SCARG(uap, arg));
 		} else {
-			struct proc *p1 = pfind((long)SCARG(uap, arg));
+			struct proc *p1 = pfind(p->p_inst->inst_proc, (long)SCARG(uap, arg));
 			if (p1 == 0) {
 				error = ESRCH;
 				break;
@@ -838,7 +839,7 @@
 	extern int cmask;
 
 	newfdp = pool_get(&fdesc_pool, PR_WAITOK|PR_ZERO);
-	if (p != NULL) {
+	if (p) {
 		struct filedesc *fdp = p->p_fd;
 
 		newfdp->fd_fd.fd_cdir = fdp->fd_cdir;
Index: kern/kern_event.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_event.c,v
retrieving revision 1.33
retrieving revision 1.33.4.2
diff -u -r1.33 -r1.33.4.2
--- kern/kern_event.c	6 May 2008 20:57:19 -0000	1.33
+++ kern/kern_event.c	18 Sep 2008 21:04:55 -0000	1.33.4.2
@@ -193,7 +193,7 @@
 {
 	struct proc *p;
 
-	p = pfind(kn->kn_id);
+	p = pfind(curproc->p_inst->inst_proc, kn->kn_id);
 	if (p == NULL)
 		return (ESRCH);
 
Index: kern/kern_exit.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_exit.c,v
retrieving revision 1.73
retrieving revision 1.73.4.9
diff -u -r1.73 -r1.73.4.9
--- kern/kern_exit.c	11 May 2008 23:54:40 -0000	1.73
+++ kern/kern_exit.c	18 Feb 2009 12:43:25 -0000	1.73.4.9
@@ -77,6 +77,9 @@
 
 #include <uvm/uvm_extern.h>
 
+
+void		waitinst(struct proc *);
+
 /*
  * exit --
  *	Death of process.
@@ -105,6 +108,35 @@
 }
 #endif
 
+void
+waitinst(struct proc *p)
+{
+	struct proc *q, *nq;
+
+	while ( ! LIST_EMPTY(&p->p_children)) {
+		for (q = LIST_FIRST(&p->p_children); q; q = nq) {
+			nq = LIST_NEXT(q, p_sibling);
+			if (SZOMB != q->p_stat)
+				continue;
+
+			log(LOG_NOTICE, "instance-%u: zapping %d\n", 
+					p->p_inst->inst_id, q->p_pid);
+
+			scheduler_wait_hook(p, q);
+			q->p_xstat = 0;
+			ruadd(&p->p_stats->p_cru, q->p_ru);
+			proc_zap(q);
+		}
+		log(LOG_NOTICE, "instance-%u: sleeping\n",
+				p->p_inst->inst_id);
+		if (LIST_EMPTY(&p->p_children))
+			break;
+		tsleep(p, PUSER, "instwait", 0);
+	}
+	log(LOG_NOTICE, "instance-%u: done waiting\n",
+			p->p_inst->inst_id);
+}
+
 /*
  * Exit: deallocate address space and other resources, change proc state
  * to zombie, and unlink proc from allproc and parent's lists.  Save exit
@@ -115,10 +147,18 @@
 {
 	struct proc *q, *nq;
 
-	if (p->p_pid == 1)
+	if (p->p_pid == 1 && p->p_inst->inst_id == 0)
 		panic("init died (signal %d, exit %d)",
 		    WTERMSIG(rv), WEXITSTATUS(rv));
-	
+
+	/* If the instance's init has died, kill off children. */
+
+	if (p == p->p_inst->inst_proc->initproc) {
+		q = LIST_FIRST(&p->p_children);
+		for (; q; q = LIST_NEXT(q, p_sibling))
+			psignal(q, SIGKILL);
+	}
+
 	/* unlink ourselves from the active threads */
 	TAILQ_REMOVE(&p->p_p->ps_threads, p, p_thr_link);
 #ifdef RTHREADS
@@ -167,6 +207,7 @@
 	atomic_clearbits_int(&p->p_flag, P_TRACED);
 	if (p->p_flag & P_PPWAIT) {
 		atomic_clearbits_int(&p->p_flag, P_PPWAIT);
+		KASSERT(p->p_pptr);
 		wakeup(p->p_pptr);
 	}
 	p->p_sigignore = ~0;
@@ -232,6 +273,10 @@
 	if (ISSET(p->p_flag, P_SYSTRACE))
 		systrace_exit(p);
 #endif
+
+	if (p == p->p_inst->inst_proc->initproc)
+		waitinst(p);
+
 	/*
 	 * NOTE: WE ARE NO LONGER ALLOWED TO SLEEP!
 	 */
@@ -246,17 +291,17 @@
          */
 	LIST_REMOVE(p, p_hash);
 	LIST_REMOVE(p, p_list);
-	LIST_INSERT_HEAD(&zombproc, p, p_list);
+	LIST_INSERT_HEAD(&p->p_inst->inst_proc->zombproc, p, p_list);
 
 	/*
 	 * Give orphaned children to init(8).
 	 */
 	q = LIST_FIRST(&p->p_children);
 	if (q)		/* only need this if any child is S_ZOMB */
-		wakeup(initproc);
+		wakeup(p->p_inst->inst_proc->initproc);
 	for (; q != 0; q = nq) {
 		nq = LIST_NEXT(q, p_sibling);
-		proc_reparent(q, initproc);
+		proc_reparent(q, p->p_inst->inst_proc->initproc);
 		/*
 		 * Traced processes are killed
 		 * since their existence means someone is screwing up.
@@ -293,9 +338,10 @@
 	 * the P_NOCLDWAIT flag set, notify process 1 instead (and hope it
 	 * will handle this situation).
 	 */
-	if ((p->p_flag & P_NOZOMBIE) || (p->p_pptr->p_flag & P_NOCLDWAIT)) {
+	if (p->p_pptr && ((p->p_flag & P_NOZOMBIE) || 
+				(p->p_pptr->p_flag & P_NOCLDWAIT))) {
 		struct proc *pp = p->p_pptr;
-		proc_reparent(p, initproc);
+		proc_reparent(p, p->p_inst->inst_proc->initproc);
 		/*
 		 * If this was the last child of our parent, notify
 		 * parent, so in case he was wait(2)ing, he will
@@ -305,9 +351,13 @@
 			wakeup(pp);
 	}
 
-	if (p->p_exitsig != 0)
+	if (p->p_exitsig != 0) {
+		KASSERT(p->p_pptr);
 		psignal(p->p_pptr, P_EXITSIG(p));
-	wakeup(p->p_pptr);
+	}
+
+	if (p->p_pptr)
+		wakeup(p->p_pptr);
 
 	/*
 	 * Release the process's signal state.
@@ -400,7 +450,7 @@
 		LIST_REMOVE(p, p_hash);
 		mtx_leave(&deadproc_mutex);
 		KERNEL_PROC_LOCK(curproc);
-
+		
 		/*
 		 * Give machine-dependent code a chance to free any
 		 * resources it couldn't free while still running on
@@ -417,7 +467,7 @@
 		uvm_exit(p);
 
 		/* Process is now a true zombie. */
-		if ((p->p_flag & P_NOZOMBIE) == 0) {
+		if (p->p_pptr && (p->p_flag & P_NOZOMBIE) == 0) {
 			p->p_stat = SZOMB;
 
 			/* Wake up the parent so it can get exit status. */
@@ -488,7 +538,7 @@
 			 * If we got the child via a ptrace 'attach',
 			 * we need to give it back to the old parent.
 			 */
-			if (p->p_oppid && (t = pfind(p->p_oppid))) {
+			if (p->p_oppid && (t = pfind(p->p_inst->inst_proc, p->p_oppid))) {
 				p->p_oppid = 0;
 				proc_reparent(p, t);
 				if (p->p_exitsig != 0)
@@ -552,7 +602,7 @@
 	if (child->p_pptr == parent)
 		return;
 
-	if (parent == initproc)
+	if (parent == parent->p_inst->inst_proc->initproc)
 		child->p_exitsig = SIGCHLD;
 
 	LIST_REMOVE(child, p_sibling);
@@ -572,8 +622,11 @@
 	 * Unlink it from its process group and free it.
 	 */
 	leavepgrp(p);
-	LIST_REMOVE(p, p_list);	/* off zombproc */
-	LIST_REMOVE(p, p_sibling);
+
+	if (p->p_pptr)
+		LIST_REMOVE(p, p_sibling);
+
+	LIST_REMOVE(p, p_list);
 
 	/*
 	 * Decrement the count of procs running with this uid.
Index: kern/kern_fork.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_fork.c,v
retrieving revision 1.95
retrieving revision 1.95.4.14
diff -u -r1.95 -r1.95.4.14
--- kern/kern_fork.c	11 May 2008 23:54:40 -0000	1.95
+++ kern/kern_fork.c	18 Feb 2009 18:20:20 -0000	1.95.4.14
@@ -70,10 +70,22 @@
 pid_t	lastpid;
 struct	forkstat forkstat;
 
-void fork_return(void *);
-int pidtaken(pid_t);
+void 	fork_return(void *);
+int 	pidtaken(struct inst_proc *, pid_t);
+void 	process_new(struct proc *);
+pid_t	pid_new(struct inst *);
 
-void process_new(struct proc *, struct proc *);
+
+pid_t
+pid_new(struct inst *inst)
+{
+
+	/* Find an unused pid satisfying 1 <= lastpid <= PID_MAX */
+	do {
+		lastpid = 1 + (randompid ? arc4random() : lastpid) % PID_MAX;
+	} while (pidtaken(inst->inst_proc, lastpid));
+	return(lastpid);
+}
 
 void
 fork_return(void *arg)
@@ -107,6 +119,7 @@
 	    NULL, retval, NULL));
 }
 
+
 int
 sys_rfork(struct proc *p, void *v, register_t *retval)
 {
@@ -153,7 +166,7 @@
  * Allocate and initialize a new process.
  */
 void
-process_new(struct proc *newproc, struct proc *parent)
+process_new(struct proc *newproc)
 {
 	struct process *pr;
 
@@ -167,6 +180,131 @@
 /* print the 'table full' message once per 10 seconds */
 struct timeval fork_tfmrate = { 10, 0 };
 
+
+int
+forkinst1(struct proc *p1, instid_t id, register_t *retval)
+{
+	struct proc	*p2;
+	struct vmspace	*vm;
+	vaddr_t		 uaddr;
+	int		 s;
+	struct inst	*inst;
+
+	extern void endtsleep(void *);
+	extern void realitexpire(void *);
+
+	if (0 != p1->p_cred->p_ruid)
+		return(EPERM);
+
+	if (NULL == (inst = instpnew(p1, id)))
+		return(EINSTEXIST);
+
+	(void)chgproccnt(0, 1);
+
+	uaddr = uvm_km_alloc1(kernel_map, USPACE, USPACE_ALIGN, 1);
+	if (uaddr == 0) {
+		(void)chgproccnt(0, -1);
+		instfree(inst);
+		return(ENOMEM);
+	}
+
+	/*
+	 * From now on, we're committed to the fork and cannot fail.
+	 */
+
+	inst->inst_proc = proc_instinit(inst);
+
+	p2 = pool_get(&proc_pool, PR_WAITOK);
+
+	p2->p_stat = SIDL;
+	p2->p_exitsig = 0;
+	p2->p_flag = 0;
+
+	process_new(p2);
+
+	bzero(&p2->p_startzero,
+	    (unsigned) ((caddr_t)&p2->p_endzero - (caddr_t)&p2->p_startzero));
+	bcopy(&p1->p_startcopy, &p2->p_startcopy,
+	    (unsigned) ((caddr_t)&p2->p_endcopy - (caddr_t)&p2->p_startcopy));
+
+	timeout_set(&p2->p_sleep_to, endtsleep, p2);
+	timeout_set(&p2->p_realit_to, realitexpire, p2);
+
+	p2->p_cpu = p1->p_cpu;
+	p2->p_emul = p1->p_emul;
+	bcopy("init", p2->p_comm, sizeof("init"));
+
+	atomic_setbits_int(&p2->p_flag, p1->p_flag & (P_SUGID | P_SUGIDEXEC));
+
+	p2->p_p->ps_cred = pool_get(&pcred_pool, PR_WAITOK | PR_ZERO);
+	bcopy(p1->p_p->ps_cred, p2->p_p->ps_cred, sizeof(*p2->p_p->ps_cred));
+	p2->p_p->ps_cred->p_refcnt = 1;
+	p2->p_p->ps_cred->pc_ucred = crnew();
+	p2->p_p->ps_cred->pc_ucred->cr_inst = inst;
+
+	p2->p_textvp = p1->p_textvp;
+	if (p2->p_textvp)
+		VREF(p2->p_textvp);
+
+	p2->p_fd = fdinit(p1);
+
+	p2->p_p->ps_limit = limcopy(p1->p_p->ps_limit);
+
+	p2->p_pptr = NULL;
+
+	LIST_INIT(&p2->p_children);
+
+	bzero(&p2->p_sibling, sizeof(p2->p_sibling));
+
+	scheduler_fork_hook(p1, p2);
+
+	p2->p_sigacts = sigactsinit(p1);
+
+	if (p2->p_emul->e_proc_fork)
+		(*p2->p_emul->e_proc_fork)(p2, p1);
+
+	p2->p_addr = (struct user *)uaddr;
+
+	uvm_fork(p1, p2, FALSE, NULL, 0, child_return, p2);
+
+	timeout_set(&p2->p_stats->p_virt_to, virttimer_trampoline, p2);
+	timeout_set(&p2->p_stats->p_prof_to, proftimer_trampoline, p2);
+
+	vm = p2->p_vmspace;
+
+	forkstat.cntfork++;
+	forkstat.sizfork += vm->vm_dsize + vm->vm_ssize;
+
+#ifdef GLOBAL_HASH
+	p2->p_pid = pid_new(p2->p_inst);
+#else
+	p2->p_pid = 1;
+#endif
+
+	proc_instadd(p2->p_inst->inst_proc, p2);
+	bzero(&p2->p_pglist, sizeof(p2->p_pglist));
+	LIST_INSERT_AFTER(p1, p2, p_pglist);
+	pgrpinit(p1, p2);
+
+	SCHED_LOCK(s);
+ 	getmicrotime(&p2->p_stats->p_start);
+	p2->p_acflag = AFORK;
+	p2->p_stat = SRUN;
+	setrunqueue(p2);
+	SCHED_UNLOCK(s);
+
+	uvmexp.forks++;
+
+	/* Set "init" process. */
+	p2->p_inst->inst_proc->initproc = p2;
+
+	retval[0] = p2->p_inst->inst_id;
+	retval[1] = 0;
+
+	return (0);
+}
+
+
 int
 fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
     void (*func)(void *), void *arg, register_t *retval,
@@ -178,6 +316,7 @@
 	int count;
 	vaddr_t uaddr;
 	int s;
+
 	extern void endtsleep(void *);
 	extern void realitexpire(void *);
 
@@ -232,10 +371,10 @@
 		p2->p_p = p1->p_p;
 		TAILQ_INSERT_TAIL(&p2->p_p->ps_threads, p2, p_thr_link);
 	} else {
-		process_new(p2, p1);
+		process_new(p2);
 	}
 #else
-	process_new(p2, p1);
+	process_new(p2);
 #endif
 
 	/*
@@ -381,14 +520,10 @@
 		forkstat.sizkthread += vm->vm_dsize + vm->vm_ssize;
 	}
 
-	/* Find an unused pid satisfying 1 <= lastpid <= PID_MAX */
-	do {
-		lastpid = 1 + (randompid ? arc4random() : lastpid) % PID_MAX;
-	} while (pidtaken(lastpid));
-	p2->p_pid = lastpid;
+	p2->p_pid = pid_new(p2->p_inst);
+
+	proc_instadd(p2->p_inst->inst_proc, p2);
 
-	LIST_INSERT_HEAD(&allproc, p2, p_list);
-	LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
 	LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling);
 	LIST_INSERT_AFTER(p1, p2, p_pglist);
 	if (p2->p_flag & P_TRACED) {
@@ -474,15 +609,15 @@
  * Checks for current use of a pid, either as a pid or pgid.
  */
 int
-pidtaken(pid_t pid)
+pidtaken(struct inst_proc *ip, pid_t pid)
 {
 	struct proc *p;
 
-	if (pfind(pid) != NULL)
+	if (pfind(ip, pid) != NULL)
 		return (1);
-	if (pgfind(pid) != NULL)
+	if (pgfind(ip, pid) != NULL)
 		return (1);
-	LIST_FOREACH(p, &zombproc, p_list)
+	LIST_FOREACH(p, &ip->zombproc, p_list)
 		if (p->p_pid == pid || p->p_pgid == pid)
 			return (1);
 	return (0);
Index: kern/kern_inst.c
===================================================================
RCS file: kern/kern_inst.c
diff -N kern/kern_inst.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ kern/kern_inst.c	18 Feb 2009 18:20:20 -0000	1.1.2.12
@@ -0,0 +1,364 @@
+/*
+ * Copyright (c) 2008 Kristaps Dzonsons <kristaps@mult.bsd.lv>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <sys/param.h>
+#include <sys/malloc.h>
+#include <sys/inst.h>
+#include <sys/mount.h>
+#include <sys/pool.h>
+#include <sys/signalvar.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+#include <sys/syscallargs.h>
+
+#include <dev/rndvar.h>
+
+#define	INST_HASH(id)	(&inst_htab[(id) & inst_hmask])
+#define	INST_SLOP	(2 * sizeof(struct kinfo_inst))
+
+LIST_HEAD(inst_head, inst);
+
+struct instlist		 inst_all;
+
+struct pool	 	 inst_pool;
+u_long		 	 inst_hmask;
+u_int		 	 inst_count;
+struct inst_head	*inst_htab;
+
+inline int		 instexist(instid_t);
+struct inst 		*instnew(instid_t);
+inline struct inst 	*instfind(instid_t);
+
+int		 	 killinst1(struct inst *, int);
+void		 	 fill_inst(struct inst *, struct kinfo_inst *);
+
+
+void
+instinit(void)
+{
+
+	pool_init(&inst_pool, sizeof(struct inst), 0, 0, 0, 
+			"instpl", &pool_allocator_nointr);
+
+	inst_count = 0;
+	inst_hmask = 0;
+
+	inst_htab = hashinit(16, M_INST, M_NOWAIT, &inst_hmask);
+
+	if (NULL == inst_htab) 
+		panic("instinit: hashinit");
+
+	LIST_INIT(&inst_all);
+}
+
+
+inline int
+instexist(instid_t id)
+{
+	struct inst	*ip;
+
+	LIST_FOREACH(ip, INST_HASH(id), inst_hash)
+		if (ip->inst_id == id)
+			return(1);
+	return(0);
+}
+
+
+inline struct inst *
+instfind(instid_t id)
+{
+	struct inst	*ip;
+
+	LIST_FOREACH(ip, INST_HASH(id), inst_hash)
+		if (ip->inst_id == id)
+			break;
+
+	return(ip);
+}
+
+
+struct inst *
+instkfind(instid_t id)
+{
+
+	/* 
+	 * Find instance without an instance context.  This is allowed
+	 * without needing to check for permission. 
+	 */
+	return(instfind(id));
+}
+
+
+struct inst *
+instpfind(struct proc *cp, instid_t id, enum instop op)
+{
+
+	/* 
+	 * TODO: check for access from one instance to the next.  For
+	 * now, accept all requests from the superuser.
+	 */
+
+	if (suser(cp, 0))
+		return(NULL);
+	return(instfind(id));
+}
+
+
+struct inst *
+instnew(instid_t id)
+{
+	struct inst	*inst;
+
+	if (INST_NOID != id && instexist(id))
+		return(NULL);
+
+	inst = pool_get(&inst_pool, PR_WAITOK|PR_ZERO);
+
+	inst->inst_ref = 1;
+
+	if (INST_NOID == id) {
+		do 
+			inst->inst_id = 1 + arc4random() % INST_MAX;
+		while (instexist(inst->inst_id));
+	}  else
+		inst->inst_id = id;
+	
+	LIST_INSERT_HEAD(INST_HASH(inst->inst_id), inst, inst_hash);
+	LIST_INSERT_HEAD(&inst_all, inst, inst_list);
+	inst_count++;
+
+	return(inst);
+}
+
+
+struct inst *
+instpnew(struct proc *cp, instid_t id)
+{
+
+	/* 
+	 * TODO: check for access to start a new instance.  For now,
+	 * accept all requests from the superuser.
+	 */
+	if (suser(cp, 0))
+		return(NULL);
+	return(instnew(id));
+}
+
+
+struct inst *
+instknew(instid_t id)
+{
+
+	/* 
+	 * New instance without an instance context.  This is allowed
+	 * without needing to check for permission. 
+	 */
+	return(instnew(id));
+}
+
+
+void
+instfree(struct inst *inst)
+{
+	instid_t	 id;
+
+	KASSERT(inst);
+
+	if (--inst->inst_ref != 0)
+		return;
+
+	if (inst->inst_proc)
+		proc_instfree(inst->inst_proc);
+
+	id = inst->inst_id;
+
+	LIST_REMOVE(inst, inst_hash);
+	LIST_REMOVE(inst, inst_list);
+	inst_count--;
+
+	pool_put(&inst_pool, inst);
+}
+
+
+void
+fill_inst(struct inst *p, struct kinfo_inst *ki)
+{
+
+	bzero(ki, sizeof(*ki));
+	ki->inst_id = p->inst_id;
+	ki->inst_ref = p->inst_ref;
+}
+
+
+int
+sysctl_doinst(struct proc *cp, int *name, 
+		u_int namelen, char *where, size_t *sizep)
+{
+	struct inst	*p;
+	char 		*dp;
+	int 		 arg, buflen, elem_size, elem_count, error, 
+			 needed, type, op;
+	struct kinfo_inst *kinst;
+
+	dp = where;
+	buflen = where != NULL ? *sizep : 0;
+	needed = error = 0;
+	type = name[0];
+
+	if (namelen != 5 || name[3] < 0 || name[4] < 0)
+		return (EINVAL);
+
+	op = name[1];
+	arg = name[2];
+	elem_size = name[3];
+	elem_count = name[4];
+	kinst = malloc(sizeof(struct kinfo_inst), M_TEMP, M_WAITOK);
+
+	p = LIST_FIRST(&inst_all);
+
+	for ( ; p; p = LIST_NEXT(p, inst_list)) {
+		switch (op) {
+		case KERN_INST_ALL:
+			break;
+		case KERN_INST_INSTID:
+			if (p->inst_id != (instid_t)arg)
+				continue;
+			break;
+		default:
+			error = EINVAL;
+			goto err;
+		}
+
+		/* For access-control rules... */
+		if (NULL == (p = instpfind(cp, p->inst_id, INST_KPROC)))
+			continue;
+
+		if (buflen >= elem_size && elem_count > 0) {
+			fill_inst(p, kinst);
+			/*
+			 * Copy out elem_size, but not larger than the
+			 * size of a struct kinfo_inst.
+			 */
+			error = copyout(kinst, dp, min(sizeof(*kinst), 
+						elem_size));
+			if (error)
+				goto err;
+
+			dp += elem_size;
+			buflen -= elem_size;
+			elem_count--;
+		}
+		needed += elem_size;
+	}
+
+	if (where != NULL) {
+		*sizep = dp - where;
+		if (needed > *sizep) {
+			error = ENOMEM;
+			goto err;
+		}
+	} else {
+		needed += INST_SLOP;
+		*sizep = needed;
+	}
+
+err:
+	if (kinst)
+		free(kinst, M_TEMP);
+
+	return (error);
+}
+
+
+int
+sys_killinst(struct proc *cp, void *v, register_t *retval)
+{
+	struct sys_killinst_args /* {
+		syscallarg(instid_t) id;
+		syscallarg(int) signum;
+	} */ *uap = v;
+	struct inst	*inst;
+	struct proc	*p;
+	instid_t	 id;
+	int		 signum, nsigs;
+
+	signum = SCARG(uap, signum);
+
+	switch (signum) {
+	case (SIGINST_TERM):
+		/* FALLTHROUGH */
+	case (SIGINST_KILL):
+		break;
+	default:
+		return(EINVAL);
+	}
+
+	id = SCARG(uap, id);
+
+	if (INST_NOID == id) {
+		nsigs = 0;
+		inst = LIST_FIRST(&inst_all);
+
+		for ( ; inst; inst = LIST_NEXT(inst, inst_list)) {
+			/* For access rules. */
+			inst = instpfind(cp, inst->inst_id, INST_SIG);
+			if (NULL == inst) 
+				continue;
+			if (inst->inst_id == cp->p_inst->inst_id)
+				continue;
+			if (inst->inst_id == 0) /* FIXME */
+				continue;
+
+			nsigs++;
+			p = inst->inst_proc->initproc;
+			psignal(p, signum);
+		}
+		return(0 == nsigs ? EINSTSRCH : 0);
+	}
+
+	if (id == 0) /* FIXME */
+		return(EINSTSRCH);
+
+	inst = instpfind(cp, id, INST_SIG);
+	if (NULL == inst) 
+		return(EINSTSRCH);
+
+	p = inst->inst_proc->initproc;
+	psignal(p, signum);
+	return(0);
+}
+
+
+int
+sys_getinstid(struct proc *p, void *v, register_t *retval)
+{
+
+	*retval = p->p_inst->inst_id;
+	return(0);
+}
+
+
+int
+sys_forkinst(struct proc *p, void *v, register_t *retval)
+{
+	struct sys_forkinst_args /* {
+		syscallarg(instid_t) id;
+	} */ *uap = v;
+
+	return(forkinst1(p, SCARG(uap, id), retval));
+}
+
Index: kern/kern_ktrace.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_ktrace.c,v
retrieving revision 1.43
retrieving revision 1.43.4.3
diff -u -r1.43 -r1.43.4.3
--- kern/kern_ktrace.c	22 May 2008 17:04:59 -0000	1.43
+++ kern/kern_ktrace.c	18 Sep 2008 17:21:02 -0000	1.43.4.3
@@ -322,7 +322,7 @@
 	 * Clear all uses of the tracefile
 	 */
 	if (ops == KTROP_CLEARFILE) {
-		LIST_FOREACH(p, &allproc, p_list) {
+		PROCLIST_FOREACH(p, curp, p_list) {
 			if (p->p_tracep == vp) {
 				if (ktrcanset(curp, p)) {
 					p->p_traceflag = 0;
@@ -347,7 +347,7 @@
 		/*
 		 * by process group
 		 */
-		pg = pgfind(-SCARG(uap, pid));
+		pg = pgfind(curp->p_inst->inst_proc, -SCARG(uap, pid));
 		if (pg == NULL) {
 			error = ESRCH;
 			goto done;
@@ -362,7 +362,7 @@
 		/*
 		 * by pid
 		 */
-		p = pfind(SCARG(uap, pid));
+		p = pfind(curp->p_inst->inst_proc, SCARG(uap, pid));
 		if (p == NULL) {
 			error = ESRCH;
 			goto done;
@@ -445,6 +445,7 @@
 ktrwrite(struct proc *p, struct ktr_header *kth)
 {
 	struct uio auio;
+	struct proc *pp;
 	struct iovec aiov[2];
 	int error;
 	struct vnode *vp = p->p_tracep;
@@ -476,7 +477,8 @@
 	 */
 	log(LOG_NOTICE, "ktrace write failed, errno %d, tracing stopped\n",
 	    error);
-	LIST_FOREACH(p, &allproc, p_list) {
+	pp = p;
+	PROCLIST_FOREACH(p, pp, p_list) {
 		if (p->p_tracep == vp) {
 			p->p_traceflag = 0;
 			ktrsettracevnode(p, NULL);
Index: kern/kern_proc.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_proc.c,v
retrieving revision 1.36
retrieving revision 1.36.6.12
diff -u -r1.36 -r1.36.6.12
--- kern/kern_proc.c	10 Oct 2007 15:53:53 -0000	1.36
+++ kern/kern_proc.c	18 Feb 2009 12:43:25 -0000	1.36.6.12
@@ -49,20 +49,18 @@
 #include <sys/signalvar.h>
 #include <sys/pool.h>
 
+
+#ifdef GLOBAL_HASH
+struct pidhhead	*pidhashtbl;
+u_long		 pidhash;
+struct pghhead	*pgrphashtbl;
+u_long		 pgrphash;
+#endif
+
 #define	UIHASH(uid)	(&uihashtbl[(uid) & uihash])
 LIST_HEAD(uihashhead, uidinfo) *uihashtbl;
 u_long uihash;		/* size of hash table - 1 */
 
-/*
- * Other process lists
- */
-struct pidhashhead *pidhashtbl;
-u_long pidhash;
-struct pgrphashhead *pgrphashtbl;
-u_long pgrphash;
-struct proclist allproc;
-struct proclist zombproc;
-
 struct pool proc_pool;
 struct pool process_pool;
 struct pool rusage_pool;
@@ -70,11 +68,9 @@
 struct pool pgrp_pool;
 struct pool session_pool;
 struct pool pcred_pool;
+struct pool instproc_pool;
 
 static void orphanpg(struct pgrp *);
-#ifdef DEBUG
-void pgrpdump(void);
-#endif
 
 /*
  * Initialize global process hashing structures.
@@ -82,16 +78,21 @@
 void
 procinit(void)
 {
-	LIST_INIT(&allproc);
-	LIST_INIT(&zombproc);
-
-
-	pidhashtbl = hashinit(maxproc / 4, M_PROC, M_NOWAIT, &pidhash);
-	pgrphashtbl = hashinit(maxproc / 4, M_PROC, M_NOWAIT, &pgrphash);
 	uihashtbl = hashinit(maxproc / 16, M_PROC, M_NOWAIT, &uihash);
-	if (!pidhashtbl || !pgrphashtbl || !uihashtbl)
+	if (!uihashtbl)
 		panic("procinit: malloc");
 
+#ifdef GLOBAL_HASH
+	pidhash = 0;
+	pgrphash = 0;
+	pidhashtbl = hashinit
+		(maxproc / 4, M_PROC, M_WAITOK, &pidhash);
+	pgrphashtbl = hashinit
+		(maxproc / 4, M_PROC, M_NOWAIT, &pgrphash);
+#endif
+
+	pool_init(&instproc_pool, sizeof(struct inst_proc), 0, 0, 0, 
+			"instprocpl", &pool_allocator_nointr);
 	pool_init(&proc_pool, sizeof(struct proc), 0, 0, 0, "procpl",
 	    &pool_allocator_nointr);
 	pool_init(&process_pool, sizeof(struct process), 0, 0, 0, "processpl",
@@ -108,6 +109,91 @@
 	    &pool_allocator_nointr);
 }
 
+
+struct inst_proc *
+proc_instinit(const struct inst *inst)
+{
+	struct inst_proc *p;
+
+	KASSERT(inst);
+
+	p = pool_get(&instproc_pool, PR_WAITOK|PR_ZERO);
+
+	LIST_INIT(&p->allproc);
+	LIST_INIT(&p->zombproc);
+
+#ifndef GLOBAL_HASH
+	p->pidhash = 0;
+	p->pgrphash = 0;
+
+	p->pidhashtbl = hashinit
+		(maxproc / 4, M_PROC, M_WAITOK, &p->pidhash);
+	p->pgrphashtbl = hashinit
+		(maxproc / 4, M_PROC, M_NOWAIT, &p->pgrphash);
+#else
+	p->instid = inst->inst_id;
+#endif
+
+	return(p);
+}
+
+
+void
+proc_instfree(struct inst_proc *p)
+{
+
+	KASSERT(p);
+	KASSERT(LIST_EMPTY(&p->allproc));
+
+#ifndef GLOBAL_HASH
+	if (p->pidhashtbl) 
+		free(p->pidhashtbl, M_PROC);
+	if (p->pgrphashtbl) 
+		free(p->pgrphashtbl, M_PROC);
+#endif
+}
+
+
+void
+proc_instadd(struct inst_proc *p, struct proc *proc)
+{
+
+	KASSERT(p);
+	KASSERT(proc);
+	KASSERT(proc->p_inst->inst_proc == p);
+	/*
+	 * Insert us into the pid hashtable and the list of all
+	 * processes.
+	 */
+
+#ifdef GLOBAL_HASH
+	LIST_INSERT_HEAD(&pidhashtbl[proc->p_pid & pidhash],
+			proc, p_hash);
+#else
+	LIST_INSERT_HEAD(&p->pidhashtbl[proc->p_pid & p->pidhash],
+			proc, p_hash);
+#endif
+
+	LIST_INSERT_HEAD(&p->allproc, proc, p_list);
+}
+
+
+void
+pgrp_instadd(struct inst_proc *p, struct pgrp *pgrp)
+{
+	KASSERT(p);
+	KASSERT(pgrp);
+
+#ifdef GLOBAL_HASH
+	LIST_INSERT_HEAD(&pgrphashtbl[pgrp->pg_id & pgrphash],
+			pgrp, pg_hash);
+#else
+	LIST_INSERT_HEAD(&p->pgrphashtbl[pgrp->pg_id & p->pgrphash],
+			pgrp, pg_hash);
+#endif
+}
+
+
 /*
  * Change the count associated with number of processes
  * a given user is using.
@@ -158,22 +244,31 @@
 {
 
 	for (; p != curproc; p = p->p_pptr)
-		if (p->p_pid == 0)
+		if (NULL == p || p->p_pid == 0)
 			return (0);
 	return (1);
 }
 
-/*
- * Locate a process by number
- */
+
 struct proc *
-pfind(pid_t pid)
+pfind(struct inst_proc *ip, pid_t pid)
 {
 	struct proc *p;
 
-	LIST_FOREACH(p, PIDHASH(pid), p_hash)
+	KASSERT(ip);
+
+#ifdef GLOBAL_HASH
+	LIST_FOREACH(p, &pidhashtbl[pid & pidhash], p_hash)
+		if (p->p_pid == pid && p->p_inst->inst_id == ip->instid)
+			return (p);
+		else if (p->p_pid == pid)
+			return (NULL);
+#else
+	LIST_FOREACH(p, &ip->pidhashtbl[pid & ip->pidhash], p_hash)
 		if (p->p_pid == pid)
 			return (p);
+#endif
+
 	return (NULL);
 }
 
@@ -181,13 +276,23 @@
  * Locate a process group by number
  */
 struct pgrp *
-pgfind(pid_t pgid)
+pgfind(struct inst_proc *ip, pid_t pgid)
 {
 	struct pgrp *pgrp;
 
-	LIST_FOREACH(pgrp, PGRPHASH(pgid), pg_hash)
+	KASSERT(ip);
+
+#ifdef GLOBAL_HASH
+	LIST_FOREACH(pgrp, &pgrphashtbl[pgid & pgrphash], pg_hash)
+		if (pgrp->pg_id == pgid && pgrp->pg_inst->inst_id == ip->instid)
+			return (pgrp);
+		else if (pgrp->pg_id == pgid)
+			return (NULL);
+#else
+	LIST_FOREACH(pgrp, &ip->pgrphashtbl[pgid & ip->pgrphash], pg_hash)
 		if (pgrp->pg_id == pgid)
 			return (pgrp);
+#endif
 	return (NULL);
 }
 
@@ -197,7 +302,10 @@
 int
 enterpgrp(struct proc *p, pid_t pgid, int mksess)
 {
-	struct pgrp *pgrp = pgfind(pgid);
+	struct pgrp *pgrp;
+
+	KASSERT(p->p_inst);
+	pgrp = pgfind(p->p_inst->inst_proc, pgid);
 
 #ifdef DIAGNOSTIC
 	if (pgrp != NULL && mksess)	/* firewalls */
@@ -215,7 +323,7 @@
 		if (p->p_pid != pgid)
 			panic("enterpgrp: new pgrp and pid != pgid");
 #endif
-		if ((np = pfind(savepid)) == NULL || np != p)
+		if ((np = pfind(p->p_inst->inst_proc, savepid)) == NULL || np != p)
 			return (ESRCH);
 		pgrp = pool_get(&pgrp_pool, PR_WAITOK);
 		if (mksess) {
@@ -229,21 +337,28 @@
 			sess->s_count = 1;
 			sess->s_ttyvp = NULL;
 			sess->s_ttyp = NULL;
+			KASSERT(p->p_session);
 			bcopy(p->p_session->s_login, sess->s_login,
 			    sizeof(sess->s_login));
 			atomic_clearbits_int(&p->p_flag, P_CONTROLT);
 			pgrp->pg_session = sess;
+#if 0
 #ifdef DIAGNOSTIC
 			if (p != curproc)
 				panic("enterpgrp: mksession and p != curproc");
 #endif
+#endif
 		} else {
+			KASSERT(p->p_session);
 			pgrp->pg_session = p->p_session;
 			pgrp->pg_session->s_count++;
 		}
 		pgrp->pg_id = pgid;
 		LIST_INIT(&pgrp->pg_members);
-		LIST_INSERT_HEAD(PGRPHASH(pgid), pgrp, pg_hash);
+		pgrp_instadd(p->p_inst->inst_proc, pgrp);
+#ifdef GLOBAL_HASH
+		pgrp->pg_inst = p->p_inst;
+#endif
 		pgrp->pg_jobc = 0;
 	} else if (pgrp == p->p_pgrp)
 		return (0);
@@ -271,6 +386,7 @@
 leavepgrp(struct proc *p)
 {
 
+	KASSERT(p->p_pgrp);
 	LIST_REMOVE(p, p_pglist);
 	if (LIST_EMPTY(&p->p_pgrp->pg_members))
 		pgdelete(p->p_pgrp);
@@ -285,6 +401,8 @@
 pgdelete(struct pgrp *pgrp)
 {
 
+	KASSERT(pgrp);
+	KASSERT(pgrp->pg_session);
 	if (pgrp->pg_session->s_ttyp != NULL && 
 	    pgrp->pg_session->s_ttyp->t_pgrp == pgrp)
 		pgrp->pg_session->s_ttyp->t_pgrp = NULL;
@@ -307,14 +425,20 @@
 fixjobc(struct proc *p, struct pgrp *pgrp, int entering)
 {
 	struct pgrp *hispgrp;
-	struct session *mysession = pgrp->pg_session;
+	struct session *mysession;
+
+	KASSERT(pgrp);
+	KASSERT(p);
+
+	mysession = pgrp->pg_session;
 
 	/*
 	 * Check p's parent to see whether p qualifies its own process
 	 * group; if so, adjust count for p's process group.
 	 */
-	if ((hispgrp = p->p_pptr->p_pgrp) != pgrp &&
-	    hispgrp->pg_session == mysession) {
+	if (NULL == p->p_pptr || 
+			((hispgrp = p->p_pptr->p_pgrp) != pgrp && 
+			 hispgrp->pg_session == mysession)) {
 		if (entering)
 			pgrp->pg_jobc++;
 		else if (--pgrp->pg_jobc == 0)
@@ -330,6 +454,7 @@
 		if ((hispgrp = p->p_pgrp) != pgrp &&
 		    hispgrp->pg_session == mysession &&
 		    P_ZOMBIE(p) == 0) {
+			KASSERT(hispgrp);
 			if (entering)
 				hispgrp->pg_jobc++;
 			else if (--hispgrp->pg_jobc == 0)
@@ -396,6 +521,7 @@
 db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
 {
 	char *mode;
+	struct inst *i;
 	int doingzomb = 0;
 	struct proc *p, *pp;
     
@@ -413,87 +539,92 @@
 		return;
 	}
 	
-	p = LIST_FIRST(&allproc);
 
 	switch (*mode) {
-
 	case 'a':
-		db_printf("   PID  %-10s  %18s  %18s  %18s\n",
+		db_printf("   PID  %10s  %-10s  %18s  %18s  %18s\n",
 		    "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
 		break;
 	case 'n':
-		db_printf("   PID  %5s  %5s  %5s  S  %10s  %-12s  %-16s\n",
+		db_printf("   PID  %10s  %5s  %5s  %5s  S  %10s  %-12s  %-16s\n",
 		    "PPID", "PGRP", "UID", "FLAGS", "WAIT", "COMMAND");
 		break;
 	case 'w':
-		db_printf("   PID  %-16s  %-8s  %18s  %s\n",
+		db_printf("   PID  %10s  %-16s  %-8s  %18s  %s\n",
 		    "COMMAND", "EMUL", "WAIT-CHANNEL", "WAIT-MSG");
 		break;
 	}
 
-	while (p != 0) {
-		pp = p->p_pptr;
-		if (p->p_stat) {
-
-			db_printf("%c%5d  ", p == curproc ? '*' : ' ',
-				p->p_pid);
-
-			switch (*mode) {
-
-			case 'a':
-				db_printf("%-10.10s  %18p  %18p  %18p\n",
-				    p->p_comm, p, p->p_addr, p->p_vmspace);
-				break;
-
-			case 'n':
-				db_printf("%5d  %5d  %5d  %d  %#10x  "
-				    "%-12.12s  %-16s\n",
-				    pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
-				    p->p_cred->p_ruid, p->p_stat, p->p_flag,
-				    (p->p_wchan && p->p_wmesg) ?
-					p->p_wmesg : "", p->p_comm);
-				break;
-
-			case 'w':
-				db_printf("%-16s  %-8s  %18p  %s\n", p->p_comm,
-				    p->p_emul->e_name, p->p_wchan,
-				    (p->p_wchan && p->p_wmesg) ? 
-					p->p_wmesg : "");
-				break;
+	LIST_FOREACH(i, &inst_all, inst_list) {
+		p = LIST_FIRST(&i->inst_proc->allproc);
+	
+		while (p != 0) {
+			pp = p->p_pptr;
+			if (p->p_stat) {
+	
+				db_printf("%c%5d  %10x  ", p == curproc ? '*' : ' ',
+					p->p_pid, p->p_inst->inst_id);
 
+				switch (*mode) {
+	
+				case 'a':
+					db_printf("%-10.10s  %18p  %18p  %18p\n",
+					    p->p_comm, p, p->p_addr, p->p_vmspace);
+					break;
+	
+				case 'n':
+					db_printf("%5d  %5d  %5d  %d  %#10x  "
+					    "%-12.12s  %-16s\n",
+					    pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
+					    p->p_cred->p_ruid, p->p_stat, p->p_flag,
+					    (p->p_wchan && p->p_wmesg) ?
+						p->p_wmesg : "", p->p_comm);
+					break;
+	
+				case 'w':
+					db_printf("%-16s  %-8s  %18p  %s\n", p->p_comm,
+					    p->p_emul->e_name, p->p_wchan,
+					    (p->p_wchan && p->p_wmesg) ? 
+						p->p_wmesg : "");
+					break;
+	
+				}
+			}
+			p = LIST_NEXT(p, p_list);
+			if (p == 0 && doingzomb == 0) {
+				doingzomb = 1;
+				p = LIST_FIRST(&i->inst_proc->zombproc);
 			}
-		}
-		p = LIST_NEXT(p, p_list);
-		if (p == 0 && doingzomb == 0) {
-			doingzomb = 1;
-			p = LIST_FIRST(&zombproc);
 		}
 	}
 }
 #endif
 
-#ifdef DEBUG
+
 void
-pgrpdump(void)
+pgrpinit(struct proc *p1, struct proc *p2)
 {
-	struct pgrp *pgrp;
-	struct proc *p;
-	int i;
+	struct pgrp	*pgrp;
+	struct session	*sess;
 
-	for (i = 0; i <= pgrphash; i++) {
-		if (!LIST_EMPTY(&pgrphashtbl[i])) {
-			printf("\tindx %d\n", i);
-			LIST_FOREACH(pgrp, &pgrphashtbl[i], pg_hash) {
-				printf("\tpgrp %p, pgid %d, sess %p, sesscnt %d, mem %p\n",
-				    pgrp, pgrp->pg_id, pgrp->pg_session,
-				    pgrp->pg_session->s_count,
-				    LIST_FIRST(&pgrp->pg_members));
-				LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
-					printf("\t\tpid %d addr %p pgrp %p\n", 
-					    p->p_pid, p, p->p_pgrp);
-				}
-			}
-		}
-	}
+	KASSERT(p1);
+	KASSERT(p2);
+
+	pgrp = pool_get(&pgrp_pool, PR_WAITOK | PR_ZERO);
+	sess = pool_get(&session_pool, PR_WAITOK | PR_ZERO);
+
+	bcopy(p1->p_session->s_login, 
+			sess->s_login, sizeof(sess->s_login));
+
+	sess->s_count = 1;
+	sess->s_leader = NULL;
+
+	pgrp->pg_session = sess;
+	p2->p_pgrp = pgrp;
+
+	pgrp_instadd(p2->p_inst->inst_proc, pgrp);
+#ifdef GLOBAL_HASH
+	pgrp->pg_inst = p2->p_inst;
+#endif
+	enterpgrp(p2, p2->p_pid, 1);
 }
-#endif /* DEBUG */
Index: kern/kern_prot.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_prot.c,v
retrieving revision 1.31
retrieving revision 1.31.4.6
diff -u -r1.31 -r1.31.4.6
--- kern/kern_prot.c	22 May 2008 21:27:40 -0000	1.31
+++ kern/kern_prot.c	13 Feb 2009 09:08:59 -0000	1.31.4.6
@@ -63,7 +63,8 @@
 	*retval = p->p_p->ps_mainproc->p_pid;
 #if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_IBCS2) || \
     defined(COMPAT_FREEBSD) || defined(COMPAT_BSDOS)
-	retval[1] = p->p_p->ps_mainproc->p_pptr->p_pid;
+	retval[1] = p->p_p->ps_mainproc->p_pptr ? 
+		p->p_p->ps_mainproc->p_pptr->p_pid : -1;
 #endif
 	return (0);
 }
@@ -87,7 +88,8 @@
 sys_getppid(struct proc *p, void *v, register_t *retval)
 {
 
-	*retval = p->p_p->ps_mainproc->p_pptr->p_pid;
+	*retval = p->p_p->ps_mainproc->p_pptr ?
+		p->p_p->ps_mainproc->p_pptr->p_pid : -1;
 	return (0);
 }
 
@@ -113,7 +115,7 @@
 
 	if (SCARG(uap, pid) == 0 || SCARG(uap, pid) == curp->p_pid)
 		goto found;
-	if ((targp = pfind(SCARG(uap, pid))) == NULL)
+	if ((targp = pfind(curp->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 		return (ESRCH);
 	if (targp->p_session != curp->p_session)
 		return (EPERM);
@@ -132,7 +134,7 @@
 
 	if (SCARG(uap, pid) == 0 || SCARG(uap, pid) == curp->p_pid)
 		goto found;
-	if ((targp = pfind(SCARG(uap, pid))) == NULL)
+	if ((targp = pfind(curp->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 		return (ESRCH);
 	if (targp->p_session != curp->p_session)
 		return (EPERM);
@@ -234,7 +236,7 @@
 sys_setsid(struct proc *p, void *v, register_t *retval)
 {
 
-	if (p->p_pgid == p->p_pid || pgfind(p->p_pid)) {
+	if (p->p_pgid == p->p_pid || pgfind(p->p_inst->inst_proc, p->p_pid)) {
 		return (EPERM);
 	} else {
 		(void)enterpgrp(p, p->p_pid, 1);
@@ -276,7 +278,7 @@
 		return (EINVAL);
 
 	if (pid != 0 && pid != curp->p_pid) {
-		if ((targp = pfind(pid)) == 0 || !inferior(targp))
+		if ((targp = pfind(curp->p_inst->inst_proc, pid)) == 0 || !inferior(targp))
 			return (ESRCH);
 		if (targp->p_session != curp->p_session)
 			return (EPERM);
@@ -289,7 +291,7 @@
 	if (pgid == 0)
 		pgid = targp->p_pid;
 	else if (pgid != targp->p_pid)
-		if ((pgrp = pgfind(pgid)) == 0 ||
+		if ((pgrp = pgfind(curp->p_inst->inst_proc, pgid)) == 0 ||
 		    pgrp->pg_session != curp->p_session)
 			return (EPERM);
 	return (enterpgrp(targp, pgid, 0));
@@ -766,16 +768,36 @@
 	return (EPERM);
 }
 
+
 /*
  * Allocate a zeroed cred structure.
  */
 struct ucred *
-crget(void)
+crnew(void)
 {
 	struct ucred *cr;
 
 	cr = pool_get(&ucred_pool, PR_WAITOK|PR_ZERO);
 	cr->cr_ref = 1;
+
+	return (cr);
+}
+
+/*
+ * Allocate a zeroed cred structure.
+ */
+struct ucred *
+crget(struct inst *inst)
+{
+	struct ucred *cr;
+
+	KASSERT(inst);
+
+	cr = pool_get(&ucred_pool, PR_WAITOK|PR_ZERO);
+	cr->cr_ref = 1;
+	cr->cr_inst = inst;
+
+	insthold(cr->cr_inst);
 	return (cr);
 }
 
@@ -787,8 +809,10 @@
 crfree(struct ucred *cr)
 {
 
-	if (--cr->cr_ref == 0)
+	if (--cr->cr_ref == 0) {
+		instfree(cr->cr_inst);
 		pool_put(&ucred_pool, cr);
+	}
 }
 
 /*
@@ -801,7 +825,7 @@
 
 	if (cr->cr_ref == 1)
 		return (cr);
-	newcr = crget();
+	newcr = crget(cr->cr_inst);
 	*newcr = *cr;
 	crfree(cr);
 	newcr->cr_ref = 1;
@@ -816,7 +840,7 @@
 {
 	struct ucred *newcr;
 
-	newcr = crget();
+	newcr = crget(cr->cr_inst);
 	*newcr = *cr;
 	newcr->cr_ref = 1;
 	return (newcr);
Index: kern/kern_resource.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_resource.c,v
retrieving revision 1.33
retrieving revision 1.33.4.6
diff -u -r1.33 -r1.33.4.6
--- kern/kern_resource.c	22 May 2008 17:04:59 -0000	1.33
+++ kern/kern_resource.c	27 Sep 2008 14:09:44 -0000	1.33.4.6
@@ -77,7 +77,7 @@
 		if (SCARG(uap, who) == 0)
 			p = curp;
 		else
-			p = pfind(SCARG(uap, who));
+			p = pfind(curp->p_inst->inst_proc, SCARG(uap, who));
 		if (p == 0)
 			break;
 		low = p->p_nice;
@@ -88,7 +88,7 @@
 
 		if (SCARG(uap, who) == 0)
 			pg = curp->p_pgrp;
-		else if ((pg = pgfind(SCARG(uap, who))) == NULL)
+		else if ((pg = pgfind(curp->p_inst->inst_proc, SCARG(uap, who))) == NULL)
 			break;
 		LIST_FOREACH(p, &pg->pg_members, p_pglist) {
 			if (p->p_nice < low)
@@ -100,7 +100,7 @@
 	case PRIO_USER:
 		if (SCARG(uap, who) == 0)
 			SCARG(uap, who) = curp->p_ucred->cr_uid;
-		LIST_FOREACH(p, &allproc, p_list)
+		PROCLIST_FOREACH(p, curp, p_list)
 			if (p->p_ucred->cr_uid == SCARG(uap, who) &&
 			    p->p_nice < low)
 				low = p->p_nice;
@@ -133,7 +133,7 @@
 		if (SCARG(uap, who) == 0)
 			p = curp;
 		else
-			p = pfind(SCARG(uap, who));
+			p = pfind(curp->p_inst->inst_proc, SCARG(uap, who));
 		if (p == 0)
 			break;
 		error = donice(curp, p, SCARG(uap, prio));
@@ -145,7 +145,7 @@
 		 
 		if (SCARG(uap, who) == 0)
 			pg = curp->p_pgrp;
-		else if ((pg = pgfind(SCARG(uap, who))) == NULL)
+		else if ((pg = pgfind(curp->p_inst->inst_proc, SCARG(uap, who))) == NULL)
 			break;
 		LIST_FOREACH(p, &pg->pg_members, p_pglist) {
 			error = donice(curp, p, SCARG(uap, prio));
@@ -157,7 +157,7 @@
 	case PRIO_USER:
 		if (SCARG(uap, who) == 0)
 			SCARG(uap, who) = curp->p_ucred->cr_uid;
-		LIST_FOREACH(p, &allproc, p_list)
+		PROCLIST_FOREACH(p, curp, p_list)
 			if (p->p_ucred->cr_uid == SCARG(uap, who)) {
 				error = donice(curp, p, SCARG(uap, prio));
 				found++;
@@ -417,8 +417,10 @@
 	}
 
 	newlim = pool_get(&plimit_pool, PR_WAITOK);
+
 	bcopy(lim->pl_rlimit, newlim->pl_rlimit,
-	    sizeof(struct rlimit) * RLIM_NLIMITS);
+			sizeof(struct rlimit) * RLIM_NLIMITS);
+
 	newlim->p_lflags = 0;
 	newlim->p_refcnt = 1;
 	return (newlim);
Index: kern/kern_sig.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_sig.c,v
retrieving revision 1.99
retrieving revision 1.99.4.11
diff -u -r1.99 -r1.99.4.11
--- kern/kern_sig.c	10 Jun 2008 20:41:52 -0000	1.99
+++ kern/kern_sig.c	18 Feb 2009 12:43:25 -0000	1.99.4.11
@@ -294,9 +294,12 @@
 		 * (init) which will reap the zombie.  Because we use
 		 * init to do our dirty work we never set P_NOCLDWAIT
 		 * for PID 1.
+		 *
+		 * Changed because init isn't necessarily process 1.
 		 */
-		if (p->p_pid != 1 && ((sa->sa_flags & SA_NOCLDWAIT) ||
-		    sa->sa_handler == SIG_IGN))
+		if (p == p->p_inst->inst_proc->initproc &&
+				((sa->sa_flags & SA_NOCLDWAIT) ||
+				 sa->sa_handler == SIG_IGN))
 			atomic_setbits_int(&p->p_flag, P_NOCLDWAIT);
 		else
 			atomic_clearbits_int(&p->p_flag, P_NOCLDWAIT);
@@ -578,7 +581,7 @@
 		return (EINVAL);
 	if (SCARG(uap, pid) > 0) {
 		/* kill single process */
-		if ((p = pfind(SCARG(uap, pid))) == NULL)
+		if ((p = pfind(cp->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 			return (ESRCH);
 		if (!cansignal(cp, pc, p, SCARG(uap, signum)))
 			return (EPERM);
@@ -613,9 +616,10 @@
 		/* 
 		 * broadcast
 		 */
-		LIST_FOREACH(p, &allproc, p_list) {
-			if (p->p_pid <= 1 || p->p_flag & P_SYSTEM || 
-			    p == cp || !cansignal(cp, pc, p, signum))
+		PROCLIST_FOREACH(p, cp, p_list) {
+			if (p->p_pid <= 1 || p == p->p_inst->inst_proc->initproc ||
+					p->p_flag & P_SYSTEM || p == cp ||
+					!cansignal(cp, pc, p, signum))
 				continue;
 			nfound++;
 			if (signum)
@@ -628,13 +632,14 @@
 			 */
 			pgrp = cp->p_pgrp;
 		else {
-			pgrp = pgfind(pgid);
+			pgrp = pgfind(cp->p_inst->inst_proc, pgid);
 			if (pgrp == NULL)
 				return (ESRCH);
 		}
 		LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
-			if (p->p_pid <= 1 || p->p_flag & P_SYSTEM ||
-			    !cansignal(cp, pc, p, signum))
+			if (p->p_pid <= 1 || p == p->p_inst->inst_proc->initproc ||
+					p->p_flag & P_SYSTEM || 
+					!cansignal(cp, pc, p, signum))
 				continue;
 			nfound++;
 			if (signum && P_ZOMBIE(p) == 0)
@@ -658,22 +663,31 @@
  * process and see if it is permitted.
  */
 void
-csignal(pid_t pgid, int signum, uid_t uid, uid_t euid)
+csignal(instid_t instid, pid_t pgid, int signum, uid_t uid, uid_t euid)
 {
 	struct pgrp *pgrp;
 	struct proc *p;
+	struct inst *inst;
 
 	if (pgid == 0)
 		return;
 	if (pgid < 0) {
 		pgid = -pgid;
-		if ((pgrp = pgfind(pgid)) == NULL)
+		inst = instkfind(instid);
+		if (NULL == inst)
+			return;
+		pgrp = pgfind(inst->inst_proc, pgid);
+		if (NULL == pgrp)
 			return;
 		LIST_FOREACH(p, &pgrp->pg_members, p_pglist)
 			if (CANDELIVER(uid, euid, p))
 				psignal(p, signum);
 	} else {
-		if ((p = pfind(pgid)) == NULL)
+		inst = instkfind(instid);
+		if (NULL == inst)
+			return;
+		p = pfind(inst->inst_proc, pgid);
+		if (NULL == p)
 			return;
 		if (CANDELIVER(uid, euid, p))
 			psignal(p, signum);
@@ -684,11 +698,19 @@
  * Send a signal to a process group.
  */
 void
-gsignal(int pgid, int signum)
+gsignal(instid_t instid, int pgid, int signum)
 {
 	struct pgrp *pgrp;
+	struct inst *inst;
+
+	if (0 == pgid)
+		return;
+
+	inst = instkfind(instid);
+	if (NULL == inst)
+		return;
 
-	if (pgid && (pgrp = pgfind(pgid)))
+	if ((pgrp = pgfind(inst->inst_proc, pgid)))
 		pgsignal(pgrp, signum, 0);
 }
 
@@ -999,8 +1021,10 @@
 	setrunnable(p);
 out:
 	SCHED_UNLOCK(s);
-	if (wakeparent)
+	if (wakeparent) {
+		KASSERT(p->p_pptr);
 		wakeup(p->p_pptr);
+	}
 }
 
 /*
@@ -1085,14 +1109,14 @@
 			/*
 			 * Don't take default actions on system processes.
 			 */
-			if (p->p_pid <= 1) {
+			if (p->p_pid <= 1 || p == p->p_inst->inst_proc->initproc) {
 #ifdef DIAGNOSTIC
 				/*
 				 * Are you sure you want to ignore SIGSEGV
 				 * in init? XXX
 				 */
-				printf("Process (pid %d) got signal %d\n",
-				    p->p_pid, signum);
+				printf("Process (pid %d, instid %u) got signal %d\n",
+				    p->p_pid, p->p_inst->inst_id, signum);
 #endif
 				break;		/* == ignore */
 			}
@@ -1194,15 +1218,20 @@
 proc_stop_sweep(void *v)
 {
 	struct proc *p;
+	struct inst *i;
 
-	LIST_FOREACH(p, &allproc, p_list) {
-		if ((p->p_flag & P_STOPPED) == 0)
-			continue;
-		atomic_clearbits_int(&p->p_flag, P_STOPPED);
-
-		if ((p->p_pptr->p_flag & P_NOCLDSTOP) == 0)
-			psignal(p->p_pptr, SIGCHLD);
-		wakeup(p->p_pptr);
+	LIST_FOREACH(i, &inst_all, inst_list) {
+		LIST_FOREACH(p, &i->inst_proc->allproc, p_list) {
+			if ((p->p_flag & P_STOPPED) == 0)
+				continue;
+			atomic_clearbits_int(&p->p_flag, P_STOPPED);
+			if (NULL == p->p_pptr)
+				/* FIXME: this shouldn't happen. */
+				continue;
+			if ((p->p_pptr->p_flag & P_NOCLDSTOP) == 0)
+				psignal(p->p_pptr, SIGCHLD);
+			wakeup(p->p_pptr);
+		}
 	}
 }
 
Index: kern/kern_sysctl.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.161
retrieving revision 1.161.4.7
diff -u -r1.161 -r1.161.4.7
--- kern/kern_sysctl.c	9 Jun 2008 07:07:16 -0000	1.161
+++ kern/kern_sysctl.c	18 Feb 2009 12:43:25 -0000	1.161.4.7
@@ -255,6 +255,7 @@
 		switch (name[0]) {
 		case KERN_PROC:
 		case KERN_PROC2:
+		case KERN_INSTPROC2:
 		case KERN_PROF:
 		case KERN_MALLOCSTATS:
 		case KERN_TTY:
@@ -271,6 +272,7 @@
 		case KERN_TIMECOUNTER:
 #endif
 		case KERN_CPTIME2:
+		case KERN_INST:
 			break;
 		default:
 			return (ENOTDIR);	/* overloaded */
@@ -341,10 +343,13 @@
 #ifndef SMALL_KERNEL
 	case KERN_PROC:
 	case KERN_PROC2:
-		return (sysctl_doproc(name, namelen, oldp, oldlenp));
+	case KERN_INSTPROC2:
+		return (sysctl_doproc(p, name, namelen, oldp, oldlenp));
 	case KERN_PROC_ARGS:
 		return (sysctl_proc_args(name + 1, namelen - 1, oldp, oldlenp,
 		     p));
+	case KERN_INST:
+		return (sysctl_doinst(p, name, namelen, oldp, oldlenp));
 #endif
 	case KERN_FILE:
 		return (sysctl_file(oldp, oldlenp));
@@ -977,19 +982,24 @@
 #define KERN_PROCSLOP	(5 * sizeof (struct kinfo_proc))
 
 int
-sysctl_doproc(int *name, u_int namelen, char *where, size_t *sizep)
+sysctl_doproc(struct proc *cp, int *name, 
+		u_int namelen, char *where, size_t *sizep)
 {
-	struct kinfo_proc2 *kproc2 = NULL;
-	struct eproc *eproc = NULL;
+	struct inst *inst;
+	struct kinfo_proc2 *kproc2;
+	struct eproc *eproc;
 	struct proc *p;
 	char *dp;
 	int arg, buflen, doingzomb, elem_size, elem_count;
 	int error, needed, type, op;
 
+	kproc2 = NULL;
+	eproc = NULL;
 	dp = where;
 	buflen = where != NULL ? *sizep : 0;
 	needed = error = 0;
 	type = name[0];
+	inst = cp->p_inst;
 
 	if (type == KERN_PROC) {
 		if (namelen != 3 && !(namelen == 2 &&
@@ -999,7 +1009,7 @@
 		arg = op == KERN_PROC_ALL ? 0 : name[2];
 		elem_size = elem_count = 0;
 		eproc = malloc(sizeof(struct eproc), M_TEMP, M_WAITOK);
-	} else /* if (type == KERN_PROC2) */ {
+	} else if (type == KERN_PROC2) {
 		if (namelen != 5 || name[3] < 0 || name[4] < 0)
 			return (EINVAL);
 		op = name[1];
@@ -1007,8 +1017,21 @@
 		elem_size = name[3];
 		elem_count = name[4];
 		kproc2 = malloc(sizeof(struct kinfo_proc2), M_TEMP, M_WAITOK);
+	} else /* if (type == KERN_INSTPROC2) */ {
+		if (namelen != 6 || name[4] < 0 || name[5] < 0)
+			return (EINVAL);
+		inst = instpfind(cp, name[1], INST_KPROC);
+		if (NULL == inst)
+			return (EINSTSRCH);
+
+		op = name[2];
+		arg = name[3];
+		elem_size = name[4];
+		elem_count = name[5];
+		kproc2 = malloc(sizeof(struct kinfo_proc2), M_TEMP, M_WAITOK);
 	}
-	p = LIST_FIRST(&allproc);
+
+	p = LIST_FIRST(&inst->inst_proc->allproc);
 	doingzomb = 0;
 again:
 	for (; p != 0; p = LIST_NEXT(p, p_list)) {
@@ -1104,7 +1127,7 @@
 		}
 	}
 	if (doingzomb == 0) {
-		p = LIST_FIRST(&zombproc);
+		p = LIST_FIRST(&cp->p_inst->inst_proc->zombproc);
 		doingzomb++;
 		goto again;
 	}
@@ -1128,6 +1151,7 @@
 
 #endif	/* SMALL_KERNEL */
 
+
 /*
  * Fill in an eproc structure for the specified process.
  */
@@ -1385,7 +1409,7 @@
 		return (EOPNOTSUPP);
 	}
 
-	if ((vp = pfind(pid)) == NULL)
+	if ((vp = pfind(cp->p_inst->inst_proc, pid)) == NULL)
 		return (ESRCH);
 
 	if (oldp == NULL) {
Index: kern/sched_bsd.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/sched_bsd.c,v
retrieving revision 1.17
retrieving revision 1.17.4.3
diff -u -r1.17 -r1.17.4.3
--- kern/sched_bsd.c	18 Jul 2008 23:43:31 -0000	1.17
+++ kern/sched_bsd.c	18 Feb 2009 12:43:25 -0000	1.17.4.3
@@ -208,6 +208,7 @@
 {
 	struct timeout *to = (struct timeout *)arg;
 	fixpt_t loadfac = loadfactor(averunnable.ldavg[0]);
+	struct inst *i;
 	struct proc *p;
 	int s;
 	unsigned int newcpu;
@@ -222,50 +223,52 @@
 	phz = stathz ? stathz : profhz;
 	KASSERT(phz);
 
-	LIST_FOREACH(p, &allproc, p_list) {
-		/*
-		 * Increment time in/out of memory and sleep time
-		 * (if sleeping).  We ignore overflow; with 16-bit int's
-		 * (remember them?) overflow takes 45 days.
-		 */
-		p->p_swtime++;
-		if (p->p_stat == SSLEEP || p->p_stat == SSTOP)
-			p->p_slptime++;
-		p->p_pctcpu = (p->p_pctcpu * ccpu) >> FSHIFT;
-		/*
-		 * If the process has slept the entire second,
-		 * stop recalculating its priority until it wakes up.
-		 */
-		if (p->p_slptime > 1)
-			continue;
-		SCHED_LOCK(s);
-		/*
-		 * p_pctcpu is only for ps.
-		 */
-#if	(FSHIFT >= CCPU_SHIFT)
-		p->p_pctcpu += (phz == 100)?
-			((fixpt_t) p->p_cpticks) << (FSHIFT - CCPU_SHIFT):
-                	100 * (((fixpt_t) p->p_cpticks)
-				<< (FSHIFT - CCPU_SHIFT)) / phz;
-#else
-		p->p_pctcpu += ((FSCALE - ccpu) *
-			(p->p_cpticks * FSCALE / phz)) >> FSHIFT;
-#endif
-		p->p_cpticks = 0;
-		newcpu = (u_int) decay_cpu(loadfac, p->p_estcpu);
-		p->p_estcpu = newcpu;
-		resetpriority(p);
-		if (p->p_priority >= PUSER) {
-			if ((p != curproc) &&
-			    p->p_stat == SRUN &&
-			    (p->p_priority / PPQ) != (p->p_usrpri / PPQ)) {
-				remrunqueue(p);
-				p->p_priority = p->p_usrpri;
-				setrunqueue(p);
-			} else
-				p->p_priority = p->p_usrpri;
+	LIST_FOREACH(i, &inst_all, inst_list) {
+		LIST_FOREACH(p, &i->inst_proc->allproc, p_list) {
+			/*
+			 * Increment time in/out of memory and sleep time
+			 * (if sleeping).  We ignore overflow; with 16-bit int's
+			 * (remember them?) overflow takes 45 days.
+			 */
+			p->p_swtime++;
+			if (p->p_stat == SSLEEP || p->p_stat == SSTOP)
+				p->p_slptime++;
+			p->p_pctcpu = (p->p_pctcpu * ccpu) >> FSHIFT;
+			/*
+			 * If the process has slept the entire second,
+			 * stop recalculating its priority until it wakes up.
+			 */
+			if (p->p_slptime > 1)
+				continue;
+			SCHED_LOCK(s);
+			/*
+			 * p_pctcpu is only for ps.
+			 */
+	#if	(FSHIFT >= CCPU_SHIFT)
+			p->p_pctcpu += (phz == 100)?
+				((fixpt_t) p->p_cpticks) << (FSHIFT - CCPU_SHIFT):
+	                	100 * (((fixpt_t) p->p_cpticks)
+					<< (FSHIFT - CCPU_SHIFT)) / phz;
+	#else
+			p->p_pctcpu += ((FSCALE - ccpu) *
+				(p->p_cpticks * FSCALE / phz)) >> FSHIFT;
+	#endif
+			p->p_cpticks = 0;
+			newcpu = (u_int) decay_cpu(loadfac, p->p_estcpu);
+			p->p_estcpu = newcpu;
+			resetpriority(p);
+			if (p->p_priority >= PUSER) {
+				if ((p != curproc) &&
+				    p->p_stat == SRUN &&
+				    (p->p_priority / PPQ) != (p->p_usrpri / PPQ)) {
+					remrunqueue(p);
+					p->p_priority = p->p_usrpri;
+					setrunqueue(p);
+				} else
+					p->p_priority = p->p_usrpri;
+			}
+			SCHED_UNLOCK(s);
 		}
-		SCHED_UNLOCK(s);
 	}
 	uvm_meter();
 	wakeup(&lbolt);
Index: kern/subr_log.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/subr_log.c,v
retrieving revision 1.15
retrieving revision 1.15.6.2
diff -u -r1.15 -r1.15.6.2
--- kern/subr_log.c	3 Sep 2007 17:51:03 -0000	1.15
+++ kern/subr_log.c	20 Sep 2008 00:09:45 -0000	1.15.6.2
@@ -58,6 +58,7 @@
 	struct	selinfo sc_selp;	/* process waiting on select call */
 	int	sc_pgid;		/* process/group for async I/O */
 	uid_t	sc_siguid;		/* uid for process that set sc_pgid */
+	instid_t sc_siginstid;		/* instid for process that set sc_pgid */
 	uid_t	sc_sigeuid;		/* euid for process that set sc_pgid */
 } logsoftc;
 
@@ -257,7 +258,7 @@
 		return;
 	selwakeup(&logsoftc.sc_selp);
 	if (logsoftc.sc_state & LOG_ASYNC)
-		csignal(logsoftc.sc_pgid, SIGIO,
+		csignal(logsoftc.sc_siginstid, logsoftc.sc_pgid, SIGIO,
 		    logsoftc.sc_siguid, logsoftc.sc_sigeuid);
 	if (logsoftc.sc_state & LOG_RDWAIT) {
 		wakeup(msgbufp);
@@ -298,6 +299,7 @@
 	case TIOCSPGRP:
 		logsoftc.sc_pgid = *(int *)data;
 		logsoftc.sc_siguid = p->p_cred->p_ruid;
+		logsoftc.sc_siginstid = p->p_inst->inst_id;
 		logsoftc.sc_sigeuid = p->p_ucred->cr_uid;
 		break;
 
Index: kern/sys_generic.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/sys_generic.c,v
retrieving revision 1.58
retrieving revision 1.58.6.5
diff -u -r1.58 -r1.58.6.5
--- kern/sys_generic.c	7 Sep 2007 15:00:20 -0000	1.58
+++ kern/sys_generic.c	18 Feb 2009 12:43:25 -0000	1.58.6.5
@@ -564,6 +564,7 @@
 
 			so->so_pgid = tmp;
 			so->so_siguid = p->p_cred->p_ruid;
+			so->so_siginstid = p->p_inst->inst_id;
 			so->so_sigeuid = p->p_ucred->cr_uid;
 			error = 0;
 			break;
@@ -571,7 +572,7 @@
 		if (tmp <= 0) {
 			tmp = -tmp;
 		} else {
-			struct proc *p1 = pfind(tmp);
+			struct proc *p1 = pfind(p->p_inst->inst_proc, tmp);
 			if (p1 == 0) {
 				error = ESRCH;
 				break;
@@ -782,15 +783,20 @@
 {
 	struct proc *p;
 	pid_t mypid;
+	instid_t myinst;
 
 	mypid = selector->p_pid;
-	if (sip->si_selpid == mypid)
+	myinst = selector->p_inst->inst_id;
+
+	if (sip->si_selpid == mypid && sip->si_selinst == myinst)
 		return;
-	if (sip->si_selpid && (p = pfind(sip->si_selpid)) &&
+	if (sip->si_selpid && (p = pfind(selector->p_inst->inst_proc, sip->si_selpid)) &&
 	    p->p_wchan == (caddr_t)&selwait)
 		sip->si_flags |= SI_COLL;
-	else
+	else {
 		sip->si_selpid = mypid;
+		sip->si_selinst = myinst;
+	}
 }
 
 /*
@@ -800,6 +806,7 @@
 selwakeup(struct selinfo *sip)
 {
 	struct proc *p;
+	struct inst *inst;
 	int s;
 
 	if (sip->si_selpid == 0)
@@ -809,8 +816,14 @@
 		sip->si_flags &= ~SI_COLL;
 		wakeup(&selwait);
 	}
-	p = pfind(sip->si_selpid);
+
+	inst = instkfind(sip->si_selinst);
+	if (NULL == inst)
+		return;
+
+	p = pfind(inst->inst_proc, sip->si_selpid);
 	sip->si_selpid = 0;
+
 	if (p != NULL) {
 		SCHED_LOCK(s);
 		if (p->p_wchan == (caddr_t)&selwait) {
Index: kern/sys_pipe.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/sys_pipe.c,v
retrieving revision 1.54
retrieving revision 1.54.4.1
diff -u -r1.54 -r1.54.4.1
--- kern/sys_pipe.c	11 Jul 2008 14:12:57 -0000	1.54
+++ kern/sys_pipe.c	19 Sep 2008 08:54:27 -0000	1.54.4.1
@@ -89,7 +89,7 @@
 
 void	pipeclose(struct pipe *);
 void	pipe_free_kmem(struct pipe *);
-int	pipe_create(struct pipe *);
+int	pipe_create(struct proc *, struct pipe *);
 int	pipelock(struct pipe *);
 void	pipeunlock(struct pipe *);
 void	pipeselwakeup(struct pipe *);
@@ -111,11 +111,11 @@
 	fdplock(fdp);
 
 	rpipe = pool_get(&pipe_pool, PR_WAITOK);
-	error = pipe_create(rpipe);
+	error = pipe_create(p, rpipe);
 	if (error != 0)
 		goto free1;
 	wpipe = pool_get(&pipe_pool, PR_WAITOK);
-	error = pipe_create(wpipe);
+	error = pipe_create(p, wpipe);
 	if (error != 0)
 		goto free2;
 
@@ -192,7 +192,7 @@
  * initialize and allocate VM and memory for pipe
  */
 int
-pipe_create(struct pipe *cpipe)
+pipe_create(struct proc *proc, struct pipe *cpipe)
 {
 	int error;
 
@@ -215,6 +215,7 @@
 	cpipe->pipe_atime = cpipe->pipe_ctime;
 	cpipe->pipe_mtime = cpipe->pipe_ctime;
 	cpipe->pipe_pgid = NO_PID;
+	cpipe->pipe_instid = proc->p_inst->inst_id;
 
 	return (0);
 }
@@ -257,7 +258,7 @@
 		selwakeup(&cpipe->pipe_sel);
 	}
 	if ((cpipe->pipe_state & PIPE_ASYNC) && cpipe->pipe_pgid != NO_PID)
-		gsignal(cpipe->pipe_pgid, SIGIO);
+		gsignal(cpipe->pipe_instid, cpipe->pipe_pgid, SIGIO);
 	KNOTE(&cpipe->pipe_sel.si_note, 0);
 }
 
Index: kern/sys_process.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/sys_process.c,v
retrieving revision 1.39
retrieving revision 1.39.8.3
diff -u -r1.39 -r1.39.8.3
--- kern/sys_process.c	10 Apr 2007 17:47:55 -0000	1.39
+++ kern/sys_process.c	18 Feb 2009 12:43:25 -0000	1.39.8.3
@@ -106,7 +106,7 @@
 	else {
 
 		/* Find the process we're supposed to be operating on. */
-		if ((t = pfind(SCARG(uap, pid))) == NULL)
+		if ((t = pfind(p->p_inst->inst_proc, SCARG(uap, pid))) == NULL)
 			return (ESRCH);
 	}
 
@@ -367,8 +367,8 @@
 		if (t->p_oppid != t->p_pptr->p_pid) {
 			struct proc *pp;
 
-			pp = pfind(t->p_oppid);
-			proc_reparent(t, pp ? pp : initproc);
+			pp = pfind(p->p_inst->inst_proc, t->p_oppid);
+			proc_reparent(t, pp ? pp : p->p_inst->inst_proc->initproc);
 		}
 
 		/* not being traced any more */
Index: kern/sys_socket.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/sys_socket.c,v
retrieving revision 1.12
retrieving revision 1.12.4.1
diff -u -r1.12 -r1.12.4.1
--- kern/sys_socket.c	23 May 2008 15:51:12 -0000	1.12
+++ kern/sys_socket.c	20 Sep 2008 00:09:45 -0000	1.12.4.1
@@ -103,6 +103,7 @@
 	case SIOCSPGRP:
 		so->so_pgid = *(int *)data;
 		so->so_siguid = p->p_cred->p_ruid;
+		so->so_siginstid = p->p_inst->inst_id;
 		so->so_sigeuid = p->p_ucred->cr_uid;
 		return (0);
 
Index: kern/syscalls.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/syscalls.c,v
retrieving revision 1.104
retrieving revision 1.104.4.3
diff -u -r1.104 -r1.104.4.3
--- kern/syscalls.c	16 Mar 2008 19:43:41 -0000	1.104
+++ kern/syscalls.c	13 Feb 2009 09:08:59 -0000	1.104.4.3
@@ -1,10 +1,10 @@
-/*	$OpenBSD$	*/
+/*	\$OpenBSD\$	*/
 
 /*
  * System call names.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from;	OpenBSD: syscalls.master,v 1.90 2008/03/16 19:42:57 otto Exp 
+ * created from;	OpenBSD: syscalls.master,v 1.89 2008/01/05 00:36:13 miod Exp 
  */
 
 char *syscallnames[] = {
@@ -427,4 +427,7 @@
 	"statfs",			/* 307 = statfs */
 	"fstatfs",			/* 308 = fstatfs */
 	"fhstatfs",			/* 309 = fhstatfs */
+	"forkinst",			/* 310 = forkinst */
+	"getinstid",			/* 311 = getinstid */
+	"killinst",			/* 312 = killinst */
 };
Index: kern/syscalls.master
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/syscalls.master,v
retrieving revision 1.90
retrieving revision 1.90.4.3
diff -u -r1.90 -r1.90.4.3
--- kern/syscalls.master	16 Mar 2008 19:42:57 -0000	1.90
+++ kern/syscalls.master	13 Feb 2009 09:08:59 -0000	1.90.4.3
@@ -618,3 +618,6 @@
 308	STD		{ int sys_fstatfs(int fd, struct statfs *buf); }
 309	STD		{ int sys_fhstatfs(const fhandle_t *fhp, \
 			    struct statfs *buf); }
+310	STD		{ instid_t sys_forkinst(instid_t id); }
+311	STD NOLOCK	{ instid_t sys_getinstid(void); }
+312	STD		{ int sys_killinst(instid_t id, int signum); }
Index: kern/tty.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/tty.c,v
retrieving revision 1.77
retrieving revision 1.77.4.1
diff -u -r1.77 -r1.77.4.1
--- kern/tty.c	28 Jul 2008 06:13:22 -0000	1.77
+++ kern/tty.c	18 Sep 2008 17:21:03 -0000	1.77.4.1
@@ -990,7 +990,7 @@
 		atomic_setbits_int(&p->p_flag, P_CONTROLT);
 		break;
 	case TIOCSPGRP: {		/* set pgrp of tty */
-		struct pgrp *pgrp = pgfind(*(int *)data);
+		struct pgrp *pgrp = pgfind(p->p_inst->inst_proc, *(int *)data);
 
 		if (!isctty(p, tp))
 			return (ENOTTY);
Index: kern/tty_pty.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/tty_pty.c,v
retrieving revision 1.38
retrieving revision 1.38.4.1
diff -u -r1.38 -r1.38.4.1
--- kern/tty_pty.c	2 Aug 2008 11:39:38 -0000	1.38
+++ kern/tty_pty.c	12 Sep 2008 13:58:49 -0000	1.38.4.1
@@ -1044,7 +1044,7 @@
 	/*
 	 * Get us a fresh cred with root privileges.
 	 */
-	cred = crget();
+	cred = crget(p->p_inst);
 	error = VOP_OPEN(vp, FREAD|FWRITE, cred, p);
 	if (!error) {
 		/* update atime/mtime */
@@ -1185,7 +1185,7 @@
 			vattr.va_gid = gid;
 			vattr.va_mode = (S_IRUSR|S_IWUSR|S_IWGRP) & ALLPERMS;
 			/* Get a fake cred to pretend we're root. */
-			cred = crget();
+			cred = crget(p->p_inst);
 			error = VOP_SETATTR(snd.ni_vp, &vattr, cred, p);
 			crfree(cred);
 			if (error) {
Index: kern/uipc_socket.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/uipc_socket.c,v
retrieving revision 1.71
retrieving revision 1.71.4.1
diff -u -r1.71 -r1.71.4.1
--- kern/uipc_socket.c	14 Jun 2008 10:55:21 -0000	1.71
+++ kern/uipc_socket.c	20 Sep 2008 00:09:45 -0000	1.71.4.1
@@ -1201,7 +1201,8 @@
 void
 sohasoutofband(struct socket *so)
 {
-	csignal(so->so_pgid, SIGURG, so->so_siguid, so->so_sigeuid);
+	csignal(so->so_siginstid, so->so_pgid, 
+			SIGURG, so->so_siguid, so->so_sigeuid);
 	selwakeup(&so->so_rcv.sb_sel);
 }
 
Index: kern/uipc_socket2.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/uipc_socket2.c,v
retrieving revision 1.44
retrieving revision 1.44.4.1
diff -u -r1.44 -r1.44.4.1
--- kern/uipc_socket2.c	23 May 2008 15:51:12 -0000	1.44
+++ kern/uipc_socket2.c	20 Sep 2008 00:09:45 -0000	1.44.4.1
@@ -178,6 +178,7 @@
 	so->so_egid = head->so_egid;
 	so->so_rgid = head->so_rgid;
 	so->so_cpid = head->so_cpid;
+	so->so_siginstid = head->so_siginstid;
 	so->so_siguid = head->so_siguid;
 	so->so_sigeuid = head->so_sigeuid;
 
@@ -324,7 +325,8 @@
 		wakeup(&sb->sb_cc);
 	}
 	if (so->so_state & SS_ASYNC)
-		csignal(so->so_pgid, SIGIO, so->so_siguid, so->so_sigeuid);
+		csignal(so->so_siginstid, so->so_pgid, SIGIO, 
+				so->so_siguid, so->so_sigeuid);
 	KNOTE(&sb->sb_sel.si_note, 0);
 }
 
Index: kern/vfs_syscalls.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/kern/vfs_syscalls.c,v
retrieving revision 1.148
retrieving revision 1.148.4.2
diff -u -r1.148 -r1.148.4.2
--- kern/vfs_syscalls.c	28 Jul 2008 14:21:17 -0000	1.148
+++ kern/vfs_syscalls.c	16 Sep 2008 23:10:38 -0000	1.148.4.2
@@ -64,7 +64,7 @@
 
 static int change_dir(struct nameidata *, struct proc *);
 
-void checkdirs(struct vnode *);
+void checkdirs(struct proc *, struct vnode *);
 
 int copyout_statfs(struct statfs *, void *, struct proc *);
 
@@ -297,7 +297,7 @@
 	if (!error) {
 		vfsp->vfc_refcount++;
 		CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
-		checkdirs(vp);
+		checkdirs(p, vp);
 		VOP_UNLOCK(vp, 0, p);
  		if ((mp->mnt_flag & MNT_RDONLY) == 0)
  			error = vfs_allocate_syncvnode(mp);
@@ -320,7 +320,7 @@
  * mounted. If so, replace them with the new mount point.
  */
 void
-checkdirs(struct vnode *olddp)
+checkdirs(struct proc *curp, struct vnode *olddp)
 {
 	struct filedesc *fdp;
 	struct vnode *newdp;
@@ -330,7 +330,7 @@
 		return;
 	if (VFS_ROOT(olddp->v_mountedhere, &newdp))
 		panic("mount: lost mount");
-	LIST_FOREACH(p, &allproc, p_list) {
+	PROCLIST_FOREACH(p, curp, p_list) {
 		fdp = p->p_fd;
 		if (fdp->fd_cdir == olddp) {
 			vrele(fdp->fd_cdir);
Index: miscfs/procfs/procfs_ctl.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/miscfs/procfs/procfs_ctl.c,v
retrieving revision 1.21
retrieving revision 1.21.8.2
diff -u -r1.21 -r1.21.8.2
--- miscfs/procfs/procfs_ctl.c	18 Jun 2007 08:30:07 -0000	1.21
+++ miscfs/procfs/procfs_ctl.c	27 Sep 2008 14:09:44 -0000	1.21.8.2
@@ -138,6 +138,7 @@
 		atomic_setbits_int(&p->p_flag, P_TRACED);
 		p->p_xstat = 0;		/* XXX ? */
 		if (p->p_pptr != curp) {
+			/* FIXME: instances */
 			p->p_oppid = p->p_pptr->p_pid;
 			proc_reparent(p, curp);
 		}
@@ -187,10 +188,11 @@
 		atomic_clearbits_int(&p->p_flag, P_TRACED);
 
 		/* give process back to original parent */
+		KASSERT(p->p_pptr); /* FIXME: instances. */
 		if (p->p_oppid != p->p_pptr->p_pid) {
 			struct proc *pp;
 
-			pp = pfind(p->p_oppid);
+			pp = pfind(curp->p_inst->inst_proc, p->p_oppid);
 			if (pp)
 				proc_reparent(p, pp);
 		}
Index: miscfs/procfs/procfs_subr.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/miscfs/procfs/procfs_subr.c,v
retrieving revision 1.28
retrieving revision 1.28.6.1
diff -u -r1.28 -r1.28.6.1
--- miscfs/procfs/procfs_subr.c	9 Dec 2007 21:34:32 -0000	1.28
+++ miscfs/procfs/procfs_subr.c	16 Sep 2008 23:10:38 -0000	1.28.6.1
@@ -201,7 +201,7 @@
 	struct pfsnode *pfs = VTOPFS(vp);
 	struct proc *p;
 
-	p = pfind(pfs->pfs_pid);
+	p = pfind(curp->p_inst->inst_proc, pfs->pfs_pid);
 	if (p == 0)
 		return (EINVAL);
 	/* Do not permit games to be played with init(8) */
Index: miscfs/procfs/procfs_vfsops.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/miscfs/procfs/procfs_vfsops.c,v
retrieving revision 1.25
retrieving revision 1.25.8.3
diff -u -r1.25 -r1.25.8.3
--- miscfs/procfs/procfs_vfsops.c	18 Jun 2007 08:30:07 -0000	1.25
+++ miscfs/procfs/procfs_vfsops.c	18 Feb 2009 12:43:25 -0000	1.25.8.3
@@ -76,6 +76,11 @@
 	struct procfs_args args;
 	int error;
 
+	/* FIXME - instances. */
+	log(LOG_ERR, "procfs: not supported with instances");
+	return(EINVAL);
+	/* FIXME - instances. */
+
 	if (UIO_MX & (UIO_MX-1)) {
 		log(LOG_ERR, "procfs: invalid directory entry size");
 		return (EINVAL);
Index: miscfs/procfs/procfs_vnops.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/miscfs/procfs/procfs_vnops.c,v
retrieving revision 1.45
retrieving revision 1.45.4.4
diff -u -r1.45 -r1.45.4.4
--- miscfs/procfs/procfs_vnops.c	9 Jun 2008 23:38:37 -0000	1.45
+++ miscfs/procfs/procfs_vnops.c	18 Feb 2009 12:43:26 -0000	1.45.4.4
@@ -197,7 +197,7 @@
 	struct proc *p2;		/* traced */
 	int error;
 
-	if ((p2 = pfind(pfs->pfs_pid)) == 0)
+	if ((p2 = pfind(p1->p_inst->inst_proc, pfs->pfs_pid)) == 0)
 		return (ENOENT);	/* was ESRCH, jsp */
 
 	switch (pfs->pfs_type) {
@@ -294,7 +294,8 @@
 	struct vnode *vp = ap->a_vp;
 	struct pfsnode *pfs = VTOPFS(vp);
 
-	if (pfind(pfs->pfs_pid) == NULL && !(vp->v_flag & VXLOCK))
+	/* FIXME: instances. */
+	if (pfind(proc0.p_inst->inst_proc, pfs->pfs_pid) == NULL && !(vp->v_flag & VXLOCK))
 		vgone(vp);
 
 	return (0);
@@ -424,7 +425,8 @@
 		break;
 
 	default:
-		procp = pfind(pfs->pfs_pid);
+		/* FIXME: instances. */
+		procp = pfind(proc0.p_inst->inst_proc, pfs->pfs_pid);
 		if (procp == 0)
 			return (ENOENT);
 	}
@@ -704,7 +706,7 @@
 		if (pid == NO_PID)
 			break;
 
-		p = pfind(pid);
+		p = pfind(curp->p_inst->inst_proc, pid);
 		if (p == 0)
 			break;
 
@@ -732,7 +734,7 @@
 			return (error);
 		}
 
-		p = pfind(pfs->pfs_pid);
+		p = pfind(curp->p_inst->inst_proc, pfs->pfs_pid);
 		if (p == 0)
 			break;
 
@@ -837,7 +839,8 @@
 		struct proc *p;
 		struct proc_target *pt;
 
-		p = pfind(pfs->pfs_pid);
+		/* FIXME: instances. */
+		p = pfind(proc0.p_inst->inst_proc, pfs->pfs_pid);
 		if (p == NULL)
 			break;
 
@@ -873,7 +876,9 @@
 		int doingzomb = 0;
 #endif
 		int pcnt = i;
-		volatile struct proc *p = LIST_FIRST(&allproc);
+		/* FIXME */
+		volatile struct proc *p = 
+			LIST_FIRST(&curproc->p_inst->inst_proc->allproc);
 
 		if (pcnt > 3)
 			pcnt = 3;
@@ -950,7 +955,7 @@
 #ifdef PROCFS_ZOMBIE
 		if (p == 0 && doingzomb == 0) {
 			doingzomb = 1;
-			p = LIST_FIRST(&zombproc);
+			p = LIST_FIRST(curproc->p_inst->inst_proc->zombproc);
 			goto again;
 		}
 #endif
Index: net/bpf.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/net/bpf.c,v
retrieving revision 1.68
retrieving revision 1.68.6.2
diff -u -r1.68 -r1.68.6.2
--- net/bpf.c	25 Jan 2008 16:14:56 -0000	1.68
+++ net/bpf.c	20 Sep 2008 00:09:45 -0000	1.68.6.2
@@ -492,7 +492,7 @@
 {
 	wakeup((caddr_t)d);
 	if (d->bd_async && d->bd_sig)
-		csignal(d->bd_pgid, d->bd_sig,
+		csignal(d->bd_siginstid, d->bd_pgid, d->bd_sig,
 		    d->bd_siguid, d->bd_sigeuid);
 
 	selwakeup(&d->bd_sel);
@@ -856,6 +856,7 @@
 	 */
 	case TIOCSPGRP:		/* Process or group to send signals to */
 		d->bd_pgid = *(int *)addr;
+		d->bd_siginstid = p->p_inst->inst_id;
 		d->bd_siguid = p->p_cred->p_ruid;
 		d->bd_sigeuid = p->p_ucred->cr_uid;
 		break;
Index: net/bpfdesc.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/net/bpfdesc.h,v
retrieving revision 1.17
retrieving revision 1.17.12.1
diff -u -r1.17 -r1.17.12.1
--- net/bpfdesc.h	25 Mar 2006 22:41:47 -0000	1.17
+++ net/bpfdesc.h	19 Sep 2008 11:07:33 -0000	1.17.12.1
@@ -82,6 +82,7 @@
 	int		bd_async;	/* non-zero if packet reception should generate signal */
 	int		bd_sig;		/* signal to send upon packet reception */
 	pid_t		bd_pgid;	/* process or group id for signal */
+	instid_t	bd_siginstid;	/* instance for process for signal */
 	uid_t		bd_siguid;	/* uid for process that set pgid */
 	uid_t		bd_sigeuid;	/* euid for process that set pgid */
 	u_int		bd_ref;		/* reference count */
Index: net/if_tun.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/net/if_tun.c,v
retrieving revision 1.94
retrieving revision 1.94.4.2
diff -u -r1.94 -r1.94.4.2
--- net/if_tun.c	4 Aug 2008 18:55:08 -0000	1.94
+++ net/if_tun.c	20 Sep 2008 00:09:45 -0000	1.94.4.2
@@ -90,6 +90,7 @@
 	struct arpcom	arpcom;		/* ethernet common data */
 	u_short		tun_flags;	/* misc flags */
 	pid_t		tun_pgid;	/* the process group - if any */
+	instid_t	tun_siginstid;	/* instid for process that set tun_pgid */
 	uid_t		tun_siguid;	/* uid for process that set tun_pgid */
 	uid_t		tun_sigeuid;	/* euid for process that set tun_pgid */
 	struct selinfo	tun_rsel;	/* read select */
@@ -585,7 +586,7 @@
 		wakeup((caddr_t)tp);
 	}
 	if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
-		csignal(tp->tun_pgid, SIGIO,
+		csignal(tp->tun_siginstid, tp->tun_pgid, SIGIO,
 		    tp->tun_siguid, tp->tun_sigeuid);
 	selwakeup(&tp->tun_rsel);
 	KNOTE(&tp->tun_rsel.si_note, 0);
@@ -669,6 +670,7 @@
 		break;
 	case TIOCSPGRP:
 		tp->tun_pgid = *(int *)data;
+		tp->tun_siginstid = p->p_inst->inst_id;
 		tp->tun_siguid = p->p_cred->p_ruid;
 		tp->tun_sigeuid = p->p_ucred->cr_uid;
 		break;
Index: nfs/nfs_vfsops.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/nfs/nfs_vfsops.c,v
retrieving revision 1.79
retrieving revision 1.79.4.1
diff -u -r1.79 -r1.79.4.1
--- nfs/nfs_vfsops.c	28 Jul 2008 13:35:14 -0000	1.79
+++ nfs/nfs_vfsops.c	12 Sep 2008 13:58:49 -0000	1.79.4.1
@@ -125,7 +125,7 @@
 	if (error)
 		return (error);
 	vp = NFSTOV(np);
-	cred = crget();
+	cred = crget(p->p_inst);
 	cred->cr_ngroups = 0;
 	if (v3 && (nmp->nm_flag & NFSMNT_GOTFSINFO) == 0)
 		(void)nfs_fsinfo(nmp, vp, cred, p);
Index: sys/_types.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/_types.h,v
retrieving revision 1.2
retrieving revision 1.2.4.1
diff -u -r1.2 -r1.2.4.1
--- sys/_types.h	16 Mar 2008 19:42:57 -0000	1.2
+++ sys/_types.h	12 Sep 2008 13:58:49 -0000	1.2.4.1
@@ -58,6 +58,7 @@
 typedef	__int32_t	__suseconds_t;	/* microseconds (signed) */
 typedef __uint64_t	__fsblkcnt_t;	/* file system block count */
 typedef __uint64_t	__fsfilcnt_t;	/* file system file count */
+typedef __uint32_t	__instid_t;	/* instance id */
 
 /*
  * mbstate_t is an opaque object to keep conversion state, during multibyte
Index: sys/errno.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/errno.h,v
retrieving revision 1.20
retrieving revision 1.20.6.2
diff -u -r1.20 -r1.20.6.2
--- sys/errno.h	3 Sep 2007 14:37:52 -0000	1.20
+++ sys/errno.h	13 Feb 2009 09:09:00 -0000	1.20.6.2
@@ -166,8 +166,13 @@
 #endif /* __BSD_VISIBLE */
 #define	EIDRM		89		/* Identifier removed */
 #define	ENOMSG		90		/* No message of desired type */
+
+/* instances */
+#define	EINSTSRCH	91		/* instance not found */
+#define	EINSTEXIST	92
+
 #if __BSD_VISIBLE
-#define	ELAST		90		/* Must be equal largest errno */
+#define	ELAST		92		/* Must be equal largest errno */
 #endif /* __BSD_VISIBLE */
 
 #ifdef _KERNEL
Index: sys/inst.h
===================================================================
RCS file: sys/inst.h
diff -N sys/inst.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sys/inst.h	18 Feb 2009 18:20:20 -0000	1.1.2.10
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008 Kristaps Dzonsons <kristaps@mult.bsd.lv>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef _SYS_INST_H_
+#define	_SYS_INST_H_
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/queue.h>
+
+#define	INST_MAX	(UINT_MAX - 1)
+#define	INST_NOID	(UINT_MAX)
+
+#define	SIGINST_TERM	(15)	/* Send SIGTERM to root. */
+#define	SIGINST_KILL	(9)	/* Send SIGKILL to root. */
+
+struct	inst_proc;
+
+struct	inst {
+	struct inst_proc*inst_proc;
+	LIST_ENTRY(inst) inst_hash;
+	LIST_ENTRY(inst) inst_list;
+	instid_t	 inst_id;
+	u_int		 inst_ref;
+};
+
+#ifdef _KERNEL
+#define insthold(inst) (inst)->inst_ref++
+
+LIST_HEAD(instlist, inst);
+
+extern struct instlist	 inst_all;
+
+enum	instop {
+	INST_KPROC,	/* Read-only statistics. */
+	INST_SIG	/* Deliver signal to a process. */
+};
+
+void			 instinit(void);
+struct inst		*instknew(instid_t);
+struct inst		*instpnew(struct proc *, instid_t);
+struct inst		*instpfind(struct proc *, 
+				instid_t, enum instop);
+struct inst		*instkfind(instid_t);
+void			 instfree(struct inst *);
+
+#endif	/* _KERNEL */
+
+#endif	/* !_SYS_INST_H_ */
Index: sys/malloc.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/malloc.h,v
retrieving revision 1.92
retrieving revision 1.92.4.1
diff -u -r1.92 -r1.92.4.1
--- sys/malloc.h	22 Jun 2008 15:52:54 -0000	1.92
+++ sys/malloc.h	12 Sep 2008 13:58:49 -0000	1.92.4.1
@@ -99,6 +99,7 @@
 #define	M_PROC		41	/* Proc structures */
 #define	M_SUBPROC	42	/* Proc sub-structures */
 #define	M_VCLUSTER	43	/* Cluster for VFS */
+#define	M_INST		44	/* Instance structures */
 /* 45-46 - free */
 #define	M_MFSNODE	46	/* MFS vnode private part */
 /* 47-48 - free */
@@ -230,7 +231,7 @@
 	"proc",		/* 41 M_PROC */ \
 	"subproc",	/* 42 M_SUBPROC */ \
 	"VFS cluster",	/* 43 M_VCLUSTER */ \
-	NULL, \
+	"inst", 	/* 44 M_INST */ \
 	NULL, \
 	"MFS node",	/* 46 M_MFSNODE */ \
 	NULL, \
Index: sys/pipe.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/pipe.h,v
retrieving revision 1.13
retrieving revision 1.13.14.1
diff -u -r1.13 -r1.13.14.1
--- sys/pipe.h	21 Nov 2005 18:16:46 -0000	1.13
+++ sys/pipe.h	19 Sep 2008 08:54:27 -0000	1.13.14.1
@@ -77,6 +77,7 @@
 	struct	timespec pipe_atime;	/* time of last access */
 	struct	timespec pipe_mtime;	/* time of last modify */
 	struct	timespec pipe_ctime;	/* time of status change */
+	instid_t pipe_instid;
 	int	pipe_pgid;		/* process/group for async I/O */
 	struct	pipe *pipe_peer;	/* link with other direction */
 	u_int	pipe_state;		/* pipe status info */
Index: sys/proc.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/proc.h,v
retrieving revision 1.103
retrieving revision 1.103.4.12
diff -u -r1.103 -r1.103.4.12
--- sys/proc.h	5 May 2008 15:37:41 -0000	1.103
+++ sys/proc.h	18 Feb 2009 12:43:26 -0000	1.103.4.12
@@ -53,6 +53,14 @@
 #define __need_process
 #endif
 
+/* 
+ * This refers to whether we internally use "functional" isolation on
+ * the process table in order to speed up performance.  This has NOT
+ * been determined to significantly slow/speed performance, so it'll be
+ * deprecated.  TODO.
+ */
+#define GLOBAL_HASH	0
+
 /*
  * One structure allocated per session.
  */
@@ -71,6 +79,9 @@
 	LIST_ENTRY(pgrp) pg_hash;	/* Hash chain. */
 	LIST_HEAD(, proc) pg_members;	/* Pointer to pgrp members. */
 	struct	session *pg_session;	/* Pointer to session. */
+#ifdef GLOBAL_HASH
+	struct	inst	*pg_inst;
+#endif
 	pid_t	pg_id;			/* Pgrp id. */
 	int	pg_jobc;	/* # procs qualifying pgrp for job control */
 };
@@ -162,6 +173,7 @@
 	struct	sigacts *p_sigacts;	/* Signal actions, state */
 #define	p_cred		p_p->ps_cred
 #define	p_ucred		p_cred->pc_ucred
+#define	p_inst		p_cred->pc_ucred->cr_inst
 #define	p_rlimit	p_p->ps_limit->pl_rlimit
 
 	int	p_exitsig;		/* Signal to send to parent on exit. */
@@ -340,7 +352,6 @@
 	long	ui_lockcnt;	/* lockf structs */
 };
 
-struct uidinfo *uid_find(uid_t);
 
 /*
  * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
@@ -375,21 +386,36 @@
 #define EXIT_NORMAL	0x00000001
 #define EXIT_THREAD	0x00000002
 
-#define	PIDHASH(pid)	(&pidhashtbl[(pid) & pidhash])
-extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
+LIST_HEAD(proclist, proc);
+LIST_HEAD(pidhhead, proc);
+LIST_HEAD(pghhead, pgrp);
+
+#ifdef GLOBAL_HASH
+extern struct pidhhead *pidhashtbl;
 extern u_long pidhash;
 
-#define	PGRPHASH(pgid)	(&pgrphashtbl[(pgid) & pgrphash])
-extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
+extern struct pghhead *pgrphashtbl;
 extern u_long pgrphash;
+#endif
 
-extern struct proc proc0;		/* Process slot for swapper. */
-extern int nprocs, maxproc;		/* Current and max number of procs. */
-extern int randompid;			/* fork() should create random pid's */
+struct	inst_proc {
+	struct proclist	 allproc;
+	struct proclist	 zombproc;
+#ifdef GLOBAL_HASH
+	instid_t	 instid; 
+#else /*!GLOBAL_HASH*/
+	struct pidhhead *pidhashtbl;
+	u_long		 pidhash;
+	struct pghhead	*pgrphashtbl;
+	u_long		 pgrphash;
+#endif /*!GLOBAL_HASH*/
+	struct proc	*initproc;
+};
 
-LIST_HEAD(proclist, proc);
-extern struct proclist allproc;		/* List of all processes. */
-extern struct proclist zombproc;	/* List of zombie processes. */
+
+extern struct proc proc0;		/* Process slot for swapper. */
+extern int nprocs, maxproc;		/* Max number of procs. */
+extern int randompid;
 
 extern struct proc *initproc;		/* Process slots for init, pager. */
 extern struct proc *syncerproc;		/* filesystem syncer daemon */
@@ -403,8 +429,9 @@
 
 struct simplelock;
 
-struct proc *pfind(pid_t);	/* Find process by id. */
-struct pgrp *pgfind(pid_t);	/* Find process group by id. */
+struct uidinfo *uid_find(uid_t);
+struct proc *pfind(struct inst_proc *, pid_t);
+struct pgrp *pgfind(struct inst_proc *, pid_t);
 void	proc_printit(struct proc *p, const char *modif,
     int (*pr)(const char *, ...));
 
@@ -427,6 +454,7 @@
 void	exit1(struct proc *, int, int);
 void	exit2(struct proc *);
 void	cpu_exit(struct proc *);
+int	forkinst1(struct proc *, instid_t, register_t *);
 int	fork1(struct proc *, int, int, void *, size_t, void (*)(void *),
 	    void *, register_t *, struct proc **);
 int	groupmember(gid_t, struct ucred *);
@@ -461,7 +489,16 @@
 void	proc_trampoline_mp(void);	/* XXX */
 #endif
 
-int proc_isunder(struct proc *, struct proc *);
+int	proc_isunder(struct proc *, struct proc *);
+
+void		  pgrpinit(struct proc *, struct proc *);
+struct inst_proc *proc_instinit(const struct inst *);
+void		  proc_instfree(struct inst_proc *);
+void		  proc_instadd(struct inst_proc *, struct proc *);
+void		  pgrp_instadd(struct inst_proc *, struct pgrp *);
+
+#define	PROCLIST_FOREACH(x, y, z) \
+	LIST_FOREACH(x, &(y)->p_inst->inst_proc->allproc, z)
 
 #endif	/* _KERNEL */
 #endif	/* !_SYS_PROC_H_ */
Index: sys/selinfo.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/selinfo.h,v
retrieving revision 1.3
retrieving revision 1.3.8.1
diff -u -r1.3 -r1.3.8.1
--- sys/selinfo.h	25 Jul 2007 23:11:53 -0000	1.3
+++ sys/selinfo.h	19 Sep 2008 08:54:27 -0000	1.3.8.1
@@ -41,6 +41,7 @@
  * notified when I/O becomes possible.
  */
 struct selinfo {
+	instid_t si_selinst;
 	pid_t	si_selpid;	/* process to be notified */
 	struct	klist si_note;	/* kernel note list */
 	short	si_flags;	/* see below */
Index: sys/signalvar.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/signalvar.h,v
retrieving revision 1.16
retrieving revision 1.16.10.2
diff -u -r1.16 -r1.16.10.2
--- sys/signalvar.h	6 Feb 2007 18:42:37 -0000	1.16
+++ sys/signalvar.h	20 Sep 2008 00:09:45 -0000	1.16.10.2
@@ -154,8 +154,8 @@
  */
 int	coredump(struct proc *p);
 void	execsigs(struct proc *p);
-void	gsignal(int pgid, int sig);
-void	csignal(pid_t pgid, int signum, uid_t uid, uid_t euid);
+void	gsignal(instid_t instid, int pgid, int sig);
+void	csignal(instid_t instid, pid_t pgid, int signum, uid_t uid, uid_t euid);
 int	issignal(struct proc *p);
 void	pgsignal(struct pgrp *pgrp, int sig, int checkctty);
 void	postsig(int sig);
Index: sys/socketvar.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/socketvar.h,v
retrieving revision 1.41
retrieving revision 1.41.4.1
diff -u -r1.41 -r1.41.4.1
--- sys/socketvar.h	23 May 2008 15:51:12 -0000	1.41
+++ sys/socketvar.h	20 Sep 2008 00:09:45 -0000	1.41.4.1
@@ -72,6 +72,7 @@
 	short	so_timeo;		/* connection timeout */
 	u_short	so_error;		/* error affecting connection */
 	pid_t	so_pgid;		/* pgid for signals */
+	instid_t so_siginstid;		/* instid of process who set so_pgid */
 	uid_t	so_siguid;		/* uid of process who set so_pgid */
 	uid_t	so_sigeuid;		/* euid of process who set so_pgid */
 	u_long	so_oobmark;		/* chars to oob mark */
Index: sys/syscall.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/syscall.h,v
retrieving revision 1.101
retrieving revision 1.101.4.3
diff -u -r1.101 -r1.101.4.3
--- sys/syscall.h	16 Mar 2008 19:43:41 -0000	1.101
+++ sys/syscall.h	13 Feb 2009 09:09:00 -0000	1.101.4.3
@@ -1,10 +1,10 @@
-/*	$OpenBSD$	*/
+/*	\$OpenBSD\$	*/
 
 /*
  * System call numbers.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from;	OpenBSD: syscalls.master,v 1.90 2008/03/16 19:42:57 otto Exp 
+ * created from;	OpenBSD: syscalls.master,v 1.89 2008/01/05 00:36:13 miod Exp 
  */
 
 /* syscall: "syscall" ret: "int" args: "int" "..." */
@@ -698,4 +698,13 @@
 /* syscall: "fhstatfs" ret: "int" args: "const fhandle_t *" "struct statfs *" */
 #define	SYS_fhstatfs	309
 
-#define	SYS_MAXSYSCALL	310
+/* syscall: "forkinst" ret: "instid_t" args: "instid_t" */
+#define	SYS_forkinst	310
+
+/* syscall: "getinstid" ret: "instid_t" args: */
+#define	SYS_getinstid	311
+
+/* syscall: "killinst" ret: "int" args: "instid_t" "int" */
+#define	SYS_killinst	312
+
+#define	SYS_MAXSYSCALL	313
Index: sys/syscallargs.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/syscallargs.h,v
retrieving revision 1.103
retrieving revision 1.103.4.3
diff -u -r1.103 -r1.103.4.3
--- sys/syscallargs.h	16 Mar 2008 19:43:41 -0000	1.103
+++ sys/syscallargs.h	13 Feb 2009 09:09:00 -0000	1.103.4.3
@@ -1,10 +1,10 @@
-/*	$OpenBSD$	*/
+/*	\$OpenBSD\$	*/
 
 /*
  * System call argument lists.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from;	OpenBSD: syscalls.master,v 1.90 2008/03/16 19:42:57 otto Exp 
+ * created from;	OpenBSD: syscalls.master,v 1.89 2008/01/05 00:36:13 miod Exp 
  */
 
 #ifdef	syscallarg
@@ -1259,6 +1259,15 @@
 	syscallarg(struct statfs *) buf;
 };
 
+struct sys_forkinst_args {
+	syscallarg(instid_t) id;
+};
+
+struct sys_killinst_args {
+	syscallarg(instid_t) id;
+	syscallarg(int) signum;
+};
+
 /*
  * System call prototypes.
  */
@@ -1580,3 +1589,6 @@
 int	sys_statfs(struct proc *, void *, register_t *);
 int	sys_fstatfs(struct proc *, void *, register_t *);
 int	sys_fhstatfs(struct proc *, void *, register_t *);
+int	sys_forkinst(struct proc *, void *, register_t *);
+int	sys_getinstid(struct proc *, void *, register_t *);
+int	sys_killinst(struct proc *, void *, register_t *);
Index: sys/sysctl.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/sysctl.h,v
retrieving revision 1.92
retrieving revision 1.92.6.2
diff -u -r1.92 -r1.92.6.2
--- sys/sysctl.h	9 Feb 2008 15:10:58 -0000	1.92
+++ sys/sysctl.h	31 Jan 2009 19:14:55 -0000	1.92.6.2
@@ -184,7 +184,9 @@
 #define	KERN_TIMECOUNTER	69	/* node: timecounter */
 #define	KERN_MAXLOCKSPERUID	70	/* int: locks per uid */
 #define	KERN_CPTIME2		71	/* array: cp_time2 */
-#define	KERN_MAXID		72	/* number of valid kern ids */
+#define	KERN_INST		72	/* struct: instance entries */
+#define	KERN_INSTPROC2		73	/* struct: process entries */
+#define	KERN_MAXID		74	/* number of valid kern ids */
 
 #define	CTL_KERN_NAMES { \
 	{ 0, 0 }, \
@@ -259,6 +261,7 @@
  	{ "timecounter", CTLTYPE_NODE }, \
  	{ "maxlocksperuid", CTLTYPE_INT }, \
  	{ "cp_time2", CTLTYPE_STRUCT }, \
+ 	{ "inst", CTLTYPE_STRUCT }, \
 }
 
 /*
@@ -269,6 +272,11 @@
 #define KERN_EMUL_NAME		0
 #define KERN_EMUL_ENABLED	1
 
+/*
+ * KERN_INST subtypes
+ */
+#define	KERN_INST_ALL		0	/* everything */
+#define	KERN_INST_INSTID	1	/* by instance id */		
 
 /*
  * KERN_PROC subtypes
@@ -347,6 +355,11 @@
 
 #define KI_NOCPU	(~(u_int64_t)0)
 
+struct kinfo_inst {
+	u_int32_t inst_id;
+	u_int32_t inst_ref;
+};
+
 struct kinfo_proc2 {
 	u_int64_t p_forw;		/* PTR: linked run/sleep queue. */
 	u_int64_t p_back;
@@ -687,7 +700,8 @@
 int sysctl_rdstruct(void *, size_t *, void *, const void *, int);
 int sysctl_struct(void *, size_t *, void *, size_t, void *, int);
 int sysctl_file(char *, size_t *);
-int sysctl_doproc(int *, u_int, char *, size_t *);
+int sysctl_doproc(struct proc *, int *, u_int, char *, size_t *);
+int sysctl_doinst(struct proc *, int *, u_int, char *, size_t *);
 struct radix_node;
 struct walkarg;
 int sysctl_dumpentry(struct radix_node *, void *);
Index: sys/types.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/types.h,v
retrieving revision 1.31
retrieving revision 1.31.4.1
diff -u -r1.31 -r1.31.4.1
--- sys/types.h	16 Mar 2008 19:42:57 -0000	1.31
+++ sys/types.h	12 Sep 2008 13:58:49 -0000	1.31.4.1
@@ -148,6 +148,7 @@
 typedef	__suseconds_t	suseconds_t;	/* microseconds (signed) */
 typedef	__fsblkcnt_t	fsblkcnt_t;	/* file system block count */
 typedef	__fsfilcnt_t	fsfilcnt_t;	/* file system file count */
+typedef	__instid_t	instid_t;	/* instance id */
 
 /*
  * XPG4.2 states that inclusion of <netinet/in.h> must pull these
Index: sys/ucred.h
===================================================================
RCS file: /cvs/OpenBSD/src/sys/sys/ucred.h,v
retrieving revision 1.6
retrieving revision 1.6.24.3
diff -u -r1.6 -r1.6.24.3
--- sys/ucred.h	15 Aug 2003 20:32:20 -0000	1.6
+++ sys/ucred.h	13 Feb 2009 09:09:00 -0000	1.6.24.3
@@ -35,6 +35,8 @@
 #ifndef _SYS_UCRED_H_
 #define	_SYS_UCRED_H_
 
+#include <sys/inst.h>			/* For struct inst */
+
 /*
  * Credentials.
  */
@@ -44,6 +46,7 @@
 	gid_t	cr_gid;			/* effective group id */
 	short	cr_ngroups;		/* number of groups */
 	gid_t	cr_groups[NGROUPS];	/* groups */
+	struct	inst *cr_inst;		/* instance */
 };
 #define NOCRED ((struct ucred *)-1)	/* no credential available */
 #define FSCRED ((struct ucred *)-2)	/* filesystem credential */
@@ -56,7 +59,8 @@
 struct ucred	*crcopy(struct ucred *cr);
 struct ucred	*crdup(struct ucred *cr);
 void		crfree(struct ucred *cr);
-struct ucred	*crget(void);
+struct ucred	*crget(struct inst *inst);
+struct ucred	*crnew(void);
 int		suser(struct proc *p, u_int flags);
 int		suser_ucred(struct ucred *cred);
 
Index: uvm/uvm_glue.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/uvm/uvm_glue.c,v
retrieving revision 1.47
retrieving revision 1.47.8.3
diff -u -r1.47 -r1.47.8.3
--- uvm/uvm_glue.c	26 May 2007 20:26:51 -0000	1.47
+++ uvm/uvm_glue.c	18 Feb 2009 12:43:26 -0000	1.47.8.3
@@ -352,6 +352,7 @@
 uvm_swapout_threads(void)
 {
 	struct proc *p;
+	struct inst *i;
 	struct proc *outp, *outp2;
 	int outpri, outpri2;
 	int didswap = 0;
@@ -369,27 +370,29 @@
 	 */
 	outp = outp2 = NULL;
 	outpri = outpri2 = 0;
-	LIST_FOREACH(p, &allproc, p_list) {
-		if (!swappable(p))
-			continue;
-		switch (p->p_stat) {
-		case SRUN:
-			if (p->p_swtime > outpri2) {
-				outp2 = p;
-				outpri2 = p->p_swtime;
+	LIST_FOREACH(i, &inst_all, inst_list) {
+		LIST_FOREACH(p, &i->inst_proc->allproc, p_list) {
+			if (!swappable(p))
+				continue;
+			switch (p->p_stat) {
+			case SRUN:
+				if (p->p_swtime > outpri2) {
+					outp2 = p;
+					outpri2 = p->p_swtime;
+				}
+				continue;
+				
+			case SSLEEP:
+			case SSTOP:
+				if (p->p_slptime >= maxslp) {
+					pmap_collect(p->p_vmspace->vm_map.pmap);
+					didswap++;
+				} else if (p->p_slptime > outpri) {
+					outp = p;
+					outpri = p->p_slptime;
+				}
+				continue;
 			}
-			continue;
-			
-		case SSLEEP:
-		case SSTOP:
-			if (p->p_slptime >= maxslp) {
-				pmap_collect(p->p_vmspace->vm_map.pmap);
-				didswap++;
-			} else if (p->p_slptime > outpri) {
-				outp = p;
-				outpri = p->p_slptime;
-			}
-			continue;
 		}
 	}
 
Index: uvm/uvm_meter.c
===================================================================
RCS file: /cvs/OpenBSD/src/sys/uvm/uvm_meter.c,v
retrieving revision 1.24
retrieving revision 1.24.6.3
diff -u -r1.24 -r1.24.6.3
--- uvm/uvm_meter.c	15 Dec 2007 03:42:57 -0000	1.24
+++ uvm/uvm_meter.c	18 Feb 2009 12:43:26 -0000	1.24.6.3
@@ -100,20 +100,23 @@
 {
 	int i, nrun;
 	struct proc *p;
+	struct inst *inst;
 
 	nrun = 0;
-	LIST_FOREACH(p, &allproc, p_list) {
-		switch (p->p_stat) {
-		case SSLEEP:
-			if (p->p_priority > PZERO || p->p_slptime > 1)
-				continue;
-		/* FALLTHROUGH */
-		case SRUN:
-		case SONPROC:
-			if (p == p->p_cpu->ci_schedstate.spc_idleproc)
-				continue;
-		case SIDL:
-			nrun++;
+	LIST_FOREACH(inst, &inst_all, inst_list) {
+		LIST_FOREACH(p, &inst->inst_proc->allproc, p_list) {
+			switch (p->p_stat) {
+			case SSLEEP:
+				if (p->p_priority > PZERO || p->p_slptime > 1)
+					continue;
+			/* FALLTHROUGH */
+			case SRUN:
+			case SONPROC:
+				if (p == p->p_cpu->ci_schedstate.spc_idleproc)
+					continue;
+			case SIDL:
+				nrun++;
+			}
 		}
 	}
 	for (i = 0; i < 3; i++)
@@ -236,6 +239,7 @@
 	struct vmtotal *totalp;
 {
 	struct proc *p;
+	struct inst *inst;
 #if 0
 	struct vm_map_entry *	entry;
 	struct vm_map *map;
@@ -248,52 +252,54 @@
 	 * calculate process statistics
 	 */
 
-	LIST_FOREACH(p, &allproc, p_list) {
-		if (p->p_flag & P_SYSTEM)
-			continue;
-		switch (p->p_stat) {
-		case 0:
-			continue;
-
-		case SSLEEP:
-		case SSTOP:
-			if (p->p_priority <= PZERO)
-				totalp->t_dw++;
-			else if (p->p_slptime < maxslp)
-				totalp->t_sl++;
-			if (p->p_slptime >= maxslp)
+	LIST_FOREACH(inst, &inst_all, inst_list) {
+		LIST_FOREACH(p, &inst->inst_proc->allproc, p_list) {
+			if (p->p_flag & P_SYSTEM)
 				continue;
-			break;
-
-		case SRUN:
-		case SIDL:
-		case SONPROC:
-			totalp->t_rq++;
-			if (p->p_stat == SIDL)
+			switch (p->p_stat) {
+			case 0:
 				continue;
-			break;
+	
+			case SSLEEP:
+			case SSTOP:
+				if (p->p_priority <= PZERO)
+					totalp->t_dw++;
+				else if (p->p_slptime < maxslp)
+					totalp->t_sl++;
+				if (p->p_slptime >= maxslp)
+					continue;
+				break;
+	
+			case SRUN:
+			case SIDL:
+			case SONPROC:
+				totalp->t_rq++;
+				if (p->p_stat == SIDL)
+					continue;
+				break;
+			}
+			/*
+			 * note active objects
+			 */
+	#if 0
+			/*
+			 * XXXCDC: BOGUS!  rethink this.   in the mean time
+			 * don't do it.
+			 */
+			paging = 0;
+			vm_map_lock(map);
+			for (map = &p->p_vmspace->vm_map, entry = map->header.next;
+			    entry != &map->header; entry = entry->next) {
+				if (entry->is_a_map || entry->is_sub_map ||
+				    entry->object.uvm_obj == NULL)
+					continue;
+				/* XXX how to do this with uvm */
+			}
+			vm_map_unlock(map);
+			if (paging)
+				totalp->t_pw++;
+	#endif
 		}
-		/*
-		 * note active objects
-		 */
-#if 0
-		/*
-		 * XXXCDC: BOGUS!  rethink this.   in the mean time
-		 * don't do it.
-		 */
-		paging = 0;
-		vm_map_lock(map);
-		for (map = &p->p_vmspace->vm_map, entry = map->header.next;
-		    entry != &map->header; entry = entry->next) {
-			if (entry->is_a_map || entry->is_sub_map ||
-			    entry->object.uvm_obj == NULL)
-				continue;
-			/* XXX how to do this with uvm */
-		}
-		vm_map_unlock(map);
-		if (paging)
-			totalp->t_pw++;
-#endif
 	}
 	/*
 	 * Calculate object memory usage statistics.
