10 friend class Kobject_mapdb;
11 friend class Jdb_mapdb;
17 Kobject_mappable() : _root(0), _cnt(0) {}
18 bool no_mappings() const { return !_root; }
21 * Insert the root mapping of an object.
24 bool insert(void *, Space *, M &m)
26 m._c->put_as_root(&_root);
31 Smword cap_ref_cnt() const { return _cnt; }
35 //----------------------------------------------------------------------------
40 #include "kobject_dbg.h"
41 #include "kobject_iface.h"
47 public virtual Kobject_common,
48 private Kobject_mappable,
52 friend class Map_traits;
55 Kobject_mappable *map_root() { return this; }
56 Kobject_dbg *dbg_info() { return this; }
57 Kobject_dbg const *dbg_info() const { return this; }
58 Kobject *kobject() { return this; }
59 Kobject const *kobject() const { return this; }
66 class Tconv<T*> { public: typedef T Base; };
69 bool is_local(Space *) const { return false; }
70 Mword obj_id() const { return ~0UL; }
71 void initiate_deletion(Kobject ***);
72 void destroy(Kobject ***);
73 bool put() { return true; }
76 static T dcast(Kobject_common *_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());
87 static T dcast(Kobject_common const *_o)
89 if (EXPECT_FALSE(!_o))
92 if (EXPECT_TRUE(_o->kobj_type() == Tconv<T>::Base::static_kobj_type))
93 return reinterpret_cast<T>(_o->kobject_start_addr());
100 Kobject *_next_to_reap;
109 #define FIASCO_DECLARE_KOBJ() \
110 public: static char const *const static_kobj_type; \
111 char const *kobj_type() const { return static_kobj_type; } \
112 Address kobject_start_addr() const { return (Address)this; } \
113 Mword kobject_size() const { return sizeof(*this); }
115 #define FIASCO_DEFINE_KOBJ(t) \
116 char const *const t::static_kobj_type = #t
119 //---------------------------------------------------------------------------
123 #include "l4_buf_iter.h"
124 #include "lock_guard.h"
126 PUBLIC inline NEEDS["lock_guard.h"]
128 Kobject_mappable::dec_cap_refcnt(Smword diff)
130 Lock_guard<Lock> g(&_lock);
138 Kobject::initiate_deletion(Kobject ***reap_list)
140 existence_lock.invalidate();
144 *reap_list = &_next_to_reap;
149 Kobject::destroy(Kobject ***)
151 LOG_TRACE("Kobject destroy", "des", current(), __fmt_kobj_destroy,
152 Log_destroy *l = tbe->payload<Log_destroy>();
155 l->type = kobj_type());
156 existence_lock.wait_free();
162 LOG_TRACE("Kobject delete (generic)", "del", current(), __fmt_kobj_destroy,
163 Log_destroy *l = tbe->payload<Log_destroy>();
170 PRIVATE inline NOEXPORT
172 Kobject::sys_dec_refcnt(L4_msg_tag tag, Utcb const *in, Utcb *out)
175 return Kobject_iface::commit_result(-L4_err::EInval);
177 Smword diff = in->values[1];
178 out->values[0] = dec_cap_refcnt(diff);
179 return Kobject_iface::commit_result(0);
184 Kobject::kobject_invoke(L4_obj_ref, Mword /*rights*/,
186 Utcb const *in, Utcb *out)
188 L4_msg_tag tag = f->tag();
190 if (EXPECT_FALSE(tag.words() < 1))
191 return Kobject_iface::commit_result(-L4_err::EInval);
193 switch (in->values[0])
196 return sys_dec_refcnt(tag, in, out);
198 return Kobject_iface::commit_result(-L4_err::ENosys);
205 Kobject::id_to_obj(unsigned long id)
206 { return static_cast<Kobject*>(Kobject_dbg::id_to_obj(id)); }
210 Kobject::pointer_to_obj(void const *p)
211 { return static_cast<Kobject*>(Kobject_dbg::pointer_to_obj(p)); }
214 //---------------------------------------------------------------------------
217 #include "tb_entry.h"
219 EXTENSION class Kobject
230 static unsigned log_fmt(Tb_entry *, int max, char *buf) asm ("__fmt_kobj_destroy");
233 //---------------------------------------------------------------------------
234 IMPLEMENTATION [debug]:
239 Kobject::log_fmt(Tb_entry *e, int max, char *buf)
241 Log_destroy *l = e->payload<Log_destroy>();
242 return snprintf(buf, max, "obj=%lx [%s] (%p) ram=%lx", l->id, l->type, l->obj, l->ram);