vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / file_systems / userlandfs / shared / ObjectTracker.cpp
blob9d5b29f2ccd3fded4921466b825b8c227b1d679c
1 // ObjectTracker.h
3 #include <new>
4 #include <typeinfo>
6 #include <AutoLocker.h>
8 #include "Debug.h"
9 #include "ObjectTracker.h"
11 static char sTrackerBuffer[sizeof(ObjectTracker)];
13 // constructor
14 ObjectTrackable::ObjectTrackable()
16 ObjectTracker* tracker = ObjectTracker::GetDefault();
17 if (tracker != NULL)
18 tracker->AddTrackable(this);
21 // destructor
22 ObjectTrackable::~ObjectTrackable()
24 ObjectTracker* tracker = ObjectTracker::GetDefault();
25 if (tracker != NULL)
26 tracker->RemoveTrackable(this);
30 // #pragma mark -
32 // constructor
33 ObjectTracker::ObjectTracker()
34 : fLock("object tracker"),
35 fTrackables()
39 // destructor
40 ObjectTracker::~ObjectTracker()
42 ObjectTrackable* trackable = fTrackables.First();
43 if (trackable) {
44 WARN(("ObjectTracker: WARNING: There are still undeleted objects:\n"));
45 #ifndef _KERNEL_MODE
46 for (; trackable; trackable = fTrackables.GetNext(trackable)) {
47 WARN((" trackable: %p: type: `%s'\n", trackable,
48 typeid(*trackable).name()));
50 #endif
54 // InitDefault
55 ObjectTracker*
56 ObjectTracker::InitDefault()
58 if (!sTracker)
59 sTracker = new(sTrackerBuffer) ObjectTracker;
60 return sTracker;
63 // ExitDefault
64 void
65 ObjectTracker::ExitDefault()
67 if (sTracker) {
68 sTracker->~ObjectTracker();
69 sTracker = NULL;
73 // GetDefault
74 ObjectTracker*
75 ObjectTracker::GetDefault()
77 return sTracker;
80 // AddTrackable
81 void
82 ObjectTracker::AddTrackable(ObjectTrackable* trackable)
84 if (trackable) {
85 AutoLocker<Locker> _(fLock);
86 fTrackables.Insert(trackable);
90 // RemoveTrackable
91 void
92 ObjectTracker::RemoveTrackable(ObjectTrackable* trackable)
94 if (trackable) {
95 AutoLocker<Locker> _(fLock);
96 fTrackables.Remove(trackable);
100 // sTracker
101 ObjectTracker* ObjectTracker::sTracker = NULL;