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

   ## Summary
   
   - **fs_romfs: add compatible for kernel build mmap.**
     `romfs_mmap()` returns `rm_xipbase + rf_startoffset + offset` as the
     mapping address. In the kernel build `rm_xipbase` is a kernel address
     (for the `/etc` romdisk it is the kernel buffer of the RAM disk), so a
     user process that `mmap()`s a ROMFS file gets a kernel pointer and
     faults on the first access.
   
     Return `-ENOTTY` from `romfs_mmap()` in the kernel build, so that
     `file_mmap_()` falls back to `rammap()` and gives the process a copy of
     the file. Flat and protected builds are unchanged.
   
   ## Impact
   
   - New feature / API change: NO.
   - Behavior, kernel build only: `mmap()` of a ROMFS file returns a private
     copy (`CONFIG_FS_RAMMAP=y`) or fails with `ENOSYS`
     (`CONFIG_FS_RAMMAP` off) instead of handing out a kernel address that
     faults on access. XIP mappings are not shared between processes in the
     kernel build.
   - Flat and protected builds: NO change.
   - Build, hardware, documentation, security, compatibility: NO.
   
   ## Testing
   
   Host: Ubuntu 22.04 x86_64, aarch64-none-elf-gcc 13.4.0, QEMU 6.2.0.
   Base: master fa7cb3c2e94.
   
   `qemu-armv8a:knsh` with `CONFIG_ETC_ROMFS=y` (the board makefile only
   packs `/etc` when `CONFIG_SYSTEM_NXINIT` is set, so that condition was
   dropped locally for the test), built and imported as described in the
   board documentation. A small user program opens `/etc/init.d/init.rc`,
   reads 16 bytes, `mmap()`s the same range with `PROT_READ`/`MAP_SHARED`
   and compares it with the data read.
   
   Testing logs before change (`CONFIG_FS_RAMMAP=y`; the same without it):
   
   ```
   romfsmap: read 16
   romfsmap: mmap 0x402b6200 errno=0
   arm64_exception_handler: FAR_ELn: 0x402b6200
   arm64_fatal_handler: Segmentation fault in romfsmap (PID 5: romfsmap)
   ```
   
   Testing logs after change, `CONFIG_FS_RAMMAP=y`:
   
   ```
   romfsmap: read 16
   romfsmap: mmap 0xc0008800 errno=0
   romfsmap: data match
   ```
   
   Testing logs after change, `CONFIG_FS_RAMMAP` off:
   
   ```
   romfsmap: read 16
   romfsmap: mmap 0xffffffffffffffff errno=38
   ```
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - `sim:nsh` with `CONFIG_FS_ROMFS`: Make and CMake builds pass with no
     warnings in the changed file; `ostest` exits with status 0.
   - `qemu-armv8a:knsh`: builds with no warnings in the changed file.
   
   ## PR verification Self-Check
   
   * [x] This PR introduces only one functional change.
   * [x] I have updated all required description fields above.
   * [x] My PR adheres to Contributing Guidelines and Documentation (git commit 
title and message, coding standard, etc).
   * [ ] My PR is still work in progress (not ready for review).
   * [x] My PR is ready for review and can be safely merged into a codebase.
   


-- 
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