You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/16 03:03:01 UTC

[incubator-nuttx] 01/02: fs/mmap: Clarify MAP_PRIVATE dependency on CONFIG_FS_RAMMAP

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 00d9f8191954c7e6f90a6c5ba5e20f575b44fe70
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Mon Mar 15 16:35:30 2021 -0300

    fs/mmap: Clarify MAP_PRIVATE dependency on CONFIG_FS_RAMMAP
---
 fs/mmap/fs_mmap.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c
index 259a06f..e7f4f40 100644
--- a/fs/mmap/fs_mmap.c
+++ b/fs/mmap/fs_mmap.c
@@ -112,7 +112,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
                int fd, off_t offset)
 {
   FAR void *addr;
-  int ret = -1;
+  int ret;
 
   /* Since only a tiny subset of mmap() functionality, we have to verify many
    * things.
@@ -132,6 +132,16 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
       goto errout;
     }
 
+#ifndef CONFIG_FS_RAMMAP
+  if ((flags & MAP_PRIVATE) != 0)
+    {
+      ferr("ERROR: MAP_PRIVATE is not supported without file mapping"
+           "emulation\n");
+      ret = -ENOSYS;
+      goto errout;
+    }
+#endif /* CONFIG_FS_RAMMAP */
+
   /* A length of 0 is invalid. */
 
   if (length == 0)
@@ -140,7 +150,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
       ret = -EINVAL;
       goto errout;
     }
-#endif
+#endif /* CONFIG_DEBUG_FEATURES */
 
   /* Check if we are just be asked to allocate memory, i.e., MAP_ANONYMOUS
    * set meaning that the memory is not backed up from a file.  The file
@@ -169,17 +179,24 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
       return alloc;
     }
 
+  if ((flags & MAP_PRIVATE) != 0)
+    {
+#ifdef CONFIG_FS_RAMMAP
+      /* Allocate memory and copy the file into memory.  We would, of course,
+       * do much better in the KERNEL build using the MMU.
+       */
+
+      return rammap(fd, length, offset);
+#endif
+    }
+
   /* Perform the ioctl to get the base address of the file in 'mapped'
    * in memory. (casting to uintptr_t first eliminates complaints on some
    * architectures where the sizeof long is different from the size of
    * a pointer).
    */
 
-  if ((flags & MAP_PRIVATE) == 0)
-    {
-      ret = nx_ioctl(fd, FIOC_MMAP, (unsigned long)((uintptr_t)&addr));
-    }
-
+  ret = nx_ioctl(fd, FIOC_MMAP, (unsigned long)((uintptr_t)&addr));
   if (ret < 0)
     {
       /* Not directly mappable, probably because the underlying media does