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

   ## Summary
   
   Partially unmapping the tail of a heap-backed anonymous mapping must retain 
the prefix before the unmap address. The allocation and mapping entry currently 
shrink to the removed tail's length instead. For an eight-page mapping, 
removing the last three pages incorrectly retains only three pages instead of 
five.
   
   Use the start offset as the retained length for both user and FS heap 
allocations, and for the mapping entry.
   
   ## Impact
   
   - Functionality: fixes anonymous tail unmapping that does not split the 
region into equal halves. Prevents freeing live prefix bytes or retaining 
addresses in the removed range.
   - Compatibility: full unmapping and rejection of non-tail unmapping are 
unchanged. No API, configuration, build-system, or hardware changes.
   - Documentation: no new feature or interface.
   - The MMU page-backed path is unchanged. The existing assumption that 
shrinking realloc preserves the address remains.
   
   ## Testing
   
   I confirm that changes are verified on local setup and work as intended:
   
   - Host: Linux x86_64, GCC 13.1.0.
   - Target: sim:nsh with assertions. Exercise mmap/munmap and 
file_mmap/file_munmap with eight-page mappings retaining 1, 3, 4, 5, and 7 
pages.
   - Check registry length, last retained byte, removed boundary, preserved 
prefix data, msync rejection for removed addresses, final unmap and balanced 
mapping counts. Also check non-tail rejection and full-unmap controls.
   - The baseline test reads only the prefix still backed by its actual 
allocation, so it reports the mismatch without reading freed bytes.
   - Repeat the fixed version with a separate 512 KiB FS heap and FS_RAMMAP 
disabled to exercise independent FS and user allocations.
   
   Testing logs before change (`a63275cdce8`):
   ```text
   ANONTAIL RESULT checks=144 failures=20
   ```
   
   Testing logs after change:
   ```text
   ANONTAIL RESULT checks=144 failures=0
   ANONTAIL RESULT checks=144 failures=0
   ```
   
   Full changed-file and commit checkpatch pass. Final Make/CMake builds pass 
with no warnings in the changed file, OSTest exits with status 0, and the 
tested-HEAD gate passes. The protected and kernel builds also pass with 
FS_ANONMAP enabled. The dedicated-FS-heap configuration logs the simulator 
startup duplicate /tmp mount failure; this regression uses anonymous memory 
mappings and passes all checks. No hardware runtime, protected/kernel runtime, 
SMP stress, or allocator-failure injection was performed.
   
   Small-configuration size (`sim:nsh`, `DEFAULT_SMALL`, optimized, 
`FS_ANONMAP` and `FS_TMPFS`, identical configuration, no regression 
application):
   
   Baseline:
   ```text
      text         data     bss     dec     hex filename
    566309         2800   12896  582005   8e175 nuttx
   ```
   Branch:
   ```text
      text         data     bss     dec     hex filename
    566309         2800   12896  582005   8e175 nuttx
   ```
   Text unchanged bytes; data and bss unchanged.
   
   ## PR verification Self-Check
   
   - [x] This PR introduces only one functional change.
   - [x] I have updated all required description fields above.
   - [x] Commit title, sign-off and coding-style checks pass.
   - [ ] 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