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
The following commit(s) were added to refs/heads/master by this push:
new ea70d7436b8 fs/mmap: preserve XIP subranges when mapping and unmapping
ea70d7436b8 is described below
commit ea70d7436b8b380e0fc9ad9b21ccc95ef392a3e5
Author: jingfei <[email protected]>
AuthorDate: Fri Nov 27 21:06:07 2026 +0800
fs/mmap: preserve XIP subranges when mapping and unmapping
Apply the requested file offset to the direct XIP address, rejecting
negative offsets and address overflow. Preserve that address when
unmapping a tail so the remaining prefix retains its mapping metadata.
Signed-off-by: jingfei <[email protected]>
---
fs/mmap/fs_rammap.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c
index 6ddd0559e8c..cb5697589ff 100644
--- a/fs/mmap/fs_rammap.c
+++ b/fs/mmap/fs_rammap.c
@@ -139,7 +139,7 @@ static int unmap_rammap(FAR struct task_group_s *group,
FAR struct file *filep = (FAR void *)((uintptr_t)entry->priv.p & ~3);
enum mm_map_type_e type =
(enum mm_map_type_e)((uintptr_t)entry->priv.p & 3);
- FAR void *newaddr = NULL;
+ FAR void *newaddr = entry->vaddr;
off_t offset;
int ret = OK;
@@ -261,6 +261,19 @@ int rammap(FAR struct file *filep, FAR struct
mm_map_entry_s *entry,
ret = file_ioctl(filep, BIOC_XIPBASE, (unsigned long)&entry->vaddr);
if (ret == OK)
{
+ if (entry->offset < 0)
+ {
+ return -EINVAL;
+ }
+
+ if ((uintmax_t)entry->offset >
+ UINTPTR_MAX - (uintptr_t)entry->vaddr)
+ {
+ return -EOVERFLOW;
+ }
+
+ entry->vaddr = (FAR void *)((uintptr_t)entry->vaddr +
+ (uintptr_t)entry->offset);
type = MAP_XIP;
goto out;
}