]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/moe/server/src/dataspace.h
update
[l4.git] / l4 / pkg / moe / server / src / dataspace.h
1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #pragma once
11
12 #include <cstddef>
13 #include <l4/sys/types.h>
14 #include <l4/cxx/list>
15 #include <l4/cxx/ipc_server>
16 #include <l4/cxx/ipc_stream>
17 #include <l4/re/dataspace>
18
19 #include "server_obj.h"
20 #include "ref_cnt.h"
21 #include "globals.h"
22 #include "quota.h"
23
24 namespace Moe {
25
26 class Dataspace : public Server_object, public Q_object
27 {
28 public:
29
30   enum Ds_rw
31   {
32     Read_only   = L4Re::Dataspace::Map_ro,
33     Writable    = L4Re::Dataspace::Map_rw,
34     Cow_enabled = 0x100,
35   };
36
37   struct Address
38   {
39     l4_fpage_t fpage;
40     l4_addr_t offs;
41
42     Address(long error) throw() : offs(-1UL) { fpage.raw = error; }
43
44     Address(l4_addr_t base, l4_addr_t size, Ds_rw rw = Read_only,
45             l4_addr_t offs = 0) throw()
46     : fpage(l4_fpage(base, size, rw ? L4_FPAGE_RWX : L4_FPAGE_RX)),
47       offs(offs) {}
48
49     unsigned long bs() const throw() { return fpage.raw & ~((1 << 12)-1); }
50     unsigned long sz() const throw() { return 1 << l4_fpage_size(fpage); }
51     unsigned long of() const throw() { return offs; }
52     l4_fpage_t fp() const throw() { return fpage; }
53
54     template< typename T >
55     T adr() const throw() { return (T)(bs() + offs); }
56
57     void *adr() const throw() { return (void*)(bs() + offs); }
58
59     bool is_nil() const throw() { return offs == -1UL; }
60     /**
61      * \brief Get the error code that led to the invalid address.
62      * \pre is_nil() must return true.
63      */
64     long error() const throw() { return fpage.raw; }
65
66   };
67
68   Dataspace(unsigned long size, unsigned long flags = 0) throw()
69     : _size(size), _flags(flags)
70   {}
71
72
73   unsigned long size() const throw() { return _size; }
74   virtual void unmap(bool ro = false) const throw() = 0;
75   virtual Address address(l4_addr_t ds_offset,
76                           Ds_rw rw = Writable, l4_addr_t hot_spot = 0,
77                           l4_addr_t min = 0, l4_addr_t max = ~0) const = 0;
78
79   virtual int pre_allocate(l4_addr_t offset, l4_size_t size, unsigned rights) = 0;
80
81   unsigned long is_writable() const throw() { return _flags & Writable; }
82   unsigned long can_cow() const throw() { return _flags & Cow_enabled; }
83   unsigned long flags() const throw() { return _flags; }
84   virtual ~Dataspace() {}
85
86   virtual unsigned long page_shift() const throw() = 0;
87   unsigned long page_size() const throw() { return 1UL << page_shift(); }
88
89   virtual bool is_static() const throw() = 0;
90   virtual long clear(unsigned long offs, unsigned long size) const throw();
91
92 protected:
93   void size(unsigned long size) throw() { _size = size; }
94
95 public:
96   unsigned long round_size() const throw()
97   { return l4_round_size(size(), page_shift()); }
98   bool check_limit(l4_addr_t offset) const throw()
99   { return offset < round_size(); }
100
101 public:
102   int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
103   int map(l4_addr_t offs, l4_addr_t spot, bool rw,
104           l4_addr_t min, l4_addr_t max, L4::Ipc::Snd_fpage &memory);
105   int stats(L4Re::Dataspace::Stats &stats);
106   //int copy_in(unsigned long dst_offs, Dataspace *src, unsigned long src_offs,
107   //    unsigned long size);
108   virtual int phys(l4_addr_t offset, l4_addr_t &phys_addr, l4_size_t &phys_size) throw();
109
110   int dispatch(unsigned long obj, unsigned long op, L4::Ipc::Iostream &ios);
111
112 private:
113   unsigned long _size;
114   unsigned long _flags;
115 };
116
117 }
118
119
120