[PATCH] pass tcp to upeek instead of just pid

Denys Vlasenko dvlasenk at redhat.com
Fri Dec 5 10:58:07 UTC 2008


Hi Dmitry, folks,

This patch does not change any logic.
It merely passes full tcp pointer to upeek instead
of passing pid. This is needed if one wants to check or change
other tcp fields.

I have patches which require this. I can imagine someone else
eventually needing the same for completely orthogonal reasons,
thus I think this needs to be done irrespective of my other patches.

Please apply.

Do you _require_ GNU formatted changelog? Here is it:

2008-11-05  Denys Vlasenko <dvlasenk at redhat.com>

	Pass tcp pointer to upeek instead of pid
	* defs.h: modify prototype of upeek
	* process.c: modify calls to upeek to take tcp
	* signal.c: modify calls to upeek to take tcp
	* strace.c: modify calls to upeek to take tcp
	* syscall.c: modify calls to upeek to take tcp
	* util.c: modify calls to upeek to take tcp


diff -d -urpN strace.0/defs.h strace.1/defs.h
--- strace.0/defs.h	2008-11-10 23:21:41.000000000 +0100
+++ strace.1/defs.h	2008-12-04 19:31:05.000000000 +0100
@@ -475,7 +475,7 @@ extern int printflags P((const struct xl
 extern const char *sprintflags P((const char *, const struct xlat *, int));
 extern int umoven P((struct tcb *, long, int, char *));
 extern int umovestr P((struct tcb *, long, int, char *));
-extern int upeek P((int, long, long *));
+extern int upeek P((struct tcb *, long, long *));
 extern void dumpiov P((struct tcb *, int, long));
 extern void dumpstr P((struct tcb *, long, int));
 extern void printstr P((struct tcb *, long, int));
diff -d -urpN strace.0/process.c strace.1/process.c
--- strace.0/process.c	2008-11-11 01:25:22.000000000 +0100
+++ strace.1/process.c	2008-12-04 19:16:29.000000000 +0100
@@ -812,7 +812,7 @@ setarg(tcp, argnum)
 	{
 		unsigned long *bsp, *ap;
 
-		if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
+		if (upeek(tcp, PT_AR_BSP, (long *) &bsp) , 0)
 			return -1;
 
 		ap = ia64_rse_skip_regs(bsp, argnum);
@@ -854,7 +854,7 @@ setarg(tcp, argnum)
 		else {
 			unsigned long *sp;
 
-			if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
+			if (upeek(tcp, REG_SP, (long *) &sp) , 0)
 				return -1;
 
 			ptrace(PTRACE_POKEDATA, tcp->pid,
diff -d -urpN strace.0/signal.c strace.1/signal.c
--- strace.0/signal.c	2008-11-10 23:53:03.000000000 +0100
+++ strace.1/signal.c	2008-12-04 19:16:22.000000000 +0100
@@ -921,7 +921,7 @@ int sig;
 #ifdef SUNOS4
 	void (*u_signal)();
 
-	if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
+	if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
 	    (long *) &u_signal) < 0) {
 		return 0;
 	}
@@ -1266,7 +1266,7 @@ struct tcb *tcp;
 
 	if (entering(tcp)) {
 		tcp->u_arg[0] = 0;
-		if (upeek(tcp->pid,PT_GPR15,&usp)<0)
+		if (upeek(tcp,PT_GPR15,&usp)<0)
 			return 0;
 		if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
 			return 0;
@@ -1287,7 +1287,7 @@ struct tcb *tcp;
 
 	if (entering(tcp)) {
 		tcp->u_arg[0] = 0;
-		if (upeek(tcp->pid, 4*UESP, &esp) < 0)
+		if (upeek(tcp, 4*UESP, &esp) < 0)
 			return 0;
 		if (umove(tcp, esp, &sc) < 0)
 			return 0;
@@ -1313,7 +1313,7 @@ struct tcb *tcp;
 		/* offset of sigcontext in the kernel's sigframe structure: */
 #		define SIGFRAME_SC_OFFSET	0x90
 		tcp->u_arg[0] = 0;
-		if (upeek(tcp->pid, PT_R12, &sp) < 0)
+		if (upeek(tcp, PT_R12, &sp) < 0)
 			return 0;
 		if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
 			return 0;
@@ -1338,7 +1338,7 @@ struct tcb *tcp;
 
 	if (entering(tcp)) {
 		tcp->u_arg[0] = 0;
-		if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
+		if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
 			return 0;
 		if (umove(tcp, esp, &sc) < 0)
 			return 0;
@@ -1362,7 +1362,7 @@ struct tcb *tcp;
 
 	if (entering(tcp)) {
 		tcp->u_arg[0] = 0;
-		if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
+		if (upeek(tcp, 4*PT_USP, &usp) < 0)
 			return 0;
 		if (umove(tcp, usp, &sc) < 0)
 			return 0;
@@ -1386,7 +1386,7 @@ struct tcb *tcp;
 
 	if (entering(tcp)) {
 		tcp->u_arg[0] = 0;
-		if (upeek(tcp->pid, REG_FP, &fp) < 0)
+		if (upeek(tcp, REG_FP, &fp) < 0)
 			return 0;
 		if (umove(tcp, fp, &sc) < 0)
 			return 0;
@@ -1441,7 +1441,7 @@ struct tcb *tcp;
 
 	if(entering(tcp)) {
 	  	tcp->u_arg[0] = 0;
-		if (upeek(tcp->pid, REG_SP, &sp) < 0)
+		if (upeek(tcp, REG_SP, &sp) < 0)
 		  	return 0;
 		/* There are six words followed by a 128-byte siginfo.  */
 		sp = sp + 6 * 4 + 128;
diff -d -urpN strace.0/strace.c strace.1/strace.c
--- strace.0/strace.c	2008-11-10 18:14:58.000000000 +0100
+++ strace.1/strace.c	2008-12-04 19:13:06.000000000 +0100
@@ -2446,8 +2446,8 @@ Process %d attached (waiting for parent)
 				struct siginfo si;
 				long psr;
 
-				upeek(pid, PT_CR_IPSR, &psr);
-				upeek(pid, PT_CR_IIP, &pc);
+				upeek(tcp, PT_CR_IPSR, &psr);
+				upeek(tcp, PT_CR_IIP, &pc);
 
 				pc += (psr >> PSR_RI) & 0x3;
 				ptrace(PT_GETSIGINFO, pid, 0, (long) &si);
diff -d -urpN strace.0/syscall.c strace.1/syscall.c
--- strace.0/syscall.c	2008-11-10 23:21:41.000000000 +0100
+++ strace.1/syscall.c	2008-12-04 19:30:18.000000000 +0100
@@ -811,7 +811,7 @@ struct tcb *tcp;
 		return 0;
 	}
 
-	if (upeek(pid, PT_GPR2, &syscall_mode) < 0)
+	if (upeek(tcp, PT_GPR2, &syscall_mode) < 0)
 			return -1;
 
 	if (syscall_mode != -ENOSYS) {
@@ -831,7 +831,7 @@ struct tcb *tcp;
 				      PT_GPR8,  PT_GPR9,  PT_GPR10,    PT_GPR11,
 				      PT_GPR12, PT_GPR13, PT_GPR14,    PT_GPR15};
 
-		if (upeek(pid, PT_PSWADDR, &pc) < 0)
+		if (upeek(tcp, PT_PSWADDR, &pc) < 0)
 			return -1;
 		errno = 0;
 		opcode = ptrace(PTRACE_PEEKTEXT, pid, (char *)(pc-sizeof(long)), 0);
@@ -865,13 +865,13 @@ struct tcb *tcp;
 
 			tmp = 0;
 			offset_reg = (opcode & 0x000f0000) >> 16;
-			if (offset_reg && (upeek(pid, gpr_offset[offset_reg], &tmp) < 0))
+			if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
 				return -1;
 			svc_addr += tmp;
 
 			tmp = 0;
 			offset_reg = (opcode & 0x0000f000) >> 12;
-			if (offset_reg && (upeek(pid, gpr_offset[offset_reg], &tmp) < 0))
+			if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
 				return -1;
 			svc_addr += tmp;
 
@@ -885,14 +885,14 @@ struct tcb *tcp;
 #endif
 			tmp = 0;
 			offset_reg = (opcode & 0x00f00000) >> 20;
-			if (offset_reg && (upeek(pid, gpr_offset[offset_reg], &tmp) < 0))
+			if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
 				return -1;
 
 			scno = (scno | tmp) & 0xff;
 		}
 	}
 #elif defined (POWERPC)
-	if (upeek(pid, sizeof(unsigned long)*PT_R0, &scno) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_R0, &scno) < 0)
 		return -1;
 	if (!(tcp->flags & TCB_INSYSCALL)) {
 		/* Check if we return from execve. */
@@ -902,16 +902,16 @@ struct tcb *tcp;
 		}
 	}
 #elif defined(BFIN)
-	if (upeek(pid, PT_ORIG_P0, &scno))
+	if (upeek(tcp, PT_ORIG_P0, &scno))
 		return -1;
 	/* Check if we return from execve. */
 	if (tcp->flags & TCB_WAITEXECVE && tcp->flags & TCB_INSYSCALL)
 		tcp->flags &= ~(TCB_INSYSCALL | TCB_WAITEXECVE);
 #elif defined (I386)
-	if (upeek(pid, 4*ORIG_EAX, &scno) < 0)
+	if (upeek(tcp, 4*ORIG_EAX, &scno) < 0)
 		return -1;
 #elif defined (X86_64)
-	if (upeek(pid, 8*ORIG_RAX, &scno) < 0)
+	if (upeek(tcp, 8*ORIG_RAX, &scno) < 0)
 		return -1;
 
 	if (!(tcp->flags & TCB_INSYSCALL)) {
@@ -924,7 +924,7 @@ struct tcb *tcp;
 		 * It takes only one ptrace and thus doesn't need
 		 * to be cached.
 		 */
-		if (upeek(pid, 8*CS, &val) < 0)
+		if (upeek(tcp, 8*CS, &val) < 0)
 			return -1;
 		switch(val)
 		{
@@ -944,7 +944,7 @@ struct tcb *tcp;
 		 */
 		unsigned long val, rip, i;
 
-		if(upeek(pid, 8*RIP, &rip)<0)
+		if(upeek(tcp, 8*RIP, &rip)<0)
 			perror("upeek(RIP)");
 
 		/* sizeof(syscall) == sizeof(int 0x80) == 2 */
@@ -980,14 +980,14 @@ struct tcb *tcp;
 	}
 #elif defined(IA64)
 #	define IA64_PSR_IS	((long)1 << 34)
-	if (upeek (pid, PT_CR_IPSR, &psr) >= 0)
+	if (upeek (tcp, PT_CR_IPSR, &psr) >= 0)
 		ia32 = (psr & IA64_PSR_IS) != 0;
 	if (!(tcp->flags & TCB_INSYSCALL)) {
 		if (ia32) {
-			if (upeek(pid, PT_R1, &scno) < 0)	/* orig eax */
+			if (upeek(tcp, PT_R1, &scno) < 0)	/* orig eax */
 				return -1;
 		} else {
-			if (upeek (pid, PT_R15, &scno) < 0)
+			if (upeek (tcp, PT_R15, &scno) < 0)
 				return -1;
 		}
 		/* Check if we return from execve. */
@@ -997,9 +997,9 @@ struct tcb *tcp;
 		}
 	} else {
 		/* syscall in progress */
-		if (upeek (pid, PT_R8, &r8) < 0)
+		if (upeek (tcp, PT_R8, &r8) < 0)
 			return -1;
-		if (upeek (pid, PT_R10, &r10) < 0)
+		if (upeek (tcp, PT_R10, &r10) < 0)
 			return -1;
 	}
 #elif defined (ARM)
@@ -1083,7 +1083,7 @@ struct tcb *tcp;
 		}
 	}
 #elif defined (M68K)
-	if (upeek(pid, 4*PT_ORIG_D0, &scno) < 0)
+	if (upeek(tcp, 4*PT_ORIG_D0, &scno) < 0)
 		return -1;
 #elif defined (LINUX_MIPSN32)
 	unsigned long long regs[38];
@@ -1111,10 +1111,10 @@ struct tcb *tcp;
 		}
 	}
 #elif defined (MIPS)
-	if (upeek(pid, REG_A3, &a3) < 0)
+	if (upeek(tcp, REG_A3, &a3) < 0)
 	  	return -1;
 	if(!(tcp->flags & TCB_INSYSCALL)) {
-	  	if (upeek(pid, REG_V0, &scno) < 0)
+	  	if (upeek(tcp, REG_V0, &scno) < 0)
 		  	return -1;
 
 		/* Check if we return from execve. */
@@ -1131,15 +1131,15 @@ struct tcb *tcp;
 			}
 		}
 	} else {
-	  	if (upeek(pid, REG_V0, &r2) < 0)
+	  	if (upeek(tcp, REG_V0, &r2) < 0)
 	    		return -1;
 	}
 #elif defined (ALPHA)
-	if (upeek(pid, REG_A3, &a3) < 0)
+	if (upeek(tcp, REG_A3, &a3) < 0)
 		return -1;
 
 	if (!(tcp->flags & TCB_INSYSCALL)) {
-		if (upeek(pid, REG_R0, &scno) < 0)
+		if (upeek(tcp, REG_R0, &scno) < 0)
 			return -1;
 
 		/* Check if we return from execve. */
@@ -1161,7 +1161,7 @@ struct tcb *tcp;
 		}
 	}
 	else {
-		if (upeek(pid, REG_R0, &r0) < 0)
+		if (upeek(tcp, REG_R0, &r0) < 0)
 			return -1;
 	}
 #elif defined (SPARC) || defined (SPARC64)
@@ -1231,7 +1231,7 @@ struct tcb *tcp;
 		}
 	}
 #elif defined(HPPA)
-	if (upeek(pid, PT_GR20, &scno) < 0)
+	if (upeek(tcp, PT_GR20, &scno) < 0)
 		return -1;
 	if (!(tcp->flags & TCB_INSYSCALL)) {
 		/* Check if we return from execve. */
@@ -1244,7 +1244,7 @@ struct tcb *tcp;
        /*
         * In the new syscall ABI, the system call number is in R3.
         */
-       if (upeek(pid, 4*(REG_REG0+3), &scno) < 0)
+       if (upeek(tcp, 4*(REG_REG0+3), &scno) < 0)
                return -1;
 
        if (scno < 0) {
@@ -1270,7 +1270,7 @@ struct tcb *tcp;
                }
        }
 #elif defined(SH64)
-	if (upeek(pid, REG_SYSCALL, &scno) < 0)
+	if (upeek(tcp, REG_SYSCALL, &scno) < 0)
 		return -1;
         scno &= 0xFFFF;
 
@@ -1284,15 +1284,15 @@ struct tcb *tcp;
 #endif /* SH64 */
 #endif /* LINUX */
 #ifdef SUNOS4
-	if (upeek(pid, uoff(u_arg[7]), &scno) < 0)
+	if (upeek(tcp, uoff(u_arg[7]), &scno) < 0)
 		return -1;
 #elif defined(SH)
         /* new syscall ABI returns result in R0 */
-        if (upeek(pid, 4*REG_REG0, (long *)&r0) < 0)
+        if (upeek(tcp, 4*REG_REG0, (long *)&r0) < 0)
                 return -1;
 #elif defined(SH64)
         /* ABI defines result returned in r9 */
-        if (upeek(pid, REG_GENERAL(9), (long *)&r9) < 0)
+        if (upeek(tcp, REG_GENERAL(9), (long *)&r9) < 0)
                 return -1;
 
 #endif
@@ -1341,9 +1341,7 @@ static int
 syscall_fixup(tcp)
 struct tcb *tcp;
 {
-#ifndef USE_PROCFS
-	int pid = tcp->pid;
-#else /* USE_PROCFS */
+#ifdef USE_PROCFS
 	int scno = known_scno(tcp);
 
 	if (!(tcp->flags & TCB_INSYSCALL)) {
@@ -1407,7 +1405,7 @@ struct tcb *tcp;
 #endif /* SUNOS4 */
 #ifdef LINUX
 #if defined (I386)
-	if (upeek(pid, 4*EAX, &eax) < 0)
+	if (upeek(tcp, 4*EAX, &eax) < 0)
 		return -1;
 	if (eax != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
 		if (debug)
@@ -1415,7 +1413,7 @@ struct tcb *tcp;
 		return 0;
 	}
 #elif defined (X86_64)
-	if (upeek(pid, 8*RAX, &rax) < 0)
+	if (upeek(tcp, 8*RAX, &rax) < 0)
 		return -1;
 	if (current_personality == 1)
 		rax = (long int)(int)rax; /* sign extend from 32 bits */
@@ -1425,7 +1423,7 @@ struct tcb *tcp;
 		return 0;
 	}
 #elif defined (S390) || defined (S390X)
-	if (upeek(pid, PT_GPR2, &gpr2) < 0)
+	if (upeek(tcp, PT_GPR2, &gpr2) < 0)
 		return -1;
 	if (syscall_mode != -ENOSYS)
 		syscall_mode = tcp->scno;
@@ -1445,14 +1443,14 @@ struct tcb *tcp;
 	}
 #elif defined (POWERPC)
 # define SO_MASK 0x10000000
-	if (upeek(pid, sizeof(unsigned long)*PT_CCR, &flags) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0)
 		return -1;
-	if (upeek(pid, sizeof(unsigned long)*PT_R3, &result) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_R3, &result) < 0)
 		return -1;
 	if (flags & SO_MASK)
 		result = -result;
 #elif defined (M68K)
-	if (upeek(pid, 4*PT_D0, &d0) < 0)
+	if (upeek(tcp, 4*PT_D0, &d0) < 0)
 		return -1;
 	if (d0 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
 		if (debug)
@@ -1464,15 +1462,15 @@ struct tcb *tcp;
 	 * Nothing required
 	 */
 #elif defined(BFIN)
-	if (upeek(pid, PT_R0, &r0) < 0)
+	if (upeek(tcp, PT_R0, &r0) < 0)
 		return -1;
 #elif defined (HPPA)
-	if (upeek(pid, PT_GR28, &r28) < 0)
+	if (upeek(tcp, PT_GR28, &r28) < 0)
 		return -1;
 #elif defined(IA64)
-	if (upeek(pid, PT_R10, &r10) < 0)
+	if (upeek(tcp, PT_R10, &r10) < 0)
 		return -1;
-	if (upeek(pid, PT_R8, &r8) < 0)
+	if (upeek(tcp, PT_R8, &r8) < 0)
 		return -1;
 	if (ia32 && r8 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
 		if (debug)
@@ -1687,12 +1685,12 @@ struct tcb *tcp;
 #endif /* LINUX */
 #ifdef SUNOS4
 		/* get error code from user struct */
-		if (upeek(pid, uoff(u_error), &u_error) < 0)
+		if (upeek(tcp, uoff(u_error), &u_error) < 0)
 			return -1;
 		u_error >>= 24; /* u_error is a char */
 
 		/* get system call return value */
-		if (upeek(pid, uoff(u_rval1), &tcp->u_rval) < 0)
+		if (upeek(tcp, uoff(u_rval1), &tcp->u_rval) < 0)
 			return -1;
 #endif /* SUNOS4 */
 #ifdef SVR4
@@ -1822,7 +1820,7 @@ force_result(tcp, error, rval)
 	    	return -1;
 #else
 #ifdef POWERPC
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_CCR, &flags) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0)
 		return -1;
 	if (error) {
 		flags |= SO_MASK;
@@ -1956,9 +1954,6 @@ static int
 syscall_enter(tcp)
 struct tcb *tcp;
 {
-#ifndef USE_PROCFS
-	int pid = tcp->pid;
-#endif /* !USE_PROCFS */
 #ifdef LINUX
 #if defined(S390) || defined(S390X)
 	{
@@ -1968,7 +1963,7 @@ struct tcb *tcp;
 		else
      	        	tcp->u_nargs = MAX_ARGS;
 		for (i = 0; i < tcp->u_nargs; i++) {
-			if (upeek(pid,i==0 ? PT_ORIGGPR2:PT_GPR2+i*sizeof(long), &tcp->u_arg[i]) < 0)
+			if (upeek(tcp,i==0 ? PT_ORIGGPR2:PT_GPR2+i*sizeof(long), &tcp->u_arg[i]) < 0)
 				return -1;
 		}
 	}
@@ -1983,7 +1978,7 @@ struct tcb *tcp;
 			/* WTA: if scno is out-of-bounds this will bomb. Add range-check
 			 * for scno somewhere above here!
 			 */
-			if (upeek(pid, REG_A0+i, &tcp->u_arg[i]) < 0)
+			if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0)
 				return -1;
 		}
 	}
@@ -1997,9 +1992,9 @@ struct tcb *tcp;
 #			  define PT_RBS_END	PT_AR_BSP
 #			endif
 
-			if (upeek(pid, PT_RBS_END, &rbs_end) < 0)
+			if (upeek(tcp, PT_RBS_END, &rbs_end) < 0)
 				return -1;
-			if (upeek(pid, PT_CFM, (long *) &cfm) < 0)
+			if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
 				return -1;
 
 			sof = (cfm >> 0) & 0x7f;
@@ -2020,17 +2015,17 @@ struct tcb *tcp;
 			int i;
 
 			if (/* EBX = out0 */
-			    upeek(pid, PT_R11, (long *) &tcp->u_arg[0]) < 0
+			    upeek(tcp, PT_R11, (long *) &tcp->u_arg[0]) < 0
 			    /* ECX = out1 */
-			    || upeek(pid, PT_R9,  (long *) &tcp->u_arg[1]) < 0
+			    || upeek(tcp, PT_R9,  (long *) &tcp->u_arg[1]) < 0
 			    /* EDX = out2 */
-			    || upeek(pid, PT_R10, (long *) &tcp->u_arg[2]) < 0
+			    || upeek(tcp, PT_R10, (long *) &tcp->u_arg[2]) < 0
 			    /* ESI = out3 */
-			    || upeek(pid, PT_R14, (long *) &tcp->u_arg[3]) < 0
+			    || upeek(tcp, PT_R14, (long *) &tcp->u_arg[3]) < 0
 			    /* EDI = out4 */
-			    || upeek(pid, PT_R15, (long *) &tcp->u_arg[4]) < 0
+			    || upeek(tcp, PT_R15, (long *) &tcp->u_arg[4]) < 0
 			    /* EBP = out5 */
-			    || upeek(pid, PT_R13, (long *) &tcp->u_arg[5]) < 0)
+			    || upeek(tcp, PT_R13, (long *) &tcp->u_arg[5]) < 0)
 				return -1;
 
 			for (i = 0; i < 6; ++i)
@@ -2075,17 +2070,17 @@ struct tcb *tcp;
 		else
      	        	nargs = tcp->u_nargs = MAX_ARGS;
 		if(nargs > 4) {
-		  	if(upeek(pid, REG_SP, &sp) < 0)
+		  	if(upeek(tcp, REG_SP, &sp) < 0)
 			  	return -1;
 			for(i = 0; i < 4; i++) {
-			  	if (upeek(pid, REG_A0 + i, &tcp->u_arg[i])<0)
+			  	if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i])<0)
 				  	return -1;
 			}
 			umoven(tcp, sp+16, (nargs-4) * sizeof(tcp->u_arg[0]),
 			       (char *)(tcp->u_arg + 4));
 		} else {
 		  	for(i = 0; i < nargs; i++) {
-			  	if (upeek(pid, REG_A0 + i, &tcp->u_arg[i]) < 0)
+			  	if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
 				  	return -1;
 			}
 		}
@@ -2101,7 +2096,7 @@ struct tcb *tcp;
 		else
      	        	tcp->u_nargs = MAX_ARGS;
 		for (i = 0; i < tcp->u_nargs; i++) {
-			if (upeek(pid, (i==0) ?
+			if (upeek(tcp, (i==0) ?
 				(sizeof(unsigned long)*PT_ORIG_R3) :
 				((i+PT_R3)*sizeof(unsigned long)),
 					&tcp->u_arg[i]) < 0)
@@ -2128,7 +2123,7 @@ struct tcb *tcp;
 		else
      	        	tcp->u_nargs = MAX_ARGS;
 		for (i = 0; i < tcp->u_nargs; i++) {
-			if (upeek(pid, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
+			if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
 				return -1;
 		}
 	}
@@ -2154,7 +2149,7 @@ struct tcb *tcp;
 			tcp->u_nargs = sizeof(argreg) / sizeof(argreg[0]);
 
 		for (i = 0; i < tcp->u_nargs; ++i)
-			if (upeek(pid, argreg[i], &tcp->u_arg[i]) < 0)
+			if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
 				return -1;
 	}
 #elif defined(SH)
@@ -2167,7 +2162,7 @@ struct tcb *tcp;
 
                tcp->u_nargs = sysent[tcp->scno].nargs;
                for (i = 0; i < tcp->u_nargs; i++) {
-                       if (upeek(pid, 4*syscall_regs[i], &tcp->u_arg[i]) < 0)
+                       if (upeek(tcp, 4*syscall_regs[i], &tcp->u_arg[i]) < 0)
                                return -1;
                }
         }
@@ -2188,7 +2183,7 @@ struct tcb *tcp;
 
 		tcp->u_nargs = sysent[tcp->scno].nargs;
 		for (i = 0; i < tcp->u_nargs; i++) {
-			if (upeek(pid, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
+			if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
 				return -1;
 		}
 	}
@@ -2206,7 +2201,7 @@ struct tcb *tcp;
 		else
      	        	tcp->u_nargs = MAX_ARGS;
 		for (i = 0; i < tcp->u_nargs; i++) {
-			if (upeek(pid, argreg[current_personality][i]*8, &tcp->u_arg[i]) < 0)
+			if (upeek(tcp, argreg[current_personality][i]*8, &tcp->u_arg[i]) < 0)
 				return -1;
 		}
 	}
@@ -2218,7 +2213,7 @@ struct tcb *tcp;
 		else
      	        	tcp->u_nargs = MAX_ARGS;
 		for (i = 0; i < tcp->u_nargs; i++) {
-			if (upeek(pid, i*4, &tcp->u_arg[i]) < 0)
+			if (upeek(tcp, i*4, &tcp->u_arg[i]) < 0)
 				return -1;
 		}
 	}
@@ -2234,7 +2229,7 @@ struct tcb *tcp;
 		for (i = 0; i < tcp->u_nargs; i++) {
 			struct user *u;
 
-			if (upeek(pid, uoff(u_arg[0]) +
+			if (upeek(tcp, uoff(u_arg[0]) +
 			    (i*sizeof(u->u_arg[0])), &tcp->u_arg[i]) < 0)
 				return -1;
 		}
@@ -2625,16 +2620,16 @@ struct tcb *tcp;
 		return -1;
 	val = regs.r_o1;
 #elif defined(SH)
-	if (upeek(tcp->pid, 4*(REG_REG0+1), &val) < 0)
+	if (upeek(tcp, 4*(REG_REG0+1), &val) < 0)
 		return -1;
 #elif defined(IA64)
-	if (upeek(tcp->pid, PT_R9, &val) < 0)
+	if (upeek(tcp, PT_R9, &val) < 0)
 		return -1;
 #endif /* SPARC || SPARC64 */
 #endif /* LINUX */
 
 #ifdef SUNOS4
-	if (upeek(tcp->pid, uoff(u_rval2), &val) < 0)
+	if (upeek(tcp, uoff(u_rval2), &val) < 0)
 		return -1;
 #endif /* SUNOS4 */
 
diff -d -urpN strace.0/util.c strace.1/util.c
--- strace.0/util.c	2008-11-11 00:19:13.000000000 +0100
+++ strace.1/util.c	2008-12-04 19:30:18.000000000 +0100
@@ -1046,8 +1046,8 @@ char *laddr;
 #ifndef USE_PROCFS
 
 int
-upeek(pid, off, res)
-int pid;
+upeek(tcp, off, res)
+struct tcb *tcp;
 long off;
 long *res;
 {
@@ -1078,10 +1078,10 @@ long *res;
 	}
 #endif /* SUNOS4_KERNEL_ARCH_KLUDGE */
 	errno = 0;
-	val = ptrace(PTRACE_PEEKUSER, pid, (char *) off, 0);
+	val = ptrace(PTRACE_PEEKUSER, tcp->pid, (char *) off, 0);
 	if (val == -1 && errno) {
 		char buf[60];
-		sprintf(buf,"upeek: ptrace(PTRACE_PEEKUSER,%d,%lu,0)",pid,off);
+		sprintf(buf,"upeek: ptrace(PTRACE_PEEKUSER,%d,%lu,0)", tcp->pid, off);
 		perror(buf);
 		return -1;
 	}
@@ -1100,31 +1100,31 @@ struct tcb *tcp;
 #ifdef LINUX
 	long pc;
 #if defined(I386)
-	if (upeek(tcp->pid, 4*EIP, &pc) < 0)
+	if (upeek(tcp, 4*EIP, &pc) < 0)
 		return -1;
 #elif defined(X86_64)
-	if (upeek(tcp->pid, 8*RIP, &pc) < 0)
+	if (upeek(tcp, 8*RIP, &pc) < 0)
 		return -1;
 #elif defined(IA64)
-	if (upeek(tcp->pid, PT_B0, &pc) < 0)
+	if (upeek(tcp, PT_B0, &pc) < 0)
 		return -1;
 #elif defined(ARM)
-	if (upeek(tcp->pid, 4*15, &pc) < 0)
+	if (upeek(tcp, 4*15, &pc) < 0)
 		return -1;
 #elif defined(BFIN)
-	if (upeek(tcp->pid, REG_PC, &pc) < 0)
+	if (upeek(tcp, REG_PC, &pc) < 0)
 		return -1;
 #elif defined(POWERPC)
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0)
 		return -1;
 #elif defined(M68K)
-	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0)
+	if (upeek(tcp, 4*PT_PC, &pc) < 0)
 		return -1;
 #elif defined(ALPHA)
-	if (upeek(tcp->pid, REG_PC, &pc) < 0)
+	if (upeek(tcp, REG_PC, &pc) < 0)
 		return -1;
 #elif defined(MIPS)
- 	if (upeek(tcp->pid, REG_EPC, &pc) < 0)
+ 	if (upeek(tcp, REG_EPC, &pc) < 0)
  		return -1;
 #elif defined(SPARC) || defined(SPARC64)
 	struct regs regs;
@@ -1132,16 +1132,16 @@ struct tcb *tcp;
 		return -1;
 	pc = regs.r_pc;
 #elif defined(S390) || defined(S390X)
-	if(upeek(tcp->pid,PT_PSWADDR,&pc) < 0)
+	if(upeek(tcp,PT_PSWADDR,&pc) < 0)
 		return -1;
 #elif defined(HPPA)
-	if(upeek(tcp->pid,PT_IAOQ0,&pc) < 0)
+	if(upeek(tcp,PT_IAOQ0,&pc) < 0)
 		return -1;
 #elif defined(SH)
-       if (upeek(tcp->pid, 4*REG_PC ,&pc) < 0)
+       if (upeek(tcp, 4*REG_PC ,&pc) < 0)
                return -1;
 #elif defined(SH64)
-       if (upeek(tcp->pid, REG_PC ,&pc) < 0)
+       if (upeek(tcp, REG_PC ,&pc) < 0)
                return -1;
 #endif
 	return pc;
@@ -1186,7 +1186,7 @@ struct tcb *tcp;
 #ifdef I386
 	long eip;
 
-	if (upeek(tcp->pid, 4*EIP, &eip) < 0) {
+	if (upeek(tcp, 4*EIP, &eip) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1194,7 +1194,7 @@ struct tcb *tcp;
 
 #elif defined(S390) || defined(S390X)
          long psw;
-         if(upeek(tcp->pid,PT_PSWADDR,&psw) < 0) {
+         if(upeek(tcp,PT_PSWADDR,&psw) < 0) {
                  PRINTBADPC;
                  return;
          }
@@ -1207,7 +1207,7 @@ struct tcb *tcp;
 #elif defined(X86_64)
 	long rip;
 
-	if (upeek(tcp->pid, 8*RIP, &rip) < 0) {
+	if (upeek(tcp, 8*RIP, &rip) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1215,7 +1215,7 @@ struct tcb *tcp;
 #elif defined(IA64)
 	long ip;
 
-	if (upeek(tcp->pid, PT_B0, &ip) < 0) {
+	if (upeek(tcp, PT_B0, &ip) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1223,7 +1223,7 @@ struct tcb *tcp;
 #elif defined(POWERPC)
 	long pc;
 
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
+	if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
 		tprintf ("[????????] ");
 		return;
 	}
@@ -1231,7 +1231,7 @@ struct tcb *tcp;
 #elif defined(M68K)
 	long pc;
 
-	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) {
+	if (upeek(tcp, 4*PT_PC, &pc) < 0) {
 		tprintf ("[????????] ");
 		return;
 	}
@@ -1239,7 +1239,7 @@ struct tcb *tcp;
 #elif defined(ALPHA)
 	long pc;
 
-	if (upeek(tcp->pid, REG_PC, &pc) < 0) {
+	if (upeek(tcp, REG_PC, &pc) < 0) {
 		tprintf ("[????????????????] ");
 		return;
 	}
@@ -1254,7 +1254,7 @@ struct tcb *tcp;
 #elif defined(HPPA)
 	long pc;
 
-	if(upeek(tcp->pid,PT_IAOQ0,&pc) < 0) {
+	if(upeek(tcp,PT_IAOQ0,&pc) < 0) {
 		tprintf ("[????????] ");
 		return;
 	}
@@ -1262,7 +1262,7 @@ struct tcb *tcp;
 #elif defined(MIPS)
 	long pc;
 
-	if (upeek(tcp->pid, REG_EPC, &pc) < 0) {
+	if (upeek(tcp, REG_EPC, &pc) < 0) {
 		tprintf ("[????????] ");
 		return;
 	}
@@ -1270,7 +1270,7 @@ struct tcb *tcp;
 #elif defined(SH)
        long pc;
 
-       if (upeek(tcp->pid, 4*REG_PC, &pc) < 0) {
+       if (upeek(tcp, 4*REG_PC, &pc) < 0) {
                tprintf ("[????????] ");
                return;
        }
@@ -1278,7 +1278,7 @@ struct tcb *tcp;
 #elif defined(SH64)
 	long pc;
 
-	if (upeek(tcp->pid, REG_PC, &pc) < 0) {
+	if (upeek(tcp, REG_PC, &pc) < 0) {
 		tprintf ("[????????????????] ");
 		return;
 	}
@@ -1286,7 +1286,7 @@ struct tcb *tcp;
 #elif defined(ARM)
 	long pc;
 
-	if (upeek(tcp->pid, 4*15, &pc) < 0) {
+	if (upeek(tcp, 4*15, &pc) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1294,7 +1294,7 @@ struct tcb *tcp;
 #elif defined(BFIN)
 	long pc;
 
-	if (upeek(tcp->pid, PT_PC, &pc) < 0) {
+	if (upeek(tcp, PT_PC, &pc) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1366,9 +1366,9 @@ arg_setup(struct tcb *tcp, arg_setup_sta
 		return 0;
 	}
 
-	if (upeek(tcp->pid, PT_AR_BSP, &bsp) < 0)
+	if (upeek(tcp, PT_AR_BSP, &bsp) < 0)
 		return -1;
-	if (upeek(tcp->pid, PT_CFM, (long *) &cfm) < 0)
+	if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
 		return -1;
 
 	sof = (cfm >> 0) & 0x7f;
@@ -1388,7 +1388,7 @@ get_arg0 (struct tcb *tcp, arg_setup_sta
 	int ret;
 
 	if (ia32)
-		ret = upeek (tcp->pid, PT_R11, valp);
+		ret = upeek (tcp, PT_R11, valp);
 	else
 		ret = umoven (tcp,
 			      (unsigned long) ia64_rse_skip_regs(*state, 0),
@@ -1402,7 +1402,7 @@ get_arg1 (struct tcb *tcp, arg_setup_sta
 	int ret;
 
 	if (ia32)
-		ret = upeek (tcp->pid, PT_R9, valp);
+		ret = upeek (tcp, PT_R9, valp);
 	else
 		ret = umoven (tcp,
 			      (unsigned long) ia64_rse_skip_regs(*state, 1),
@@ -1511,9 +1511,9 @@ typedef int arg_setup_state;
 # define arg_setup(tcp, state) (0)
 # define arg_finish_change(tcp, state)	0
 # define get_arg0(tcp, cookie, valp) \
-  (upeek ((tcp)->pid, arg0_offset, (valp)))
+  (upeek ((tcp), arg0_offset, (valp)))
 # define get_arg1(tcp, cookie, valp) \
-  (upeek ((tcp)->pid, arg1_offset, (valp)))
+  (upeek ((tcp), arg1_offset, (valp)))
 
 static int
 set_arg0 (struct tcb *tcp, void *cookie, long val)
@@ -1700,7 +1700,7 @@ struct tcb *tcp;
 				tcp->pid);
 			return -1;
 		}
-		if (upeek(tcp->pid, PT_CR_IIP, &tcp->baddr) < 0)
+		if (upeek(tcp, PT_CR_IIP, &tcp->baddr) < 0)
 			return -1;
 		if (debug)
 			fprintf(stderr, "[%d] setting bpt at %lx\n",
@@ -1734,9 +1734,9 @@ struct tcb *tcp;
 		pid_t pid;
 
 		pid = tcp->pid;
-		if (upeek(pid, PT_CR_IPSR, &ipsr) < 0)
+		if (upeek(tcp, PT_CR_IPSR, &ipsr) < 0)
 			return -1;
-		if (upeek(pid, PT_CR_IIP, &addr) < 0)
+		if (upeek(tcp, PT_CR_IIP, &addr) < 0)
 			return -1;
 		/* store "ri" in low two bits */
 		tcp->baddr = addr | ((ipsr >> 41) & 0x3);
@@ -1795,13 +1795,13 @@ struct tcb *tcp;
 		return -1;
 	}
 #if defined (I386)
-	if (upeek(tcp->pid, 4*EIP, &tcp->baddr) < 0)
+	if (upeek(tcp, 4*EIP, &tcp->baddr) < 0)
 		return -1;
 #elif defined (X86_64)
-	if (upeek(tcp->pid, 8*RIP, &tcp->baddr) < 0)
+	if (upeek(tcp, 8*RIP, &tcp->baddr) < 0)
 		return -1;
 #elif defined (M68K)
-	if (upeek(tcp->pid, 4*PT_PC, &tcp->baddr) < 0)
+	if (upeek(tcp, 4*PT_PC, &tcp->baddr) < 0)
 	  return -1;
 #elif defined (ALPHA)
 	return -1;
@@ -1810,17 +1810,17 @@ struct tcb *tcp;
 #elif defined (MIPS)
 	return -1;		/* FIXME: I do not know what i do - Flo */
 #elif defined (POWERPC)
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &tcp->baddr) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &tcp->baddr) < 0)
 		return -1;
 #elif defined(S390) || defined(S390X)
-	if (upeek(tcp->pid,PT_PSWADDR, &tcp->baddr) < 0)
+	if (upeek(tcp,PT_PSWADDR, &tcp->baddr) < 0)
 		return -1;
 #elif defined(HPPA)
-	if (upeek(tcp->pid, PT_IAOQ0, &tcp->baddr) < 0)
+	if (upeek(tcp, PT_IAOQ0, &tcp->baddr) < 0)
 		return -1;
 	tcp->baddr &= ~0x03;
 #elif defined(SH)
-       if (upeek(tcp->pid, 4*REG_PC, &tcp->baddr) < 0)
+       if (upeek(tcp, 4*REG_PC, &tcp->baddr) < 0)
                return -1;
 #else
 #error unknown architecture
@@ -1946,7 +1946,7 @@ struct tcb *tcp;
 		}
 		tcp->flags &= ~TCB_BPTSET;
 
-		if (upeek(tcp->pid, PT_CR_IIP, &addr) < 0)
+		if (upeek(tcp, PT_CR_IIP, &addr) < 0)
 			return -1;
 		if (addr != tcp->baddr) {
 			/* The breakpoint has not been reached yet.  */
@@ -1962,9 +1962,9 @@ struct tcb *tcp;
 
 		pid = tcp->pid;
 
-		if (upeek(pid, PT_CR_IPSR, &ipsr) < 0)
+		if (upeek(tcp, PT_CR_IPSR, &ipsr) < 0)
 			return -1;
-		if (upeek(pid, PT_CR_IIP, &addr) < 0)
+		if (upeek(tcp, PT_CR_IIP, &addr) < 0)
 			return -1;
 
 		/* restore original bundle: */
@@ -2012,7 +2012,7 @@ struct tcb *tcp;
 	tcp->flags &= ~TCB_BPTSET;
 
 #ifdef I386
-	if (upeek(tcp->pid, 4*EIP, &eip) < 0)
+	if (upeek(tcp, 4*EIP, &eip) < 0)
 		return -1;
 	if (eip != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -2023,7 +2023,7 @@ struct tcb *tcp;
 		return 0;
 	}
 #elif defined(X86_64)
-	if (upeek(tcp->pid, 8*RIP, &eip) < 0)
+	if (upeek(tcp, 8*RIP, &eip) < 0)
 		return -1;
 	if (eip != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -2034,7 +2034,7 @@ struct tcb *tcp;
 		return 0;
 	}
 #elif defined(POWERPC)
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0)
 		return -1;
 	if (pc != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -2044,7 +2044,7 @@ struct tcb *tcp;
 		return 0;
 	}
 #elif defined(M68K)
-	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0)
+	if (upeek(tcp, 4*PT_PC, &pc) < 0)
 		return -1;
 	if (pc != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -2054,7 +2054,7 @@ struct tcb *tcp;
 		return 0;
 	}
 #elif defined(ALPHA)
-	if (upeek(tcp->pid, REG_PC, &pc) < 0)
+	if (upeek(tcp, REG_PC, &pc) < 0)
 		return -1;
 	if (pc != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -2064,7 +2064,7 @@ struct tcb *tcp;
 		return 0;
 	}
 #elif defined(HPPA)
-	if (upeek(tcp->pid, PT_IAOQ0, &iaoq) < 0)
+	if (upeek(tcp, PT_IAOQ0, &iaoq) < 0)
 		return -1;
 	iaoq &= ~0x03;
 	if (iaoq != tcp->baddr && iaoq != tcp->baddr + 4) {
@@ -2082,7 +2082,7 @@ struct tcb *tcp;
 	ptrace(PTRACE_POKEUSER, tcp->pid, (void *)PT_IAOQ0, iaoq);
 	ptrace(PTRACE_POKEUSER, tcp->pid, (void *)PT_IAOQ1, iaoq);
 #elif defined(SH)
-       if (upeek(tcp->pid, 4*REG_PC, &pc) < 0)
+       if (upeek(tcp, 4*REG_PC, &pc) < 0)
                return -1;
         if (pc != tcp->baddr) {
                 /* The breakpoint has not been reached yet.  */
@@ -2156,15 +2156,15 @@ struct tcb *tcp;
 #ifdef SUNOS4
 
 static int
-getex(pid, hdr)
-int pid;
+getex(tcp, hdr)
+struct tcb *tcp;
 struct exec *hdr;
 {
 	int n;
 
 	for (n = 0; n < sizeof *hdr; n += 4) {
 		long res;
-		if (upeek(pid, uoff(u_exdata) + n, &res) < 0)
+		if (upeek(tcp, uoff(u_exdata) + n, &res) < 0)
 			return -1;
 		memcpy(((char *) hdr) + n, &res, 4);
 	}
@@ -2192,7 +2192,7 @@ struct tcb *tcp;
 	struct link_dynamic_2 ld;
 	char *strtab, *cp;
 
-	if (getex(pid, &hdr) < 0)
+	if (getex(tcp, &hdr) < 0)
 		return -1;
 	if (!hdr.a_dynamic)
 		return -1;






More information about the Strace-devel mailing list