Browse Source

Send proper flags to userspace

Godzil 4 years ago
parent
commit
a54adc616d
2 changed files with 17 additions and 2 deletions
  1. 5 0
      include/fusd_msg.h
  2. 12 2
      kfusd/kfusd.c

+ 5 - 0
include/fusd_msg.h

@@ -110,6 +110,11 @@ typedef struct {
   unsigned long offset;
   unsigned int cmd;  /* ioctl cmd, poll_diff cached_state */
 
+  /* mmap parameters */
+  unsigned long mmprot;
+  unsigned long mmflags;
+  unsigned long mmoffset;
+
   union {
     unsigned long arg; /* ioctl */
     void *ptr_arg;

+ 12 - 2
kfusd/kfusd.c

@@ -65,6 +65,7 @@
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/mm.h>
+#include <linux/mman.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/poll.h>
@@ -1663,8 +1664,17 @@ static int fusd_client_mmap(struct file *file, struct vm_area_struct *vma)
 		/* send the message */
 		init_fusd_msg(&fusd_msg);
 		fusd_msg.subcmd = FUSD_MMAP;
-		fusd_msg.parm.fops_msg.offset = vma->vm_pgoff << PAGE_SHIFT;
-		fusd_msg.parm.fops_msg.flags = vma->vm_flags;
+		fusd_msg.parm.fops_msg.mmoffset = vma->vm_pgoff << PAGE_SHIFT;
+
+		fusd_msg.parm.fops_msg.mmprot = ((vma->vm_flags & VM_READ) ? PROT_READ : 0) |
+			                        ((vma->vm_flags & VM_WRITE) ? PROT_WRITE : 0) |
+			                        ((vma->vm_flags & VM_EXEC) ? PROT_EXEC : 0);
+		fusd_msg.parm.fops_msg.mmflags = ((vma->vm_flags & VM_SHARED) ? MAP_SHARED : 0 ) |
+					       ((vma->vm_flags & VM_GROWSDOWN) ? MAP_GROWSDOWN : 0) |
+					       ((vma->vm_flags & VM_DENYWRITE) ? MAP_DENYWRITE : 0) |
+					       ((vma->vm_flags & VM_EXEC) ? MAP_EXECUTABLE : 0) |
+					       ((vma->vm_flags & VM_LOCKED) ? MAP_LOCKED : 0);
+
 		fusd_msg.parm.fops_msg.length = vma->vm_end - vma->vm_start;
 
 		/* send message to userspace */