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/util/atomic.h> 12 #include <l4/sys/consts.h> 13 #include <cassert> 14 15 namespace Moe { 16 namespace Pages { 17 extern l4_addr_t base_addr; 18 extern l4_addr_t max_addr; 19 extern l4_uint32_t *pages; 20 21 inline ref_count(void * addr)22 l4_uint32_t &ref_count(void *addr) 23 { 24 assert(l4_addr_t(addr) >= base_addr); 25 assert(l4_addr_t(addr) < max_addr); 26 return pages[(l4_addr_t(addr) - base_addr) >> L4_PAGESHIFT]; 27 } 28 29 inline share(void * addr)30 unsigned long share(void *addr) 31 { return l4util_inc32_res(&ref_count(addr)); } 32 33 inline unshare(void * addr)34 unsigned long unshare(void *addr) 35 { return l4util_dec32_res(&ref_count(addr)); } 36 }; 37 }; 38 39