fs/mmap: Support the no backing file for anonymous mapping
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
ab67d6a75b
commit
fcd4a421e3
@ -55,7 +55,7 @@
|
|||||||
#ifdef CONFIG_FS_ANONMAP
|
#ifdef CONFIG_FS_ANONMAP
|
||||||
int map_anonymous(FAR struct mm_map_entry_s *entry, bool kernel);
|
int map_anonymous(FAR struct mm_map_entry_s *entry, bool kernel);
|
||||||
#else
|
#else
|
||||||
#define map_anonymous(entry,kernel) (-ENOSYS)
|
# define map_anonymous(entry, kernel) (-ENOSYS)
|
||||||
#endif /* CONFIG_FS_ANONMAP */
|
#endif /* CONFIG_FS_ANONMAP */
|
||||||
|
|
||||||
#endif /* __FS_MMAP_FS_ANONMAP_H */
|
#endif /* __FS_MMAP_FS_ANONMAP_H */
|
||||||
|
@ -94,6 +94,22 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_DEBUG_FEATURES */
|
#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)
|
if ((filep->f_oflags & O_WROK) == 0 && prot == PROT_WRITE)
|
||||||
{
|
{
|
||||||
ferr("ERROR: Unsupported options for read-only file descriptor,"
|
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;
|
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'
|
/* Call driver's mmap to get the base address of the file in 'mapped'
|
||||||
* in memory.
|
* in memory.
|
||||||
*/
|
*/
|
||||||
@ -218,7 +223,7 @@ int file_mmap(FAR struct file *filep, FAR void *start, size_t length,
|
|||||||
* MAP_NORESERVE - Ignored
|
* MAP_NORESERVE - Ignored
|
||||||
* MAP_POPULATE - Ignored
|
* MAP_POPULATE - Ignored
|
||||||
* MAP_NONBLOCK - 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
|
* offset The offset into the file to map
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* 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,
|
FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
|
||||||
int fd, off_t offset)
|
int fd, off_t offset)
|
||||||
{
|
{
|
||||||
FAR struct file *filep;
|
FAR struct file *filep = NULL;
|
||||||
FAR void *mapped;
|
FAR void *mapped;
|
||||||
int ret;
|
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);
|
ferr("ERROR: Invalid file descriptor, fd=%d\n", fd);
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user