xref: /haiku/src/kits/debugger/debug_managers/TeamMemoryBlockManager.h (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
1*fce4895dSRene Gollent /*
2*fce4895dSRene Gollent  * Copyright 2011, Rene Gollent, rene@gollent.com.
3*fce4895dSRene Gollent  * Distributed under the terms of the MIT License.
4*fce4895dSRene Gollent  */
5*fce4895dSRene Gollent #ifndef TEAM_MEMORY_BLOCK_MANAGER_H
6*fce4895dSRene Gollent #define TEAM_MEMORY_BLOCK_MANAGER_H
7*fce4895dSRene Gollent 
8*fce4895dSRene Gollent 
9*fce4895dSRene Gollent #include <Locker.h>
10*fce4895dSRene Gollent #include <Referenceable.h>
11*fce4895dSRene Gollent #include <util/DoublyLinkedList.h>
12*fce4895dSRene Gollent #include <util/OpenHashTable.h>
13*fce4895dSRene Gollent 
14*fce4895dSRene Gollent #include "Types.h"
15*fce4895dSRene Gollent 
16*fce4895dSRene Gollent 
17*fce4895dSRene Gollent struct MemoryBlockHashDefinition;
18*fce4895dSRene Gollent class TeamMemoryBlock;
19*fce4895dSRene Gollent 
20*fce4895dSRene Gollent 
21*fce4895dSRene Gollent class TeamMemoryBlockManager
22*fce4895dSRene Gollent {
23*fce4895dSRene Gollent public:
24*fce4895dSRene Gollent 								TeamMemoryBlockManager();
25*fce4895dSRene Gollent 								~TeamMemoryBlockManager();
26*fce4895dSRene Gollent 
27*fce4895dSRene Gollent 		status_t				Init();
28*fce4895dSRene Gollent 
29*fce4895dSRene Gollent 		TeamMemoryBlock*		GetMemoryBlock(target_addr_t address);
30*fce4895dSRene Gollent 
31*fce4895dSRene Gollent private:
32*fce4895dSRene Gollent 		struct Key;
33*fce4895dSRene Gollent 		struct MemoryBlockEntry;
34*fce4895dSRene Gollent 		struct MemoryBlockHashDefinition;
35*fce4895dSRene Gollent 		typedef BOpenHashTable<MemoryBlockHashDefinition> MemoryBlockTable;
36*fce4895dSRene Gollent 		typedef DoublyLinkedList<TeamMemoryBlock> DeadBlockTable;
37*fce4895dSRene Gollent 
38*fce4895dSRene Gollent private:
39*fce4895dSRene Gollent 		void					_Cleanup();
40*fce4895dSRene Gollent 		void					_MarkDeadBlock(target_addr_t address);
41*fce4895dSRene Gollent 		void					_RemoveBlock(target_addr_t address);
42*fce4895dSRene Gollent 
43*fce4895dSRene Gollent private:
44*fce4895dSRene Gollent 		friend class TeamMemoryBlockOwner;
45*fce4895dSRene Gollent 
46*fce4895dSRene Gollent private:
47*fce4895dSRene Gollent 		BLocker					fLock;
48*fce4895dSRene Gollent 		MemoryBlockTable*		fActiveBlocks;
49*fce4895dSRene Gollent 		DeadBlockTable*			fDeadBlocks;
50*fce4895dSRene Gollent };
51*fce4895dSRene Gollent 
52*fce4895dSRene Gollent 
53*fce4895dSRene Gollent class TeamMemoryBlockOwner
54*fce4895dSRene Gollent {
55*fce4895dSRene Gollent public:
56*fce4895dSRene Gollent 								TeamMemoryBlockOwner(
57*fce4895dSRene Gollent 									TeamMemoryBlockManager* manager);
58*fce4895dSRene Gollent 								~TeamMemoryBlockOwner();
59*fce4895dSRene Gollent 
60*fce4895dSRene Gollent 		void					RemoveBlock(TeamMemoryBlock* block);
61*fce4895dSRene Gollent 
62*fce4895dSRene Gollent private:
63*fce4895dSRene Gollent 	TeamMemoryBlockManager* 	fBlockManager;
64*fce4895dSRene Gollent };
65*fce4895dSRene Gollent 
66*fce4895dSRene Gollent 
67*fce4895dSRene Gollent #endif // TEAM_MEMORY_BLOCK_MANAGER_H
68