00001
00002
00003 #ifndef vmem_alloc_h
00004 #define vmem_alloc_h
00005
00006 #include "paging.h"
00007 #include "kern_types.h"
00008
00009
00010
00011
00012
00013
00014 class Space;
00015
00016 class Vmem_alloc
00017 {
00018 public:
00019
00020 enum Zero_fill {
00021 NO_ZERO_FILL = 0,
00022 ZERO_FILL,
00023 ZERO_MAP,
00024 };
00025
00026 static void init();
00027
00036 static void *page_alloc (void *address,
00037 Zero_fill zf = NO_ZERO_FILL,
00038 Page::Attribs pa = Page::USER_NO);
00039
00046 static void page_free (void *page);
00047
00054 static void *page_attr (void *address, Page::Attribs pa);
00055
00056 private:
00057 static void page_map (void *address, int order, Zero_fill zf,
00058 Address phys);
00059
00060 static void page_unmap (void *address, int size);
00061 private:
00062
00063 private:
00064 static P_ptr<void> zero_page;
00065
00066 public:
00075 static bool local_alloc(Space *space, Address virt_addr, int size,
00076 unsigned int page_attributes);
00077
00086 static void local_free(Space *space, Address virt_addr, int size);
00087 };
00088
00089
00090
00091
00092
00093 #include "config.h"
00094 #include "kmem.h"
00095 #include "mapped_alloc.h"
00096 #include "mem_unit.h"
00097 #include "paging.h"
00098
00099
00100
00101
00102
00103
00104
00105
00106 inline void
00107 Vmem_alloc::page_free(void *page)
00108 {
00109 Address phys = Kmem::virt_to_phys(page);
00110
00111 if (phys == (Address) -1)
00112 return;
00113
00114
00115 if (phys != zero_page.get_unsigned())
00116 Mapped_allocator::allocator()->free(Config::PAGE_SHIFT, page);
00117
00118 Address va = reinterpret_cast<Address>(page);
00119
00120 if (va < Mem_layout::Vmem_end)
00121 {
00122
00123 *(Kmem::kdir->lookup(va)->ptab()->lookup(va)) = 0;
00124 page_unmap (page, 0);
00125 Mem_unit::tlb_flush(va);
00126 }
00127 }
00128
00129
00130
00131 inline void
00132 Vmem_alloc::page_map(void * , int , Zero_fill ,
00133 Address )
00134 {}
00135
00136
00137
00138 inline void
00139 Vmem_alloc::page_unmap(void * , int )
00140 {}
00141
00142 #endif // vmem_alloc_h