This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a5243361fa8a3a4e468ab0b728efa201397e874a Author: shenjunyuan <[email protected]> AuthorDate: Wed Aug 5 12:02:03 2026 +0800 mm/map: add mm_map_exist() to query overlapping mappings Add mm_map_exist(mm, vaddr, length), which returns whether any existing mapping in the task group overlaps the given address range. This lets callers ask the mm layer whether a buffer is currently mapped instead of maintaining their own mapping reference counts. Used by tmpfs to decide whether growing (and possibly relocating) a file's backing buffer is safe. Assisted-by: Kiro Signed-off-by: shenjunyuan <[email protected]> --- include/nuttx/mm/map.h | 19 +++++++++++++++++++ mm/map/mm_map.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/nuttx/mm/map.h b/include/nuttx/mm/map.h index b9e1cfd8eae..1b9247961f7 100644 --- a/include/nuttx/mm/map.h +++ b/include/nuttx/mm/map.h @@ -308,6 +308,25 @@ FAR struct mm_map_entry_s *mm_map_find(FAR struct mm_map_s *mm, FAR const void *vaddr, size_t length); +/**************************************************************************** + * Name: mm_map_exist + * + * Description: + * Return whether any existing mapping overlaps the given address range. + * + * Input Parameters: + * mm - A pointer to mm_map_s, which describes the virtual memory area + * vaddr - Start address of the range to test + * length - Length of the range to test + * + * Returned Value: + * true if an overlapping mapping exists, false otherwise + * + ****************************************************************************/ + +bool mm_map_exist(FAR struct mm_map_s *mm, FAR const void *vaddr, + size_t length); + /**************************************************************************** * Name: mm_map_remove * diff --git a/mm/map/mm_map.c b/mm/map/mm_map.c index 40240d39d84..6169e46e588 100644 --- a/mm/map/mm_map.c +++ b/mm/map/mm_map.c @@ -303,6 +303,45 @@ FAR struct mm_map_entry_s *mm_map_find(FAR struct mm_map_s *mm, return found_entry; } +/**************************************************************************** + * Name: mm_map_exist + * + * Description: + * Return whether any existing mapping overlaps the address range + * [vaddr, vaddr + length). + * + ****************************************************************************/ + +bool mm_map_exist(FAR struct mm_map_s *mm, FAR const void *vaddr, + size_t length) +{ + FAR struct mm_map_entry_s *entry; + FAR const char *start = vaddr; + FAR const char *end = start + length; + bool exist = false; + + if (nxrmutex_lock(&mm->mm_map_mutex) == OK) + { + for (entry = (FAR struct mm_map_entry_s *)sq_peek(&mm->mm_map_sq); + entry != NULL; + entry = (FAR struct mm_map_entry_s *)sq_next((sq_entry_t *)entry)) + { + FAR const char *e_start = entry->vaddr; + FAR const char *e_end = e_start + entry->length; + + if (start < e_end && e_start < end) + { + exist = true; + break; + } + } + + nxrmutex_unlock(&mm->mm_map_mutex); + } + + return exist; +} + /**************************************************************************** * Name: mm_map_remove *
