]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/moe/server/src/page_alloc.cc
Update
[l4.git] / l4 / pkg / l4re-core / moe / server / src / page_alloc.cc
1 /*
2  * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #include <l4/util/util.h>
10
11 #include <l4/cxx/iostream>
12 #include <l4/cxx/list_alloc>
13 #include <l4/cxx/exceptions>
14 #include <l4/sys/kdebug.h>
15 #include "page_alloc.h"
16 #include "debug.h"
17
18 #if 1
19 enum { page_alloc_debug = 0 };
20 #else
21 unsigned page_alloc_debug = 0;
22 #endif
23
24 class LA : public cxx::List_alloc
25 {
26 #if 0
27 public:
28   ~LA()
29     {
30       L4::cout << "~LA(): avail = " << avail() << '\n';
31     }
32 #endif
33 #if 0
34 public:
35   void *alloc(unsigned long size, unsigned long align)
36   {
37     L4::cout << "PA::alloc: " << L4::hex << size << '(' << align << ") -> \n";
38     void *p = cxx::List_alloc::alloc(size, align);
39     L4::cout << p << "\n";
40     return p;
41   }
42 #endif
43 #if 0
44 public:
45   void free(void *p, unsigned long size)
46   {
47     L4::cout << "free: " << p << '(' << size << ") -> "; 
48     cxx::List_alloc::free(p, size);
49     L4::cout << avail() << "\n";
50   }
51 #endif
52 };
53
54 static LA *page_alloc()
55 {
56   static LA pa;
57   return &pa;
58 }
59
60 Single_page_alloc_base::Single_page_alloc_base()
61 {}
62
63 unsigned long Single_page_alloc_base::_avail()
64 {
65   return page_alloc()->avail();
66 }
67
68 void *Single_page_alloc_base::_alloc(Nothrow)
69 {
70   void *ret = page_alloc()->alloc(L4_PAGESIZE, L4_PAGESIZE);
71
72   if (page_alloc_debug)
73     L4::cout << "pa(" << __builtin_return_address(0) << "): alloc(PAGE) @" << ret << '\n';
74   return ret;
75 }
76
77 void Single_page_alloc_base::_free(void *p)
78 {
79   if (page_alloc_debug)
80     L4::cout << "pa(" << __builtin_return_address(0) << "): free(PAGE) @" << p << '\n';
81   page_alloc()->free(p, L4_PAGESIZE); 
82 }
83
84 void *Single_page_alloc_base::_alloc_max(unsigned long min,
85                                          unsigned long *max,
86                                          unsigned align,
87                                          unsigned granularity)
88 {
89   void *ret = page_alloc()->alloc_max(min, max, align, granularity);
90   if (page_alloc_debug)
91     L4::cout << "pa(" << __builtin_return_address(0) << "): alloc(" << *max << ") @" << ret << '\n';
92   return ret;
93 }
94
95 void *Single_page_alloc_base::_alloc(Nothrow, unsigned long size,
96                                      unsigned long align)
97 {
98   void *ret = page_alloc()->alloc(size, align);
99   if (page_alloc_debug)
100     L4::cout << "pa(" << __builtin_return_address(0) << "): alloc(" << size << ") @" << ret << '\n';
101   return ret;
102 }
103
104 void Single_page_alloc_base::_free(void *p, unsigned long size, bool initial_mem)
105 {
106   if (page_alloc_debug)
107     L4::cout << "pa(" << __builtin_return_address(0) << "): free(" << size << ") @" << p << '\n';
108   page_alloc()->free(p, size, initial_mem);
109 }
110
111 #ifndef NDEBUG
112 void Single_page_alloc_base::_dump_free(Dbg &dbg)
113 {
114   page_alloc()->dump_free_list(dbg);
115 }
116 #endif