From owner-svn-src-head@FreeBSD.ORG Sun May 24 15:03:12 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2C20FBAF; Sun, 24 May 2015 15:03:12 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1A1CA1A2A; Sun, 24 May 2015 15:03:12 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t4OF3Bp6039913; Sun, 24 May 2015 15:03:11 GMT (envelope-from dchagin@FreeBSD.org) Received: (from dchagin@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t4OF3AQA039904; Sun, 24 May 2015 15:03:10 GMT (envelope-from dchagin@FreeBSD.org) Message-Id: <201505241503.t4OF3AQA039904@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: dchagin set sender to dchagin@FreeBSD.org using -f From: Dmitry Chagin Date: Sun, 24 May 2015 15:03:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r283391 - in head/sys: amd64/linux32 compat/linux i386/linux X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 May 2015 15:03:12 -0000 Author: dchagin Date: Sun May 24 15:03:09 2015 New Revision: 283391 URL: https://svnweb.freebsd.org/changeset/base/283391 Log: To reduce code duplication introduce linux_copyout_rusage() method. Use it in linux_wait4() system call and move linux_wait4() to the MI path. While here add a prototype for the static bsd_to_linux_rusage(). Differential Revision: https://reviews.freebsd.org/D2138 Reviewed by: trasz Modified: head/sys/amd64/linux32/linux.h head/sys/amd64/linux32/linux32_genassym.c head/sys/amd64/linux32/linux32_machdep.c head/sys/compat/linux/linux_misc.c head/sys/i386/linux/linux.h head/sys/i386/linux/linux_machdep.c Modified: head/sys/amd64/linux32/linux.h ============================================================================== --- head/sys/amd64/linux32/linux.h Sun May 24 15:00:27 2015 (r283390) +++ head/sys/amd64/linux32/linux.h Sun May 24 15:03:09 2015 (r283391) @@ -780,6 +780,7 @@ struct l_iovec32 { int linux32_copyiniov(struct l_iovec32 *iovp32, l_ulong iovcnt, struct iovec **iovp, int error); +int linux_copyout_rusage(struct rusage *ru, void *uaddr); /* robust futexes */ struct linux_robust_list { Modified: head/sys/amd64/linux32/linux32_genassym.c ============================================================================== --- head/sys/amd64/linux32/linux32_genassym.c Sun May 24 15:00:27 2015 (r283390) +++ head/sys/amd64/linux32/linux32_genassym.c Sun May 24 15:03:09 2015 (r283391) @@ -3,6 +3,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include Modified: head/sys/amd64/linux32/linux32_machdep.c ============================================================================== --- head/sys/amd64/linux32/linux32_machdep.c Sun May 24 15:00:27 2015 (r283390) +++ head/sys/amd64/linux32/linux32_machdep.c Sun May 24 15:03:09 2015 (r283391) @@ -72,6 +72,8 @@ __FBSDID("$FreeBSD$"); #include #include +static void bsd_to_linux_rusage(struct rusage *ru, struct l_rusage *lru); + struct l_old_select_argv { l_int nfds; l_uintptr_t readfds; @@ -133,6 +135,16 @@ bsd_to_linux_rusage(struct rusage *ru, s } int +linux_copyout_rusage(struct rusage *ru, void *uaddr) +{ + struct l_rusage lru; + + bsd_to_linux_rusage(ru, &lru); + + return (copyout(&lru, uaddr, sizeof(struct l_rusage))); +} + +int linux_execve(struct thread *td, struct linux_execve_args *args) { struct image_args eargs; @@ -908,17 +920,14 @@ linux_settimeofday(struct thread *td, st int linux_getrusage(struct thread *td, struct linux_getrusage_args *uap) { - struct l_rusage s32; struct rusage s; int error; error = kern_getrusage(td, uap->who, &s); if (error != 0) return (error); - if (uap->rusage != NULL) { - bsd_to_linux_rusage(&s, &s32); - error = copyout(&s32, uap->rusage, sizeof(s32)); - } + if (uap->rusage != NULL) + error = linux_copyout_rusage(&s, uap->rusage); return (error); } @@ -1024,37 +1033,3 @@ 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; - -#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); - if (args->rusage != NULL) { - bsd_to_linux_rusage(rup, &lru); - error = copyout(&lru, args->rusage, sizeof(lru)); - } - - return (error); -} Modified: head/sys/compat/linux/linux_misc.c ============================================================================== --- head/sys/compat/linux/linux_misc.c Sun May 24 15:00:27 2015 (r283390) +++ head/sys/compat/linux/linux_misc.c Sun May 24 15:03:09 2015 (r283391) @@ -886,6 +886,35 @@ linux_waitpid(struct thread *td, struct return (linux_common_wait(td, args->pid, args->status, options, NULL)); } +int +linux_wait4(struct thread *td, struct linux_wait4_args *args) +{ + int error, options; + struct rusage ru, *rup; + +#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 != 0) + return (error); + if (args->rusage != NULL) + error = linux_copyout_rusage(&ru, args->rusage); + return (error); +} int linux_mknod(struct thread *td, struct linux_mknod_args *args) Modified: head/sys/i386/linux/linux.h ============================================================================== --- head/sys/i386/linux/linux.h Sun May 24 15:00:27 2015 (r283390) +++ head/sys/i386/linux/linux.h Sun May 24 15:03:09 2015 (r283391) @@ -741,6 +741,8 @@ struct l_desc_struct { #define LINUX_GET_USEABLE(desc) \ (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1) +#define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r)) + /* robust futexes */ struct linux_robust_list { struct linux_robust_list *next; Modified: head/sys/i386/linux/linux_machdep.c ============================================================================== --- head/sys/i386/linux/linux_machdep.c Sun May 24 15:00:27 2015 (r283390) +++ head/sys/i386/linux/linux_machdep.c Sun May 24 15:03:09 2015 (r283391) @@ -1047,34 +1047,3 @@ linux_mq_getsetattr(struct thread *td, s return (ENOSYS); #endif } - -int -linux_wait4(struct thread *td, struct linux_wait4_args *args) -{ - int error, options; - struct rusage ru, *rup; - -#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); - if (args->rusage != NULL) - error = copyout(&ru, args->rusage, sizeof(ru)); - - return (error); -}