diff options
author | Alan Cox <alc@FreeBSD.org> | 2003-11-10 01:37:40 +0000 |
---|---|---|
committer | Alan Cox <alc@FreeBSD.org> | 2003-11-10 01:37:40 +0000 |
commit | d88346020b75c3db732441a769f7f7a1d0824f7d (patch) | |
tree | 9f9445306d056c8d74e579030ddec7cb2c11e1bc /sys/vm/vm_mmap.c | |
parent | 8f101a2f3112f3936ae21fc8849bc267fad84fbe (diff) | |
download | src-d88346020b75c3db732441a769f7f7a1d0824f7d.tar.gz src-d88346020b75c3db732441a769f7f7a1d0824f7d.zip |
- The Open Group Base Specifications Issue 6 specifies that an munmap(2)
must return EINVAL if size is zero. Submitted by: tegge
- In order to avoid a race condition in multithreaded applications, the
check and removal operations by munmap(2) must be in the same critical
section. To accomodate this, vm_map_check_protection() is modified to
require its caller to obtain at least a read lock on the map.
Notes
Notes:
svn path=/head/; revision=122384
Diffstat (limited to 'sys/vm/vm_mmap.c')
-rw-r--r-- | sys/vm/vm_mmap.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index 95e335aa7009..9025c4692e58 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -585,6 +585,8 @@ munmap(td, uap) addr = (vm_offset_t) uap->addr; size = uap->len; + if (size == 0) + return (EINVAL); pageoff = (addr & PAGE_MASK); addr -= pageoff; @@ -593,23 +595,23 @@ munmap(td, uap) if (addr + size < addr) return (EINVAL); - if (size == 0) - return (0); - /* * Check for illegal addresses. Watch out for address wrap... */ map = &td->td_proc->p_vmspace->vm_map; if (addr < vm_map_min(map) || addr + size > vm_map_max(map)) return (EINVAL); + vm_map_lock(map); /* * Make sure entire range is allocated. */ - if (!vm_map_check_protection(map, addr, addr + size, VM_PROT_NONE)) + if (!vm_map_check_protection(map, addr, addr + size, VM_PROT_NONE)) { + vm_map_unlock(map); return (EINVAL); - + } /* returns nothing but KERN_SUCCESS anyway */ - (void) vm_map_remove(map, addr, addr + size); + vm_map_delete(map, addr, addr + size); + vm_map_unlock(map); return (0); } |