]> rtime.felk.cvut.cz Git - l4.git/blobdiff - kernel/fiasco/src/kern/kobject.cpp
update
[l4.git] / kernel / fiasco / src / kern / kobject.cpp
index bbdc6c1c2cab6fd8b64ed67bdf2c040c15ceb1ac..0f88303d43a8c0e9b7e153dddcf04e461433a73b 100644 (file)
@@ -2,6 +2,7 @@ INTERFACE:
 
 #include "lock.h"
 #include "obj_space.h"
+#include <cxx/hlist>
 
 
 class Kobject_mappable
@@ -9,13 +10,14 @@ class Kobject_mappable
 private:
   friend class Kobject_mapdb;
   friend class Jdb_mapdb;
-  Obj::Mapping *_root;
+
+  Obj::Mapping::List _root;
   Smword _cnt;
   Lock _lock;
 
 public:
-  Kobject_mappable() : _root(0), _cnt(0) {}
-  bool no_mappings() const { return !_root; }
+  Kobject_mappable() : _cnt(0) {}
+  bool no_mappings() const { return _root.empty(); }
 
   /**
    * Insert the root mapping of an object.
@@ -23,7 +25,8 @@ public:
   template<typename M>
   bool insert(void *, Space *, M &m)
   {
-    m._c->put_as_root(&_root);
+    m._c->put_as_root();
+    _root.add(m._c);
     _cnt = 1;
     return true;
   }
@@ -36,61 +39,20 @@ public:
 INTERFACE:
 
 #include "context.h"
-#include "irq_pin.h"
 #include "kobject_dbg.h"
+#include "kobject_iface.h"
 #include "l4_error.h"
 #include "rcupdate.h"
 #include "space.h"
 
-class Syscall_frame;
-class Utcb;
-
-class Kobject;
-
-class Kobject_common
-{
-public:
-  virtual char const *kobj_type() const = 0;
-  virtual Address kobject_start_addr() const = 0;
-
-  virtual bool is_local(Space *) const  = 0;
-  virtual Mword obj_id() const  = 0;
-  virtual void initiate_deletion(Kobject ***) = 0;
-  virtual void destroy(Kobject ***) = 0;
-  virtual bool put() = 0;
-
-  virtual Kobject_mappable *map_root() = 0;
-
-  virtual Kobject_dbg *dbg_info() = 0;
-  virtual Kobject_dbg const *dbg_info() const = 0;
-
-  virtual Kobject *kobject() = 0;
-  virtual Kobject const *kobject() const = 0;
-};
-
-class Kobject_iface : public virtual Kobject_common
-{
-public:
-  virtual void invoke(L4_obj_ref self, Mword rights, Syscall_frame *, Utcb *) = 0;
-  virtual Kobject_iface *downgrade(unsigned long del_attribs)
-  { (void)del_attribs; return this; }
-};
-
 class Kobject :
-  public virtual Kobject_common,
+  public Kobject_iface,
   private Kobject_mappable,
-  public Kobject_dbg
+  private Kobject_dbg
 {
   template<typename T>
   friend class Map_traits;
 
-public:
-  Kobject_mappable *map_root() { return this; }
-  Kobject_dbg *dbg_info() { return this; }
-  Kobject_dbg const *dbg_info() const { return this; }
-  Kobject *kobject() { return this; }
-  Kobject const *kobject() const { return this; }
-
 private:
   template<typename T>
   class Tconv {};
@@ -99,12 +61,6 @@ private:
   class Tconv<T*> { public: typedef T Base; };
 
 public:
-  bool is_local(Space *) const { return false; }
-  Mword obj_id() const { return ~0UL; }
-  void initiate_deletion(Kobject ***);
-  void destroy(Kobject ***);
-  bool put() { return true; }
-
   template<typename T>
   static T dcast(Kobject_common *_o)
   {
@@ -127,6 +83,8 @@ public:
     return 0;
   }
 
+  using Kobject_dbg::dbg_id;
+
   Lock existence_lock;
 
 public:
@@ -141,12 +99,15 @@ public:
 
 #define FIASCO_DECLARE_KOBJ() \
   public: static char const *const static_kobj_type; \
-          char const *kobj_type() const { return static_kobj_type; } \
-          Address kobject_start_addr() const { return (Address)this; } \
-          Mword kobject_size() const { return sizeof(*this); }
+          char const *kobj_type() const; \
+          Address kobject_start_addr() const; \
+          Mword kobject_size() const;
 
 #define FIASCO_DEFINE_KOBJ(t) \
-  char const *const t::static_kobj_type = #t
+  char const *const t::static_kobj_type = #t; \
+  char const *t::kobj_type() const { return static_kobj_type; } \
+  Address t::kobject_start_addr() const { return (Address)this; } \
+  Mword t::kobject_size() const { return sizeof(*this); }
 
 
 //---------------------------------------------------------------------------
@@ -156,17 +117,22 @@ IMPLEMENTATION:
 #include "l4_buf_iter.h"
 #include "lock_guard.h"
 
+
+PUBLIC bool  Kobject::is_local(Space *) const { return false; }
+PUBLIC Mword Kobject::obj_id() const { return ~0UL; }
+PUBLIC virtual bool  Kobject::put() { return true; }
+PUBLIC Kobject_mappable *Kobject::map_root() { return this; }
+
 PUBLIC inline NEEDS["lock_guard.h"]
 Smword
 Kobject_mappable::dec_cap_refcnt(Smword diff)
 {
-  Lock_guard<Lock> g(&_lock);
+  auto g = lock_guard(_lock);
   _cnt -= diff;
   return _cnt;
 }
 
-
-IMPLEMENT inline
+PUBLIC
 void
 Kobject::initiate_deletion(Kobject ***reap_list)
 {
@@ -177,12 +143,11 @@ Kobject::initiate_deletion(Kobject ***reap_list)
   *reap_list = &_next_to_reap;
 }
 
-IMPLEMENT
+PUBLIC virtual
 void
 Kobject::destroy(Kobject ***)
 {
-  LOG_TRACE("Kobject destroy", "des", current(), __fmt_kobj_destroy,
-      Log_destroy *l = tbe->payload<Log_destroy>();
+  LOG_TRACE("Kobject destroy", "des", current(), Log_destroy,
       l->id = dbg_id();
       l->obj = this;
       l->type = kobj_type());
@@ -192,8 +157,7 @@ Kobject::destroy(Kobject ***)
 PUBLIC virtual
 Kobject::~Kobject()
 {
-  LOG_TRACE("Kobject delete (generic)", "del", current(), __fmt_kobj_destroy,
-      Log_destroy *l = tbe->payload<Log_destroy>();
+  LOG_TRACE("Kobject delete (generic)", "del", current(), Log_destroy,
       l->id = dbg_id();
       l->obj = this;
       l->type = "unk");
@@ -214,7 +178,7 @@ Kobject::sys_dec_refcnt(L4_msg_tag tag, Utcb const *in, Utcb *out)
 
 PUBLIC
 L4_msg_tag
-Kobject::kobject_invoke(L4_obj_ref, Mword /*rights*/,
+Kobject::kobject_invoke(L4_obj_ref, L4_fpage::Rights /*rights*/,
                         Syscall_frame *f,
                         Utcb const *in, Utcb *out)
 {
@@ -233,36 +197,6 @@ Kobject::kobject_invoke(L4_obj_ref, Mword /*rights*/,
 
 }
 
-
-PUBLIC static inline
-L4_msg_tag
-Kobject_iface::commit_result(Mword error,
-                             unsigned words = 0, unsigned items = 0)
-{
-  return L4_msg_tag(words, items, 0, error);
-}
-
-PUBLIC static inline
-L4_msg_tag
-Kobject_iface::commit_error(Utcb const *utcb, L4_error const &e,
-                            L4_msg_tag const &tag = L4_msg_tag(0, 0, 0, 0))
-{
-  const_cast<Utcb*>(utcb)->error = e;
-  return L4_msg_tag(tag, L4_msg_tag::Error);
-}
-
-
-PUBLIC static
-Kobject *
-Kobject::id_to_obj(unsigned long id)
-{ return static_cast<Kobject*>(Kobject_dbg::id_to_obj(id)); }
-
-PUBLIC static inline
-Kobject *
-Kobject::pointer_to_obj(void const *p)
-{ return static_cast<Kobject*>(Kobject_dbg::pointer_to_obj(p)); }
-
-
 //---------------------------------------------------------------------------
 INTERFACE [debug]:
 
@@ -271,25 +205,41 @@ INTERFACE [debug]:
 EXTENSION class Kobject
 {
 protected:
-  struct Log_destroy
+  struct Log_destroy : public Tb_entry
   {
     Kobject    *obj;
     Mword       id;
     char const *type;
     Mword       ram;
+    unsigned print(int max, char *buf) const;
   };
-
-  static unsigned log_fmt(Tb_entry *, int max, char *buf) asm ("__fmt_kobj_destroy");
 };
 
 //---------------------------------------------------------------------------
 IMPLEMENTATION [debug]:
 
+PUBLIC static inline
+Kobject *
+Kobject::from_dbg(Kobject_dbg *d)
+{ return static_cast<Kobject*>(d); }
+
+PUBLIC static inline
+Kobject *
+Kobject::from_dbg(Kobject_dbg::Iterator const &d)
+{
+  if (d != Kobject_dbg::end())
+    return static_cast<Kobject*>(*d);
+  return 0;
+}
+
+PUBLIC
+Kobject_dbg *
+Kobject::dbg_info() const
+{ return const_cast<Kobject*>(this); }
 
 IMPLEMENT
 unsigned
-Kobject::log_fmt(Tb_entry *e, int max, char *buf)
+Kobject::Log_destroy::print(int max, char *buf) const
 {
-  Log_destroy *l = e->payload<Log_destroy>();
-  return snprintf(buf, max, "obj=%lx [%s] (%p) ram=%lx", l->id, l->type, l->obj, l->ram);
+  return snprintf(buf, max, "obj=%lx [%s] (%p) ram=%lx", id, type, obj, ram);
 }