1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef VM_USER_ADDRESS_SPACE_H 6 #define VM_USER_ADDRESS_SPACE_H 7 8 9 #include <vm/VMAddressSpace.h> 10 11 #include "VMUserArea.h" 12 13 14 struct VMUserAddressSpace : VMAddressSpace { 15 public: 16 VMUserAddressSpace(team_id id, addr_t base, 17 size_t size); 18 virtual ~VMUserAddressSpace(); 19 20 virtual VMArea* FirstArea() const; 21 virtual VMArea* NextArea(VMArea* area) const; 22 23 virtual VMArea* LookupArea(addr_t address) const; 24 virtual VMArea* CreateArea(const char* name, uint32 wiring, 25 uint32 protection, uint32 allocationFlags); 26 virtual void DeleteArea(VMArea* area, 27 uint32 allocationFlags); 28 virtual status_t InsertArea(VMArea* area, size_t size, 29 const virtual_address_restrictions* 30 addressRestrictions, 31 uint32 allocationFlags, void** _address); 32 virtual void RemoveArea(VMArea* area, 33 uint32 allocationFlags); 34 35 virtual bool CanResizeArea(VMArea* area, size_t newSize); 36 virtual status_t ResizeArea(VMArea* area, size_t newSize, 37 uint32 allocationFlags); 38 virtual status_t ShrinkAreaHead(VMArea* area, size_t newSize, 39 uint32 allocationFlags); 40 virtual status_t ShrinkAreaTail(VMArea* area, size_t newSize, 41 uint32 allocationFlags); 42 43 virtual status_t ReserveAddressRange(size_t size, 44 const virtual_address_restrictions* 45 addressRestrictions, 46 uint32 flags, uint32 allocationFlags, 47 void** _address); 48 virtual status_t UnreserveAddressRange(addr_t address, 49 size_t size, uint32 allocationFlags); 50 virtual void UnreserveAllAddressRanges( 51 uint32 allocationFlags); 52 53 virtual void Dump() const; 54 55 private: 56 inline bool _IsRandomized(uint32 addressSpec) const; 57 static addr_t _RandomizeAddress(addr_t start, addr_t end, 58 size_t alignment, bool initial = false); 59 60 status_t _InsertAreaIntoReservedRegion(addr_t start, 61 size_t size, VMUserArea* area, 62 uint32 allocationFlags); 63 status_t _InsertAreaSlot(addr_t start, addr_t size, 64 addr_t end, uint32 addressSpec, 65 size_t alignment, VMUserArea* area, 66 uint32 allocationFlags); 67 68 private: 69 static const addr_t kMaxRandomize; 70 static const addr_t kMaxInitialRandomize; 71 72 VMUserAreaList fAreas; 73 mutable VMUserArea* fAreaHint; 74 }; 75 76 77 #endif /* VM_USER_ADDRESS_SPACE_H */ 78