From owner-svn-src-stable@FreeBSD.ORG Wed Mar 2 06:03:54 2011 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E4E371065673; Wed, 2 Mar 2011 06:03:54 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D11208FC15; Wed, 2 Mar 2011 06:03:54 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p2263sTe082447; Wed, 2 Mar 2011 06:03:54 GMT (envelope-from dchagin@svn.freebsd.org) Received: (from dchagin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p2263sKa082442; Wed, 2 Mar 2011 06:03:54 GMT (envelope-from dchagin@svn.freebsd.org) Message-Id: <201103020603.p2263sKa082442@svn.freebsd.org> From: Dmitry Chagin Date: Wed, 2 Mar 2011 06:03:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r219161 - in stable/8/sys: amd64/linux32 compat/linux i386/linux X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Mar 2011 06:03:55 -0000 Author: dchagin Date: Wed Mar 2 06:03:54 2011 New Revision: 219161 URL: http://svn.freebsd.org/changeset/base/219161 Log: MFC r218030: Implement a variation of the linux_common_wait() which should be used by linuxolator itself. Move linux_wait4() to MD path as it requires native struct rusage translation to struct l_rusage on linux32/amd64. Modified: stable/8/sys/amd64/linux32/linux32_machdep.c stable/8/sys/compat/linux/linux_misc.c stable/8/sys/compat/linux/linux_misc.h stable/8/sys/i386/linux/linux_machdep.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) Modified: stable/8/sys/amd64/linux32/linux32_machdep.c ============================================================================== --- stable/8/sys/amd64/linux32/linux32_machdep.c Wed Mar 2 06:01:49 2011 (r219160) +++ stable/8/sys/amd64/linux32/linux32_machdep.c Wed Mar 2 06:03:54 2011 (r219161) @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -66,6 +67,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1268,3 +1270,44 @@ linux_set_thread_area(struct thread *td, return (0); } + +int +linux_wait4(struct thread *td, struct linux_wait4_args *args) +{ + int error, options; + struct rusage ru, *rup; + struct l_rusage lru; + struct proc *p; + +#ifdef DEBUG + if (ldebug(wait4)) + printf(ARGS(wait4, "%d, %p, %d, %p"), + args->pid, (void *)args->status, args->options, + (void *)args->rusage); +#endif + + options = (args->options & (WNOHANG | WUNTRACED)); + /* WLINUXCLONE should be equal to __WCLONE, but we make sure */ + if (args->options & __WCLONE) + options |= WLINUXCLONE; + + if (args->rusage != NULL) + rup = &ru; + else + rup = NULL; + error = linux_common_wait(td, args->pid, args->status, options, rup); + if (error) + return (error); + + p = td->td_proc; + PROC_LOCK(p); + sigqueue_delete(&p->p_sigqueue, SIGCHLD); + PROC_UNLOCK(p); + + if (args->rusage != NULL) { + bsd_to_linux_rusage(rup, &lru); + error = copyout(&lru, args->rusage, sizeof(lru)); + } + + return (error); +} Modified: stable/8/sys/compat/linux/linux_misc.c ============================================================================== --- stable/8/sys/compat/linux/linux_misc.c Wed Mar 2 06:01:49 2011 (r219160) +++ stable/8/sys/compat/linux/linux_misc.c Wed Mar 2 06:03:54 2011 (r219161) @@ -847,35 +847,17 @@ linux_futimesat(struct thread *td, struc } #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ -#define __WCLONE 0x80000000 - int -linux_waitpid(struct thread *td, struct linux_waitpid_args *args) +linux_common_wait(struct thread *td, int pid, int *status, + int options, struct rusage *ru) { - int error, options, tmpstat; - -#ifdef DEBUG - if (ldebug(waitpid)) - printf(ARGS(waitpid, "%d, %p, %d"), - args->pid, (void *)args->status, args->options); -#endif - /* - * this is necessary because the test in kern_wait doesn't work - * because we mess with the options here - */ - if (args->options & ~(WUNTRACED | WNOHANG | WCONTINUED | __WCLONE)) - return (EINVAL); + int error, tmpstat; - options = (args->options & (WNOHANG | WUNTRACED)); - /* WLINUXCLONE should be equal to __WCLONE, but we make sure */ - if (args->options & __WCLONE) - options |= WLINUXCLONE; - - error = kern_wait(td, args->pid, &tmpstat, options, NULL); + error = kern_wait(td, pid, &tmpstat, options, ru); if (error) - return error; + return (error); - if (args->status) { + if (status) { tmpstat &= 0xffff; if (WIFSIGNALED(tmpstat)) tmpstat = (tmpstat & 0xffffff80) | @@ -883,60 +865,38 @@ linux_waitpid(struct thread *td, struct else if (WIFSTOPPED(tmpstat)) tmpstat = (tmpstat & 0xffff00ff) | (BSD_TO_LINUX_SIGNAL(WSTOPSIG(tmpstat)) << 8); - return copyout(&tmpstat, args->status, sizeof(int)); + error = copyout(&tmpstat, status, sizeof(int)); } - return (0); + return (error); } int -linux_wait4(struct thread *td, struct linux_wait4_args *args) +linux_waitpid(struct thread *td, struct linux_waitpid_args *args) { - int error, options, tmpstat; - struct rusage ru, *rup; - struct proc *p; - + int options; + #ifdef DEBUG - if (ldebug(wait4)) - printf(ARGS(wait4, "%d, %p, %d, %p"), - args->pid, (void *)args->status, args->options, - (void *)args->rusage); + if (ldebug(waitpid)) + printf(ARGS(waitpid, "%d, %p, %d"), + args->pid, (void *)args->status, args->options); #endif - + /* + * this is necessary because the test in kern_wait doesn't work + * because we mess with the options here + */ + if (args->options & ~(WUNTRACED | WNOHANG | WCONTINUED | __WCLONE)) + return (EINVAL); + options = (args->options & (WNOHANG | WUNTRACED)); /* WLINUXCLONE should be equal to __WCLONE, but we make sure */ if (args->options & __WCLONE) options |= WLINUXCLONE; - if (args->rusage != NULL) - rup = &ru; - else - rup = NULL; - error = kern_wait(td, args->pid, &tmpstat, options, rup); - if (error) - return error; - - p = td->td_proc; - PROC_LOCK(p); - sigqueue_delete(&p->p_sigqueue, SIGCHLD); - PROC_UNLOCK(p); - - if (args->status) { - tmpstat &= 0xffff; - if (WIFSIGNALED(tmpstat)) - tmpstat = (tmpstat & 0xffffff80) | - BSD_TO_LINUX_SIGNAL(WTERMSIG(tmpstat)); - else if (WIFSTOPPED(tmpstat)) - tmpstat = (tmpstat & 0xffff00ff) | - (BSD_TO_LINUX_SIGNAL(WSTOPSIG(tmpstat)) << 8); - error = copyout(&tmpstat, args->status, sizeof(int)); - } - if (args->rusage != NULL && error == 0) - error = copyout(&ru, args->rusage, sizeof(ru)); - - return (error); + return (linux_common_wait(td, args->pid, args->status, options, NULL)); } + int linux_mknod(struct thread *td, struct linux_mknod_args *args) { Modified: stable/8/sys/compat/linux/linux_misc.h ============================================================================== --- stable/8/sys/compat/linux/linux_misc.h Wed Mar 2 06:01:49 2011 (r219160) +++ stable/8/sys/compat/linux/linux_misc.h Wed Mar 2 06:03:54 2011 (r219161) @@ -67,4 +67,9 @@ extern const char *linux_platform; extern int stclohz; +#define __WCLONE 0x80000000 + +int linux_common_wait(struct thread *td, int pid, int *status, + int options, struct rusage *ru); + #endif /* _LINUX_MISC_H_ */ Modified: stable/8/sys/i386/linux/linux_machdep.c ============================================================================== --- stable/8/sys/i386/linux/linux_machdep.c Wed Mar 2 06:01:49 2011 (r219160) +++ stable/8/sys/i386/linux/linux_machdep.c Wed Mar 2 06:03:54 2011 (r219161) @@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1312,3 +1313,40 @@ linux_mq_getsetattr(struct thread *td, s #endif } +int +linux_wait4(struct thread *td, struct linux_wait4_args *args) +{ + int error, options; + struct rusage ru, *rup; + struct proc *p; + +#ifdef DEBUG + if (ldebug(wait4)) + printf(ARGS(wait4, "%d, %p, %d, %p"), + args->pid, (void *)args->status, args->options, + (void *)args->rusage); +#endif + + options = (args->options & (WNOHANG | WUNTRACED)); + /* WLINUXCLONE should be equal to __WCLONE, but we make sure */ + if (args->options & __WCLONE) + options |= WLINUXCLONE; + + if (args->rusage != NULL) + rup = &ru; + else + rup = NULL; + error = linux_common_wait(td, args->pid, args->status, options, rup); + if (error) + return (error); + + p = td->td_proc; + PROC_LOCK(p); + sigqueue_delete(&p->p_sigqueue, SIGCHLD); + PROC_UNLOCK(p); + + if (args->rusage != NULL) + error = copyout(&ru, args->rusage, sizeof(ru)); + + return (error); +}