00001 /* 00002 * See the dyninst/COPYRIGHT file for copyright information. 00003 * 00004 * We provide the Paradyn Tools (below described as "Paradyn") 00005 * on an AS IS basis, and do not warrant its validity or performance. 00006 * We reserve the right to update, modify, or discontinue this 00007 * software at any time. We shall have no obligation to supply such 00008 * updates or modifications or any other form of support to you. 00009 * 00010 * By your use of Paradyn, you understand and agree that we (or any 00011 * other person or entity with proprietary rights in Paradyn) are 00012 * under no obligation to provide either maintenance services, 00013 * update services, notices of latent defects, or correction of 00014 * defects for Paradyn. 00015 * 00016 * This library is free software; you can redistribute it and/or 00017 * modify it under the terms of the GNU Lesser General Public 00018 * License as published by the Free Software Foundation; either 00019 * version 2.1 of the License, or (at your option) any later version. 00020 * 00021 * This library is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 * Lesser General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU Lesser General Public 00027 * License along with this library; if not, write to the Free Software 00028 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00029 */ 00030 #ifndef __MAPPEDFILE_H__ 00031 #define __MAPPEDFILE_H__ 00032 00033 #include "headers.h" 00034 00035 #include <string> 00036 #include "Types.h" 00037 00038 class MappedFile { 00039 static dyn_hash_map<std::string, MappedFile *> mapped_files; 00040 00041 public: 00042 COMMON_EXPORT static MappedFile *createMappedFile(std::string fullpath_); 00043 COMMON_EXPORT static MappedFile *createMappedFile(void *map_loc, unsigned long size_, const std::string &name); 00044 COMMON_EXPORT static void closeMappedFile(MappedFile *&mf); 00045 00046 COMMON_EXPORT std::string pathname(); 00047 COMMON_EXPORT std::string filename(); 00048 COMMON_EXPORT void *base_addr() {return map_addr;} 00049 #if defined(os_windows) 00050 COMMON_EXPORT HANDLE getFileHandle() {return hFile;} 00051 #else 00052 COMMON_EXPORT int getFD() {return fd;} 00053 #endif 00054 COMMON_EXPORT unsigned long size() {return file_size;} 00055 COMMON_EXPORT MappedFile *clone() { refCount++; return this; } 00056 00057 COMMON_EXPORT void setSharing(bool s); 00058 COMMON_EXPORT bool canBeShared(); 00059 00060 private: 00061 00062 MappedFile(std::string fullpath_, bool &ok); 00063 MappedFile(void *loc, unsigned long size_, const std::string & name, bool &ok); 00064 ~MappedFile(); 00065 bool clean_up(); 00066 00067 bool check_path(std::string &); 00068 bool open_file(); 00069 bool open_file(void *, unsigned long size_ = 0); 00070 bool map_file(); 00071 bool unmap_file(); 00072 bool close_file(); 00073 00074 std::string fullpath; 00075 void *map_addr; 00076 00077 #if defined (os_windows) 00078 HANDLE hMap; 00079 HANDLE hFile; 00080 #else 00081 int fd; 00082 #endif 00083 00084 bool remote_file; 00085 bool did_mmap; 00086 bool did_open; 00087 bool can_share; 00088 unsigned long file_size; 00089 int refCount; 00090 }; 00091 00092 #endif
1.6.1