jingfei195887 opened a new pull request, #21754:
URL: https://github.com/apache/nuttx/pull/21754

   ## Summary
   
   POSIX conformance fixes in the generic mmap path and in shmfs.
   
   - `mmap()` handed every mapping to the object's own mmap method, so a
     writable `MAP_PRIVATE` mapping of a tmpfs or shm file shared the backing
     store and writes through it changed the file. A writable `MAP_PRIVATE`
     mapping of a file now gets a private copy from `rammap()`. Read-only
     private mappings and drivers, whose mmap defines its own semantics, still
     use the object's mmap, so XIP files are not copied to RAM.
   - `shmfs_munmap()` rejected an unmap of part of a mapping with EINVAL. The
     mapping is now shrunk, or split in two when the middle is unmapped.
   - `msync()` accepted unknown flags and `MS_SYNC | MS_ASYNC`; both now fail
     with EINVAL.
   - `mmap()` returned ENOSYS for `MAP_FIXED`; it now returns ENOTSUP, which
     POSIX defines for an unsupported mapping type.
   
   ## Impact
   
   A writable `MAP_PRIVATE` mapping of a tmpfs or shm file now uses RAM for
   the private copy, and writes to it no longer reach the file. Shared
   mappings, read-only private mappings and driver mappings are unchanged.
   
   ## Testing
   
   Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 
72c45233a0 (rebased onto 72c45233a0; no
   new commit touches fs/mmap or fs/shm), `sim:nsh` with `CONFIG_FS_TMPFS` and
   `CONFIG_FS_SHMFS`. A small test program on a tmpfs file holding "abcd" and
   on an 8 KB shm object:
   
   | step | master | this PR |
   |---|---|---|
   | writable `MAP_PRIVATE`, write 'X', unmap, read the file | "Xbcd" | "abcd" |
   | read-only `MAP_PRIVATE` | ok | ok |
   | `mmap(MAP_FIXED)` | ENOSYS | ENOTSUP |
   | `msync(MS_SYNC \| MS_ASYNC)` | 0 | -1, EINVAL |
   | shm: `munmap()` of the second 4 KB | -1, EINVAL | 0 |
   | shm: `munmap()` of the rest | 0 | 0 |
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - Make and CMake builds pass; `ostest` exits with status 0.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to