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 #pragma once 10 11 #include <l4/re/mem_alloc> 12 #include <l4/sys/cxx/ipc_epiface> 13 #include "quota.h" 14 #include "server_obj.h" 15 16 #include <l4/cxx/list> 17 18 #ifndef NDEBUG 19 #include <l4/re/debug> 20 typedef L4Re::Debug_obj_t<L4::Factory> Allocator_iface; 21 #else 22 typedef L4::Factory Allocator_iface; 23 #endif 24 25 namespace Moe { 26 class Dataspace; 27 } 28 29 class Allocator : 30 public L4::Epiface_t<Allocator, Allocator_iface, Moe::Server_object> 31 { 32 private: 33 Moe::Q_alloc _qalloc; 34 long _sched_prio_limit; 35 36 public: 37 explicit Allocator(size_t limit, unsigned prio_limit = 0) _qalloc(limit)38 : _qalloc(limit), _sched_prio_limit(prio_limit) 39 {} 40 41 template<typename T, typename ...ARGS> make_obj(ARGS &&...args)42 T *make_obj(ARGS &&...args) 43 { 44 T *o = qalloc()->make_obj<T>(cxx::forward<ARGS>(args)...); 45 Obj_list::insert_after(o, Obj_list::iter(this)); 46 return o; 47 } 48 qalloc()49 Moe::Q_alloc *qalloc() { return &_qalloc; } 50 51 Moe::Dataspace *alloc(long size, unsigned long flags = 0, 52 unsigned long align = 0); 53 54 /// Return the quota allocator that contains this factory. parent_qalloc()55 Moe::Q_alloc *parent_qalloc() 56 { 57 return dynamic_cast<Moe::Q_alloc *>(Moe::Malloc_container::from_ptr(this)); 58 } 59 60 virtual ~Allocator(); 61 62 int op_create(L4::Factory::Rights rights, L4::Ipc::Cap<void> &, long, 63 L4::Ipc::Varg_list<> &&args); 64 65 #ifndef NDEBUG 66 long op_debug(L4Re::Debug_obj::Rights, unsigned long function); 67 #endif 68 69 static Allocator *root_allocator(); 70 71 }; 72