require '_h2ph_pre.ph';

unless(defined(&_VM_MAP_)) {
    eval 'sub _VM_MAP_ () {1;}' unless defined(&_VM_MAP_);
    if(defined(&UVM)) {
	require 'uvm/uvm_anon.ph';
    }
    if(defined(&UVM)) {
    } else {
    }
    if(defined( &UVM)) {
    } else {
    }
    if(defined(&UVM)) {
	eval 'sub uvm_map_entry_stop_copy () { &flags;}' unless defined(&uvm_map_entry_stop_copy);
	eval 'sub UVM_MAP_STATIC () {0x01;}' unless defined(&UVM_MAP_STATIC);
    }
    eval 'sub VM_MAPENT_ISWIRED {
        local($entry) = @_;
	    eval q((($entry)-> &wired_count != 0));
    }' unless defined(&VM_MAPENT_ISWIRED);
    unless(defined(&UVM)) {
    }
    if(defined(&UVM)) {
    } else {
    }
    eval 'sub min_offset () { ($header->{start});}' unless defined(&min_offset);
    eval 'sub max_offset () { ($header->{end});}' unless defined(&max_offset);
    if(defined(&UVM)) {
	eval 'sub VM_MAP_PAGEABLE () {0x01;}' unless defined(&VM_MAP_PAGEABLE);
	eval 'sub VM_MAP_INTRSAFE () {0x02;}' unless defined(&VM_MAP_INTRSAFE);
	eval 'sub VM_MAP_WIREFUTURE () {0x04;}' unless defined(&VM_MAP_WIREFUTURE);
	if(defined(&_KERNEL)) {
	}
    }
    unless(defined(&UVM)) {
    }
    if(defined(&UVM)) {
	if(defined(&_KERNEL)) {
	    require 'sys/time.ph';
	    require 'sys/proc.ph';
	    if(defined(&DIAGNOSTIC)) {
		eval 'sub _vm_map_lock {
		    local($map) = @_;
    		    eval q( &do {  &if ( &lockmgr(($map)-> &lock,  &LK_EXCLUSIVE,  &NULL,  &curproc) != 0)  &panic(\\"vm_map_lock: failed to get lock\\"); }  &while (0));
		}' unless defined(&_vm_map_lock);
	    } else {
		eval 'sub _vm_map_lock {
		    local($map) = @_;
    		    eval q(  &lockmgr(($map)-> &lock,  &LK_EXCLUSIVE,  &NULL,  &curproc));
		}' unless defined(&_vm_map_lock);
	    }
	    eval 'sub vm_map_lock {
	        local($map) = @_;
    		eval q( &do {  &if (($map)-> &flags &  &VM_MAP_INTRSAFE)  &simple_lock(($map)-> ($lock->{lk_interlock}));  &else  &_vm_map_lock(($map)); ($map)-> &timestamp++; }  &while (0));
	    }' unless defined(&vm_map_lock);
	    if(defined(&DIAGNOSTIC)) {
		eval 'sub vm_map_lock_read {
		    local($map) = @_;
    		    eval q( &do {  &if ( ($map->{flags}) &  &VM_MAP_INTRSAFE)  &panic(\\"vm_map_lock_read: intrsafe map\\");  &lockmgr(($map)-> &lock,  &LK_SHARED,  &NULL,  &curproc); }  &while (0));
		}' unless defined(&vm_map_lock_read);
	    } else {
		eval 'sub vm_map_lock_read {
		    local($map) = @_;
    		    eval q(  &lockmgr(($map)-> &lock,  &LK_SHARED,  &NULL,  &curproc));
		}' unless defined(&vm_map_lock_read);
	    }
	    eval 'sub vm_map_unlock {
	        local($map) = @_;
    		eval q( &do {  &if (-> &flags &  &VM_MAP_INTRSAFE)  &simple_unlock(&-> ($lock->{lk_interlock}));  &else  &lockmgr(($map)-> &lock,  &LK_RELEASE,  &NULL,  &curproc);}  &while (0));
	    }' unless defined(&vm_map_unlock);
	    eval 'sub vm_map_unlock_read {
	        local($map) = @_;
    		eval q(  &lockmgr(($map)-> &lock,  &LK_RELEASE,  &NULL,  &curproc));
	    }' unless defined(&vm_map_unlock_read);
	}
    } else {
	require 'sys/proc.ph';
	eval 'sub vm_map_lock_drain_interlock {
	    local($map) = @_;
    	    eval q({  &lockmgr(($map)-> &lock,  &LK_DRAIN| &LK_INTERLOCK, ($map)-> &ref_lock,  &curproc); ($map)-> &timestamp++; });
	}' unless defined(&vm_map_lock_drain_interlock);
	if(defined(&DIAGNOSTIC)) {
	    eval 'sub vm_map_lock {
	        local($map) = @_;
    		eval q({  &if ( &lockmgr(($map)-> &lock,  &LK_EXCLUSIVE,  &NULL,  &curproc) != 0) {  &panic(\\"vm_map_lock: failed to get lock\\"); } ($map)-> &timestamp++; });
	    }' unless defined(&vm_map_lock);
	} else {
	    eval 'sub vm_map_lock {
	        local($map) = @_;
    		eval q({  &lockmgr(($map)-> &lock,  &LK_EXCLUSIVE,  &NULL,  &curproc); ($map)-> &timestamp++; });
	    }' unless defined(&vm_map_lock);
	}
	eval 'sub vm_map_unlock {
	    local($map) = @_;
    	    eval q( &lockmgr(($map)-> &lock,  &LK_RELEASE,  &NULL,  &curproc));
	}' unless defined(&vm_map_unlock);
	eval 'sub vm_map_lock_read {
	    local($map) = @_;
    	    eval q( &lockmgr(($map)-> &lock,  &LK_SHARED,  &NULL,  &curproc));
	}' unless defined(&vm_map_lock_read);
	eval 'sub vm_map_unlock_read {
	    local($map) = @_;
    	    eval q( &lockmgr(($map)-> &lock,  &LK_RELEASE,  &NULL,  &curproc));
	}' unless defined(&vm_map_unlock_read);
	eval 'sub vm_map_set_recursive {
	    local($map) = @_;
    	    eval q({  &simple_lock(($map)-> &lk_interlock); ($map)-> &lk_flags |=  &LK_CANRECURSE;  &simple_unlock(($map)-> &lk_interlock); });
	}' unless defined(&vm_map_set_recursive);
	eval 'sub vm_map_clear_recursive {
	    local($map) = @_;
    	    eval q({  &simple_lock(($map)-> &lk_interlock); ($map)-> &lk_flags &= ~ &LK_CANRECURSE;  &simple_unlock(($map)-> &lk_interlock); });
	}' unless defined(&vm_map_clear_recursive);
    }
    eval 'sub vm_map_min {
        local($map) = @_;
	    eval q((($map)-> &min_offset));
    }' unless defined(&vm_map_min);
    eval 'sub vm_map_max {
        local($map) = @_;
	    eval q((($map)-> &max_offset));
    }' unless defined(&vm_map_max);
    eval 'sub vm_map_pmap {
        local($map) = @_;
	    eval q((($map)-> &pmap));
    }' unless defined(&vm_map_pmap);
    unless(defined(&MAX_KMAP)) {
	eval 'sub MAX_KMAP () {20;}' unless defined(&MAX_KMAP);
    }
    unless(defined(&MAX_KMAPENT)) {
	if((50+ (2* (defined(&NPROC) ? &NPROC : 0)) > 1000)) {
	    eval 'sub MAX_KMAPENT () {(50+ (2*  &NPROC));}' unless defined(&MAX_KMAPENT);
	} else {
	    eval 'sub MAX_KMAPENT () {1000;}' unless defined(&MAX_KMAPENT);
	}
    }
    if(defined( &_KERNEL)  && !defined( &UVM)) {
    }
}
1;
