From owner-svn-src-stable@freebsd.org Sun Apr 23 06:43:53 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C5E5CD4CDCA; Sun, 23 Apr 2017 06:43:53 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 A126EEC7; Sun, 23 Apr 2017 06:43:53 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3N6hqVn025036; Sun, 23 Apr 2017 06:43:52 GMT (envelope-from dchagin@FreeBSD.org) Received: (from dchagin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3N6hqkA025031; Sun, 23 Apr 2017 06:43:52 GMT (envelope-from dchagin@FreeBSD.org) Message-Id: <201704230643.v3N6hqkA025031@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dchagin set sender to dchagin@FreeBSD.org using -f From: Dmitry Chagin Date: Sun, 23 Apr 2017 06:43:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r317317 - in stable/11/sys: amd64/linux amd64/linux32 compat/linux i386/linux X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 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: Sun, 23 Apr 2017 06:43:53 -0000 Author: dchagin Date: Sun Apr 23 06:43:52 2017 New Revision: 317317 URL: https://svnweb.freebsd.org/changeset/base/317317 Log: MFC r315505: Implement getrandom() syscall. Note. GRND_RANDOM option is not supported for now. Modified: stable/11/sys/amd64/linux/linux_dummy.c stable/11/sys/amd64/linux32/linux32_dummy.c stable/11/sys/compat/linux/linux_misc.c stable/11/sys/compat/linux/linux_misc.h stable/11/sys/i386/linux/linux_dummy.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/amd64/linux/linux_dummy.c ============================================================================== --- stable/11/sys/amd64/linux/linux_dummy.c Sun Apr 23 03:36:03 2017 (r317316) +++ stable/11/sys/amd64/linux/linux_dummy.c Sun Apr 23 06:43:52 2017 (r317317) @@ -135,7 +135,6 @@ DUMMY(sched_getattr); DUMMY(renameat2); /* linux 3.15: */ DUMMY(seccomp); -DUMMY(getrandom); DUMMY(memfd_create); DUMMY(kexec_file_load); /* linux 3.18: */ Modified: stable/11/sys/amd64/linux32/linux32_dummy.c ============================================================================== --- stable/11/sys/amd64/linux32/linux32_dummy.c Sun Apr 23 03:36:03 2017 (r317316) +++ stable/11/sys/amd64/linux32/linux32_dummy.c Sun Apr 23 06:43:52 2017 (r317317) @@ -144,7 +144,6 @@ DUMMY(sched_getattr); DUMMY(renameat2); /* linux 3.15: */ DUMMY(seccomp); -DUMMY(getrandom); DUMMY(memfd_create); /* linux 3.18: */ DUMMY(bpf); Modified: stable/11/sys/compat/linux/linux_misc.c ============================================================================== --- stable/11/sys/compat/linux/linux_misc.c Sun Apr 23 03:36:03 2017 (r317316) +++ stable/11/sys/compat/linux/linux_misc.c Sun Apr 23 06:43:52 2017 (r317317) @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -65,6 +66,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include @@ -2508,3 +2510,27 @@ linux_to_bsd_waitopts(int options, int * if (options & __WCLONE) *bsdopts |= WLINUXCLONE; } + +int +linux_getrandom(struct thread *td, struct linux_getrandom_args *args) +{ + struct uio uio; + struct iovec iov; + + if (args->flags & ~(LINUX_GRND_NONBLOCK|LINUX_GRND_RANDOM)) + return (EINVAL); + if (args->count > INT_MAX) + args->count = INT_MAX; + + iov.iov_base = args->buf; + iov.iov_len = args->count; + + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + uio.uio_resid = iov.iov_len; + uio.uio_segflg = UIO_USERSPACE; + uio.uio_rw = UIO_READ; + uio.uio_td = td; + + return (read_random_uio(&uio, args->flags & LINUX_GRND_NONBLOCK)); +} Modified: stable/11/sys/compat/linux/linux_misc.h ============================================================================== --- stable/11/sys/compat/linux/linux_misc.h Sun Apr 23 03:36:03 2017 (r317316) +++ stable/11/sys/compat/linux/linux_misc.h Sun Apr 23 06:43:52 2017 (r317317) @@ -145,6 +145,10 @@ extern int stclohz; #define LINUX_RLIM_INFINITY (~0UL) +/* Linux getrandom flags */ +#define LINUX_GRND_NONBLOCK 0x0001 +#define LINUX_GRND_RANDOM 0x0002 + int linux_common_wait(struct thread *td, int pid, int *status, int options, struct rusage *ru); void linux_to_bsd_waitopts(int options, int *bsdopts); Modified: stable/11/sys/i386/linux/linux_dummy.c ============================================================================== --- stable/11/sys/i386/linux/linux_dummy.c Sun Apr 23 03:36:03 2017 (r317316) +++ stable/11/sys/i386/linux/linux_dummy.c Sun Apr 23 06:43:52 2017 (r317317) @@ -140,7 +140,6 @@ DUMMY(sched_getattr); DUMMY(renameat2); /* linux 3.15: */ DUMMY(seccomp); -DUMMY(getrandom); DUMMY(memfd_create); /* linux 3.18: */ DUMMY(bpf);