src/sys/kern/uipc_shm.c
/*
 * We require the caller to unmap the entire entry.  This allows us to
 * safely decrement shm_kmappings when a mapping is removed.
 */
We require the caller to unmap the entire entry.  This allows us to
safely decrement shm_kmappings when a mapping is removed.
We require the caller to unmap the entire entry . This allows us to safely decrement shm_kmappings when a mapping is removed .
int
shm_unmap(struct file *fp, void *mem, size_t size)
{
	struct shmfd *shmfd;
	vm_map_entry_t entry;
	vm_offset_t kva, ofs;
	vm_object_t obj;
	vm_pindex_t pindex;
	vm_prot_t prot;
	boolean_t wired;
	vm_map_t map;
	int rv;
	if (fp->f_type != DTYPE_SHM)
		return (EINVAL);
	shmfd = fp->f_data;
	kva = (vm_offset_t)mem;
	ofs = kva & PAGE_MASK;
	kva = trunc_page(kva);
	size = round_page(size + ofs);
	map = kernel_map;
	rv = vm_map_lookup(&map, kva, VM_PROT_READ | VM_PROT_WRITE, &entry,
	    &obj, &pindex, &prot, &wired);
	if (rv != KERN_SUCCESS)
		return (EINVAL);
	if (entry->start != kva || entry->end != kva + size) {
		vm_map_lookup_done(map, entry);
		return (EINVAL);
	}
	vm_map_lookup_done(map, entry);
	if (obj != shmfd->shm_object)
		return (EINVAL);
	vm_map_remove(map, kva, kva + size);
	VM_OBJECT_WLOCK(obj);
	KASSERT(shmfd->shm_kmappings > 0, ("shm_unmap: object not mapped"));
	shmfd->shm_kmappings--;
	VM_OBJECT_WUNLOCK(obj);
	return (0);
}
int shm_unmap ( struct file * fp , void * mem , size_t size ) { struct shmfd * shmfd ; vm_map_entry_t entry ; vm_offset_t kva , ofs ; vm_object_t obj ; vm_pindex_t pindex ; vm_prot_t prot ; boolean_t wired ; vm_map_t map ; int rv ; if ( fp -> f_type != DTYPE_SHM ) return ( EINVAL ) ; shmfd = fp -> f_data ; kva = ( vm_offset_t ) mem ; ofs = kva & PAGE_MASK ; kva = trunc_page ( kva ) ; size = round_page ( size + ofs ) ; map = kernel_map ; rv = vm_map_lookup ( & map , kva , VM_PROT_READ | VM_PROT_WRITE , & entry , & obj , & pindex , & prot , & wired ) ; if ( rv != KERN_SUCCESS ) return ( EINVAL ) ; if ( entry -> start != kva || entry -> end != kva + size ) { vm_map_lookup_done ( map , entry ) ; return ( EINVAL ) ; } vm_map_lookup_done ( map , entry ) ; if ( obj != shmfd -> shm_object ) return ( EINVAL ) ; vm_map_remove ( map , kva , kva + size ) ; VM_OBJECT_WLOCK ( obj ) ; KASSERT ( shmfd -> shm_kmappings > 0 , ( " " ) ) ; shmfd -> shm_kmappings -- ; VM_OBJECT_WUNLOCK ( obj ) ; return ( 0 ) ; }
We require the caller to unmap the entire entry.
We require the caller to unmap the entire entry .