1 /* 2 * Copyright 2006-2008, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 #ifndef AREA_KEEPER_H 9 #define AREA_KEEPER_H 10 11 12 #include <KernelExport.h> 13 #include <OS.h> 14 15 #include <util/kernel_cpp.h> 16 17 18 class AreaKeeper { 19 public: 20 AreaKeeper(); 21 ~AreaKeeper(); 22 23 area_id Create(const char *name, void **_virtualAddress, uint32 spec, 24 size_t size, uint32 lock, uint32 protection); 25 area_id Map(const char *name, phys_addr_t physicalAddress, 26 size_t numBytes, uint32 spec, uint32 protection, 27 void **_virtualAddress); 28 29 status_t InitCheck() { return fArea < B_OK ? (status_t)fArea : B_OK; } 30 void Detach(); 31 32 private: 33 area_id fArea; 34 }; 35 36 37 AreaKeeper::AreaKeeper() 38 : 39 fArea(-1) 40 { 41 } 42 43 44 AreaKeeper::~AreaKeeper() 45 { 46 if (fArea >= B_OK) 47 delete_area(fArea); 48 } 49 50 51 area_id 52 AreaKeeper::Create(const char *name, void **_virtualAddress, uint32 spec, 53 size_t size, uint32 lock, uint32 protection) 54 { 55 fArea = create_area(name, _virtualAddress, spec, size, lock, protection); 56 return fArea; 57 } 58 59 60 area_id 61 AreaKeeper::Map(const char *name, phys_addr_t physicalAddress, size_t numBytes, 62 uint32 spec, uint32 protection, void **_virtualAddress) 63 { 64 fArea = map_physical_memory(name, physicalAddress, numBytes, spec, 65 protection, _virtualAddress); 66 return fArea; 67 } 68 69 70 void 71 AreaKeeper::Detach() 72 { 73 fArea = -1; 74 } 75 76 #endif // AREA_KEEPER_H 77