diff options
Diffstat (limited to 'llvm/lib/System')
| -rw-r--r-- | llvm/lib/System/MappedFile.cpp | 34 | ||||
| -rw-r--r-- | llvm/lib/System/Unix/MappedFile.inc | 97 | ||||
| -rw-r--r-- | llvm/lib/System/Win32/MappedFile.inc | 104 | 
3 files changed, 0 insertions, 235 deletions
diff --git a/llvm/lib/System/MappedFile.cpp b/llvm/lib/System/MappedFile.cpp deleted file mode 100644 index d2bc40355ee..00000000000 --- a/llvm/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/llvm/lib/System/Unix/MappedFile.inc b/llvm/lib/System/Unix/MappedFile.inc deleted file mode 100644 index c85a53d6641..00000000000 --- a/llvm/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 <fcntl.h> -#endif - -#ifdef HAVE_SYS_MMAN_H -#include <sys/mman.h> -#endif - -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#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/llvm/lib/System/Win32/MappedFile.inc b/llvm/lib/System/Win32/MappedFile.inc deleted file mode 100644 index 4f30f56f74c..00000000000 --- a/llvm/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; -} - -} -  | 

