//
// The LLVM Compiler Infrastructure
//
-// This file was developed by Jeff Cohen and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//===----------------------------------------------------------------------===//
#include "Win32.h"
-#include "llvm/System/MappedFile.h"
#include "llvm/System/Process.h"
namespace llvm {
size_t size;
};
-void MappedFile::initialize() {
+bool MappedFile::initialize(std::string* ErrMsg) {
assert(!info_);
info_ = new MappedFileInfo;
info_->hFile = INVALID_HANDLE_VALUE;
if (info_->hFile == INVALID_HANDLE_VALUE) {
delete info_;
info_ = NULL;
- ThrowError(std::string("Can't open file: ") + path_.get());
+ return MakeErrMsg(ErrMsg,
+ std::string("Can't open file: ") + path_.toString());
}
LARGE_INTEGER size;
CloseHandle(info_->hFile);
delete info_;
info_ = NULL;
- ThrowError(std::string("Can't get size of file: ") + path_.get());
+ return MakeErrMsg(ErrMsg,
+ std::string("Can't get size of file: ") + path_.toString());
}
+
+ return false;
}
void MappedFile::terminate() {
}
}
-void* MappedFile::map() {
+void* MappedFile::map(std::string* ErrMsg) {
if (!isMapped()) {
DWORD prot = PAGE_READONLY;
if (options_ & EXEC_ACCESS)
else if (options_ & WRITE_ACCESS)
prot = PAGE_READWRITE;
info_->hMapping = CreateFileMapping(info_->hFile, NULL, prot, 0, 0, NULL);
- if (info_->hMapping == NULL)
- ThrowError(std::string("Can't map file: ") + path_.get());
+ if (info_->hMapping == NULL) {
+ MakeErrMsg(ErrMsg, std::string("Can't map file: ") + path_.toString());
+ return 0;
+ }
prot = (options_ & WRITE_ACCESS) ? FILE_MAP_WRITE : FILE_MAP_READ;
base_ = MapViewOfFileEx(info_->hMapping, prot, 0, 0, 0, NULL);
if (base_ == NULL) {
CloseHandle(info_->hMapping);
info_->hMapping = NULL;
- ThrowError(std::string("Can't map file: ") + path_.get());
+ MakeErrMsg(ErrMsg, std::string("Can't map file: ") + path_.toString());
+ return 0;
}
}
return base_;
}
-size_t MappedFile::size() {
+size_t MappedFile::size() const {
assert(info_ && "MappedFile not initialized");
return info_->size;
}
-void MappedFile::size(size_t new_size) {
+bool MappedFile::size(size_t new_size, std::string* ErrMsg) {
assert(info_ && "MappedFile not initialized");
// Take the mapping out of memory.
LARGE_INTEGER eof;
eof.QuadPart = new_size;
if (!SetFilePointerEx(info_->hFile, eof, NULL, FILE_BEGIN))
- ThrowError(std::string("Can't set end of file: ") + path_.get());
+ return MakeErrMsg(ErrMsg,
+ std::string("Can't set end of file: ") + path_.toString());
if (!SetEndOfFile(info_->hFile))
- ThrowError(std::string("Can't set end of file: ") + path_.get());
+ return MakeErrMsg(ErrMsg,
+ std::string("Can't set end of file: ") + path_.toString());
info_->size = new_size;
}
// Remap the file.
- map();
+ return map(ErrMsg);
}
}
-// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab