Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 May 2006 06:34:25 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 97134 for review
Message-ID:  <200605140634.k4E6YP1c009681@repoman.freebsd.org>

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

Change 97134 by jb@jb_freebsd2 on 2006/05/14 06:33:59

	Add a td_errno field to the struct thread just so that DTrace can
	access it when running the syscall:::return probe. The value can
	then be accessed in a D script using 'curthread->td_errno' or just
	using 'errno' if the mapping is present in a library script in
	/usr/lib/dtrace.
	
	Change the syscall:::return probe arguments to match the 
	syscall:::entry arguments. This is a change away from the behaviour
	on Solaris. I don't understand why Sun chose to pass just the error
	variable as arg0 and arg1 to the return probe, leaving the rest of
	the arguments zero, when they have saved the error variable in the
	lwp structure (which is the equivailent of our thread structure)
	and they could make the syscall parameters visible. They seem to
	have a lot of code for handling syscalls compared to FreeBSD.
	
	This allows us to do things like:
	
	syscall::stat:return
	/execname == "make" && errno == 2/
	{
		trace(copyinstr(arg0));
	}
	
	to report files that make is trying to stat(2) and not finding.
	
	Run that and I guarantee you will be AMAZED at what make actually
	does. 8-)

Affected files ...

.. //depot/projects/dtrace/src/sys/i386/i386/trap.c#4 edit
.. //depot/projects/dtrace/src/sys/sys/proc.h#4 edit

Differences ...

==== //depot/projects/dtrace/src/sys/i386/i386/trap.c#4 (text+ko) ====

@@ -1113,8 +1113,8 @@
 		AUDIT_SYSCALL_EXIT(error, td);
 
 #ifdef KDTRACE
-		args[0] = error;
-		args[1] = error;
+		/* Save the error return variable for DTrace to reference. */
+		td->td_errno = error;
 
 		/*
 		 * If the systrace module has registered it's probe
@@ -1122,7 +1122,7 @@
 		 * syscall 'return', process the probe.
 		 */
 		if (systrace_probe_func != NULL && callp->sy_return != 0)
-			(*systrace_probe_func)(callp->sy_return, code, NULL,
+			(*systrace_probe_func)(callp->sy_return, code, callp,
 			    args);
 #endif
 	}

==== //depot/projects/dtrace/src/sys/sys/proc.h#4 (text+ko) ====

@@ -368,6 +368,7 @@
 	uintptr_t	td_dtrace_astpc;
 					/* DTrace return sequence location. */
 	u_int64_t	td_hrtime;	/* Last time on cpu. */
+	int		td_errno;	/* Syscall return value. */
 /* End of DTrace-specific fields. */
 };
 



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