From 98b7e612b2320ae83d2896b7828ea591a9bb7345 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 1 Apr 2008 06:20:44 +0000 Subject: MappedFile is dead, remove it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49035 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/System/MappedFile.cpp | 34 ------------- lib/System/Unix/MappedFile.inc | 97 ------------------------------------- lib/System/Win32/MappedFile.inc | 104 ---------------------------------------- 3 files changed, 235 deletions(-) delete mode 100644 lib/System/MappedFile.cpp delete mode 100644 lib/System/Unix/MappedFile.inc delete mode 100644 lib/System/Win32/MappedFile.inc (limited to 'lib/System') diff --git a/lib/System/MappedFile.cpp b/lib/System/MappedFile.cpp deleted file mode 100644 index d2bc403..0000000 --- a/lib/System/MappedFile.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===- MappedFile.cpp - MappedFile Support ----------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the mapped file concept. -// -//===----------------------------------------------------------------------===// - -#include "llvm/System/MappedFile.h" -#include "llvm/Config/config.h" - -namespace llvm { -using namespace sys; - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only TRULY operating system -//=== independent code. -//===----------------------------------------------------------------------===// - -} - -// Include the platform-specific parts of this class. -#ifdef LLVM_ON_UNIX -#include "Unix/MappedFile.inc" -#endif -#ifdef LLVM_ON_WIN32 -#include "Win32/MappedFile.inc" -#endif - diff --git a/lib/System/Unix/MappedFile.inc b/lib/System/Unix/MappedFile.inc deleted file mode 100644 index c85a53d..0000000 --- a/lib/System/Unix/MappedFile.inc +++ /dev/null @@ -1,97 +0,0 @@ -//===- Unix/MappedFile.inc - Unix MappedFile Implementation -----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides the generic Unix implementation of the MappedFile concept. -// -//===----------------------------------------------------------------------===// - -#include "Unix.h" -#include "llvm/System/Process.h" - -#ifdef HAVE_FCNTL_H -#include -#endif - -#ifdef HAVE_SYS_MMAN_H -#include -#endif - -#ifdef HAVE_SYS_STAT_H -#include -#endif - -using namespace llvm; -using namespace sys; - -namespace llvm { - namespace sys { - struct MappedFileInfo { - int FD; - off_t Size; - }; - } -} - -bool MappedFile::initialize(std::string* ErrMsg) { - int FD = ::open(Path.c_str(), O_RDONLY); - if (FD < 0) { - MakeErrMsg(ErrMsg, "can't open file '" + Path.toString() + "'"); - return true; - } - const FileStatus *Status = Path.getFileStatus(false, ErrMsg); - if (!Status) { - ::close(FD); - return true; - } - MapInfo = new MappedFileInfo(); - MapInfo->FD = FD; - MapInfo->Size = Status->getSize(); - return false; -} - -void MappedFile::terminate() { - unmap(); - assert(MapInfo && "MappedFile not initialized"); - ::close(MapInfo->FD); - delete MapInfo; - MapInfo = 0; -} - -void MappedFile::unmap() { - assert(MapInfo && "MappedFile not initialized"); - if (!isMapped()) return; - - ::munmap(BasePtr, MapInfo->Size); - BasePtr = 0; // Mark this as non-mapped. -} - -const void* MappedFile::map(std::string* ErrMsg) { - assert(MapInfo && "MappedFile not initialized"); - if (isMapped()) return BasePtr; - - int flags = MAP_PRIVATE; -#ifdef MAP_FILE - flags |= MAP_FILE; -#endif - size_t PageSize = Process::GetPageSize(); - size_t map_size = ((MapInfo->Size / PageSize)+1) * PageSize; - - BasePtr = ::mmap(0, map_size, PROT_READ, flags, MapInfo->FD, 0); - if (BasePtr == MAP_FAILED) { - MakeErrMsg(ErrMsg, "Can't map file:" + Path.toString()); - return 0; - } - return BasePtr; -} - -size_t MappedFile::size() const { - assert(MapInfo && "MappedFile not initialized"); - return MapInfo->Size; -} - diff --git a/lib/System/Win32/MappedFile.inc b/lib/System/Win32/MappedFile.inc deleted file mode 100644 index 4f30f56..0000000 --- a/lib/System/Win32/MappedFile.inc +++ /dev/null @@ -1,104 +0,0 @@ -//===- Win32/MappedFile.cpp - Win32 MappedFile Implementation ---*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides the Win32 implementation of the MappedFile concept. -// -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only Win32 code. -//===----------------------------------------------------------------------===// - -#include "Win32.h" -#include "llvm/System/Process.h" - -namespace llvm { -using namespace sys; - -struct sys::MappedFileInfo { - HANDLE hFile; - HANDLE hMapping; - size_t size; -}; - -bool MappedFile::initialize(std::string* ErrMsg) { - assert(!MapInfo); - MapInfo = new MappedFileInfo; - MapInfo->hFile = INVALID_HANDLE_VALUE; - MapInfo->hMapping = NULL; - - MapInfo->hFile = CreateFile(Path.c_str(), GENERIC_READ, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (MapInfo->hFile == INVALID_HANDLE_VALUE) { - delete MapInfo; - MapInfo = NULL; - return MakeErrMsg(ErrMsg, - std::string("Can't open file: ") + Path.toString()); - } - - LARGE_INTEGER size; - if (!GetFileSizeEx(MapInfo->hFile, &size) || - (MapInfo->size = size_t(size.QuadPart), MapInfo->size != size.QuadPart)) { - CloseHandle(MapInfo->hFile); - delete MapInfo; - MapInfo = NULL; - return MakeErrMsg(ErrMsg, - std::string("Can't get size of file: ") + Path.toString()); - } - - return false; -} - -void MappedFile::terminate() { - unmap(); - if (MapInfo->hFile != INVALID_HANDLE_VALUE) - CloseHandle(MapInfo->hFile); - delete MapInfo; - MapInfo = NULL; -} - -void MappedFile::unmap() { - assert(MapInfo && "MappedFile not initialized"); - if (isMapped()) { - UnmapViewOfFile(BasePtr); - BasePtr = NULL; - } - if (MapInfo->hMapping != INVALID_HANDLE_VALUE) { - CloseHandle(MapInfo->hMapping); - MapInfo->hMapping = NULL; - } -} - -const void* MappedFile::map(std::string* ErrMsg) { - if (!isMapped()) { - MapInfo->hMapping = CreateFileMapping(MapInfo->hFile, NULL, PAGE_READONLY, - 0, 0, NULL); - if (MapInfo->hMapping == NULL) { - MakeErrMsg(ErrMsg, std::string("Can't map file: ") + Path.toString()); - return 0; - } - - BasePtr = MapViewOfFileEx(MapInfo->hMapping, FILE_MAP_READ, 0, 0, 0, NULL); - if (BasePtr == NULL) { - CloseHandle(MapInfo->hMapping); - MapInfo->hMapping = NULL; - MakeErrMsg(ErrMsg, std::string("Can't map file: ") + Path.toString()); - return 0; - } - } - return BasePtr; -} - -size_t MappedFile::size() const { - assert(MapInfo && "MappedFile not initialized"); - return MapInfo->size; -} - -} - -- cgit v1.1