summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Archive/ArchiveReader.cpp22
-rw-r--r--lib/Bytecode/Archive/ArchiveReader.cpp22
-rw-r--r--lib/Bytecode/Reader/ArchiveReader.cpp22
-rw-r--r--lib/Bytecode/Reader/ReaderWrappers.cpp24
4 files changed, 30 insertions, 60 deletions
diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp
index 8671c422a1..1e2d2b4713 100644
--- a/lib/Archive/ArchiveReader.cpp
+++ b/lib/Archive/ArchiveReader.cpp
@@ -19,8 +19,6 @@
#include "llvm/Bytecode/Reader.h"
#include "llvm/Module.h"
#include "Support/FileUtilities.h"
-#include "Config/sys/mman.h"
-#include "Config/fcntl.h"
#include <cstdlib>
using namespace llvm;
@@ -166,25 +164,21 @@ static bool ReadArchiveBuffer(const std::string &ArchiveName,
//
bool llvm::ReadArchiveFile(const std::string &Filename,
std::vector<Module*> &Objects,std::string *ErrorStr){
- int Length = getFileSize(Filename);
- if (Length == -1)
- return Error(ErrorStr, "Error getting file length!");
+ unsigned Length;
- int FD = open(Filename.c_str(), O_RDONLY);
- if (FD == -1)
- return Error(ErrorStr, "Error opening file!");
-
// mmap in the file all at once...
- unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ,
- MAP_PRIVATE, FD, 0);
- if (Buffer == (unsigned char*)MAP_FAILED)
- return Error(ErrorStr, "Error mmapping file!");
+ unsigned char *Buffer =
+ (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
+ if (Buffer == 0) {
+ if (ErrorStr) *ErrorStr = "Error reading file '" + Filename + "'!";
+ return true;
+ }
// Parse the archive files we mmap'ped in
bool Result = ReadArchiveBuffer(Filename, Buffer, Length, Objects, ErrorStr);
// Unmmap the archive...
- munmap((char*)Buffer, Length);
+ UnmapFileFromAddressSpace(Buffer, Length);
if (Result) // Free any loaded objects
while (!Objects.empty()) {
diff --git a/lib/Bytecode/Archive/ArchiveReader.cpp b/lib/Bytecode/Archive/ArchiveReader.cpp
index 8671c422a1..1e2d2b4713 100644
--- a/lib/Bytecode/Archive/ArchiveReader.cpp
+++ b/lib/Bytecode/Archive/ArchiveReader.cpp
@@ -19,8 +19,6 @@
#include "llvm/Bytecode/Reader.h"
#include "llvm/Module.h"
#include "Support/FileUtilities.h"
-#include "Config/sys/mman.h"
-#include "Config/fcntl.h"
#include <cstdlib>
using namespace llvm;
@@ -166,25 +164,21 @@ static bool ReadArchiveBuffer(const std::string &ArchiveName,
//
bool llvm::ReadArchiveFile(const std::string &Filename,
std::vector<Module*> &Objects,std::string *ErrorStr){
- int Length = getFileSize(Filename);
- if (Length == -1)
- return Error(ErrorStr, "Error getting file length!");
+ unsigned Length;
- int FD = open(Filename.c_str(), O_RDONLY);
- if (FD == -1)
- return Error(ErrorStr, "Error opening file!");
-
// mmap in the file all at once...
- unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ,
- MAP_PRIVATE, FD, 0);
- if (Buffer == (unsigned char*)MAP_FAILED)
- return Error(ErrorStr, "Error mmapping file!");
+ unsigned char *Buffer =
+ (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
+ if (Buffer == 0) {
+ if (ErrorStr) *ErrorStr = "Error reading file '" + Filename + "'!";
+ return true;
+ }
// Parse the archive files we mmap'ped in
bool Result = ReadArchiveBuffer(Filename, Buffer, Length, Objects, ErrorStr);
// Unmmap the archive...
- munmap((char*)Buffer, Length);
+ UnmapFileFromAddressSpace(Buffer, Length);
if (Result) // Free any loaded objects
while (!Objects.empty()) {
diff --git a/lib/Bytecode/Reader/ArchiveReader.cpp b/lib/Bytecode/Reader/ArchiveReader.cpp
index 8671c422a1..1e2d2b4713 100644
--- a/lib/Bytecode/Reader/ArchiveReader.cpp
+++ b/lib/Bytecode/Reader/ArchiveReader.cpp
@@ -19,8 +19,6 @@
#include "llvm/Bytecode/Reader.h"
#include "llvm/Module.h"
#include "Support/FileUtilities.h"
-#include "Config/sys/mman.h"
-#include "Config/fcntl.h"
#include <cstdlib>
using namespace llvm;
@@ -166,25 +164,21 @@ static bool ReadArchiveBuffer(const std::string &ArchiveName,
//
bool llvm::ReadArchiveFile(const std::string &Filename,
std::vector<Module*> &Objects,std::string *ErrorStr){
- int Length = getFileSize(Filename);
- if (Length == -1)
- return Error(ErrorStr, "Error getting file length!");
+ unsigned Length;
- int FD = open(Filename.c_str(), O_RDONLY);
- if (FD == -1)
- return Error(ErrorStr, "Error opening file!");
-
// mmap in the file all at once...
- unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ,
- MAP_PRIVATE, FD, 0);
- if (Buffer == (unsigned char*)MAP_FAILED)
- return Error(ErrorStr, "Error mmapping file!");
+ unsigned char *Buffer =
+ (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
+ if (Buffer == 0) {
+ if (ErrorStr) *ErrorStr = "Error reading file '" + Filename + "'!";
+ return true;
+ }
// Parse the archive files we mmap'ped in
bool Result = ReadArchiveBuffer(Filename, Buffer, Length, Objects, ErrorStr);
// Unmmap the archive...
- munmap((char*)Buffer, Length);
+ UnmapFileFromAddressSpace(Buffer, Length);
if (Result) // Free any loaded objects
while (!Objects.empty()) {
diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp
index ef5e70d42b..be1541707e 100644
--- a/lib/Bytecode/Reader/ReaderWrappers.cpp
+++ b/lib/Bytecode/Reader/ReaderWrappers.cpp
@@ -18,9 +18,7 @@
#include "llvm/Instructions.h"
#include "Support/FileUtilities.h"
#include "Support/StringExtras.h"
-#include "Config/fcntl.h"
#include "Config/unistd.h"
-#include "Config/sys/mman.h"
#include <cerrno>
using namespace llvm;
@@ -34,7 +32,7 @@ namespace {
class BytecodeFileReader : public BytecodeParser {
private:
unsigned char *Buffer;
- int Length;
+ unsigned Length;
BytecodeFileReader(const BytecodeFileReader&); // Do not implement
void operator=(const BytecodeFileReader &BFR); // Do not implement
@@ -50,32 +48,22 @@ static std::string ErrnoMessage (int savedErrNum, std::string descr) {
}
BytecodeFileReader::BytecodeFileReader(const std::string &Filename) {
- Length = getFileSize(Filename);
- if (Length == -1)
- throw ErrnoMessage(errno, "stat '" + Filename + "'");
-
- FDHandle FD(open(Filename.c_str(), O_RDONLY));
- if (FD == -1)
- throw ErrnoMessage(errno, "open '" + Filename + "'");
-
- // mmap in the file all at once...
- Buffer = (unsigned char*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0);
-
- if (Buffer == (unsigned char*)MAP_FAILED)
- throw ErrnoMessage(errno, "map '" + Filename + "' into memory");
+ Buffer = (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
+ if (Buffer == 0)
+ throw "Error reading file '" + Filename + "'.";
try {
// Parse the bytecode we mmapped in
ParseBytecode(Buffer, Length, Filename);
} catch (...) {
- munmap((char*)Buffer, Length);
+ UnmapFileFromAddressSpace(Buffer, Length);
throw;
}
}
BytecodeFileReader::~BytecodeFileReader() {
// Unmmap the bytecode...
- munmap((char*)Buffer, Length);
+ UnmapFileFromAddressSpace(Buffer, Length);
}
//===----------------------------------------------------------------------===//