]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/moe/server/src/dataspace_annon.cc
update
[l4.git] / l4 / pkg / moe / server / src / dataspace_annon.cc
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 #include "dataspace_annon.h"
11 #include "page_alloc.h"
12 #include "slab_alloc.h"
13
14 #include <l4/cxx/exceptions>
15
16 #include <cstring>
17
18 typedef Moe::Q_alloc<Moe::Dataspace_annon, Slab_alloc> Allocator;
19
20 static Allocator *alloc()
21 {
22   static Allocator a;
23   return &a;
24 }
25
26 void *Moe::Dataspace_annon::operator new (size_t, Quota *q)
27 {
28   return alloc()->alloc(q);
29 }
30
31 void Moe::Dataspace_annon::operator delete (void *m) throw()
32 { alloc()->free((Moe::Dataspace_annon*)m); }
33
34
35 Moe::Dataspace_annon::Dataspace_annon(unsigned long _size, bool w,
36                                       unsigned char page_shift)
37 : Moe::Dataspace_cont(0, 0, w), _page_shift(page_shift)
38 {
39   unsigned long r_size = (_size + page_size() - 1) & ~(page_size() -1);
40   Quota_guard g(quota(), r_size);
41
42   void *m = Single_page_alloc_base::_alloc(r_size, page_size());
43   memset(m, 0, r_size);
44   start(m);
45   size(_size);
46   g.done();
47 }
48
49 Moe::Dataspace_annon::~Dataspace_annon()
50 {
51   void *adr = start();
52   if (adr)
53     {
54       unsigned long r_size = (size() + page_size() - 1) & ~(page_size() -1);
55       Single_page_alloc_base::_free(adr, r_size);
56       quota()->free(r_size);
57     }
58 }