xiaoxiang781216 commented on code in PR #20416:
URL: https://github.com/apache/nuttx/pull/20416#discussion_r4157426566
##########
fs/mmap/fs_anonmap.c:
##########
@@ -115,6 +118,111 @@ static int unmap_anonymous(FAR struct task_group_s *group,
return ret;
}
+#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_ARCH_VMA_MAPPING)
+static int unmap_anonymous_pages(FAR struct task_group_s *group,
+ FAR struct mm_map_entry_s *entry,
+ FAR void *start,
+ size_t length)
+{
+ FAR uintptr_t *pages = entry->priv.p;
+ unsigned int npages = MM_NPAGES(entry->length);
+ unsigned int first;
+ unsigned int i;
+
+ if (!MM_ISALIGNED(start) || start < entry->vaddr)
+ {
+ return -EINVAL;
+ }
+
+ first = ((uintptr_t)start - (uintptr_t)entry->vaddr) >> MM_PGSHIFT;
+ if (first + MM_NPAGES(length) < npages)
+ {
+ ferr("ERROR: Cannot umap without unmapping to the end\n");
+ return -ENOSYS;
+ }
+
+ if (group != NULL)
+ {
+ up_shmdt((uintptr_t)start, npages - first);
+ vm_release_region(get_group_mm(group), start,
+ (size_t)(npages - first) << MM_PGSHIFT);
Review Comment:
remove the cast
##########
fs/mmap/fs_anonmap.c:
##########
@@ -123,6 +231,13 @@ int map_anonymous(FAR struct mm_map_entry_s *entry, bool
kernel)
{
int ret;
+#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_ARCH_VMA_MAPPING)
+ if (!kernel)
+ {
+ return map_anonymous_pages(entry);
+ }
+#endif
+
/* REVISIT: Should reside outside of the heap. That is really the
Review Comment:
remove
##########
fs/mmap/fs_anonmap.c:
##########
@@ -115,6 +118,111 @@ static int unmap_anonymous(FAR struct task_group_s *group,
return ret;
}
+#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_ARCH_VMA_MAPPING)
+static int unmap_anonymous_pages(FAR struct task_group_s *group,
+ FAR struct mm_map_entry_s *entry,
+ FAR void *start,
+ size_t length)
+{
+ FAR uintptr_t *pages = entry->priv.p;
+ unsigned int npages = MM_NPAGES(entry->length);
+ unsigned int first;
+ unsigned int i;
+
+ if (!MM_ISALIGNED(start) || start < entry->vaddr)
+ {
+ return -EINVAL;
+ }
+
+ first = ((uintptr_t)start - (uintptr_t)entry->vaddr) >> MM_PGSHIFT;
+ if (first + MM_NPAGES(length) < npages)
+ {
+ ferr("ERROR: Cannot umap without unmapping to the end\n");
+ return -ENOSYS;
+ }
+
+ if (group != NULL)
+ {
+ up_shmdt((uintptr_t)start, npages - first);
+ vm_release_region(get_group_mm(group), start,
+ (size_t)(npages - first) << MM_PGSHIFT);
+ }
+
+ for (i = first; i < npages; i++)
+ {
+ mm_pgfree(pages[i], 1);
+ }
+
+ if (first > 0)
+ {
+ entry->length = (size_t)first << MM_PGSHIFT;
+ return OK;
+ }
+
+ kmm_free(pages);
+ return group != NULL ? mm_map_remove(get_group_mm(group), entry) : OK;
+}
+
+static int map_anonymous_pages(FAR struct mm_map_entry_s *entry)
+{
+ FAR struct mm_map_s *mm = get_current_mm();
+ unsigned int npages = MM_NPAGES(entry->length);
+ FAR uintptr_t *pages;
+ unsigned int i;
+ int ret = -ENOMEM;
+
+ pages = kmm_zalloc(npages * sizeof(*pages));
+ if (pages == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ for (i = 0; i < npages; i++)
+ {
+ pages[i] = mm_pgalloc(1);
+ if (pages[i] == 0)
+ {
+ goto errout;
+ }
+
+ up_addrenv_page_wipe(pages[i]);
+ }
+
+ entry->length = (size_t)npages << MM_PGSHIFT;
Review Comment:
change npages/i to size_t and remove the cast
##########
fs/mmap/fs_anonmap.c:
##########
@@ -115,6 +118,111 @@ static int unmap_anonymous(FAR struct task_group_s *group,
return ret;
}
+#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_ARCH_VMA_MAPPING)
+static int unmap_anonymous_pages(FAR struct task_group_s *group,
+ FAR struct mm_map_entry_s *entry,
+ FAR void *start,
+ size_t length)
+{
+ FAR uintptr_t *pages = entry->priv.p;
+ unsigned int npages = MM_NPAGES(entry->length);
+ unsigned int first;
+ unsigned int i;
+
+ if (!MM_ISALIGNED(start) || start < entry->vaddr)
+ {
+ return -EINVAL;
+ }
+
+ first = ((uintptr_t)start - (uintptr_t)entry->vaddr) >> MM_PGSHIFT;
+ if (first + MM_NPAGES(length) < npages)
+ {
+ ferr("ERROR: Cannot umap without unmapping to the end\n");
+ return -ENOSYS;
+ }
+
+ if (group != NULL)
+ {
+ up_shmdt((uintptr_t)start, npages - first);
+ vm_release_region(get_group_mm(group), start,
+ (size_t)(npages - first) << MM_PGSHIFT);
+ }
+
+ for (i = first; i < npages; i++)
+ {
+ mm_pgfree(pages[i], 1);
+ }
+
+ if (first > 0)
+ {
+ entry->length = (size_t)first << MM_PGSHIFT;
Review Comment:
remove the cast by changing first/npages/i to size_t
--
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]