rem: unsigned int flags, flags2;
add: uint32 flags, flags2;
context: scan_pages(vm_address_space *aspace, addr free_target){	vm_region *first_region;	vm_region *region;	vm_page *page;	addr va;	addr pa;	unsigned int flags, flags2;//	int err;	int quantum = PAGE_SCAN_QUANTUM;//	dprintf("scan_pages called on aspace 0x%x, id 0x%x, free_target %d\n", aspace, aspace->id, free_target);	acquire_sem_etc(aspace->virtual_map.sem, READ_COUNT, 0, 0);	first_region = aspace->virtual_map.region_list;	while (first_region && (first_region->base + (first_region->size - 1)) < aspace->scan_va)		first_region = first_region->aspace_next;	if (!first_region)		first_region = aspace->virtual_map.region_list;	if (!first_region) {		release_sem_etc(aspace->virtual_map.sem, READ_COUNT, 0);		return;	}	region = first_region;	for (;;) {		// ignore reserved ranges		while (region != NULL && region->id == RESERVED_REGION_ID)			region = region->aspace_next;		if (region == NULL)			break;		// scan the pages in this region		mutex_lock(&region->cache_ref->lock);		if (!region->cache_ref->cache->scan_skip) {			for(va = region->base; va < (region->base + region->size); va += PAGE_SIZE) {				aspace->translation_map.ops->lock(&aspace->translation_map);				aspace->translation_map.ops->query(&aspace->translation_map, va, &pa, &flags);				if ((flags & PAGE_PRESENT) == 0) {					aspace->translation_map.ops->unlock(&aspace->translation_map);					continue;				}				page = vm_lookup_page(pa / PAGE_SIZE);				if (!page) {					aspace->translation_map.ops->unlock(&aspace->translation_map);					continue;				}				// see if this page is busy, if it is lets forget it and move on				if (page->state == PAGE_STATE_BUSY || page->state == PAGE_STATE_WIRED) {					aspace->translation_map.ops->unlock(&aspace->translation_map);					continue;				}				flags2 = 0;				if (free_target > 0) {					// look for a page we can steal					if (!(flags & PAGE_ACCESSED) && page->state == PAGE_STATE_ACTIVE) {						// unmap the page						aspace->translation_map.ops->unmap(&aspace->translation_map, va, va + PAGE_SIZE);						// flush the tlbs of all cpus						aspace->translation_map.ops->flush(&aspace->translation_map);						// re-query the flags on the old pte, to make sure we have accurate modified bit data						aspace->translation_map.ops->query(&aspace->translation_map, va, &pa, &flags2);						// clear the modified and accessed bits on the entries						aspace->translation_map.ops->clear_flags(&aspace->translation_map, va, PAGE_MODIFIED|PAGE_ACCESSED);						// decrement the ref count on the page. If we just unmapped it for the last time,						// put the page on the inactive list						if (atomic_add(&page->ref_count, -1) == 1) {							vm_page_set_state(page, PAGE_STATE_INACTIVE);							free_target--;						}					}				}				// if the page is modified, but the state is active or inactive, put it on the modified list				if (((flags & PAGE_MODIFIED) || (flags2 & PAGE_MODIFIED))					&& (page->state == PAGE_STATE_ACTIVE || page->state == PAGE_STATE_INACTIVE)) {					vm_page_set_state(page, PAGE_STATE_MODIFIED);				}				aspace->translation_map.ops->unlock(&aspace->translation_map);				if (--quantum == 0)					break;			}		}		mutex_unlock(&region->cache_ref->lock);		// move to the next region, wrapping around and stopping if we get back to the first region		region = region->aspace_next ? region->aspace_next : aspace->virtual_map.region_list;		if (region == first_region)			break;		if (quantum == 0)			break;	}	aspace->scan_va = region ? (first_region->base + first_region->size) : aspace->virtual_map.base;	release_sem_etc(aspace->virtual_map.sem, READ_COUNT, 0);//	dprintf("exiting scan_pages\n");}