1 /* 2 * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef VM_KERNEL_ADDRESS_SPACE_H 6 #define VM_KERNEL_ADDRESS_SPACE_H 7 8 9 #include <vm/VMAddressSpace.h> 10 11 #include "VMKernelArea.h" 12 13 14 struct ObjectCache; 15 16 17 struct VMKernelAddressSpace : VMAddressSpace { 18 public: 19 VMKernelAddressSpace(team_id id, addr_t base, 20 size_t size); 21 virtual ~VMKernelAddressSpace(); 22 23 virtual status_t InitObject(); 24 25 virtual VMArea* FirstArea() const; 26 virtual VMArea* NextArea(VMArea* area) const; 27 28 virtual VMArea* LookupArea(addr_t address) const; 29 virtual VMArea* FindClosestArea(addr_t address, bool less) 30 const; 31 virtual VMArea* CreateArea(const char* name, uint32 wiring, 32 uint32 protection, uint32 allocationFlags); 33 virtual void DeleteArea(VMArea* area, 34 uint32 allocationFlags); 35 virtual status_t InsertArea(VMArea* area, size_t size, 36 const virtual_address_restrictions* 37 addressRestrictions, 38 uint32 allocationFlags, void** _address); 39 virtual void RemoveArea(VMArea* area, 40 uint32 allocationFlags); 41 42 virtual bool CanResizeArea(VMArea* area, size_t newSize); 43 virtual status_t ResizeArea(VMArea* area, size_t newSize, 44 uint32 allocationFlags); 45 virtual status_t ShrinkAreaHead(VMArea* area, size_t newSize, 46 uint32 allocationFlags); 47 virtual status_t ShrinkAreaTail(VMArea* area, size_t newSize, 48 uint32 allocationFlags); 49 50 virtual status_t ReserveAddressRange(size_t size, 51 const virtual_address_restrictions* 52 addressRestrictions, 53 uint32 flags, uint32 allocationFlags, 54 void** _address); 55 virtual status_t UnreserveAddressRange(addr_t address, 56 size_t size, uint32 allocationFlags); 57 virtual void UnreserveAllAddressRanges( 58 uint32 allocationFlags); 59 60 virtual void Dump() const; 61 62 private: 63 typedef VMKernelAddressRange Range; 64 typedef VMKernelAddressRangeTree RangeTree; 65 typedef DoublyLinkedList<Range, 66 DoublyLinkedListMemberGetLink<Range, &Range::listLink> > 67 RangeList; 68 typedef DoublyLinkedList<Range, VMKernelAddressRangeGetFreeListLink> 69 RangeFreeList; 70 71 private: 72 inline void _FreeListInsertRange(Range* range, size_t size); 73 inline void _FreeListRemoveRange(Range* range, size_t size); 74 75 void _InsertRange(Range* range); 76 void _RemoveRange(Range* range); 77 78 status_t _AllocateRange( 79 const virtual_address_restrictions* 80 addressRestrictions, 81 size_t size, bool allowReservedRange, 82 uint32 allocationFlags, Range*& _range); 83 Range* _FindFreeRange(addr_t start, size_t size, 84 size_t alignment, uint32 addressSpec, 85 bool allowReservedRange, 86 addr_t& _foundAddress); 87 void _FreeRange(Range* range, 88 uint32 allocationFlags); 89 90 void _CheckStructures() const; 91 92 private: 93 RangeTree fRangeTree; 94 RangeList fRangeList; 95 RangeFreeList* fFreeLists; 96 int fFreeListCount; 97 ObjectCache* fAreaObjectCache; 98 ObjectCache* fRangesObjectCache; 99 }; 100 101 102 #endif /* VM_KERNEL_ADDRESS_SPACE_H */ 103