From owner-svn-src-head@freebsd.org Sat Mar 18 18:34:30 2017 Return-Path: Delivered-To: svn-src-head@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 CF60CD1256C; Sat, 18 Mar 2017 18:34:30 +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 AA15B103A; Sat, 18 Mar 2017 18:34:30 +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 v2IIYTIi075409; Sat, 18 Mar 2017 18:34:29 GMT (envelope-from dchagin@FreeBSD.org) Received: (from dchagin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2IIYTal075402; Sat, 18 Mar 2017 18:34:29 GMT (envelope-from dchagin@FreeBSD.org) Message-Id: <201703181834.v2IIYTal075402@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dchagin set sender to dchagin@FreeBSD.org using -f From: Dmitry Chagin Date: Sat, 18 Mar 2017 18:34:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315505 - in head/sys: amd64/linux 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.23 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: Sat, 18 Mar 2017 18:34:30 -0000 Author: dchagin Date: Sat Mar 18 18:34:29 2017 New Revision: 315505 URL: https://svnweb.freebsd.org/changeset/base/315505 Log: Implement getrandom() syscall. Note. GRND_RANDOM option is not supported for now. MFC after: 1 month Modified: head/sys/amd64/linux/linux_dummy.c head/sys/amd64/linux32/linux32_dummy.c head/sys/compat/linux/linux_misc.c head/sys/compat/linux/linux_misc.h head/sys/i386/linux/linux_dummy.c Modified: head/sys/amd64/linux/linux_dummy.c ============================================================================== --- head/sys/amd64/linux/linux_dummy.c Sat Mar 18 18:31:45 2017 (r315504) +++ head/sys/amd64/linux/linux_dummy.c Sat Mar 18 18:34:29 2017 (r315505) @@ -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: head/sys/amd64/linux32/linux32_dummy.c ============================================================================== --- head/sys/amd64/linux32/linux32_dummy.c Sat Mar 18 18:31:45 2017 (r315504) +++ head/sys/amd64/linux32/linux32_dummy.c Sat Mar 18 18:34:29 2017 (r315505) @@ -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: head/sys/compat/linux/linux_misc.c ============================================================================== --- head/sys/compat/linux/linux_misc.c Sat Mar 18 18:31:45 2017 (r315504) +++ head/sys/compat/linux/linux_misc.c Sat Mar 18 18:34:29 2017 (r315505) @@ -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: head/sys/compat/linux/linux_misc.h ============================================================================== --- head/sys/compat/linux/linux_misc.h Sat Mar 18 18:31:45 2017 (r315504) +++ head/sys/compat/linux/linux_misc.h Sat Mar 18 18:34:29 2017 (r315505) @@ -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: head/sys/i386/linux/linux_dummy.c ============================================================================== --- head/sys/i386/linux/linux_dummy.c Sat Mar 18 18:31:45 2017 (r315504) +++ head/sys/i386/linux/linux_dummy.c Sat Mar 18 18:34:29 2017 (r315505) @@ -140,7 +140,6 @@ DUMMY(sched_getattr); DUMMY(renameat2); /* linux 3.15: */ DUMMY(seccomp); -DUMMY(getrandom); DUMMY(memfd_create); /* linux 3.18: */ DUMMY(bpf);