DawnLiu66 opened a new pull request, #21916:
URL: https://github.com/apache/nuttx/pull/21916
## Summary
Anonymous mappings come from the heap, which does not guarantee page
alignment, while user space is entitled to rely on `mmap()` returning
page-aligned memory (the libfuse node slab allocator masks the node pointer
to a page boundary to find its slab header).
- `map_anonymous()` now allocates with `fs_heap_memalign()`/`kumm_memalign()`
aligned to `getpagesize()` and clears the memory with `memset()`.
- Without `CONFIG_MM_PGSIZE`, `sysconf(_SC_PAGESIZE)`/`getpagesize()`
returned `CONFIG_PTHREAD_STACK_MIN` (256 by default). It now falls back to
the common 4KB page size.
## Impact
- New feature: NO.
- User adaptation: NO.
- Build: NO.
- Hardware: NO.
- Documentation: NO.
- Security: NO.
- Compatibility: without `CONFIG_MM_PGSIZE`, `getpagesize()` returns 4096
instead of `CONFIG_PTHREAD_STACK_MIN`, and each anonymous mapping may use
up
to one page more heap for the alignment.
## Testing
I confirm that changes are verified on local setup and works as intended:
- Build Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0,
master `a3b67d70e0`.
- Target: `sim:nsh` (`CONFIG_FS_ANONMAP` is on by default). Verified on sim
only, no real hardware.
- `./tools/checkpatch.sh -m -g master..HEAD`: all checks pass.
- Make and CMake builds pass, `ostest` exits with status 0.
A small test program maps 16 anonymous regions of different sizes with
`mmap(MAP_PRIVATE | MAP_ANONYMOUS)` and counts the ones not aligned to
`getpagesize()`.
Testing logs before change:
```
getpagesize()=256, misaligned anonymous mmap: 16 of 16 -> fail
```
Testing logs after change:
```
getpagesize()=4096, misaligned anonymous mmap: 0 of 16 -> ok
```
## 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]