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

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


The following commit(s) were added to refs/heads/master by this push:
     new d50b768840c fs_romfs: add compatible for kernel build mmap
d50b768840c is described below

commit d50b768840c413e0172039d2f3ae582dce7d47c1
Author: buxiasen <[email protected]>
AuthorDate: Fri Nov 20 00:04:53 2026 +0800

    fs_romfs: add compatible for kernel build mmap
    
    Before fix the mmap with romfs fd will cause user access kernel address
    
    In the kernel build rm_xipbase is a kernel address, so romfs_mmap()
    returns -ENOTTY there and mmap() falls back to a copy of the file.
    
    Signed-off-by: buxiasen <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/romfs/fs_romfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c
index c272430c6d2..dfff39220fd 100644
--- a/fs/romfs/fs_romfs.c
+++ b/fs/romfs/fs_romfs.c
@@ -636,6 +636,15 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
 static int romfs_mmap(FAR struct file *filep, FAR struct mm_map_entry_s *map)
 {
+#ifdef CONFIG_BUILD_KERNEL
+  /* rm_xipbase is a kernel address that a user process cannot access.
+   * -ENOTTY makes mmap() fall back to a copy of the file.
+   */
+
+  UNUSED(filep);
+  UNUSED(map);
+  return -ENOTTY;
+#else
   FAR struct romfs_mountpt_s *rm;
   FAR struct romfs_file_s *rf;
 
@@ -660,6 +669,7 @@ static int romfs_mmap(FAR struct file *filep, FAR struct 
mm_map_entry_s *map)
     }
 
   return -ENOTTY;
+#endif
 }
 
 /****************************************************************************

Reply via email to