xref: /haiku/src/system/kernel/vm/VMKernelAddressSpace.h (revision c90684742e7361651849be4116d0e5de3a817194)
1 /*
2  * Copyright 2009-2010, 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 VMKernelAddressSpace : VMAddressSpace {
15 public:
16 								VMKernelAddressSpace(team_id id, addr_t base,
17 									size_t size);
18 	virtual						~VMKernelAddressSpace();
19 
20 	virtual	status_t			InitObject();
21 
22 	virtual	VMArea*				FirstArea() const;
23 	virtual	VMArea*				NextArea(VMArea* area) const;
24 
25 	virtual	VMArea*				LookupArea(addr_t address) const;
26 	virtual	VMArea*				CreateArea(const char* name, uint32 wiring,
27 									uint32 protection, uint32 allocationFlags);
28 	virtual	void				DeleteArea(VMArea* area,
29 									uint32 allocationFlags);
30 	virtual	status_t			InsertArea(VMArea* area, size_t size,
31 									const virtual_address_restrictions*
32 										addressRestrictions,
33 									uint32 allocationFlags, void** _address);
34 	virtual	void				RemoveArea(VMArea* area,
35 									uint32 allocationFlags);
36 
37 	virtual	bool				CanResizeArea(VMArea* area, size_t newSize);
38 	virtual	status_t			ResizeArea(VMArea* area, size_t newSize,
39 									uint32 allocationFlags);
40 	virtual	status_t			ShrinkAreaHead(VMArea* area, size_t newSize,
41 									uint32 allocationFlags);
42 	virtual	status_t			ShrinkAreaTail(VMArea* area, size_t newSize,
43 									uint32 allocationFlags);
44 
45 	virtual	status_t			ReserveAddressRange(size_t size,
46 									const virtual_address_restrictions*
47 										addressRestrictions,
48 									uint32 flags, uint32 allocationFlags,
49 									void** _address);
50 	virtual	status_t			UnreserveAddressRange(addr_t address,
51 									size_t size, uint32 allocationFlags);
52 	virtual	void				UnreserveAllAddressRanges(
53 									uint32 allocationFlags);
54 
55 	virtual	void				Dump() const;
56 
57 private:
58 			typedef VMKernelAddressRange Range;
59 			typedef VMKernelAddressRangeTree RangeTree;
60 			typedef DoublyLinkedList<Range,
61 				DoublyLinkedListMemberGetLink<Range, &Range::listLink> >
62 					RangeList;
63 			typedef DoublyLinkedList<Range, VMKernelAddressRangeGetFreeListLink>
64 				RangeFreeList;
65 
66 private:
67 	inline	void				_FreeListInsertRange(Range* range, size_t size);
68 	inline	void				_FreeListRemoveRange(Range* range, size_t size);
69 
70 			void				_InsertRange(Range* range);
71 			void				_RemoveRange(Range* range);
72 
73 			status_t			_AllocateRange(
74 									const virtual_address_restrictions*
75 										addressRestrictions,
76 									size_t size, bool allowReservedRange,
77 									uint32 allocationFlags, Range*& _range);
78 			Range*				_FindFreeRange(addr_t start, size_t size,
79 									size_t alignment, uint32 addressSpec,
80 									bool allowReservedRange,
81 									addr_t& _foundAddress);
82 			void				_FreeRange(Range* range,
83 									uint32 allocationFlags);
84 
85 			void				_CheckStructures() const;
86 
87 private:
88 			RangeTree			fRangeTree;
89 			RangeList			fRangeList;
90 			RangeFreeList*		fFreeLists;
91 			int					fFreeListCount;
92 };
93 
94 
95 #endif	/* VM_KERNEL_ADDRESS_SPACE_H */
96