xref: /haiku/src/system/kernel/vm/VMUserAddressSpace.h (revision 909af08f4328301fbdef1ffb41f566c3b5bec0c7)
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 final : 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*				FindClosestArea(addr_t address, bool less)
25 									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 	inline	bool				_IsRandomized(uint32 addressSpec) const;
59 	static	addr_t				_RandomizeAddress(addr_t start, addr_t end,
60 									size_t alignment, bool initial = false);
61 
62 			status_t			_InsertAreaIntoReservedRegion(addr_t start,
63 									size_t size, VMUserArea* area,
64 									uint32 allocationFlags);
65 			status_t			_InsertAreaSlot(addr_t start, addr_t size,
66 									addr_t end, uint32 addressSpec,
67 									size_t alignment, VMUserArea* area,
68 									uint32 allocationFlags);
69 
70 private:
71 	static	const addr_t		kMaxRandomize;
72 	static	const addr_t		kMaxInitialRandomize;
73 
74 			VMUserAreaTree		fAreas;
75 			addr_t				fNextInsertHint;
76 };
77 
78 
79 #endif	/* VM_USER_ADDRESS_SPACE_H */
80