1 /* 2 * Copyright (C) 2015 Kernkonzept GmbH. 3 * Author(s): Sarah Hoffmann <sarah.hoffmann@kernkonzept.com> 4 * 5 * This file is distributed under the terms of the GNU General Public 6 * License, version 2. Please see the COPYING-GPL-2 file for details. 7 */ 8 #include "quota.h" 9 10 #include <cstdio> 11 #include <cassert> 12 13 namespace Moe { 14 allocator()15Moe_alloc *Moe_alloc::allocator() 16 { 17 static Moe_alloc a; 18 return &a; 19 } 20 get_mem()21void *Q_alloc::get_mem() 22 { 23 if (_quota.alloc(L4_PAGESIZE)) 24 { 25 void *p = Malloc_container::get_mem(); 26 if (!p) 27 _quota.free(L4_PAGESIZE); 28 return p; 29 } 30 31 return 0; 32 } 33 free_mem(void * page)34void Q_alloc::free_mem(void *page) 35 { 36 Malloc_container::free_mem(page); 37 _quota.free(L4_PAGESIZE); 38 } 39 reparent(Malloc_container * new_container)40void Q_alloc::reparent(Malloc_container *new_container) 41 { 42 auto newq = dynamic_cast<Q_alloc *>(new_container); 43 assert(newq != 0); 44 newq->quota()->free(_quota.limit()); 45 46 } 47 48 49 } // namespace 50