svn commit: r234455 - in stable/9/sys: kern sys

Konstantin Belousov kib at FreeBSD.org
Thu Apr 19 10:36:24 UTC 2012


Author: kib
Date: Thu Apr 19 10:36:23 2012
New Revision: 234455
URL: http://svn.freebsd.org/changeset/base/234455

Log:
  MFC r234172:
  Add thread-private flag to indicate that error value is already placed
  in td_errno. Flag is supposed to be used by syscalls returning
  EJUSTRETURN because errno was already placed into the usermode frame
  by a call to set_syscall_retval(9). Both ktrace and dtrace get errno
  value from td_errno if the flag is set.
  
  Use the flag to fix sigsuspend(2) error return ktrace records.

Modified:
  stable/9/sys/kern/kern_sig.c
  stable/9/sys/kern/subr_syscall.c
  stable/9/sys/sys/proc.h
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/kern/kern_sig.c
==============================================================================
--- stable/9/sys/kern/kern_sig.c	Thu Apr 19 10:17:28 2012	(r234454)
+++ stable/9/sys/kern/kern_sig.c	Thu Apr 19 10:36:23 2012	(r234455)
@@ -1465,6 +1465,8 @@ kern_sigsuspend(struct thread *td, sigse
 		mtx_unlock(&p->p_sigacts->ps_mtx);
 	}
 	PROC_UNLOCK(p);
+	td->td_errno = EINTR;
+	td->td_pflags |= TDP_NERRNO;
 	return (EJUSTRETURN);
 }
 

Modified: stable/9/sys/kern/subr_syscall.c
==============================================================================
--- stable/9/sys/kern/subr_syscall.c	Thu Apr 19 10:17:28 2012	(r234454)
+++ stable/9/sys/kern/subr_syscall.c	Thu Apr 19 10:36:23 2012	(r234455)
@@ -136,7 +136,8 @@ syscallenter(struct thread *td, struct s
 		AUDIT_SYSCALL_EXIT(error, td);
 
 		/* Save the latest error return value. */
-		td->td_errno = error;
+		if ((td->td_pflags & TDP_NERRNO) == 0)
+			td->td_errno = error;
 
 #ifdef KDTRACE_HOOKS
 		/*
@@ -191,9 +192,12 @@ syscallret(struct thread *td, int error,
 	    syscallname(p, sa->code), td, td->td_proc->p_pid, td->td_name);
 
 #ifdef KTRACE
-	if (KTRPOINT(td, KTR_SYSRET))
-		ktrsysret(sa->code, error, td->td_retval[0]);
+	if (KTRPOINT(td, KTR_SYSRET)) {
+		ktrsysret(sa->code, (td->td_pflags & TDP_NERRNO) == 0 ?
+		    error : td->td_errno, td->td_retval[0]);
+	}
 #endif
+	td->td_pflags &= ~TDP_NERRNO;
 
 	if (p->p_flag & P_TRACED) {
 		traced = 1;

Modified: stable/9/sys/sys/proc.h
==============================================================================
--- stable/9/sys/sys/proc.h	Thu Apr 19 10:17:28 2012	(r234454)
+++ stable/9/sys/sys/proc.h	Thu Apr 19 10:36:23 2012	(r234455)
@@ -417,6 +417,7 @@ do {									\
 #define	TDP_AUDITREC	0x01000000 /* Audit record pending on thread */
 #define	TDP_RFPPWAIT	0x02000000 /* Handle RFPPWAIT on syscall exit */
 #define	TDP_RESETSPUR	0x04000000 /* Reset spurious page fault history. */
+#define	TDP_NERRNO	0x08000000 /* Last errno is already in td_errno */
 
 /*
  * Reasons that the current thread can not be run yet.


More information about the svn-src-stable-9 mailing list