diff --git a/sys/amd64/linux32/linux32_machdep.c b/sys/amd64/linux32/linux32_machdep.c index ac0b9c1ad184..7e9274f24d1c 100644 --- a/sys/amd64/linux32/linux32_machdep.c +++ b/sys/amd64/linux32/linux32_machdep.c @@ -793,7 +793,9 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args) if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC)) bsd_args.prot |= PROT_READ | PROT_EXEC; - if (linux_args->fd != -1) { + /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */ + bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : linux_args->fd; + if (bsd_args.fd != -1) { /* * Linux follows Solaris mmap(2) description: * The file descriptor fildes is opened with @@ -801,7 +803,7 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args) * protection options specified. */ - if ((error = fget(td, linux_args->fd, &fp)) != 0) + if ((error = fget(td, bsd_args.fd, &fp)) != 0) return (error); if (fp->f_type != DTYPE_VNODE) { fdrop(fp, td); @@ -816,7 +818,6 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args) fdrop(fp, td); } - bsd_args.fd = linux_args->fd; if (linux_args->flags & LINUX_MAP_GROWSDOWN) { /* diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c index 83aa0d38782b..9f7eb1823ca6 100644 --- a/sys/i386/linux/linux_machdep.c +++ b/sys/i386/linux/linux_machdep.c @@ -684,7 +684,9 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args) if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC)) bsd_args.prot |= PROT_READ | PROT_EXEC; - if (linux_args->fd != -1) { + /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */ + bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : linux_args->fd; + if (bsd_args.fd != -1) { /* * Linux follows Solaris mmap(2) description: * The file descriptor fildes is opened with @@ -692,7 +694,7 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args) * protection options specified. */ - if ((error = fget(td, linux_args->fd, &fp)) != 0) + if ((error = fget(td, bsd_args.fd, &fp)) != 0) return (error); if (fp->f_type != DTYPE_VNODE) { fdrop(fp, td); @@ -707,7 +709,6 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args) fdrop(fp, td); } - bsd_args.fd = linux_args->fd; if (linux_args->flags & LINUX_MAP_GROWSDOWN) { /*