summaryrefslogtreecommitdiffstats
path: root/sys/vm/vm_mmap.c
diff options
context:
space:
mode:
authordillon <dillon@FreeBSD.org>1999-09-21 05:00:48 +0000
committerdillon <dillon@FreeBSD.org>1999-09-21 05:00:48 +0000
commit37bee3bb3f0cedaa15e074e03de098469f37fe08 (patch)
tree724796750696919d0118ee89b80a7938648019ed /sys/vm/vm_mmap.c
parente286d87af176929d88bb2fbe5aee591986ad1b41 (diff)
downloadFreeBSD-src-37bee3bb3f0cedaa15e074e03de098469f37fe08.zip
FreeBSD-src-37bee3bb3f0cedaa15e074e03de098469f37fe08.tar.gz
cleanup madvise code, add a few more sanity checks.
Reviewed by: Alan Cox <alc@cs.rice.edu>, dg@root.com
Diffstat (limited to 'sys/vm/vm_mmap.c')
-rw-r--r--sys/vm/vm_mmap.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c
index 9fb8458..0151508 100644
--- a/sys/vm/vm_mmap.c
+++ b/sys/vm/vm_mmap.c
@@ -136,6 +136,15 @@ ogetpagesize(p, uap)
* modulo the PAGE_SIZE (POSIX 1003.1b). If the address is not
* page-aligned, the actual mapping starts at trunc_page(addr)
* and the return value is adjusted up by the page offset.
+ *
+ * Generally speaking, only character devices which are themselves
+ * memory-based, such as a video framebuffer, can be mmap'd. Otherwise
+ * there would be no cache coherency between a descriptor and a VM mapping
+ * both to the same character device.
+ *
+ * Block devices can be mmap'd no matter what they represent. Cache coherency
+ * is maintained as long as you do not write directly to the underlying
+ * character device.
*/
#ifndef _SYS_SYSPROTO_H_
struct mmap_args {
@@ -615,6 +624,12 @@ madvise(p, uap)
struct madvise_args *uap;
{
vm_offset_t start, end;
+
+ /*
+ * Check for illegal behavior
+ */
+ if (uap->behav < 0 || uap->behav > MADV_FREE)
+ return (EINVAL);
/*
* Check for illegal addresses. Watch out for address wrap... Note
* that VM_*_ADDRESS are not constants due to casts (argh).
@@ -636,8 +651,8 @@ madvise(p, uap)
start = trunc_page((vm_offset_t) uap->addr);
end = round_page((vm_offset_t) uap->addr + uap->len);
- vm_map_madvise(&p->p_vmspace->vm_map, start, end, uap->behav);
-
+ if (vm_map_madvise(&p->p_vmspace->vm_map, start, end, uap->behav))
+ return (EINVAL);
return (0);
}
OpenPOWER on IntegriCloud