You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/01/12 17:12:04 UTC
[nuttx] branch master updated (120594079a -> fd0195b0d8)
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
from 120594079a add function for strtof
new ab67d6a75b fs/mmap: Remove the duplication rammap handling
new fcd4a421e3 fs/mmap: Support the no backing file for anonymous mapping
new fd0195b0d8 fs/mmap: Suppor the partial unmap for anonymous mapping
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
fs/mmap/fs_anonmap.c | 59 +++++++++++++++++++++++++++++++++++++++---------
fs/mmap/fs_anonmap.h | 2 +-
fs/mmap/fs_mmap.c | 64 ++++++++++++++++++----------------------------------
fs/mmap/fs_rammap.c | 19 ++++++++--------
fs/mmap/fs_rammap.h | 4 +++-
5 files changed, 83 insertions(+), 65 deletions(-)
[nuttx] 03/03: fs/mmap: Suppor the partial unmap for anonymous mapping
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit fd0195b0d8efd25d501a73bb23ecb0b6587c81d4
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Jan 11 01:09:04 2023 +0800
fs/mmap: Suppor the partial unmap for anonymous mapping
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
fs/mmap/fs_anonmap.c | 59 ++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 48 insertions(+), 11 deletions(-)
diff --git a/fs/mmap/fs_anonmap.c b/fs/mmap/fs_anonmap.c
index 534806e9af..9e53a49198 100644
--- a/fs/mmap/fs_anonmap.c
+++ b/fs/mmap/fs_anonmap.c
@@ -39,32 +39,69 @@ static int unmap_anonymous(FAR struct task_group_s *group,
FAR void *start,
size_t length)
{
- int ret;
+ FAR void *newaddr;
+ off_t offset;
+ bool kernel = entry->priv.i;
+ int ret = OK;
+
+ /* Get the offset from the beginning of the region and the actual number
+ * of bytes to "unmap". All mappings must extend to the end of the region.
+ * There is no support for freeing a block of memory but leaving a block of
+ * memory at the end. This is a consequence of using kumm_realloc() to
+ * simulate the unmapping.
+ */
+
+ offset = start - entry->vaddr;
+ if (offset + length < entry->length)
+ {
+ ferr("ERROR: Cannot umap without unmapping to the end\n");
+ return -ENOSYS;
+ }
- /* De-allocate memory.
- * NB: This is incomplete anounymous mapping implementation
- * see file_mmap_ below
+ /* Okay.. the region is being unmapped to the end. Make sure the length
+ * indicates that.
*/
- if (start == entry->vaddr && length == entry->length)
+ length = entry->length - offset;
+
+ /* Are we unmapping the entire region (offset == 0)? */
+
+ if (length >= entry->length)
{
- /* entry->priv marks allocation from kernel heap */
+ /* Free the region */
- if (entry->priv.i)
+ if (kernel)
{
- kmm_free(start);
+ kmm_free(entry->vaddr);
}
else
{
- kumm_free(start);
+ kumm_free(entry->vaddr);
}
+ /* Then remove the mapping from the list */
+
ret = mm_map_remove(get_group_mm(group), entry);
}
+
+ /* No.. We have been asked to "unmap' only a portion of the memory
+ * (offset > 0).
+ */
+
else
{
- ret = -EINVAL;
- ferr("ERROR: Unknown map type\n");
+ if (kernel)
+ {
+ newaddr = kmm_realloc(entry->vaddr, length);
+ }
+ else
+ {
+ newaddr = kumm_realloc(entry->vaddr, length);
+ }
+
+ DEBUGASSERT(newaddr == entry->vaddr);
+ entry->vaddr = newaddr;
+ entry->length = length;
}
return ret;
[nuttx] 01/03: fs/mmap: Remove the duplication rammap handling
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit ab67d6a75bdeb6b219c064a15188b188e84a9e6a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Jan 11 00:48:45 2023 +0800
fs/mmap: Remove the duplication rammap handling
and minor ifx for style and format
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
fs/mmap/fs_mmap.c | 37 ++++++-------------------------------
fs/mmap/fs_rammap.c | 19 +++++++++----------
fs/mmap/fs_rammap.h | 4 +++-
3 files changed, 18 insertions(+), 42 deletions(-)
diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c
index b979805b6d..a533602f76 100644
--- a/fs/mmap/fs_mmap.c
+++ b/fs/mmap/fs_mmap.c
@@ -85,15 +85,6 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
return -ENOSYS;
}
-#ifndef CONFIG_FS_RAMMAP
- if ((flags & MAP_PRIVATE) != 0)
- {
- ferr("ERROR: MAP_PRIVATE is not supported without file mapping"
- "emulation\n");
- return -ENOSYS;
- }
-#endif /* CONFIG_FS_RAMMAP */
-
/* A length of 0 is invalid. */
if (length == 0)
@@ -103,8 +94,7 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
}
#endif /* CONFIG_DEBUG_FEATURES */
- if ((filep->f_oflags & O_WROK) == 0 && prot == PROT_WRITE &&
- (flags & MAP_SHARED) != 0)
+ if ((filep->f_oflags & O_WROK) == 0 && prot == PROT_WRITE)
{
ferr("ERROR: Unsupported options for read-only file descriptor,"
"prot=%x flags=%04x\n", prot, flags);
@@ -128,45 +118,30 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
return map_anonymous(&entry, kernel);
}
- if ((flags & MAP_PRIVATE) != 0)
- {
-#ifdef CONFIG_FS_RAMMAP
- /* Allocate memory and copy the file into memory. We would, of course,
- * do much better in the KERNEL build using the MMU.
- */
-
- return rammap(filep, &entry, kernel);
-#endif
- }
-
/* Call driver's mmap to get the base address of the file in 'mapped'
* in memory.
*/
- if (filep->f_inode && filep->f_inode->u.i_ops->mmap != NULL)
+ if ((flags & MAP_PRIVATE) == 0 && filep->f_inode &&
+ filep->f_inode->u.i_ops->mmap != NULL)
{
ret = filep->f_inode->u.i_ops->mmap(filep, &entry);
if (ret == OK)
{
- *mapped = (void *)entry.vaddr;
+ *mapped = entry.vaddr;
}
}
else
{
- /* Not directly mappable, probably because the underlying media does
- * not support random access.
+ /* Caller request the private mapping. Or not directly mappable,
+ * probably because the underlying media doesn't support random access.
*/
-#ifdef CONFIG_FS_RAMMAP
/* Allocate memory and copy the file into memory. We would, of course,
* do much better in the KERNEL build using the MMU.
*/
return rammap(filep, &entry, kernel);
-#else
- ferr("ERROR: mmap not supported \n");
- return -ENOSYS;
-#endif
}
/* Return */
diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c
index 5e346b8a5e..16ea937659 100644
--- a/fs/mmap/fs_rammap.c
+++ b/fs/mmap/fs_rammap.c
@@ -51,9 +51,9 @@ static int unmap_rammap(FAR struct task_group_s *group,
size_t length)
{
FAR void *newaddr;
- unsigned int offset;
- bool kernel = entry->priv.i != 0 ? true : false;
- int ret;
+ off_t offset;
+ bool kernel = entry->priv.i;
+ int ret = OK;
/* Get the offset from the beginning of the region and the actual number
* of bytes to "unmap". All mappings must extend to the end of the region.
@@ -111,9 +111,8 @@ static int unmap_rammap(FAR struct task_group_s *group,
}
DEBUGASSERT(newaddr == entry->vaddr);
- UNUSED(newaddr); /* May not be used */
+ entry->vaddr = newaddr;
entry->length = length;
- ret = OK;
}
return ret;
@@ -176,7 +175,7 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
rdbuffer = kernel ? kmm_malloc(length) : kumm_malloc(length);
if (!rdbuffer)
{
- ferr("ERROR: Region allocation failed, length: %d\n", (int)length);
+ ferr("ERROR: Region allocation failed, length: %zu\n", length);
return -ENOMEM;
}
@@ -189,7 +188,7 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
* the correct response.
*/
- ferr("ERROR: Seek to position %d failed\n", (int)entry->offset);
+ ferr("ERROR: Seek to position %zu failed\n", (size_t)entry->offset);
ret = fpos;
goto errout_with_region;
}
@@ -209,8 +208,8 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
{
/* All other read errors are bad. */
- ferr("ERROR: Read failed: offset=%d ret=%d\n",
- (int)entry->offset, (int)nread);
+ ferr("ERROR: Read failed: offset=%zu ret=%zd\n",
+ (size_t)entry->offset, nread);
ret = nread;
goto errout_with_region;
@@ -237,7 +236,7 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
/* Add the buffer to the list of regions */
entry->vaddr = rdbuffer;
- entry->priv.i = kernel ? 1 : 0;
+ entry->priv.i = kernel;
entry->munmap = unmap_rammap;
ret = mm_map_add(entry);
diff --git a/fs/mmap/fs_rammap.h b/fs/mmap/fs_rammap.h
index a3c0a49fa1..32fc0c132b 100644
--- a/fs/mmap/fs_rammap.h
+++ b/fs/mmap/fs_rammap.h
@@ -89,6 +89,8 @@
int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
bool kernel);
-
+#else
+# define rammap(file, entry, kernel) (-ENOSYS)
#endif /* CONFIG_FS_RAMMAP */
+
#endif /* __FS_MMAP_FS_RAMMAP_H */
[nuttx] 02/03: fs/mmap: Support the no backing file for anonymous mapping
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit fcd4a421e341d3f6fa3b9fb48acc3d52faf37805
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Jan 11 00:51:35 2023 +0800
fs/mmap: Support the no backing file for anonymous mapping
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
fs/mmap/fs_anonmap.h | 2 +-
fs/mmap/fs_mmap.c | 33 +++++++++++++++++++--------------
2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/fs/mmap/fs_anonmap.h b/fs/mmap/fs_anonmap.h
index 70725c5623..1413d53bd5 100644
--- a/fs/mmap/fs_anonmap.h
+++ b/fs/mmap/fs_anonmap.h
@@ -55,7 +55,7 @@
#ifdef CONFIG_FS_ANONMAP
int map_anonymous(FAR struct mm_map_entry_s *entry, bool kernel);
#else
-#define map_anonymous(entry,kernel) (-ENOSYS)
+# define map_anonymous(entry, kernel) (-ENOSYS)
#endif /* CONFIG_FS_ANONMAP */
#endif /* __FS_MMAP_FS_ANONMAP_H */
diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c
index a533602f76..8d7a3f6d2a 100644
--- a/fs/mmap/fs_mmap.c
+++ b/fs/mmap/fs_mmap.c
@@ -94,6 +94,22 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
}
#endif /* CONFIG_DEBUG_FEATURES */
+ /* Check if we are just be asked to allocate memory, i.e., MAP_ANONYMOUS
+ * set meaning that the memory is not backed up from a file. The file
+ * descriptor should be -1 (or refer to opened /dev/zero) in this case.
+ * The file descriptor is ignored in either case.
+ */
+
+ if ((flags & MAP_ANONYMOUS) != 0)
+ {
+ return map_anonymous(&entry, kernel);
+ }
+
+ if (filep == NULL)
+ {
+ return -EBADF;
+ }
+
if ((filep->f_oflags & O_WROK) == 0 && prot == PROT_WRITE)
{
ferr("ERROR: Unsupported options for read-only file descriptor,"
@@ -107,17 +123,6 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
return -EACCES;
}
- /* Check if we are just be asked to allocate memory, i.e., MAP_ANONYMOUS
- * set meaning that the memory is not backed up from a file. The file
- * descriptor should be -1 (or refer to opened /dev/zero) in this case.
- * The file descriptor is ignored in either case.
- */
-
- if ((flags & MAP_ANONYMOUS) != 0)
- {
- return map_anonymous(&entry, kernel);
- }
-
/* Call driver's mmap to get the base address of the file in 'mapped'
* in memory.
*/
@@ -218,7 +223,7 @@ int file_mmap(FAR struct file *filep, FAR void *start, size_t length,
* MAP_NORESERVE - Ignored
* MAP_POPULATE - Ignored
* MAP_NONBLOCK - Ignored
- * fd file descriptor of the backing file -- required.
+ * fd file descriptor of the backing file.
* offset The offset into the file to map
*
* Returned Value:
@@ -247,11 +252,11 @@ int file_mmap(FAR struct file *filep, FAR void *start, size_t length,
FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
int fd, off_t offset)
{
- FAR struct file *filep;
+ FAR struct file *filep = NULL;
FAR void *mapped;
int ret;
- if (fs_getfilep(fd, &filep) < 0)
+ if (fd != -1 && fs_getfilep(fd, &filep) < 0)
{
ferr("ERROR: Invalid file descriptor, fd=%d\n", fd);
ret = -EBADF;