Loading libutils/FileMap.cpp +36 −44 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <utils/FileMap.h> #include <utils/Log.h> #include <inttypes.h> #include <stdio.h> #include <stdlib.h> Loading @@ -39,24 +40,19 @@ using namespace android; /*static*/ long FileMap::mPageSize = -1; /* * Constructor. Create an empty object. */ // Constructor. Create an empty object. FileMap::FileMap(void) : mRefCount(1), mFileName(NULL), mBasePtr(NULL), mBaseLength(0), mDataPtr(NULL), mDataLength(0) { } /* * Destructor. */ // Destructor. FileMap::~FileMap(void) { assert(mRefCount == 0); //printf("+++ removing FileMap %p %u\n", mDataPtr, mDataLength); //printf("+++ removing FileMap %p %zu\n", mDataPtr, mDataLength); mRefCount = -100; // help catch double-free if (mFileName != NULL) { Loading @@ -64,12 +60,12 @@ FileMap::~FileMap(void) } #ifdef HAVE_POSIX_FILEMAP if (mBasePtr && munmap(mBasePtr, mBaseLength) != 0) { ALOGD("munmap(%p, %d) failed\n", mBasePtr, (int) mBaseLength); ALOGD("munmap(%p, %zu) failed\n", mBasePtr, mBaseLength); } #endif #ifdef HAVE_WIN32_FILEMAP if (mBasePtr && UnmapViewOfFile(mBasePtr) == 0) { ALOGD("UnmapViewOfFile(%p) failed, error = %ld\n", mBasePtr, ALOGD("UnmapViewOfFile(%p) failed, error = %" PRId32 "\n", mBasePtr, GetLastError() ); } if (mFileMapping != INVALID_HANDLE_VALUE) { Loading @@ -80,14 +76,12 @@ FileMap::~FileMap(void) } /* * Create a new mapping on an open file. * * Closing the file descriptor does not unmap the pages, so we don't * claim ownership of the fd. * * Returns "false" on failure. */ // Create a new mapping on an open file. // // Closing the file descriptor does not unmap the pages, so we don't // claim ownership of the fd. // // Returns "false" on failure. bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t length, bool readOnly) { Loading @@ -108,7 +102,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le mFileHandle = (HANDLE) _get_osfhandle(fd); mFileMapping = CreateFileMapping( mFileHandle, NULL, protect, 0, 0, NULL); if (mFileMapping == NULL) { ALOGE("CreateFileMapping(%p, %lx) failed with error %ld\n", ALOGE("CreateFileMapping(%p, %" PRIx32 ") failed with error %" PRId32 "\n", mFileHandle, protect, GetLastError() ); return false; } Loading @@ -123,7 +117,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le (DWORD)(adjOffset), adjLength ); if (mBasePtr == NULL) { ALOGE("MapViewOfFile(%ld, %ld) failed with error %ld\n", ALOGE("MapViewOfFile(%" PRId64 ", %zu) failed with error %" PRId32 "\n", adjOffset, adjLength, GetLastError() ); CloseHandle(mFileMapping); mFileMapping = INVALID_HANDLE_VALUE; Loading @@ -142,7 +136,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le assert(offset >= 0); assert(length > 0); /* init on first use */ // init on first use if (mPageSize == -1) { #if NOT_USING_KLIBC mPageSize = sysconf(_SC_PAGESIZE); Loading @@ -151,7 +145,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le return false; } #else /* this holds for Linux, Darwin, Cygwin, and doesn't pain the ARM */ // this holds for Linux, Darwin, Cygwin, and doesn't pain the ARM mPageSize = 4096; #endif } Loading @@ -175,12 +169,12 @@ try_again: goto try_again; } ALOGE("mmap(%ld,%ld) failed: %s\n", (long) adjOffset, (long) adjLength, strerror(errno)); ALOGE("mmap(%" PRId64 ",%zu) failed: %s\n", adjOffset, adjLength, strerror(errno)); return false; } mBasePtr = ptr; #endif /* HAVE_POSIX_FILEMAP */ #endif // HAVE_POSIX_FILEMAP mFileName = origFileName != NULL ? strdup(origFileName) : NULL; mBaseLength = adjLength; Loading @@ -190,15 +184,13 @@ try_again: assert(mBasePtr != NULL); ALOGV("MAP: base %p/%d data %p/%d\n", mBasePtr, (int) mBaseLength, mDataPtr, (int) mDataLength); ALOGV("MAP: base %p/%zu data %p/%zu\n", mBasePtr, mBaseLength, mDataPtr, mDataLength); return true; } /* * Provide guidance to the system. */ // Provide guidance to the system. int FileMap::advise(MapAdvice advice) { #if HAVE_MADVISE Loading Loading
libutils/FileMap.cpp +36 −44 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <utils/FileMap.h> #include <utils/Log.h> #include <inttypes.h> #include <stdio.h> #include <stdlib.h> Loading @@ -39,24 +40,19 @@ using namespace android; /*static*/ long FileMap::mPageSize = -1; /* * Constructor. Create an empty object. */ // Constructor. Create an empty object. FileMap::FileMap(void) : mRefCount(1), mFileName(NULL), mBasePtr(NULL), mBaseLength(0), mDataPtr(NULL), mDataLength(0) { } /* * Destructor. */ // Destructor. FileMap::~FileMap(void) { assert(mRefCount == 0); //printf("+++ removing FileMap %p %u\n", mDataPtr, mDataLength); //printf("+++ removing FileMap %p %zu\n", mDataPtr, mDataLength); mRefCount = -100; // help catch double-free if (mFileName != NULL) { Loading @@ -64,12 +60,12 @@ FileMap::~FileMap(void) } #ifdef HAVE_POSIX_FILEMAP if (mBasePtr && munmap(mBasePtr, mBaseLength) != 0) { ALOGD("munmap(%p, %d) failed\n", mBasePtr, (int) mBaseLength); ALOGD("munmap(%p, %zu) failed\n", mBasePtr, mBaseLength); } #endif #ifdef HAVE_WIN32_FILEMAP if (mBasePtr && UnmapViewOfFile(mBasePtr) == 0) { ALOGD("UnmapViewOfFile(%p) failed, error = %ld\n", mBasePtr, ALOGD("UnmapViewOfFile(%p) failed, error = %" PRId32 "\n", mBasePtr, GetLastError() ); } if (mFileMapping != INVALID_HANDLE_VALUE) { Loading @@ -80,14 +76,12 @@ FileMap::~FileMap(void) } /* * Create a new mapping on an open file. * * Closing the file descriptor does not unmap the pages, so we don't * claim ownership of the fd. * * Returns "false" on failure. */ // Create a new mapping on an open file. // // Closing the file descriptor does not unmap the pages, so we don't // claim ownership of the fd. // // Returns "false" on failure. bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t length, bool readOnly) { Loading @@ -108,7 +102,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le mFileHandle = (HANDLE) _get_osfhandle(fd); mFileMapping = CreateFileMapping( mFileHandle, NULL, protect, 0, 0, NULL); if (mFileMapping == NULL) { ALOGE("CreateFileMapping(%p, %lx) failed with error %ld\n", ALOGE("CreateFileMapping(%p, %" PRIx32 ") failed with error %" PRId32 "\n", mFileHandle, protect, GetLastError() ); return false; } Loading @@ -123,7 +117,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le (DWORD)(adjOffset), adjLength ); if (mBasePtr == NULL) { ALOGE("MapViewOfFile(%ld, %ld) failed with error %ld\n", ALOGE("MapViewOfFile(%" PRId64 ", %zu) failed with error %" PRId32 "\n", adjOffset, adjLength, GetLastError() ); CloseHandle(mFileMapping); mFileMapping = INVALID_HANDLE_VALUE; Loading @@ -142,7 +136,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le assert(offset >= 0); assert(length > 0); /* init on first use */ // init on first use if (mPageSize == -1) { #if NOT_USING_KLIBC mPageSize = sysconf(_SC_PAGESIZE); Loading @@ -151,7 +145,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le return false; } #else /* this holds for Linux, Darwin, Cygwin, and doesn't pain the ARM */ // this holds for Linux, Darwin, Cygwin, and doesn't pain the ARM mPageSize = 4096; #endif } Loading @@ -175,12 +169,12 @@ try_again: goto try_again; } ALOGE("mmap(%ld,%ld) failed: %s\n", (long) adjOffset, (long) adjLength, strerror(errno)); ALOGE("mmap(%" PRId64 ",%zu) failed: %s\n", adjOffset, adjLength, strerror(errno)); return false; } mBasePtr = ptr; #endif /* HAVE_POSIX_FILEMAP */ #endif // HAVE_POSIX_FILEMAP mFileName = origFileName != NULL ? strdup(origFileName) : NULL; mBaseLength = adjLength; Loading @@ -190,15 +184,13 @@ try_again: assert(mBasePtr != NULL); ALOGV("MAP: base %p/%d data %p/%d\n", mBasePtr, (int) mBaseLength, mDataPtr, (int) mDataLength); ALOGV("MAP: base %p/%zu data %p/%zu\n", mBasePtr, mBaseLength, mDataPtr, mDataLength); return true; } /* * Provide guidance to the system. */ // Provide guidance to the system. int FileMap::advise(MapAdvice advice) { #if HAVE_MADVISE Loading