This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 15baca451affbdc699a738ae52da32f5be2eba28 Author: Marco Casaroli <[email protected]> AuthorDate: Sun Oct 11 23:22:41 2026 +0200 fs/mmap: Write a shared mapping back to the file on munmap(). With CONFIG_FS_RAMMAP, mmap() of a file on a file system without its own mmap copies the file into memory. munmap() freed that copy without writing it back, so the changes made through a MAP_SHARED, PROT_WRITE mapping were lost: POSIX says that they reach the file. msync() wrote them, but programs that map a file, change it and unmap it do not call msync(). munmap() of a shared, writable mapping now writes the unmapped range back to the file first. Private mappings are not written. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- fs/mmap/fs_rammap.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c index 34efb6438c2..2ed0cf490b0 100644 --- a/fs/mmap/fs_rammap.c +++ b/fs/mmap/fs_rammap.c @@ -27,6 +27,7 @@ #include <nuttx/config.h> #include <sys/types.h> #include <sys/ioctl.h> +#include <sys/mman.h> #include <assert.h> #include <nuttx/debug.h> @@ -160,6 +161,17 @@ static int unmap_rammap(FAR struct task_group_s *group, length = entry->length - offset; + /* The changes to a shared mapping go to the file */ + + if ((entry->flags & MAP_SHARED) != 0 && (entry->prot & PROT_WRITE) != 0) + { + ret = msync_rammap(entry, start, length, MS_SYNC); + if (ret < 0) + { + ferr("ERROR: Write back failed: %d\n", ret); + } + } + /* Are we unmapping the entire region (offset == 0)? */ if (length >= entry->length)
