+ mep->next = NULL;
+}
+
+/*
+ * Allocate a vmspace structure, including a vm_map and pmap,
+ * and initialize those structures. The refcnt is set to 1.
+ * The remaining fields must be initialized by the caller.
+ */
+struct vmspace *
+vmspace_alloc(min, max, pageable)
+ vm_offset_t min, max;
+ int pageable;
+{
+ register struct vmspace *vm;
+
+ MALLOC(vm, struct vmspace *, sizeof(struct vmspace), M_VMMAP, M_WAITOK);
+ bzero(vm, (caddr_t) &vm->vm_startcopy - (caddr_t) vm);
+ vm_map_init(&vm->vm_map, min, max, pageable);
+ pmap_pinit(&vm->vm_pmap);
+ vm->vm_map.pmap = &vm->vm_pmap; /* XXX */
+ vm->vm_refcnt = 1;
+ return (vm);
+}
+
+void
+vmspace_free(vm)
+ register struct vmspace *vm;
+{
+
+ if (--vm->vm_refcnt == 0) {
+ /*
+ * Lock the map, to wait out all other references to it.
+ * Delete all of the mappings and pages they hold,
+ * then call the pmap module to reclaim anything left.
+ */
+ vm_map_lock(&vm->vm_map);
+ (void) vm_map_delete(&vm->vm_map, vm->vm_map.min_offset,
+ vm->vm_map.max_offset);
+ pmap_release(&vm->vm_pmap);
+ FREE(vm, M_VMMAP);
+ }