11 friend class Kobject_mapdb;
12 friend class Jdb_mapdb;
14 Obj::Mapping::List _root;
19 Kobject_mappable() : _cnt(0) {}
20 bool no_mappings() const { return _root.empty(); }
23 * Insert the root mapping of an object.
26 bool insert(void *, Space *, M &m)
34 Smword cap_ref_cnt() const { return _cnt; }
38 //----------------------------------------------------------------------------
42 #include "kobject_dbg.h"
43 #include "kobject_iface.h"
50 private Kobject_mappable,
54 friend class Map_traits;
61 class Tconv<T*> { public: typedef T Base; };
65 static T dcast(Kobject_common *_o)
67 if (EXPECT_FALSE(!_o))
70 if (EXPECT_TRUE(_o->kobj_type() == Tconv<T>::Base::static_kobj_type))
71 return reinterpret_cast<T>(_o->kobject_start_addr());
76 static T dcast(Kobject_common const *_o)
78 if (EXPECT_FALSE(!_o))
81 if (EXPECT_TRUE(_o->kobj_type() == Tconv<T>::Base::static_kobj_type))
82 return reinterpret_cast<T>(_o->kobject_start_addr());
86 using Kobject_dbg::dbg_id;
91 Kobject *_next_to_reap;
100 #define FIASCO_DECLARE_KOBJ() \
101 public: static char const *const static_kobj_type; \
102 char const *kobj_type() const; \
103 Address kobject_start_addr() const; \
104 Mword kobject_size() const;
106 #define FIASCO_DEFINE_KOBJ(t) \
107 char const *const t::static_kobj_type = #t; \
108 char const *t::kobj_type() const { return static_kobj_type; } \
109 Address t::kobject_start_addr() const { return (Address)this; } \
110 Mword t::kobject_size() const { return sizeof(*this); }
113 //---------------------------------------------------------------------------
117 #include "l4_buf_iter.h"
118 #include "lock_guard.h"
121 PUBLIC bool Kobject::is_local(Space *) const { return false; }
122 PUBLIC Mword Kobject::obj_id() const { return ~0UL; }
123 PUBLIC virtual bool Kobject::put() { return true; }
124 PUBLIC Kobject_mappable *Kobject::map_root() { return this; }
126 PUBLIC inline NEEDS["lock_guard.h"]
128 Kobject_mappable::dec_cap_refcnt(Smword diff)
130 auto g = lock_guard(_lock);
137 Kobject::initiate_deletion(Kobject ***reap_list)
139 existence_lock.invalidate();
143 *reap_list = &_next_to_reap;
148 Kobject::destroy(Kobject ***)
150 LOG_TRACE("Kobject destroy", "des", current(), Log_destroy,
153 l->type = kobj_type());
154 existence_lock.wait_free();
160 LOG_TRACE("Kobject delete (generic)", "del", current(), Log_destroy,
167 PRIVATE inline NOEXPORT
169 Kobject::sys_dec_refcnt(L4_msg_tag tag, Utcb const *in, Utcb *out)
172 return Kobject_iface::commit_result(-L4_err::EInval);
174 Smword diff = in->values[1];
175 out->values[0] = dec_cap_refcnt(diff);
176 return Kobject_iface::commit_result(0);
181 Kobject::kobject_invoke(L4_obj_ref, Mword /*rights*/,
183 Utcb const *in, Utcb *out)
185 L4_msg_tag tag = f->tag();
187 if (EXPECT_FALSE(tag.words() < 1))
188 return Kobject_iface::commit_result(-L4_err::EInval);
190 switch (in->values[0])
193 return sys_dec_refcnt(tag, in, out);
195 return Kobject_iface::commit_result(-L4_err::ENosys);
200 //---------------------------------------------------------------------------
203 #include "tb_entry.h"
205 EXTENSION class Kobject
208 struct Log_destroy : public Tb_entry
214 unsigned print(int max, char *buf) const;
218 //---------------------------------------------------------------------------
219 IMPLEMENTATION [debug]:
223 Kobject::from_dbg(Kobject_dbg *d)
224 { return static_cast<Kobject*>(d); }
228 Kobject::from_dbg(Kobject_dbg::Iterator const &d)
230 if (d != Kobject_dbg::end())
231 return static_cast<Kobject*>(*d);
237 Kobject::dbg_info() const
238 { return const_cast<Kobject*>(this); }
242 Kobject::Log_destroy::print(int max, char *buf) const
244 return snprintf(buf, max, "obj=%lx [%s] (%p) ram=%lx", id, type, obj, ram);