Author: bonefish Date: 2009-12-02 17:12:15 +0100 (Wed, 02 Dec 2009) New Revision: 34447 Changeset: http://dev.haiku-os.org/changeset/34447/haiku Modified: haiku/trunk/headers/private/kernel/vm.h haiku/trunk/headers/private/kernel/vm_address_space.h haiku/trunk/headers/private/kernel/vm_types.h haiku/trunk/src/system/kernel/arch/arm/arch_vm.cpp haiku/trunk/src/system/kernel/arch/generic/generic_vm_physical_page_mapper.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_int.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_thread.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_vm.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_int.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/arch/x86/x86_physical_page_mapper_large_memory.cpp haiku/trunk/src/system/kernel/device_manager/IORequest.cpp haiku/trunk/src/system/kernel/elf.cpp haiku/trunk/src/system/kernel/slab/Slab.cpp haiku/trunk/src/system/kernel/team.cpp haiku/trunk/src/system/kernel/thread.cpp haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_address_space.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: * Moved VMAddressSpace definition to vm_address_space.h. * "Classified" VMAddressSpace, i.e. turned the vm_address_space_*() functions into methods, made all attributes (but "areas") private, and added accessors. * Also turned the vm.cpp functions vm_area_lookup() and remove_area_from_address_space() into VMAddressSpace methods. The rest of the area management functionality will follow soon. Modified: haiku/trunk/headers/private/kernel/vm.h =================================================================== --- haiku/trunk/headers/private/kernel/vm.h 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/headers/private/kernel/vm.h 2009-12-02 16:12:15 UTC (rev 34447) @@ -87,8 +87,6 @@ area_id sourceArea, bool kernel); status_t vm_delete_area(team_id teamID, area_id areaID, bool kernel); status_t vm_create_vnode_cache(struct vnode *vnode, struct VMCache **_cache); -struct VMArea *vm_area_lookup(struct VMAddressSpace *addressSpace, - addr_t address); status_t vm_set_area_memory_type(area_id id, addr_t physicalBase, uint32 type); status_t vm_get_page_mapping(team_id team, addr_t vaddr, addr_t *paddr); bool vm_test_map_modification(struct vm_page *page); Modified: haiku/trunk/headers/private/kernel/vm_address_space.h =================================================================== --- haiku/trunk/headers/private/kernel/vm_address_space.h 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/headers/private/kernel/vm_address_space.h 2009-12-02 16:12:15 UTC (rev 34447) @@ -1,4 +1,5 @@ /* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx * Copyright 2002-2008, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved. * Distributed under the terms of the MIT License. * @@ -11,33 +12,107 @@ #include <OS.h> +#include <vm_translation_map.h> -struct kernel_args; -struct VMAddressSpace; +struct VMArea; + +struct VMAddressSpace { + VMAddressSpace(team_id id, addr_t base, + size_t size, bool kernel); + ~VMAddressSpace(); + + static status_t Init(); + static status_t InitPostSem(); + + team_id ID() const { return fID; } + addr_t Base() const { return fBase; } + size_t Size() const { return fSize; } + bool IsBeingDeleted() const { return fDeleting; } + + vm_translation_map& TranslationMap() { return fTranslationMap; } + + status_t ReadLock() + { return rw_lock_read_lock(&fLock); } + void ReadUnlock() + { rw_lock_read_unlock(&fLock); } + status_t WriteLock() + { return rw_lock_write_lock(&fLock); } + void WriteUnlock() + { rw_lock_write_unlock(&fLock); } + + int32 RefCount() const + { return fRefCount; } + + void Get() { atomic_add(&fRefCount, 1); } + void Put(); + void RemoveAndPut(); + + void IncrementFaultCount() + { atomic_add(&fFaultCount, 1); } + void IncrementChangeCount() + { fChangeCount++; } + + VMArea* LookupArea(addr_t address); + void RemoveArea(VMArea* area); + + static status_t Create(team_id teamID, addr_t base, size_t size, + bool kernel, + VMAddressSpace** _addressSpace); + + static team_id KernelID() + { return sKernelAddressSpace->ID(); } + static VMAddressSpace* Kernel() + { return sKernelAddressSpace; } + static VMAddressSpace* GetKernel(); + + static team_id CurrentID(); + static VMAddressSpace* GetCurrent(); + + static VMAddressSpace* Get(team_id teamID); + + VMAddressSpace*& HashTableLink() { return fHashTableLink; } + + void Dump() const; + +private: + static int _DumpCommand(int argc, char** argv); + static int _DumpListCommand(int argc, char** argv); + +public: + VMArea* areas; + +private: + struct HashDefinition; + +private: + VMAddressSpace* fHashTableLink; + addr_t fBase; + size_t fSize; + rw_lock fLock; + team_id fID; + int32 fRefCount; + int32 fFaultCount; + int32 fChangeCount; + vm_translation_map fTranslationMap; + VMArea* fAreaHint; + bool fDeleting; + static VMAddressSpace* sKernelAddressSpace; +}; + + + #ifdef __cplusplus extern "C" { #endif -status_t vm_address_space_init(void); -status_t vm_address_space_init_post_sem(void); - -void vm_delete_address_space(struct VMAddressSpace *aspace); -status_t vm_create_address_space(team_id id, addr_t base, addr_t size, - bool kernel, struct VMAddressSpace **_aspace); status_t vm_delete_areas(struct VMAddressSpace *aspace); -struct VMAddressSpace *vm_get_kernel_address_space(void); -struct VMAddressSpace *vm_kernel_address_space(void); -team_id vm_kernel_address_space_id(void); -struct VMAddressSpace *vm_get_current_user_address_space(void); -team_id vm_current_user_address_space_id(void); -struct VMAddressSpace *vm_get_address_space(team_id team); -void vm_put_address_space(struct VMAddressSpace *aspace); #define vm_swap_address_space(from, to) arch_vm_aspace_swap(from, to) #ifdef __cplusplus } #endif + #endif /* _KERNEL_VM_ADDRESS_SPACE_H */ Modified: haiku/trunk/headers/private/kernel/vm_types.h =================================================================== --- haiku/trunk/headers/private/kernel/vm_types.h 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/headers/private/kernel/vm_types.h 2009-12-02 16:12:15 UTC (rev 34447) @@ -1,4 +1,5 @@ /* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx * Copyright 2002-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx * Distributed under the terms of the MIT License. * @@ -307,28 +308,10 @@ struct VMArea* cache_next; struct VMArea* cache_prev; struct VMArea* hash_next; -}; - -enum { - VM_ASPACE_STATE_NORMAL = 0, - VM_ASPACE_STATE_DELETION + bool ContainsAddress(addr_t address) const + { return address >= base && address <= base + (size - 1); } }; -struct VMAddressSpace { - struct VMArea* areas; - struct VMArea* area_hint; - rw_lock lock; - addr_t base; - addr_t size; - int32 change_count; - vm_translation_map translation_map; - team_id id; - int32 ref_count; - int32 fault_count; - int32 state; - struct VMAddressSpace* hash_next; -}; - #endif // _KERNEL_VM_TYPES_H Modified: haiku/trunk/src/system/kernel/arch/arm/arch_vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/arm/arch_vm.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/arm/arch_vm.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -76,7 +76,7 @@ arch_vm_aspace_swap(struct VMAddressSpace *from, struct VMAddressSpace *to) { #warning ARM:WRITEME -// m68k_set_pgdir(m68k_translation_map_get_pgdir(&to->translation_map)); +// m68k_set_pgdir(m68k_translation_map_get_pgdir(&to->TranslationMap())); } Modified: haiku/trunk/src/system/kernel/arch/generic/generic_vm_physical_page_mapper.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/generic/generic_vm_physical_page_mapper.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/generic/generic_vm_physical_page_mapper.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -307,7 +307,7 @@ TRACE(("generic_vm_physical_page_mapper_init_post_area: creating iospace\n")); temp = (void *)sIOSpaceBase; - area_id ioSpaceArea = vm_create_null_area(vm_kernel_address_space_id(), + area_id ioSpaceArea = vm_create_null_area(VMAddressSpace::KernelID(), "iospace", &temp, B_EXACT_ADDRESS, sIOSpaceSize); if (ioSpaceArea < 0) { panic("generic_vm_physical_page_mapper_init_post_area(): Failed to " Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_int.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_int.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_int.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -69,7 +69,7 @@ //static void *sPICCookie; -void +void arch_int_enable_io_interrupt(int irq) { //if (!sPIC) @@ -81,7 +81,7 @@ } -void +void arch_int_disable_io_interrupt(int irq) { //if (!sPIC) @@ -95,7 +95,7 @@ /* arch_int_*_interrupts() and friends are in arch_asm.S */ -static void +static void print_iframe(struct iframe *frame) { dprintf("iframe at %p:\n", frame); @@ -163,7 +163,7 @@ } extern "C" void m68k_exception_entry(struct iframe *iframe); -void +void m68k_exception_entry(struct iframe *iframe) { int vector = iframe->cpu.vector >> 2; @@ -199,7 +199,7 @@ break; } - + // otherwise, not really panic("page fault in debugger without fault handler! Touching " "address %p from ip %p\n", (void *)fault_address(iframe), @@ -245,7 +245,7 @@ } break; } - + case 24: // spurious interrupt dprintf("spurious interrupt\n"); break; @@ -318,7 +318,7 @@ } -status_t +status_t arch_int_init(kernel_args *args) { status_t err; @@ -334,7 +334,7 @@ vbr = args->arch_args.phys_vbr; /* point VBR to the new table */ asm volatile ("movec %0,%%vbr" : : "r"(vbr):); - + return B_OK; } @@ -457,7 +457,7 @@ { const char *namePrefix = "interrupt_controllers/"; size_t namePrefixLen = strlen(namePrefix); - + char name[B_PATH_NAME_LENGTH]; size_t length; uint32 cookie = 0; @@ -513,7 +513,7 @@ panic("arch_int_init_post_device_manager(): Found no PIC modules!"); return B_ENTRY_NOT_FOUND; } - + // get the device manager module device_manager_info *deviceManager; status_t error = get_module(B_DEVICE_MANAGER_MODULE_NAME, @@ -579,14 +579,14 @@ // translate to physical address addr_t physicalPage; addr_t inPageOffset = (addr_t)context & (B_PAGE_SIZE - 1); - status_t error = vm_get_page_mapping(vm_kernel_address_space_id(), + status_t error = vm_get_page_mapping(VMAddressSpace::KernelID(), (addr_t)context - inPageOffset, &physicalPage); if (error != B_OK) { panic("m68k_set_current_cpu_exception_context(): Failed to get physical " "address!"); return; } - + asm volatile("mtsprg0 %0" : : "r"(physicalPage + inPageOffset)); } Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_thread.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_thread.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -102,16 +102,19 @@ return NULL; } // switching to a new address space - return m68k_translation_map_get_pgdir(&to->team->address_space->translation_map); + return m68k_translation_map_get_pgdir( + &to->team->address_space->TranslationMap()); } else if (from->team->address_space == NULL && to->team->address_space == NULL) { // they must both be kernel space threads return NULL; } else if (to->team->address_space == NULL) { // the one we're switching to is kernel space - return m68k_translation_map_get_pgdir(&vm_kernel_address_space()->translation_map); + return m68k_translation_map_get_pgdir( + &VMAddressSpace::Kernel()->TranslationMap()); } - return m68k_translation_map_get_pgdir(&to->team->address_space->translation_map); + return m68k_translation_map_get_pgdir( + &to->team->address_space->TranslationMap()); } // #pragma mark - Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_vm.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_vm.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -105,7 +105,7 @@ void arch_vm_aspace_swap(struct VMAddressSpace *from, struct VMAddressSpace *to) { - m68k_set_pgdir(m68k_translation_map_get_pgdir(&to->translation_map)); + m68k_set_pgdir(m68k_translation_map_get_pgdir(&to->TranslationMap())); } Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -1190,7 +1190,7 @@ recursive_lock_destroy(&map->lock); return B_NO_MEMORY; } - vm_get_page_mapping(vm_kernel_address_space_id(), + vm_get_page_mapping(VMAddressSpace::KernelID(), (addr_t)map->arch_data->rtdir_virt, (addr_t *)&map->arch_data->rtdir_phys); } else { // kernel @@ -1360,7 +1360,7 @@ // page table, which is not yet enforced (or even tested)! // Note we don't support SMP which makes things simpler. - area = vm_create_null_area(vm_kernel_address_space_id(), + area = vm_create_null_area(VMAddressSpace::KernelID(), "interrupt query pages", (void **)&queryPage, B_ANY_ADDRESS, B_PAGE_SIZE); if (area < B_OK) Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_int.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_int.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_int.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -49,7 +49,7 @@ static void *sPICCookie; -void +void arch_int_enable_io_interrupt(int irq) { if (!sPIC) @@ -60,7 +60,7 @@ } -void +void arch_int_disable_io_interrupt(int irq) { if (!sPIC) @@ -73,7 +73,7 @@ /* arch_int_*_interrupts() and friends are in arch_asm.S */ -static void +static void print_iframe(struct iframe *frame) { dprintf("iframe at %p:\n", frame); @@ -93,7 +93,7 @@ extern "C" void ppc_exception_entry(int vector, struct iframe *iframe); -void +void ppc_exception_entry(int vector, struct iframe *iframe) { int ret = B_HANDLED_INTERRUPT; @@ -165,7 +165,7 @@ } break; } - + case 0x500: // external interrupt { if (!sPIC) { @@ -251,7 +251,7 @@ } -status_t +status_t arch_int_init(kernel_args *args) { return B_OK; @@ -279,7 +279,7 @@ // create a region to map the irq vector code into (physical address 0x0) area_id exceptionArea = create_area("exception_handlers", - &handlers, B_EXACT_ADDRESS, args->arch_args.exception_handlers.size, + &handlers, B_EXACT_ADDRESS, args->arch_args.exception_handlers.size, B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); if (exceptionArea < B_OK) panic("arch_int_init2: could not create exception handler region\n"); @@ -415,7 +415,7 @@ { const char *namePrefix = "interrupt_controllers/"; size_t namePrefixLen = strlen(namePrefix); - + char name[B_PATH_NAME_LENGTH]; size_t length; uint32 cookie = 0; @@ -470,7 +470,7 @@ panic("arch_int_init_post_device_manager(): Found no PIC modules!"); return B_ENTRY_NOT_FOUND; } - + // get the device manager module device_manager_info *deviceManager; status_t error = get_module(B_DEVICE_MANAGER_MODULE_NAME, @@ -536,14 +536,14 @@ // translate to physical address addr_t physicalPage; addr_t inPageOffset = (addr_t)context & (B_PAGE_SIZE - 1); - status_t error = vm_get_page_mapping(vm_kernel_address_space_id(), + status_t error = vm_get_page_mapping(VMAddressSpace::KernelID(), (addr_t)context - inPageOffset, &physicalPage); if (error != B_OK) { panic("ppc_set_current_cpu_exception_context(): Failed to get physical " "address!"); return; } - + asm volatile("mtsprg0 %0" : : "r"(physicalPage + inPageOffset)); } Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -17,6 +17,7 @@ #include <boot/stage2.h> #include <kernel.h> #include <thread.h> +#include <vm_address_space.h> #include <vm_types.h> //#include <arch/vm_translation_map.h> @@ -189,7 +190,8 @@ // the target thread has is user space if (t_from->team != t_to->team) { // switching to a new address space - ppc_translation_map_change_asid(&t_to->team->address_space->translation_map); + ppc_translation_map_change_asid( + &t_to->team->address_space->TranslationMap()); } } Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -681,12 +681,12 @@ virtualAddress = ROUNDDOWN(virtualAddress, B_PAGE_SIZE); physicalAddress = ROUNDDOWN(physicalAddress, B_PAGE_SIZE); - VMAddressSpace *addressSpace = vm_kernel_address_space(); + VMAddressSpace *addressSpace = VMAddressSpace::Kernel(); // map the pages for (; virtualAddress < virtualEnd; virtualAddress += B_PAGE_SIZE, physicalAddress += B_PAGE_SIZE) { - status_t error = map_tmap(&addressSpace->translation_map, + status_t error = map_tmap(&addressSpace->TranslationMap(), virtualAddress, physicalAddress, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); if (error != B_OK) @@ -703,10 +703,11 @@ addr_t virtualEnd = ROUNDUP(virtualAddress + size, B_PAGE_SIZE); virtualAddress = ROUNDDOWN(virtualAddress, B_PAGE_SIZE); - VMAddressSpace *addressSpace = vm_kernel_address_space(); + VMAddressSpace *addressSpace = VMAddressSpace::Kernel(); for (0; virtualAddress < virtualEnd; virtualAddress += B_PAGE_SIZE) - remove_page_table_entry(&addressSpace->translation_map, virtualAddress); + remove_page_table_entry(&addressSpace->TranslationMap(), + virtualAddress); } @@ -716,18 +717,18 @@ addr_t virtualAddress = ROUNDDOWN(*_virtualAddress, B_PAGE_SIZE); size = ROUNDUP(*_virtualAddress + size - virtualAddress, B_PAGE_SIZE); - VMAddressSpace *addressSpace = vm_kernel_address_space(); + VMAddressSpace *addressSpace = VMAddressSpace::Kernel(); // reserve space in the address space void *newAddress = NULL; - status_t error = vm_reserve_address_range(addressSpace->id, &newAddress, + status_t error = vm_reserve_address_range(addressSpace->ID(), &newAddress, B_ANY_KERNEL_ADDRESS, size, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); if (error != B_OK) return error; // get the area's first physical page page_table_entry *entry = lookup_page_table_entry( - &addressSpace->translation_map, virtualAddress); + &addressSpace->TranslationMap(), virtualAddress); if (!entry) return B_ERROR; addr_t physicalBase = entry->physical_page_number << 12; Modified: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -652,7 +652,7 @@ B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); vm_translation_map_arch_info* kernelArchTranslationMap - = vm_kernel_address_space()->translation_map.arch_data; + = VMAddressSpace::Kernel()->TranslationMap().arch_data; // setup task-state segments for (i = 0; i < args->num_cpus; i++) { Modified: haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -21,6 +21,7 @@ #include <kimage.h> #include <thread.h> #include <vm.h> +#include <vm_address_space.h> #include <vm_types.h> #include <arch_cpu.h> @@ -297,7 +298,7 @@ VMArea *area = NULL; if (thread != NULL && thread->team != NULL && thread->team->address_space != NULL) { - area = vm_area_lookup(thread->team->address_space, eip); + area = thread->team->address_space->LookupArea(eip); } if (area != NULL) { kprintf("%ld:%s@%p + %#lx\n", area->id, area->name, @@ -643,7 +644,7 @@ } else { VMArea *area = NULL; if (thread->team->address_space != NULL) - area = vm_area_lookup(thread->team->address_space, eip); + area = thread->team->address_space->LookupArea(eip); if (area != NULL) { kprintf("%ld:%s@%p + %#lx", area->id, area->name, (void *)area->base, eip - area->base); Modified: haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -196,9 +196,9 @@ } if (toAddressSpace == NULL) - toAddressSpace = vm_kernel_address_space(); + toAddressSpace = VMAddressSpace::Kernel(); - return i386_translation_map_get_pgdir(&toAddressSpace->translation_map); + return i386_translation_map_get_pgdir(&toAddressSpace->TranslationMap()); } @@ -377,7 +377,7 @@ addr_t newPageDirectory; vm_translation_map_arch_info* toMap; if (toAddressSpace != NULL - && (toMap = toAddressSpace->translation_map.arch_data) != activeMap) { + && (toMap = toAddressSpace->TranslationMap().arch_data) != activeMap) { // update on which CPUs the address space is used int cpu = cpuData->cpu_num; atomic_and(&activeMap->active_on_cpus, ~((uint32)1 << cpu)); Modified: haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -781,7 +781,7 @@ map->arch_data->page_mapper->Delete(); return B_NO_MEMORY; } - vm_get_page_mapping(vm_kernel_address_space_id(), + vm_get_page_mapping(VMAddressSpace::KernelID(), (addr_t)map->arch_data->pgdir_virt, (addr_t*)&map->arch_data->pgdir_phys); } else { Modified: haiku/trunk/src/system/kernel/arch/x86/x86_physical_page_mapper_large_memory.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/x86_physical_page_mapper_large_memory.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/arch/x86/x86_physical_page_mapper_large_memory.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -536,7 +536,7 @@ // create an area for the virtual address space temp = (void*)fInitialPool.virtualBase; - area = vm_create_null_area(vm_kernel_address_space_id(), + area = vm_create_null_area(VMAddressSpace::KernelID(), "physical page pool space", &temp, B_EXACT_ADDRESS, 1024 * B_PAGE_SIZE); if (area < B_OK) { @@ -736,7 +736,7 @@ // create the null area for the virtual address space void* virtualBase; area_id virtualArea = vm_create_null_area( - vm_kernel_address_space_id(), "physical page pool space", + VMAddressSpace::KernelID(), "physical page pool space", &virtualBase, B_ANY_KERNEL_BLOCK_ADDRESS, 1024 * B_PAGE_SIZE); if (virtualArea < 0) { delete_area(dataArea); @@ -748,7 +748,7 @@ // get the page table's physical address addr_t physicalTable; - vm_translation_map* map = &vm_kernel_address_space()->translation_map; + vm_translation_map* map = &VMAddressSpace::Kernel()->TranslationMap(); uint32 dummyFlags; cpu_status state = disable_interrupts(); map->ops->query_interrupt(map, (addr_t)data, &physicalTable, Modified: haiku/trunk/src/system/kernel/device_manager/IORequest.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/IORequest.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/device_manager/IORequest.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -162,7 +162,7 @@ addr_t mappedSize; cookie->mapped_area = vm_map_physical_memory_vecs( - vm_kernel_address_space_id(), "io buffer mapped physical vecs", + VMAddressSpace::KernelID(), "io buffer mapped physical vecs", &mappedAddress, B_ANY_KERNEL_ADDRESS, &mappedSize, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, fVecs, fVecCount); Modified: haiku/trunk/src/system/kernel/elf.cpp =================================================================== --- haiku/trunk/src/system/kernel/elf.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/elf.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -2062,7 +2062,7 @@ } // reserve that space and allocate the areas from that one - if (vm_reserve_address_range(vm_kernel_address_space_id(), &reservedAddress, + if (vm_reserve_address_range(VMAddressSpace::KernelID(), &reservedAddress, B_ANY_KERNEL_ADDRESS, reservedSize, 0) < B_OK) { status = B_NO_MEMORY; goto error3; @@ -2183,7 +2183,7 @@ // There might be a hole between the two segments, and we don't need to // reserve this any longer - vm_unreserve_address_range(vm_kernel_address_space_id(), reservedAddress, + vm_unreserve_address_range(VMAddressSpace::KernelID(), reservedAddress, reservedSize); // ToDo: this should be enabled by kernel settings! @@ -2203,7 +2203,7 @@ error5: error4: - vm_unreserve_address_range(vm_kernel_address_space_id(), reservedAddress, + vm_unreserve_address_range(VMAddressSpace::KernelID(), reservedAddress, reservedSize); error3: free(programHeaders); Modified: haiku/trunk/src/system/kernel/slab/Slab.cpp =================================================================== --- haiku/trunk/src/system/kernel/slab/Slab.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/slab/Slab.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -465,7 +465,7 @@ // if we are allocating, it is because we need the pages immediatly // so we lock them. when moving the slab to the empty list we should // unlock them, and lock them again when getting one from the empty list. - area_id areaId = create_area_etc(vm_kernel_address_space_id(), + area_id areaId = create_area_etc(VMAddressSpace::KernelID(), cache->name, pages, addressSpec, cache->slab_size, lock, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, 0, (flags & CACHE_DONT_SLEEP) != 0 ? CREATE_AREA_DONT_WAIT : 0); Modified: haiku/trunk/src/system/kernel/team.cpp =================================================================== --- haiku/trunk/src/system/kernel/team.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/team.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -1229,7 +1229,7 @@ vfs_exec_io_context(team->io_context); // create an address space for this team - status = vm_create_address_space(team->id, USER_BASE, USER_SIZE, false, + status = VMAddressSpace::Create(team->id, USER_BASE, USER_SIZE, false, &team->address_space); if (status != B_OK) goto err3; @@ -1301,7 +1301,7 @@ sNotificationService.Notify(TEAM_REMOVED, team); delete_team_user_data(team); err4: - vm_put_address_space(team->address_space); + team->address_space->Put(); err3: vfs_put_io_context(team->io_context); err2: @@ -1567,7 +1567,7 @@ } // create an address space for this team - status = vm_create_address_space(team->id, USER_BASE, USER_SIZE, false, + status = VMAddressSpace::Create(team->id, USER_BASE, USER_SIZE, false, &team->address_space); if (status < B_OK) goto err3; @@ -1590,7 +1590,7 @@ forkArgs->user_thread = team_allocate_user_thread(team); } else { void* address; - area_id area = vm_copy_area(team->address_space->id, info.name, + area_id area = vm_copy_area(team->address_space->ID(), info.name, &address, B_CLONE_ADDRESS, info.protection, info.area); if (area < B_OK) { status = area; @@ -1659,7 +1659,7 @@ sNotificationService.Notify(TEAM_REMOVED, team); remove_images(team); err4: - vm_delete_address_space(team->address_space); + team->address_space->RemoveAndPut(); err3: delete_realtime_sem_context(team->realtime_sem_context); err25: @@ -2488,7 +2488,7 @@ delete_owned_ports(team); sem_delete_owned_sems(team); remove_images(team); - vm_delete_address_space(team->address_space); + team->address_space->RemoveAndPut(); delete_team_struct(team); @@ -2532,7 +2532,7 @@ if (id == 1) { // we're the kernel team, so we don't have to go through all // the hassle (locking and hash lookup) - *_addressSpace = vm_get_kernel_address_space(); + *_addressSpace = VMAddressSpace::GetKernel(); return B_OK; } @@ -2541,7 +2541,7 @@ team = team_get_team_struct_locked(id); if (team != NULL) { - atomic_add(&team->address_space->ref_count, 1); + team->address_space->Get(); *_addressSpace = team->address_space; status = B_OK; } else Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/thread.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -1496,7 +1496,7 @@ RELEASE_TEAM_LOCK(); // swap address spaces, to make sure we're running on the kernel's pgdir - vm_swap_address_space(team->address_space, vm_kernel_address_space()); + vm_swap_address_space(team->address_space, VMAddressSpace::Kernel()); restore_interrupts(state); TRACE(("thread_exit: thread %ld now a kernel thread!\n", thread->id)); Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2009-12-02 14:10:17 UTC (rev 34446) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2009-12-02 16:12:15 UTC (rev 34447) @@ -274,18 +274,18 @@ { Unlock(); if (fSpace != NULL) - vm_put_address_space(fSpace); + fSpace->Put(); } status_t AddressSpaceReadLocker::SetTo(team_id team) { - fSpace = vm_get_address_space(team); + fSpace = VMAddressSpace::Get(team); if (fSpace == NULL) return B_BAD_TEAM_ID; - rw_lock_read_lock(&fSpace->lock); + fSpace->ReadLock(); fLocked = true; return B_OK; } @@ -300,9 +300,9 @@ fSpace = space; if (getNewReference) - atomic_add(&fSpace->ref_count, 1); + fSpace->Get(); - rw_lock_read_lock(&fSpace->lock); + fSpace->ReadLock(); fLocked = true; } @@ -314,14 +314,14 @@ if (fSpace == NULL) return B_BAD_TEAM_ID; - rw_lock_read_lock(&fSpace->lock); + fSpace->ReadLock(); rw_lock_read_lock(&sAreaHashLock); area = (VMArea*)hash_lookup(sAreaHash, &areaID); rw_lock_read_unlock(&sAreaHashLock); if (area == NULL || area->address_space != fSpace) { - rw_lock_read_unlock(&fSpace->lock); + fSpace->ReadUnlock(); return B_BAD_VALUE; } @@ -338,7 +338,7 @@ if (fSpace == NULL) return false; - rw_lock_read_lock(&fSpace->lock); + fSpace->ReadLock(); fLocked = true; return true; @@ -349,7 +349,7 @@ AddressSpaceReadLocker::Unlock() { if (fLocked) { - rw_lock_read_unlock(&fSpace->lock); + fSpace->ReadUnlock(); fLocked = false; } } @@ -388,18 +388,18 @@ { Unlock(); if (fSpace != NULL) - vm_put_address_space(fSpace); + fSpace->Put(); } status_t AddressSpaceWriteLocker::SetTo(team_id team) { - fSpace = vm_get_address_space(team); + fSpace = VMAddressSpace::Get(team); if (fSpace == NULL) return B_BAD_TEAM_ID; - rw_lock_write_lock(&fSpace->lock); + fSpace->WriteLock(); fLocked = true; return B_OK; } @@ -412,14 +412,14 @@ if (fSpace == NULL) return B_BAD_VALUE; - rw_lock_write_lock(&fSpace->lock); + fSpace->WriteLock(); rw_lock_read_lock(&sAreaHashLock); area = (VMArea*)hash_lookup(sAreaHash, &areaID); rw_lock_read_unlock(&sAreaHashLock); if (area == NULL || area->address_space != fSpace) { - rw_lock_write_unlock(&fSpace->lock); + fSpace->WriteUnlock(); return B_BAD_VALUE; } @@ -436,10 +436,10 @@ area = (VMArea*)hash_lookup(sAreaHash, &areaID); if (area != NULL - && (area->address_space->id == team - || (allowKernel && team == vm_kernel_address_space_id()))) { + && (area->address_space->ID() == team + || (allowKernel && team == VMAddressSpace::KernelID()))) { fSpace = area->address_space; - atomic_add(&fSpace->ref_count, 1); + fSpace->Get(); } rw_lock_read_unlock(&sAreaHashLock); @@ -450,14 +450,14 @@ // Second try to get the area -- this time with the address space // write lock held - rw_lock_write_lock(&fSpace->lock); + fSpace->WriteLock(); rw_lock_read_lock(&sAreaHashLock); area = (VMArea*)hash_lookup(sAreaHash, &areaID); rw_lock_read_unlock(&sAreaHashLock); if (area == NULL) { - rw_lock_write_unlock(&fSpace->lock); + fSpace->WriteUnlock(); return B_BAD_VALUE; } @@ -479,9 +479,9 @@ { if (fLocked) { if (fDegraded) - rw_lock_read_unlock(&fSpace->lock); + fSpace->ReadUnlock(); else - rw_lock_write_unlock(&fSpace->lock); + fSpace->WriteUnlock(); fLocked = false; fDegraded = false; } [... truncated: 1773 lines follow ...]