vfs: check userland buffers before reading them.
[haiku.git] / headers / private / debugger / model / TeamMemoryBlock.h
blobda347b2908735260775b6883eb25fd4455c49ff7
1 /*
2 * Copyright 2011, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef TEAM_MEMORY_BLOCK_H
6 #define TEAM_MEMORY_BLOCK_H
9 #include <OS.h>
11 #include <Locker.h>
12 #include <Referenceable.h>
13 #include <util/DoublyLinkedList.h>
15 #include "Types.h"
18 class TeamMemoryBlockOwner;
21 class TeamMemoryBlock : public BReferenceable,
22 public DoublyLinkedListLinkImpl<TeamMemoryBlock> {
23 public:
24 class Listener;
26 public:
27 TeamMemoryBlock(target_addr_t baseAddress,
28 TeamMemoryBlockOwner* owner);
29 ~TeamMemoryBlock();
31 void AddListener(Listener* listener);
32 bool HasListener(Listener* listener);
33 void RemoveListener(Listener* listener);
35 bool IsValid() const { return fValid; };
36 void MarkValid();
37 void Invalidate();
39 target_addr_t BaseAddress() const { return fBaseAddress; };
40 uint8* Data() { return fData; };
41 size_t Size() const { return sizeof(fData); };
42 bool Contains(target_addr_t address) const;
44 bool IsWritable() const { return fWritable; }
45 void SetWritable(bool writable);
47 void NotifyDataRetrieved(status_t result = B_OK);
49 protected:
50 virtual void LastReferenceReleased();
52 private:
53 typedef DoublyLinkedList<Listener> ListenerList;
55 private:
56 bool fValid;
57 bool fWritable;
58 target_addr_t fBaseAddress;
59 uint8 fData[B_PAGE_SIZE];
60 ListenerList fListeners;
61 TeamMemoryBlockOwner*
62 fBlockOwner;
63 BLocker fLock;
67 class TeamMemoryBlock::Listener : public DoublyLinkedListLinkImpl<Listener> {
68 public:
69 virtual ~Listener();
71 virtual void MemoryBlockRetrieved(TeamMemoryBlock* block);
73 virtual void MemoryBlockRetrievalFailed(TeamMemoryBlock* block,
74 status_t result);
78 #endif // TEAM_MEMORY_BLOCK_H