Implement getrandom() syscall.

Note. GRND_RANDOM option is not supported for now.

MFC after:	1 month
This commit is contained in:
dchagin 2017-03-18 18:34:29 +00:00
parent d56d166349
commit 69ea87350f
5 changed files with 30 additions and 3 deletions

View File

@ -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: */

View File

@ -144,7 +144,6 @@ DUMMY(sched_getattr);
DUMMY(renameat2);
/* linux 3.15: */
DUMMY(seccomp);
DUMMY(getrandom);
DUMMY(memfd_create);
/* linux 3.18: */
DUMMY(bpf);

View File

@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/racct.h>
#include <sys/random.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
#include <sys/sdt.h>
@ -65,6 +66,7 @@ __FBSDID("$FreeBSD$");
#include <sys/vnode.h>
#include <sys/wait.h>
#include <sys/cpuset.h>
#include <sys/uio.h>
#include <security/mac/mac_framework.h>
@ -2508,3 +2510,27 @@ linux_to_bsd_waitopts(int options, int *bsdopts)
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));
}

View File

@ -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);

View File

@ -140,7 +140,6 @@ DUMMY(sched_getattr);
DUMMY(renameat2);
/* linux 3.15: */
DUMMY(seccomp);
DUMMY(getrandom);
DUMMY(memfd_create);
/* linux 3.18: */
DUMMY(bpf);