00001 /** \file page.h 00002 * \brief Page-oriented bit maps. 00003 */ 00004 #ifndef tm_PAGE_H 00005 #define tm_PAGE_H 00006 00007 #include "util/bitset.h" 00008 00009 00010 /*! True if ptr is aligned to a tm_block */ 00011 #define tm_ptr_is_aligned_to_block(ptr) !(((unsigned long) ptr) % tm_block_SIZE) 00012 /*! True if ptr is aligned to a OS page. */ 00013 #define tm_ptr_is_aligned_to_page(ptr) !(((unsigned long) ptr) % tm_page_SIZE) 00014 00015 00016 /***************************************************************************/ 00017 00018 00019 /*! Returns the index of a ptr into page-orientated bit map */ 00020 #define tm_page_index(X) (((unsigned long) X) / tm_page_SIZE) 00021 00022 00023 /** 00024 * Is page at ptr in use? 00025 */ 00026 static __inline 00027 int _tm_page_in_use(void *ptr) 00028 { 00029 size_t i = tm_page_index(ptr); 00030 return bitset_get(tm.page_in_use, i); 00031 } 00032 00033 /** 00034 * Mark page at ptr in use. 00035 */ 00036 static __inline 00037 void _tm_page_mark_used(void *ptr) 00038 { 00039 size_t i = tm_page_index(ptr); 00040 bitset_set(tm.page_in_use, i); 00041 } 00042 00043 00044 /** 00045 * Mark page at ptr unused. 00046 */ 00047 static __inline 00048 void _tm_page_mark_unused(void *ptr) 00049 { 00050 size_t i = tm_page_index(ptr); 00051 bitset_clr(tm.page_in_use, i); 00052 } 00053 00054 00055 /** 00056 * Mark freed pages at ptr for size bytes as used. 00057 */ 00058 static __inline 00059 void _tm_page_mark_used_range(void *ptr, size_t size) 00060 { 00061 tm_assert_test(tm_ptr_is_aligned_to_page(ptr)); 00062 tm_assert_test(tm_ptr_is_aligned_to_page(size)); 00063 00064 while ( size > 0 ) { 00065 _tm_page_mark_used(ptr); 00066 ptr += tm_page_SIZE; 00067 size -= tm_page_SIZE; 00068 } 00069 } 00070 00071 00072 /** 00073 * Mark freed pages at ptr for size bytes as unused. 00074 */ 00075 static __inline 00076 void _tm_page_mark_unused_range(void *ptr, size_t size) 00077 { 00078 tm_assert_test(tm_ptr_is_aligned_to_page(ptr)); 00079 tm_assert_test(tm_ptr_is_aligned_to_page(size)); 00080 00081 while ( size > 0 ) { 00082 _tm_page_mark_unused(ptr); 00083 ptr += tm_page_SIZE; 00084 size -= tm_page_SIZE; 00085 } 00086 } 00087 00088 #endif