Merge "logd: libsysutils: logd startup outside init environment"
diff --git a/libutils/BlobCache.cpp b/libutils/BlobCache.cpp
index 0fb1d8e..660917b 100644
--- a/libutils/BlobCache.cpp
+++ b/libutils/BlobCache.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "BlobCache"
//#define LOG_NDEBUG 0
+#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
@@ -54,18 +55,18 @@
void BlobCache::set(const void* key, size_t keySize, const void* value,
size_t valueSize) {
if (mMaxKeySize < keySize) {
- ALOGV("set: not caching because the key is too large: %d (limit: %d)",
+ ALOGV("set: not caching because the key is too large: %zu (limit: %zu)",
keySize, mMaxKeySize);
return;
}
if (mMaxValueSize < valueSize) {
- ALOGV("set: not caching because the value is too large: %d (limit: %d)",
+ ALOGV("set: not caching because the value is too large: %zu (limit: %zu)",
valueSize, mMaxValueSize);
return;
}
if (mMaxTotalSize < keySize + valueSize) {
ALOGV("set: not caching because the combined key/value size is too "
- "large: %d (limit: %d)", keySize + valueSize, mMaxTotalSize);
+ "large: %zu (limit: %zu)", keySize + valueSize, mMaxTotalSize);
return;
}
if (keySize == 0) {
@@ -94,15 +95,15 @@
continue;
} else {
ALOGV("set: not caching new key/value pair because the "
- "total cache size limit would be exceeded: %d "
- "(limit: %d)",
+ "total cache size limit would be exceeded: %zu "
+ "(limit: %zu)",
keySize + valueSize, mMaxTotalSize);
break;
}
}
mCacheEntries.add(CacheEntry(keyBlob, valueBlob));
mTotalSize = newTotalSize;
- ALOGV("set: created new cache entry with %d byte key and %d byte value",
+ ALOGV("set: created new cache entry with %zu byte key and %zu byte value",
keySize, valueSize);
} else {
// Update the existing cache entry.
@@ -116,14 +117,14 @@
continue;
} else {
ALOGV("set: not caching new value because the total cache "
- "size limit would be exceeded: %d (limit: %d)",
+ "size limit would be exceeded: %zu (limit: %zu)",
keySize + valueSize, mMaxTotalSize);
break;
}
}
mCacheEntries.editItemAt(index).setValue(valueBlob);
mTotalSize = newTotalSize;
- ALOGV("set: updated existing cache entry with %d byte key and %d byte "
+ ALOGV("set: updated existing cache entry with %zu byte key and %zu byte "
"value", keySize, valueSize);
}
break;
@@ -133,7 +134,7 @@
size_t BlobCache::get(const void* key, size_t keySize, void* value,
size_t valueSize) {
if (mMaxKeySize < keySize) {
- ALOGV("get: not searching because the key is too large: %d (limit %d)",
+ ALOGV("get: not searching because the key is too large: %zu (limit %zu)",
keySize, mMaxKeySize);
return 0;
}
@@ -141,7 +142,7 @@
CacheEntry dummyEntry(dummyKey, NULL);
ssize_t index = mCacheEntries.indexOf(dummyEntry);
if (index < 0) {
- ALOGV("get: no cache entry found for key of size %d", keySize);
+ ALOGV("get: no cache entry found for key of size %zu", keySize);
return 0;
}
@@ -150,10 +151,10 @@
sp<Blob> valueBlob(mCacheEntries[index].getValue());
size_t valueBlobSize = valueBlob->getSize();
if (valueBlobSize <= valueSize) {
- ALOGV("get: copying %d bytes to caller's buffer", valueBlobSize);
+ ALOGV("get: copying %zu bytes to caller's buffer", valueBlobSize);
memcpy(value, valueBlob->getData(), valueBlobSize);
} else {
- ALOGV("get: caller's buffer is too small for value: %d (needs %d)",
+ ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)",
valueSize, valueBlobSize);
}
return valueBlobSize;
@@ -229,7 +230,7 @@
}
const Header* header = reinterpret_cast<const Header*>(buffer);
if (header->mMagicNumber != blobCacheMagic) {
- ALOGE("unflatten: bad magic number: %d", header->mMagicNumber);
+ ALOGE("unflatten: bad magic number: %" PRIu32, header->mMagicNumber);
return BAD_VALUE;
}
if (header->mBlobCacheVersion != blobCacheVersion ||
diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp
index 9ce370e..933e7aa 100644
--- a/libutils/FileMap.cpp
+++ b/libutils/FileMap.cpp
@@ -23,6 +23,7 @@
#include <utils/FileMap.h>
#include <utils/Log.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@@ -39,37 +40,32 @@
/*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) {
free(mFileName);
}
-#ifdef HAVE_POSIX_FILEMAP
+#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) {
@@ -80,14 +76,12 @@
}
-/*
- * 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)
{
@@ -98,32 +92,32 @@
if (mPageSize == -1) {
SYSTEM_INFO si;
-
+
GetSystemInfo( &si );
mPageSize = si.dwAllocationGranularity;
}
DWORD protect = readOnly ? PAGE_READONLY : PAGE_READWRITE;
-
+
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;
}
-
+
adjust = offset % mPageSize;
adjOffset = offset - adjust;
adjLength = length + adjust;
-
- mBasePtr = MapViewOfFile( mFileMapping,
+
+ mBasePtr = MapViewOfFile( mFileMapping,
readOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS,
0,
(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;
@@ -142,7 +136,7 @@
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);
@@ -151,7 +145,7 @@
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
}
@@ -168,19 +162,19 @@
ptr = mmap(NULL, adjLength, prot, flags, fd, adjOffset);
if (ptr == MAP_FAILED) {
- // Cygwin does not seem to like file mapping files from an offset.
- // So if we fail, try again with offset zero
- if (adjOffset > 0) {
- adjust = offset;
- goto try_again;
- }
-
- ALOGE("mmap(%ld,%ld) failed: %s\n",
- (long) adjOffset, (long) adjLength, strerror(errno));
+ // Cygwin does not seem to like file mapping files from an offset.
+ // So if we fail, try again with offset zero
+ if (adjOffset > 0) {
+ adjust = offset;
+ goto try_again;
+ }
+
+ 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;
@@ -190,15 +184,13 @@
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
@@ -220,6 +212,6 @@
ALOGW("madvise(%d) failed: %s\n", sysAdvice, strerror(errno));
return cc;
#else
- return -1;
+ return -1;
#endif // HAVE_MADVISE
}