From d61dccef3de59bb8933dce75b43d5157544de952 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sat, 5 Dec 2020 00:59:37 +0100
Subject: [PATCH 4/4] kernel/mmap_single: Pass a_fp properly into the
 *_mmap_single dev op.

Add an fp argument to vm_mmap().

8c530b23e3584f72dc8c660b3816187017eeeb6b had added it to the dev_d*
functions but in mmap_single's case the chain wasn't fully linked.

This allows kernel drivers to use for example devfs_get_cdevpriv()
in their *_mmap_single dev op, too.
---
 sys/dev/drm/drm_bufs.c  | 4 ++--
 sys/kern/imgact_gzip.c  | 7 ++++---
 sys/kern/kern_fp.c      | 2 +-
 sys/libprop/prop_kern.c | 2 +-
 sys/vm/vm_extern.h      | 3 ++-
 sys/vm/vm_mmap.c        | 7 ++++---
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/sys/dev/drm/drm_bufs.c b/sys/dev/drm/drm_bufs.c
index ac82b72079..a7173f01c9 100644
--- a/sys/dev/drm/drm_bufs.c
+++ b/sys/dev/drm/drm_bufs.c
@@ -1498,14 +1498,14 @@ int drm_legacy_mapbufs(struct drm_device *dev, void *data,
 					  VM_PROT_ALL,
 					  MAP_SHARED,
 					  SLIST_FIRST(&dev->devnode->si_hlist),
-					  token);
+					  token, NULL);
 		} else {
 			virtual = vm_mmap(&vms->vm_map, 0, dma->byte_count,
 					  PROT_READ | PROT_WRITE,
 					  VM_PROT_ALL,
 					  MAP_SHARED,
 					  SLIST_FIRST(&dev->devnode->si_hlist),
-					  0);
+					  0, NULL);
 		}
 		if (virtual > -1024UL) {
 			/* Real error */
diff --git a/sys/kern/imgact_gzip.c b/sys/kern/imgact_gzip.c
index 3811104ffe..997b0bb0c0 100644
--- a/sys/kern/imgact_gzip.c
+++ b/sys/kern/imgact_gzip.c
@@ -7,7 +7,6 @@
  * ----------------------------------------------------------------------------
  *
  * $FreeBSD: src/sys/kern/imgact_gzip.c,v 1.40.2.1 2001/11/03 01:41:08 ps Exp $
- * $DragonFly: src/sys/kern/imgact_gzip.c,v 1.9 2006/12/28 21:24:01 dillon Exp $
  *
  * This module handles execution of a.out files which have been run through
  * "gzip".  This saves diskspace, but wastes cpu-cycles and VM.
@@ -231,7 +230,8 @@ do_aout_hdr(struct imgact_gzip * gz)
 			gz->a_out.a_text + gz->a_out.a_data,
 			VM_PROT_ALL, VM_PROT_ALL, MAP_ANON | MAP_FIXED,
 			0,
-			0);
+			0,
+			NULL);
 
 	if (error) {
 		gz->where = __LINE__;
@@ -304,7 +304,8 @@ NextByte(void *vp)
 			VM_PROT_READ,	/* max protection */
 			0,	/* flags */
 			(caddr_t) igz->ip->vp,	/* vnode */
-			igz->offset);	/* offset */
+			igz->offset,	/* offset */
+			NULL);		/* fp */
 	if (error) {
 		igz->where = __LINE__;
 		igz->error = error;
diff --git a/sys/kern/kern_fp.c b/sys/kern/kern_fp.c
index c8fe4d7043..6d415ba547 100644
--- a/sys/kern/kern_fp.c
+++ b/sys/kern/kern_fp.c
@@ -547,7 +547,7 @@ fp_mmap(void *addr_arg, size_t size, int prot, int flags, struct file *fp,
 	handle = (void *)vp;
     }
     error = vm_mmap(&vms->vm_map, &addr, size, prot, 
-		    maxprot, flags, handle, pos);
+		    maxprot, flags, handle, pos, fp);
     if (error == 0 && addr_arg)
 	*resp = (void *)addr;
 done:
diff --git a/sys/libprop/prop_kern.c b/sys/libprop/prop_kern.c
index 90335e9ef6..3ea942af42 100644
--- a/sys/libprop/prop_kern.c
+++ b/sys/libprop/prop_kern.c
@@ -522,7 +522,7 @@ _prop_object_copyout(struct plistref *pref, prop_object_t obj)
 			 VM_PROT_READ|VM_PROT_WRITE,
 			 VM_PROT_READ|VM_PROT_WRITE,
 			 MAP_PRIVATE|MAP_ANON,
-			 NULL, 0);
+			 NULL, 0, NULL);
 	if (error == 0) {
 		error = copyout(buf, (char *)uaddr, len);
 		if (error == 0) {
diff --git a/sys/vm/vm_extern.h b/sys/vm/vm_extern.h
index e056e3d46b..64fb4ab629 100644
--- a/sys/vm/vm_extern.h
+++ b/sys/vm/vm_extern.h
@@ -94,7 +94,8 @@ void vm_wait_nominal(void);
 void vm_init_limits(struct proc *);
 
 int vm_mmap(struct vm_map *, vm_offset_t *, vm_size_t,
-			vm_prot_t, vm_prot_t, int, void *, vm_ooffset_t);
+			vm_prot_t, vm_prot_t, int, void *, vm_ooffset_t,
+			struct file *fp);
 int vm_mmap_to_errno(int rv);
 vm_offset_t kmem_alloc_contig(vm_offset_t, vm_paddr_t,
 			vm_paddr_t, vm_offset_t);
diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c
index ee804930d3..138a4d250b 100644
--- a/sys/vm/vm_mmap.c
+++ b/sys/vm/vm_mmap.c
@@ -380,7 +380,7 @@ kern_mmap(struct vmspace *vms, caddr_t uaddr, size_t ulen,
 	}
 
 	error = vm_mmap(&vms->vm_map, &addr, size, prot, maxprot,
-			flags, handle, pos);
+			flags, handle, pos, fp);
 	if (error == 0)
 		*res = (void *)(addr + pageoff);
 
@@ -1180,7 +1180,8 @@ sys_munlock(struct sysmsg *sysmsg, const struct munlock_args *uap)
  */
 int
 vm_mmap(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
-	vm_prot_t maxprot, int flags, void *handle, vm_ooffset_t foff)
+	vm_prot_t maxprot, int flags, void *handle, vm_ooffset_t foff,
+	struct file *fp)
 {
 	boolean_t fitit;
 	vm_object_t object;
@@ -1342,7 +1343,7 @@ vm_mmap(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
 			 * Force them to be shared.
 			 */
 			error = dev_dmmap_single(vp->v_rdev, &foff, objsize,
-						&object, prot, NULL);
+						&object, prot, fp);
 
 			if (error == ENODEV) {
 				handle = (void *)(intptr_t)vp->v_rdev;
-- 
2.28.0

