svn commit: r274245 - in user/dchagin/lemul/sys: amd64/linux amd64/linux32 i386/linux

Dmitry Chagin dchagin at FreeBSD.org
Fri Nov 7 17:00:30 UTC 2014


Author: dchagin
Date: Fri Nov  7 17:00:28 2014
New Revision: 274245
URL: https://svnweb.freebsd.org/changeset/base/274245

Log:
  1. Linux always set WEXITED option, not a WUNTRACED|WNOHANG! This is a strange bug.
  2. Fix siginfo in WNOHANG case waitid() system call.

Modified:
  user/dchagin/lemul/sys/amd64/linux/linux_machdep.c
  user/dchagin/lemul/sys/amd64/linux32/linux32_machdep.c
  user/dchagin/lemul/sys/i386/linux/linux_machdep.c

Modified: user/dchagin/lemul/sys/amd64/linux/linux_machdep.c
==============================================================================
--- user/dchagin/lemul/sys/amd64/linux/linux_machdep.c	Fri Nov  7 16:35:31 2014	(r274244)
+++ user/dchagin/lemul/sys/amd64/linux/linux_machdep.c	Fri Nov  7 17:00:28 2014	(r274245)
@@ -503,11 +503,12 @@ linux_wait4(struct thread *td, struct li
 		    args->pid, (void *)args->status, args->options,
 		    (void *)args->rusage);
 #endif
+	if (args->options & ~(LINUX_WUNTRACED | LINUX_WNOHANG |
+	    LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL))
+		return (EINVAL);
 
-	options = (args->options & (WNOHANG | WUNTRACED));
-	/* WLINUXCLONE should be equal to __WCLONE, but we make sure */
-	if (args->options & __WCLONE)
-		options |= WLINUXCLONE;
+	options = WEXITED;
+	linux_to_bsd_waitopts(args->options, &options);
 
 	if (args->rusage != NULL)
 		rup = &ru;
@@ -530,6 +531,7 @@ linux_waitid(struct thread *td, struct l
 	siginfo_t siginfo;
 	l_siginfo_t lsi;
 	idtype_t idtype;
+	struct proc *p;
 	int error;
 
 	options = 0;
@@ -562,22 +564,23 @@ linux_waitid(struct thread *td, struct l
 	    &wru, &siginfo);
 	if (error)
 		return (error);
-	td->td_retval[0] = 0;
-
 	if (args->rusage != NULL) {
 		error = copyout(&wru.wru_children, args->rusage,
 		    sizeof(wru.wru_children));
 		if (error)
 			return (error);
 	}
-
 	if (args->info != NULL) {
-		sig = siginfo.si_signo;
-		if (siginfo.si_signo <= td->td_proc->p_sysent->sv_sigsize)
-			sig = td->td_proc->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
-		siginfo_to_lsiginfo(&siginfo, &lsi, sig);
+		p = td->td_proc;
+		if (td->td_retval[0] == 0)
+			bzero(&lsi, sizeof(lsi));
+		else {
+			sig = BSD_TO_LINUX_SIGNAL(siginfo.si_signo);
+			siginfo_to_lsiginfo(&siginfo, &lsi, sig);
+		}
 		error = copyout(&lsi, args->info, sizeof(lsi));
 	}
+	td->td_retval[0] = 0;
 
 	return (error);
 }

Modified: user/dchagin/lemul/sys/amd64/linux32/linux32_machdep.c
==============================================================================
--- user/dchagin/lemul/sys/amd64/linux32/linux32_machdep.c	Fri Nov  7 16:35:31 2014	(r274244)
+++ user/dchagin/lemul/sys/amd64/linux32/linux32_machdep.c	Fri Nov  7 17:00:28 2014	(r274245)
@@ -1039,8 +1039,11 @@ linux_wait4(struct thread *td, struct li
 		    args->pid, (void *)args->status, args->options,
 		    (void *)args->rusage);
 #endif
+	if (args->options & ~(LINUX_WUNTRACED | LINUX_WNOHANG |
+	    LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL))
+		return (EINVAL);
 
-	options = 0;
+	options = WEXITED;
 	linux_to_bsd_waitopts(args->options, &options);
 
 	if (args->rusage != NULL)
@@ -1067,6 +1070,7 @@ linux_waitid(struct thread *td, struct l
 	siginfo_t siginfo;
 	l_siginfo_t lsi;
 	idtype_t idtype;
+	struct proc *p;
 	int error;
 
 	options = 0;
@@ -1099,20 +1103,23 @@ linux_waitid(struct thread *td, struct l
 	    &wru, &siginfo);
 	if (error)
 		return (error);
-	td->td_retval[0] = 0;
-
 	if (args->rusage != NULL) {
 		bsd_to_linux_rusage(&wru.wru_children, &lru);
 		error = copyout(&lru, args->rusage, sizeof(lru));
 		if (error)
 			return (error);
 	}
-
 	if (args->info != NULL) {
-		sig = BSD_TO_LINUX_SIGNAL(siginfo.si_signo);
-		siginfo_to_lsiginfo(&siginfo, &lsi, sig);
+		p = td->td_proc;
+		if (td->td_retval[0] == 0)
+			bzero(&lsi, sizeof(lsi));
+		else {
+			sig = BSD_TO_LINUX_SIGNAL(siginfo.si_signo);
+			siginfo_to_lsiginfo(&siginfo, &lsi, sig);
+		}
 		error = copyout(&lsi, args->info, sizeof(lsi));
 	}
+	td->td_retval[0] = 0;
 
 	return (error);
 }

Modified: user/dchagin/lemul/sys/i386/linux/linux_machdep.c
==============================================================================
--- user/dchagin/lemul/sys/i386/linux/linux_machdep.c	Fri Nov  7 16:35:31 2014	(r274244)
+++ user/dchagin/lemul/sys/i386/linux/linux_machdep.c	Fri Nov  7 17:00:28 2014	(r274245)
@@ -1058,11 +1058,12 @@ linux_wait4(struct thread *td, struct li
 		    args->pid, (void *)args->status, args->options,
 		    (void *)args->rusage);
 #endif
+	if (args->options & ~(LINUX_WUNTRACED | LINUX_WNOHANG |
+	    LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL))
+		return (EINVAL);
 
-	options = (args->options & (WNOHANG | WUNTRACED));
-	/* WLINUXCLONE should be equal to __WCLONE, but we make sure */
-	if (args->options & __WCLONE)
-		options |= WLINUXCLONE;
+	options = WEXITED;
+	linux_to_bsd_waitopts(args->options, &options);
 
 	if (args->rusage != NULL)
 		rup = &ru;
@@ -1085,6 +1086,7 @@ linux_waitid(struct thread *td, struct l
 	siginfo_t siginfo;
 	l_siginfo_t lsi;
 	idtype_t idtype;
+	struct proc *p;
 	int error;
 
 	options = 0;
@@ -1117,22 +1119,24 @@ linux_waitid(struct thread *td, struct l
 	    &wru, &siginfo);
 	if (error)
 		return (error);
-	td->td_retval[0] = 0;
-
 	if (args->rusage != NULL) {
 		error = copyout(&wru.wru_children, args->rusage,
 		    sizeof(wru.wru_children));
 		if (error)
 			return (error);
 	}
-
 	if (args->info != NULL) {
-		sig = siginfo.si_signo;
-		if (siginfo.si_signo <= td->td_proc->p_sysent->sv_sigsize)
-			sig = td->td_proc->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
+		p = td->td_proc;
+		if (td->td_retval[0] == 0)
+			bzero(&lsi, sizeof(lsi));
+		else {
+			sig = BSD_TO_LINUX_SIGNAL(siginfo.si_signo);
+			siginfo_to_lsiginfo(&siginfo, &lsi, sig);
+		}
 		siginfo_to_lsiginfo(&siginfo, &lsi, sig);
 		error = copyout(&lsi, args->info, sizeof(lsi));
 	}
+	td->td_retval[0] = 0;
 
 	return (error);
 }


More information about the svn-src-user mailing list