]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/kobject_iface.cpp
Update
[l4.git] / kernel / fiasco / src / kern / kobject_iface.cpp
1 INTERFACE:
2
3 #include "l4_types.h"
4 #include <cxx/dyn_cast>
5
6 class Kobject;
7 class Kobject_dbg;
8 class Kobject_mappable;
9
10 class Space;
11 class Ram_quota;
12 class Syscall_frame;
13 class Utcb;
14
15 class Kobject_common : public cxx::Dyn_castable<Kobject_common>
16 {
17 public:
18   Kobject_common() = default;
19   Kobject_common(Kobject_common const &) = delete;
20   Kobject_common &operator = (Kobject_common const &) = delete;
21
22   virtual bool is_local(Space *) const  = 0;
23   virtual Mword obj_id() const  = 0;
24   virtual void initiate_deletion(Kobject ***) = 0;
25
26   virtual Kobject_mappable *map_root() = 0;
27   virtual ~Kobject_common() = 0;
28 };
29
30 class Kobject_iface : public cxx::Dyn_castable<Kobject_iface, Kobject_common>
31 {
32 public:
33   virtual void invoke(L4_obj_ref self, L4_fpage::Rights rights, Syscall_frame *, Utcb *) = 0;
34
35   typedef Kobject_iface *Factory_func(Ram_quota *q,
36                                       Space *current_space,
37                                       L4_msg_tag tag,
38                                       Utcb const *utcb, int *err);
39   enum { Max_factory_index = -L4_msg_tag::Max_factory_label };
40   static Factory_func *factory[Max_factory_index + 1];
41 };
42
43 IMPLEMENTATION:
44
45 #include "panic.h"
46
47 IMPLEMENT inline Kobject_common::~Kobject_common() {}
48
49 Kobject_iface::Factory_func *Kobject_iface::factory[Max_factory_index + 1];
50
51 PUBLIC static inline
52 L4_msg_tag
53 Kobject_iface::commit_result(Mword error,
54                              unsigned words = 0, unsigned items = 0)
55 {
56   return L4_msg_tag(words, items, 0, error);
57 }
58
59 PUBLIC static inline
60 L4_msg_tag
61 Kobject_iface::commit_error(Utcb const *utcb, L4_error const &e,
62                             L4_msg_tag const &tag = L4_msg_tag(0, 0, 0, 0))
63 {
64   const_cast<Utcb*>(utcb)->error = e;
65   return L4_msg_tag(tag, L4_msg_tag::Error);
66 }
67
68 PUBLIC virtual
69 Kobject_iface *
70 Kobject_iface::downgrade(unsigned long del_attribs)
71 { (void)del_attribs; return this; }
72
73 PUBLIC static
74 void
75 Kobject_iface::set_factory(long label, Factory_func *f)
76 {
77   if (label > 0 || -label > Max_factory_index)
78     panic("error: registering factory for invalid protocol/label: %ld\n",
79           label);
80
81   if (factory[-label])
82     panic("error: factory for protocol/label %ld already registered: %p\n",
83           label, factory[-label]);
84
85   factory[-label] = f;
86 }
87
88 PUBLIC static inline
89 Kobject_iface *
90 Kobject_iface::manufacture(long label, Ram_quota *q,
91                            Space *current_space,
92                            L4_msg_tag tag, Utcb const *utcb, int *err)
93 {
94   *err = L4_err::ENodev;
95   if (EXPECT_FALSE(label > 0 || -label > Max_factory_index
96                    || !factory[-label]))
97     return 0;
98
99   return factory[-label](q, current_space, tag, utcb, err);
100 }
101
102 // ------------------------------------------------------------------------
103 IMPLEMENTATION [debug]:
104
105 PUBLIC virtual Kobject_dbg *Kobject_common::dbg_info() const = 0;