mmap: check if mapping a character device is actually possible

This commit is contained in:
Matheus
2024-09-03 18:41:26 -03:00
parent af92e8eb87
commit e75aab367d
3 changed files with 18 additions and 0 deletions
+11
View File
@@ -68,6 +68,8 @@ syscallret_t syscall_mmap(context_t *context, void *hint, size_t len, int prot,
return ret;
}
// check if the file is of a type that can be mapped
// and if the fd was opened with the required permissions
int type = file->vnode->type;
if ((type != V_TYPE_REGULAR && type != V_TYPE_BLKDEV && type != V_TYPE_CHDEV)
|| ((prot & PROT_READ) && (file->flags & FILE_READ) == 0)
@@ -76,6 +78,15 @@ syscallret_t syscall_mmap(context_t *context, void *hint, size_t len, int prot,
goto cleanup;
}
// not all charcter devices support mapping, so check if its supported
// (regular files and block devices go through the page cache)
// TODO move this check to vmm_map once the return value of mmap is fixed to return an errno
if (type == V_TYPE_CHDEV) {
ret.errno = VOP_MMAP(file->vnode, VOP_MMAP_ADDRESS_MMAP_SUPPORTED, 0, 0, NULL);
if (ret.errno)
goto cleanup;
}
vfd.node = file->vnode;
vfd.offset = offset;
}