Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 May 98 07:02:01 EDT
From:      luoqi@watermarkgroup.com (Luoqi Chen)
To:        jb@cimlogic.com.au, luoqi@watermarkgroup.com
Cc:        current@FreeBSD.ORG
Subject:   Re: 'fatal trap 12' on boot (smp and up)
Message-ID:  <9805041102.AA13313@watermarkgroup.com>

next in thread | raw e-mail | index | archive | help
> I think I made a mistake in my patch that cause the core dump. Try to
> enclose the two lines in the patch that reset fs and gs inside
> if (pcb == curpcb) {}. Without this, the code might trash fs & gs in
> another process' context.
Probably pcb->pcb_fs and pcb->pcb_gs need to be reset too. Please use the
following patch (I've also sent it in a follow-up to the original PR i386/6219).
-lq

Index: machdep.c
===================================================================
RCS file: /fun/cvs/src/sys/i386/i386/machdep.c,v
retrieving revision 1.294
diff -u -r1.294 machdep.c
--- machdep.c	1998/04/06 15:46:17	1.294
+++ machdep.c	1998/05/04 10:40:30
@@ -768,14 +768,15 @@
 	u_long stack;
 {
 	struct trapframe *regs = p->p_md.md_regs;
-
-#ifdef USER_LDT
 	struct pcb *pcb = &p->p_addr->u_pcb;
 
+#ifdef USER_LDT
 	/* was i386_user_cleanup() in NetBSD */
 	if (pcb->pcb_ldt) {
-		if (pcb == curpcb)
-			lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
+		if (pcb == curpcb) {
+			lldt(_default_ldt);
+			currentldt = _default_ldt;
+		}
 		kmem_free(kernel_map, (vm_offset_t)pcb->pcb_ldt,
 			pcb->pcb_ldt_len * sizeof(union descriptor));
 		pcb->pcb_ldt_len = (int)pcb->pcb_ldt = 0;
@@ -790,6 +791,14 @@
 	regs->tf_ds = _udatasel;
 	regs->tf_es = _udatasel;
 	regs->tf_cs = _ucodesel;
+
+	/* reset %fs and %gs as well */
+	pcb->pcb_fs = _udatasel;
+	pcb->pcb_gs = _udatasel;
+	if (pcb == curpcb) {
+		__asm("mov %0,%%fs" : : "r" (_udatasel));
+		__asm("mov %0,%%gs" : : "r" (_udatasel));
+	}
 
 	/*
 	 * Initialize the math emulator (if any) for the current process.
Index: vm_machdep.c
===================================================================
RCS file: /fun/cvs/src/sys/i386/i386/vm_machdep.c,v
retrieving revision 1.105
diff -u -r1.105 vm_machdep.c
--- vm_machdep.c	1998/03/23 19:52:42	1.105
+++ vm_machdep.c	1998/04/14 01:30:21
@@ -703,8 +703,10 @@
 #endif
 #ifdef USER_LDT
 	if (pcb->pcb_ldt != 0) {
-		if (pcb == curpcb)
-			lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
+		if (pcb == curpcb) {
+			lldt(_default_ldt);
+			currentldt = _default_ldt;
+		}
 		kmem_free(kernel_map, (vm_offset_t)pcb->pcb_ldt,
 			pcb->pcb_ldt_len * sizeof(union descriptor));
 		pcb->pcb_ldt_len = (int)pcb->pcb_ldt = 0;

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9805041102.AA13313>