mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
mm/map: limit the count of memory mapping for the task
No memory map count limit that will exhaust memory and cause the system hang. Also that fix pass LTP posix case mmap/24-1.c Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
This commit is contained in:
+1
-1
@@ -26,7 +26,7 @@ ifeq ($(CONFIG_ARCH_VMA_MAPPING),y)
|
||||
CSRCS += vm_region.c
|
||||
endif
|
||||
|
||||
# Add the shared memory directory to the build
|
||||
# Add the map directory to the build
|
||||
|
||||
DEPPATH += --dep-path map
|
||||
VPATH += :map
|
||||
|
||||
@@ -93,6 +93,7 @@ void mm_map_initialize(FAR struct mm_map_s *mm, bool kernel)
|
||||
{
|
||||
sq_init(&mm->mm_map_sq);
|
||||
nxrmutex_init(&mm->mm_map_mutex);
|
||||
mm->map_count = 0;
|
||||
|
||||
/* Create the virtual pages allocator for user process */
|
||||
|
||||
@@ -148,9 +149,13 @@ void mm_map_destroy(FAR struct mm_map_s *mm)
|
||||
}
|
||||
}
|
||||
|
||||
mm->map_count--;
|
||||
|
||||
kmm_free(entry);
|
||||
}
|
||||
|
||||
DEBUGASSERT(mm->map_count == 0);
|
||||
|
||||
nxrmutex_destroy(&mm->mm_map_mutex);
|
||||
|
||||
/* Release the virtual pages allocator */
|
||||
@@ -198,6 +203,17 @@ int mm_map_add(FAR struct mm_map_s *mm, FAR struct mm_map_entry_s *entry)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Too many mappings? */
|
||||
|
||||
if (mm->map_count >= CONFIG_MM_MAP_COUNT_MAX)
|
||||
{
|
||||
kmm_free(new_entry);
|
||||
nxrmutex_unlock(&mm->mm_map_mutex);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
mm->map_count++;
|
||||
|
||||
sq_addfirst((sq_entry_t *)new_entry, &mm->mm_map_sq);
|
||||
|
||||
nxrmutex_unlock(&mm->mm_map_mutex);
|
||||
@@ -309,6 +325,7 @@ int mm_map_remove(FAR struct mm_map_s *mm,
|
||||
if (entry == prev_entry)
|
||||
{
|
||||
sq_remfirst(&mm->mm_map_sq);
|
||||
mm->map_count--;
|
||||
removed_entry = prev_entry;
|
||||
}
|
||||
else
|
||||
@@ -321,6 +338,7 @@ int mm_map_remove(FAR struct mm_map_s *mm,
|
||||
if (entry == removed_entry)
|
||||
{
|
||||
sq_remafter((sq_entry_t *)prev_entry, &mm->mm_map_sq);
|
||||
mm->map_count--;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user