aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-01 06:20:44 +0000
committerChris Lattner <sabre@nondot.org>2008-04-01 06:20:44 +0000
commit98b7e612b2320ae83d2896b7828ea591a9bb7345 (patch)
tree144b9660cc8f70537979855612632636ef22f769
parent9ffd19af2e2a17ccd0c7ad7b4cf6d8c3e9a56bae (diff)
downloadexternal_llvm-98b7e612b2320ae83d2896b7828ea591a9bb7345.zip
external_llvm-98b7e612b2320ae83d2896b7828ea591a9bb7345.tar.gz
external_llvm-98b7e612b2320ae83d2896b7828ea591a9bb7345.tar.bz2
MappedFile is dead, remove it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49035 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/System/MappedFile.h85
-rw-r--r--lib/System/MappedFile.cpp34
-rw-r--r--lib/System/Unix/MappedFile.inc97
-rw-r--r--lib/System/Win32/MappedFile.inc104
4 files changed, 0 insertions, 320 deletions
diff --git a/include/llvm/System/MappedFile.h b/include/llvm/System/MappedFile.h
deleted file mode 100644
index 127c04f..0000000
--- a/include/llvm/System/MappedFile.h
+++ /dev/null
@@ -1,85 +0,0 @@
-//===- llvm/System/MappedFile.h - MappedFile OS Concept ---------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file declares the llvm::sys::MappedFile class.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SYSTEM_MAPPEDFILE_H
-#define LLVM_SYSTEM_MAPPEDFILE_H
-
-#include "llvm/System/Path.h"
-
-namespace llvm {
-namespace sys {
-
- /// Forward declare a class used for holding platform specific information
- /// that needs to be
- struct MappedFileInfo;
-
- /// This class provides an abstraction for a memory mapped file in the
- /// operating system's filesystem. It provides platform independent operations
- /// for mapping a file into memory for read access.
- class MappedFile {
- sys::PathWithStatus Path; ///< Path to the file.
- void *BasePtr; ///< Pointer to the base memory address
- mutable MappedFileInfo *MapInfo; ///< Platform specific info for the mapping
-
- MappedFile& operator=(const MappedFile &that); // DO NOT IMPLEMENT
- MappedFile(const MappedFile &that); // DO NOT IMPLEMENT
- public:
- MappedFile() : BasePtr(0), MapInfo(0) {}
-
- /// Destruct a MappedFile and release all memory associated with it.
- ~MappedFile() { close(); }
-
- public: // Accessors
-
- /// This function determines if the file is currently mapped or not.
- bool isMapped() const { return BasePtr != 0; }
-
- /// getBase - Returns a const void* pointer to the base address of the file
- /// mapping. This is the memory address of the first byte in the file.
- const void *getBase() const { return BasePtr; }
-
- /// This function returns a reference to the sys::Path object kept by the
- /// MappedFile object. This contains the path to the file that is or
- /// will be mapped.
- const sys::PathWithStatus &path() const { return Path; }
-
- /// This function returns the number of bytes in the file.
- size_t size() const;
-
- public: // Mutators
-
- /// Open a file to be mapped and get its size but don't map it yet. Return
- /// true on error.
- bool open(const sys::Path &P, std::string *ErrMsg = 0) {
- Path = P;
- return initialize(ErrMsg);
- }
-
- /// unmap - Remove the mapped file from memory.
- void unmap();
-
- /// map - Reserve space for the file, map it into memory, and return a
- /// pointer to it. This returns the base memory address of the mapped file
- /// or 0 if an error occurred.
- const void *map(std::string* ErrMsg = 0);
-
- void close() { if (MapInfo) terminate(); }
-
- private:
- bool initialize(std::string *ErrMsg);
- void terminate();
- };
-} // end namespace sys
-} // end namespace llvm
-
-#endif
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 <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/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;
-}
-
-}
-