Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Mar 2007 20:37:14 GMT
From:      Oleksandr Tymoshenko <gonzo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 116360 for review
Message-ID:  <200703222037.l2MKbEWt016745@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=116360

Change 116360 by gonzo@gonzo_jeeves on 2007/03/22 20:36:35

	o Add support for restartable syscalls (ERESTART handling).
	o Send SIGSEGV to process if there was memory access fault
	    in userland.
	o Add userland -> kernel routine like in arm: update credentials,
	    call thread_user_enter. 

Affected files ...

.. //depot/projects/mips2/src/sys/mips/mips/trap.c#17 edit

Differences ...

==== //depot/projects/mips2/src/sys/mips/mips/trap.c#17 (text+ko) ====

@@ -118,6 +118,17 @@
 static volatile char *trap_addr;
 static volatile int trap_error;
 
+static void
+call_trapsignal(struct thread *td, int sig, u_long code)
+{
+	ksiginfo_t ksi;
+
+	ksiginfo_init_trap(&ksi);
+	ksi.ksi_signo = sig;
+	ksi.ksi_code = (int)code;
+	trapsignal(td, &ksi);
+}
+
 void
 trap(struct trapframe * tf, u_int cause, void *badvaddr)
 {
@@ -130,17 +141,26 @@
 
 	platform_trap_enter();
 
+	td = curthread;
+	va = trunc_page(badvaddr);
 	code = (cause & MIPS3_CR_EXC_CODE) >> MIPS_CR_EXC_CODE_SHIFT;
 	kernelmode = (tf->tf_regs[TF_SR] & MIPS_SR_KSU_USER) == 0;
 
 	if(! kernelmode)
+	{
+                td->td_pticks = 0;
+                td->td_frame = tf;
+                if (td->td_ucred != td->td_proc->p_ucred)
+                        cred_update_thread(td);
+                if (td->td_pflags & TDP_SA)
+                        thread_user_enter(td);
+
 		code |= TrUser;
+	}
 
 	/*
 	 * Handle that which we can.
 	 */
-	va = trunc_page(badvaddr);
-	td = curthread;
 
 	switch (code) {
 	case TrMod:
@@ -226,11 +246,12 @@
 		if (kernelmode)
 			break;
 
-		/* TODO: send signal */
 		printf("Userland memory access error %d on va=%p, pc=%08x\n",
 		    error, badvaddr, tf->tf_regs[TF_EPC]);
 
-		panic("TODO: signal on memory access errors");
+		call_trapsignal(curthread, SIGSEGV, 0);
+		goto done;	
+		break;
 
 	case TrSys + TrUser:
 		syscall(curthread, tf);
@@ -251,7 +272,9 @@
 			tf->tf_regs[TF_EPC] += 4;
 			goto done;
 		}
-		/* fall through */
+		call_trapsignal(curthread, SIGSEGV, 0);
+		goto done;	
+		break;
 	default:
 		/* Fatal! */
 		break;
@@ -355,12 +378,15 @@
 	int locked = 0;
 	int args_shift = 0;
 	int quad_syscall = 0;
+	register_t ov0, opc;
 
 	PCPU_LAZY_INC(cnt.v_syscall);
 	td->td_pticks = 0;
 	if (td->td_ucred != td->td_proc->p_ucred)
 		cred_update_thread(td);
 
+	opc = frame->tf_regs[TF_EPC];
+	ov0 = frame->tf_regs[TF_V0];
 	/* 
 	 * XXXMIPS(1): Check for branch delay?
 	 * XXXMIPS(2): Right now frame and td->td_frame point
@@ -472,8 +498,8 @@
 		/*
 		 * Reconstruct the pc to point at the swi.
 		 */
-		panic("TODO: implement ERESTART in syscall");
-		/* frame->tf_pc -= INSN_SIZE; */
+		frame->tf_regs[TF_EPC] = opc;
+		frame->tf_regs[TF_V0] = ov0;
 		break;
 
 	case EJUSTRETURN:                                       



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