shithub: riscv

Download patch

ref: 580a8ae857229123e9b5112940fd40a000c994f4
parent: 4ae38efc1c28c968d2c5e26d305d917dd25b6594
author: cinap_lenrek <[email protected]>
date: Tue Dec 4 02:26:33 EST 2012

syscallfmt: fix syscall trace for kw/opamp4

--- a/sys/src/9/kw/syscall.c
+++ b/sys/src/9/kw/syscall.c
@@ -206,29 +206,20 @@
 	spllo();
 	sp = ureg->sp;
 
-	if(up->procctl == Proc_tracesyscall){
-		/*
-		 * Redundant validaddr.  Do we care?
-		 * Tracing syscalls is not exactly a fast path...
-		 * Beware, validaddr currently does a pexit rather
-		 * than an error if there's a problem; that might
-		 * change in the future.
-		 */
-		if(sp < (USTKTOP-BY2PG) || sp > (USTKTOP-sizeof(Sargs)-BY2WD))
-			validaddr(sp, sizeof(Sargs)+BY2WD, 0);
-
-		syscallfmt(scallnr, ureg->pc, (va_list)(sp+BY2WD));
-		up->procctl = Proc_stopme;
-		procctl(up);
-		if (up->syscalltrace) 
-			free(up->syscalltrace);
-		up->syscalltrace = nil;
-	}
-
 	up->nerrlab = 0;
 	ret = -1;
-	startns = todget(nil);
 	if(!waserror()){
+		if(sp < (USTKTOP-BY2PG) || sp > (USTKTOP-sizeof(Sargs)-BY2WD))
+			validaddr(sp, sizeof(Sargs)+BY2WD, 0);
+		up->s = *((Sargs*)(sp+BY2WD));
+		if(up->procctl == Proc_tracesyscall){
+			syscallfmt(scallnr, ureg->pc, (va_list)up->s.args);
+			s = splhi();
+			up->procctl = Proc_stopme;
+			procctl(up);
+			splx(s);
+			startns = todget(nil);
+		}
 		if(scallnr >= nsyscall){
 			pprint("bad sys call number %d pc %#lux\n",
 				scallnr, ureg->pc);
@@ -235,11 +226,6 @@
 			postnote(up, 1, "sys: bad sys call", NDebug);
 			error(Ebadarg);
 		}
-
-		if(sp < (USTKTOP-BY2PG) || sp > (USTKTOP-sizeof(Sargs)-BY2WD))
-			validaddr(sp, sizeof(Sargs)+BY2WD, 0);
-
-		up->s = *((Sargs*)(sp+BY2WD));
 		up->psstate = sysctab[scallnr];
 
 	/*	iprint("%s: syscall %s\n", up->text, sysctab[scallnr]?sysctab[scallnr]:"huh?"); */
@@ -270,14 +256,11 @@
 
 	if(up->procctl == Proc_tracesyscall){
 		stopns = todget(nil);
-		up->procctl = Proc_stopme;
-		sysretfmt(scallnr, (va_list)(sp+BY2WD), ret, startns, stopns);
+		sysretfmt(scallnr, (va_list)up->s.args, ret, startns, stopns);
 		s = splhi();
+		up->procctl = Proc_stopme;
 		procctl(up);
 		splx(s);
-		if(up->syscalltrace)
-			free(up->syscalltrace);
-		up->syscalltrace = nil;
 	}
 
 	up->insyscall = 0;
@@ -284,7 +267,7 @@
 	up->psstate = 0;
 
 	if(scallnr == NOTED)
-		noted(ureg, *(ulong*)(sp+BY2WD));
+		noted(ureg, up->s.args[0]);
 
 	splhi();
 	if(scallnr != RFORK && (up->procctl || up->nnote))
--- a/sys/src/9/omap4/trap.c
+++ b/sys/src/9/omap4/trap.c
@@ -317,6 +317,7 @@
 	int scall, ret;
 	ulong s, sp;
 	char *e;
+	vlong startns, stopns;
 
 	m->syscall++;
 	up->insyscall = 1;
@@ -323,10 +324,6 @@
 	up->pc = ureg->pc;
 	up->dbgreg = ureg;
 	cycles(&up->kentry);
-	if(up->procctl == Proc_tracesyscall){
-		up->procctl = Proc_stopme;
-		procctl(up);
-	}
 	scall = ureg->r0;
 	up->scallnr = scall;
 	spllo();
@@ -335,12 +332,20 @@
 	up->nerrlab = 0;
 	ret = -1;
 	if(!waserror()){
+		validaddr(sp, sizeof(Sargs) + BY2WD, 0);
+		up->s = *((Sargs*)(sp + BY2WD));
+		if(up->procctl == Proc_tracesyscall){
+			syscallfmt(scall, ureg->pc, (va_list)up->s.args);
+			s = splhi();
+			up->procctl = Proc_stopme;
+			procctl(up);
+			splx(s);
+			startns = todget(nil);
+		}
 		if(scall >= nsyscall){
 			postnote(up, 1, "sys: bad syscall", NDebug);
 			error(Ebadarg);
 		}
-		validaddr(sp, sizeof(Sargs) + BY2WD, 0);
-		up->s = *((Sargs*)(sp + BY2WD));
 		up->psstate = sysctab[scall];
 		ret = systab[scall](up->s.args);
 		poperror();
@@ -354,8 +359,10 @@
 	ureg->r0 = ret;
 
 	if(up->procctl == Proc_tracesyscall){
-		up->procctl = Proc_stopme;
+		stopns = todget(nil);
+		sysretfmt(scall, (va_list)up->s.args, ret, startns, stopns);
 		s = splhi();
+		up->procctl = Proc_stopme;
 		procctl(up);
 		splx(s);
 	}
@@ -364,7 +371,7 @@
 	up->psstate = nil;
 
 	if(scall == NOTED)
-		noted(ureg, *(ulong *)(sp + BY2WD));
+		noted(ureg, up->s.args[0]);
 	if(scall != RFORK && (up->procctl || up->nnote)){
 		splhi();
 		notify(ureg);