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:
fangxinyong
2023-07-18 19:39:26 +08:00
committed by Xiang Xiao
parent 7e90855d76
commit 43b0421b2a
5 changed files with 28 additions and 2 deletions
+1 -1
View File
@@ -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
+18
View File
@@ -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;
}