diff options
author | Derek Schuff <dschuff@chromium.org> | 2012-07-09 10:52:46 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2012-07-09 11:00:37 -0700 |
commit | 5dbcc7e0c9c12f4a4042fb4a226654aee927999c (patch) | |
tree | b316a3370e9286cb4e6f81b2f9d8bd8b54ce5123 /lib/Support/MemoryBuffer.cpp | |
parent | 86dc97be9ac3b4804528e087b04b4f4192cdee54 (diff) |
LOCALMODs from hg 0b098ca44de7 against r158408 (hg 90a87d6bfe45)
(only non-new files; new files in git 4f429c8b)
Change-Id: Ia39f818088485bd90e4d048db404f8d6ba5f836b
Diffstat (limited to 'lib/Support/MemoryBuffer.cpp')
-rw-r--r-- | lib/Support/MemoryBuffer.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index 16e5c7a9f7..90672b68f7 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -231,7 +231,7 @@ error_code MemoryBuffer::getFile(const char *Filename, static bool shouldUseMmap(int FD, size_t FileSize, size_t MapSize, - off_t Offset, + int64_t Offset, bool RequiresNullTerminator, int PageSize) { // We don't use mmap for small files because this can severely fragment our @@ -243,6 +243,10 @@ static bool shouldUseMmap(int FD, return true; +// LLVM uses mmap to read the file contents. This disallows use of the +// wrapper syscalls defined in tools/llc/nacl_file.c. Thus, when NACL_SRPC +// is specified, code sequence execising the read syscall below is used. +#if !defined(NACL_SRPC) // If we don't know the file size, use fstat to find out. fstat on an open // file descriptor is cheaper than stat on a random path. // FIXME: this chunk of code is duplicated, but it avoids a fstat when @@ -255,6 +259,9 @@ static bool shouldUseMmap(int FD, } FileSize = FileInfo.st_size; } +#else + assert(FileSize != -1 && "invalid file size!"); +#endif // If we need a null terminator and the end of the map is inside the file, // we cannot use mmap. @@ -282,6 +289,7 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename, if (MapSize == uint64_t(-1)) { // If we don't know the file size, use fstat to find out. fstat on an open // file descriptor is cheaper than stat on a random path. +#if !defined(NACL_SRPC) if (FileSize == uint64_t(-1)) { struct stat FileInfo; // TODO: This should use fstat64 when available. @@ -290,13 +298,16 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename, } FileSize = FileInfo.st_size; } +#else + assert(FileSize != -1 && "invalid file size!"); +#endif MapSize = FileSize; } if (shouldUseMmap(FD, FileSize, MapSize, Offset, RequiresNullTerminator, PageSize)) { - off_t RealMapOffset = Offset & ~(PageSize - 1); - off_t Delta = Offset - RealMapOffset; + int64_t RealMapOffset = Offset & ~(PageSize - 1); + int64_t Delta = Offset - RealMapOffset; size_t RealMapSize = MapSize + Delta; if (const char *Pages = sys::Path::MapInFilePages(FD, |