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
page_alloc()54 static LA *page_alloc()
55 {
56 static LA pa;
57 return &pa;
58 }
59
Single_page_alloc_base()60 Single_page_alloc_base::Single_page_alloc_base()
61 {}
62
_avail()63 unsigned long Single_page_alloc_base::_avail()
64 {
65 return page_alloc()->avail();
66 }
67
_alloc_max(unsigned long min,unsigned long * max,unsigned align,unsigned granularity)68 void *Single_page_alloc_base::_alloc_max(unsigned long min,
69 unsigned long *max,
70 unsigned align,
71 unsigned granularity)
72 {
73 void *ret = page_alloc()->alloc_max(min, max, align, granularity);
74 if (page_alloc_debug)
75 L4::cout << "pa(" << __builtin_return_address(0) << "): alloc(" << *max << ") @" << ret << '\n';
76 return ret;
77 }
78
_alloc(Nothrow,unsigned long size,unsigned long align)79 void *Single_page_alloc_base::_alloc(Nothrow, unsigned long size,
80 unsigned long align)
81 {
82 void *ret = page_alloc()->alloc(size, align);
83 if (page_alloc_debug)
84 L4::cout << "pa(" << __builtin_return_address(0) << "): alloc(" << size << ") @" << ret << '\n';
85 return ret;
86 }
87
_free(void * p,unsigned long size,bool initial_mem)88 void Single_page_alloc_base::_free(void *p, unsigned long size, bool initial_mem)
89 {
90 if (page_alloc_debug)
91 L4::cout << "pa(" << __builtin_return_address(0) << "): free(" << size << ") @" << p << '\n';
92 page_alloc()->free(p, size, initial_mem);
93 }
94
95 #ifndef NDEBUG
_dump_free(Dbg & dbg)96 void Single_page_alloc_base::_dump_free(Dbg &dbg)
97 {
98 page_alloc()->dump_free_list(dbg);
99 }
100 #endif
101