summaryrefslogtreecommitdiffstats
path: root/libs/binder
diff options
context:
space:
mode:
Diffstat (limited to 'libs/binder')
-rw-r--r--libs/binder/Android.mk10
-rw-r--r--libs/binder/Binder.cpp22
-rw-r--r--libs/binder/BpBinder.cpp4
-rw-r--r--libs/binder/Debug.cpp2
-rw-r--r--libs/binder/IMemory.cpp14
-rw-r--r--libs/binder/IPCThreadState.cpp88
-rw-r--r--libs/binder/MemoryDealer.cpp6
-rw-r--r--libs/binder/Parcel.cpp149
-rw-r--r--libs/binder/ProcessState.cpp39
9 files changed, 174 insertions, 160 deletions
diff --git a/libs/binder/Android.mk b/libs/binder/Android.mk
index f3f8daf..673fc82 100644
--- a/libs/binder/Android.mk
+++ b/libs/binder/Android.mk
@@ -42,6 +42,11 @@ LOCAL_LDLIBS += -lpthread
LOCAL_MODULE := libbinder
LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
LOCAL_SRC_FILES := $(sources)
+ifneq ($(TARGET_USES_64_BIT_BINDER),true)
+ifneq ($(TARGET_IS_64_BIT),true)
+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1
+endif
+endif
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
@@ -49,4 +54,9 @@ LOCAL_LDLIBS += -lpthread
LOCAL_MODULE := libbinder
LOCAL_STATIC_LIBRARIES += libutils
LOCAL_SRC_FILES := $(sources)
+ifneq ($(TARGET_USES_64_BIT_BINDER),true)
+ifneq ($(TARGET_IS_64_BIT),true)
+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1
+endif
+endif
include $(BUILD_STATIC_LIBRARY)
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index 1f21f9c..71e62ab 100644
--- a/libs/binder/Binder.cpp
+++ b/libs/binder/Binder.cpp
@@ -39,7 +39,7 @@ IBinder::~IBinder()
// ---------------------------------------------------------------------------
-sp<IInterface> IBinder::queryLocalInterface(const String16& descriptor)
+sp<IInterface> IBinder::queryLocalInterface(const String16& /*descriptor*/)
{
return NULL;
}
@@ -117,19 +117,20 @@ status_t BBinder::transact(
}
status_t BBinder::linkToDeath(
- const sp<DeathRecipient>& recipient, void* cookie, uint32_t flags)
+ const sp<DeathRecipient>& /*recipient*/, void* /*cookie*/,
+ uint32_t /*flags*/)
{
return INVALID_OPERATION;
}
status_t BBinder::unlinkToDeath(
- const wp<DeathRecipient>& recipient, void* cookie, uint32_t flags,
- wp<DeathRecipient>* outRecipient)
+ const wp<DeathRecipient>& /*recipient*/, void* /*cookie*/,
+ uint32_t /*flags*/, wp<DeathRecipient>* /*outRecipient*/)
{
return INVALID_OPERATION;
}
-status_t BBinder::dump(int fd, const Vector<String16>& args)
+ status_t BBinder::dump(int /*fd*/, const Vector<String16>& /*args*/)
{
return NO_ERROR;
}
@@ -142,8 +143,13 @@ void BBinder::attachObject(
if (!e) {
e = new Extras;
+#ifdef __LP64__
+ if (android_atomic_release_cas64(0, reinterpret_cast<int64_t>(e),
+ reinterpret_cast<volatile int64_t*>(&mExtras)) != 0) {
+#else
if (android_atomic_cmpxchg(0, reinterpret_cast<int32_t>(e),
reinterpret_cast<volatile int32_t*>(&mExtras)) != 0) {
+#endif
delete e;
e = mExtras;
}
@@ -184,7 +190,7 @@ BBinder::~BBinder()
status_t BBinder::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
+ uint32_t code, const Parcel& data, Parcel* reply, uint32_t /*flags*/)
{
switch (code) {
case INTERFACE_TRANSACTION:
@@ -246,14 +252,14 @@ void BpRefBase::onFirstRef()
android_atomic_or(kRemoteAcquired, &mState);
}
-void BpRefBase::onLastStrongRef(const void* id)
+void BpRefBase::onLastStrongRef(const void* /*id*/)
{
if (mRemote) {
mRemote->decStrong(this);
}
}
-bool BpRefBase::onIncStrongAttempted(uint32_t flags, const void* id)
+bool BpRefBase::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/)
{
return mRemote ? mRefs->attemptIncStrong(this) : false;
}
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 47a62db..1bad67a 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -343,7 +343,7 @@ void BpBinder::onFirstRef()
if (ipc) ipc->incStrongHandle(mHandle);
}
-void BpBinder::onLastStrongRef(const void* id)
+void BpBinder::onLastStrongRef(const void* /*id*/)
{
ALOGV("onLastStrongRef BpBinder %p handle %d\n", this, mHandle);
IF_ALOGV() {
@@ -353,7 +353,7 @@ void BpBinder::onLastStrongRef(const void* id)
if (ipc) ipc->decStrongHandle(mHandle);
}
-bool BpBinder::onIncStrongAttempted(uint32_t flags, const void* id)
+bool BpBinder::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/)
{
ALOGV("onIncStrongAttempted BpBinder %p handle %d\n", this, mHandle);
IPCThreadState* ipc = IPCThreadState::self();
diff --git a/libs/binder/Debug.cpp b/libs/binder/Debug.cpp
index a8b6e83..0ffafbb 100644
--- a/libs/binder/Debug.cpp
+++ b/libs/binder/Debug.cpp
@@ -38,7 +38,7 @@ const char* stringForIndent(int32_t indentLevel)
// ---------------------------------------------------------------------
-static void defaultPrintFunc(void* cookie, const char* txt)
+static void defaultPrintFunc(void* /*cookie*/, const char* txt)
{
printf("%s", txt);
}
diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp
index 07cb41a..d8ed995 100644
--- a/libs/binder/IMemory.cpp
+++ b/libs/binder/IMemory.cpp
@@ -244,7 +244,7 @@ BpMemoryHeap::~BpMemoryHeap() {
sp<IBinder> binder = const_cast<BpMemoryHeap*>(this)->asBinder();
if (VERBOSE) {
- ALOGD("UNMAPPING binder=%p, heap=%p, size=%d, fd=%d",
+ ALOGD("UNMAPPING binder=%p, heap=%p, size=%zu, fd=%d",
binder.get(), this, mSize, mHeapId);
CallStack stack(LOG_TAG);
}
@@ -296,11 +296,11 @@ void BpMemoryHeap::assertReallyMapped() const
uint32_t flags = reply.readInt32();
uint32_t offset = reply.readInt32();
- ALOGE_IF(err, "binder=%p transaction failed fd=%d, size=%ld, err=%d (%s)",
+ ALOGE_IF(err, "binder=%p transaction failed fd=%d, size=%zd, err=%d (%s)",
asBinder().get(), parcel_fd, size, err, strerror(-err));
int fd = dup( parcel_fd );
- ALOGE_IF(fd==-1, "cannot dup fd=%d, size=%ld, err=%d (%s)",
+ ALOGE_IF(fd==-1, "cannot dup fd=%d, size=%zd, err=%d (%s)",
parcel_fd, size, err, strerror(errno));
int access = PROT_READ;
@@ -313,7 +313,7 @@ void BpMemoryHeap::assertReallyMapped() const
mRealHeap = true;
mBase = mmap(0, size, access, MAP_SHARED, fd, offset);
if (mBase == MAP_FAILED) {
- ALOGE("cannot map BpMemoryHeap (binder=%p), size=%ld, fd=%d (%s)",
+ ALOGE("cannot map BpMemoryHeap (binder=%p), size=%zd, fd=%d (%s)",
asBinder().get(), size, fd, strerror(errno));
close(fd);
} else {
@@ -402,7 +402,7 @@ sp<IMemoryHeap> HeapCache::find_heap(const sp<IBinder>& binder)
if (i>=0) {
heap_info_t& info = mHeapCache.editValueAt(i);
ALOGD_IF(VERBOSE,
- "found binder=%p, heap=%p, size=%d, fd=%d, count=%d",
+ "found binder=%p, heap=%p, size=%zu, fd=%d, count=%d",
binder.get(), info.heap.get(),
static_cast<BpMemoryHeap*>(info.heap.get())->mSize,
static_cast<BpMemoryHeap*>(info.heap.get())->mHeapId,
@@ -435,7 +435,7 @@ void HeapCache::free_heap(const wp<IBinder>& binder)
int32_t c = android_atomic_dec(&info.count);
if (c == 1) {
ALOGD_IF(VERBOSE,
- "removing binder=%p, heap=%p, size=%d, fd=%d, count=%d",
+ "removing binder=%p, heap=%p, size=%zu, fd=%d, count=%d",
binder.unsafe_get(), info.heap.get(),
static_cast<BpMemoryHeap*>(info.heap.get())->mSize,
static_cast<BpMemoryHeap*>(info.heap.get())->mHeapId,
@@ -466,7 +466,7 @@ void HeapCache::dump_heaps()
for (int i=0 ; i<c ; i++) {
const heap_info_t& info = mHeapCache.valueAt(i);
BpMemoryHeap const* h(static_cast<BpMemoryHeap const *>(info.heap.get()));
- ALOGD("hey=%p, heap=%p, count=%d, (fd=%d, base=%p, size=%d)",
+ ALOGD("hey=%p, heap=%p, count=%d, (fd=%d, base=%p, size=%zu)",
mHeapCache.keyAt(i).unsafe_get(),
info.heap.get(), info.count,
h->mHeapId, h->mBase, h->mSize);
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index 5951a3f..35dba12 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -533,7 +533,7 @@ status_t IPCThreadState::handlePolledCommands()
return result;
}
-void IPCThreadState::stopProcess(bool immediate)
+void IPCThreadState::stopProcess(bool /*immediate*/)
{
//ALOGI("**** STOPPING PROCESS");
flushCommands();
@@ -635,6 +635,7 @@ void IPCThreadState::decWeakHandle(int32_t handle)
status_t IPCThreadState::attemptIncStrongHandle(int32_t handle)
{
+#if HAS_BC_ATTEMPT_ACQUIRE
LOG_REMOTEREFS("IPCThreadState::attemptIncStrongHandle(%d)\n", handle);
mOut.writeInt32(BC_ATTEMPT_ACQUIRE);
mOut.writeInt32(0); // xxx was thread priority
@@ -649,6 +650,11 @@ status_t IPCThreadState::attemptIncStrongHandle(int32_t handle)
#endif
return result;
+#else
+ (void)handle;
+ ALOGE("%s(%d): Not supported\n", __func__, handle);
+ return INVALID_OPERATION;
+#endif
}
void IPCThreadState::expungeHandle(int32_t handle, IBinder* binder)
@@ -663,7 +669,7 @@ status_t IPCThreadState::requestDeathNotification(int32_t handle, BpBinder* prox
{
mOut.writeInt32(BC_REQUEST_DEATH_NOTIFICATION);
mOut.writeInt32((int32_t)handle);
- mOut.writeInt32((int32_t)proxy);
+ mOut.writePointer((uintptr_t)proxy);
return NO_ERROR;
}
@@ -671,7 +677,7 @@ status_t IPCThreadState::clearDeathNotification(int32_t handle, BpBinder* proxy)
{
mOut.writeInt32(BC_CLEAR_DEATH_NOTIFICATION);
mOut.writeInt32((int32_t)handle);
- mOut.writeInt32((int32_t)proxy);
+ mOut.writePointer((uintptr_t)proxy);
return NO_ERROR;
}
@@ -753,23 +759,23 @@ status_t IPCThreadState::waitForResponse(Parcel *reply, status_t *acquireResult)
reply->ipcSetDataReference(
reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
tr.data_size,
- reinterpret_cast<const size_t*>(tr.data.ptr.offsets),
- tr.offsets_size/sizeof(size_t),
+ reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
+ tr.offsets_size/sizeof(binder_size_t),
freeBuffer, this);
} else {
- err = *static_cast<const status_t*>(tr.data.ptr.buffer);
+ err = *reinterpret_cast<const status_t*>(tr.data.ptr.buffer);
freeBuffer(NULL,
reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
tr.data_size,
- reinterpret_cast<const size_t*>(tr.data.ptr.offsets),
- tr.offsets_size/sizeof(size_t), this);
+ reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
+ tr.offsets_size/sizeof(binder_size_t), this);
}
} else {
freeBuffer(NULL,
reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
tr.data_size,
- reinterpret_cast<const size_t*>(tr.data.ptr.offsets),
- tr.offsets_size/sizeof(size_t), this);
+ reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
+ tr.offsets_size/sizeof(binder_size_t), this);
continue;
}
}
@@ -809,12 +815,12 @@ status_t IPCThreadState::talkWithDriver(bool doReceive)
const size_t outAvail = (!doReceive || needRead) ? mOut.dataSize() : 0;
bwr.write_size = outAvail;
- bwr.write_buffer = (long unsigned int)mOut.data();
+ bwr.write_buffer = (uintptr_t)mOut.data();
// This is what we'll read.
if (doReceive && needRead) {
bwr.read_size = mIn.dataCapacity();
- bwr.read_buffer = (long unsigned int)mIn.data();
+ bwr.read_buffer = (uintptr_t)mIn.data();
} else {
bwr.read_size = 0;
bwr.read_buffer = 0;
@@ -861,14 +867,14 @@ status_t IPCThreadState::talkWithDriver(bool doReceive)
} while (err == -EINTR);
IF_LOG_COMMANDS() {
- alog << "Our err: " << (void*)err << ", write consumed: "
+ alog << "Our err: " << (void*)(intptr_t)err << ", write consumed: "
<< bwr.write_consumed << " (of " << mOut.dataSize()
<< "), read consumed: " << bwr.read_consumed << endl;
}
if (err >= NO_ERROR) {
if (bwr.write_consumed > 0) {
- if (bwr.write_consumed < (ssize_t)mOut.dataSize())
+ if (bwr.write_consumed < mOut.dataSize())
mOut.remove(0, bwr.write_consumed);
else
mOut.setDataSize(0);
@@ -898,6 +904,7 @@ status_t IPCThreadState::writeTransactionData(int32_t cmd, uint32_t binderFlags,
{
binder_transaction_data tr;
+ tr.target.ptr = 0; /* Don't pass uninitialized stack data to a remote process */
tr.target.handle = handle;
tr.code = code;
tr.flags = binderFlags;
@@ -909,15 +916,15 @@ status_t IPCThreadState::writeTransactionData(int32_t cmd, uint32_t binderFlags,
if (err == NO_ERROR) {
tr.data_size = data.ipcDataSize();
tr.data.ptr.buffer = data.ipcData();
- tr.offsets_size = data.ipcObjectsCount()*sizeof(size_t);
+ tr.offsets_size = data.ipcObjectsCount()*sizeof(binder_size_t);
tr.data.ptr.offsets = data.ipcObjects();
} else if (statusBuffer) {
tr.flags |= TF_STATUS_CODE;
*statusBuffer = err;
tr.data_size = sizeof(status_t);
- tr.data.ptr.buffer = statusBuffer;
+ tr.data.ptr.buffer = reinterpret_cast<uintptr_t>(statusBuffer);
tr.offsets_size = 0;
- tr.data.ptr.offsets = NULL;
+ tr.data.ptr.offsets = 0;
} else {
return (mLastError = err);
}
@@ -950,8 +957,8 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
break;
case BR_ACQUIRE:
- refs = (RefBase::weakref_type*)mIn.readInt32();
- obj = (BBinder*)mIn.readInt32();
+ refs = (RefBase::weakref_type*)mIn.readPointer();
+ obj = (BBinder*)mIn.readPointer();
ALOG_ASSERT(refs->refBase() == obj,
"BR_ACQUIRE: object %p does not match cookie %p (expected %p)",
refs, obj, refs->refBase());
@@ -961,13 +968,13 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
obj->printRefs();
}
mOut.writeInt32(BC_ACQUIRE_DONE);
- mOut.writeInt32((int32_t)refs);
- mOut.writeInt32((int32_t)obj);
+ mOut.writePointer((uintptr_t)refs);
+ mOut.writePointer((uintptr_t)obj);
break;
case BR_RELEASE:
- refs = (RefBase::weakref_type*)mIn.readInt32();
- obj = (BBinder*)mIn.readInt32();
+ refs = (RefBase::weakref_type*)mIn.readPointer();
+ obj = (BBinder*)mIn.readPointer();
ALOG_ASSERT(refs->refBase() == obj,
"BR_RELEASE: object %p does not match cookie %p (expected %p)",
refs, obj, refs->refBase());
@@ -979,17 +986,17 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
break;
case BR_INCREFS:
- refs = (RefBase::weakref_type*)mIn.readInt32();
- obj = (BBinder*)mIn.readInt32();
+ refs = (RefBase::weakref_type*)mIn.readPointer();
+ obj = (BBinder*)mIn.readPointer();
refs->incWeak(mProcess.get());
mOut.writeInt32(BC_INCREFS_DONE);
- mOut.writeInt32((int32_t)refs);
- mOut.writeInt32((int32_t)obj);
+ mOut.writePointer((uintptr_t)refs);
+ mOut.writePointer((uintptr_t)obj);
break;
case BR_DECREFS:
- refs = (RefBase::weakref_type*)mIn.readInt32();
- obj = (BBinder*)mIn.readInt32();
+ refs = (RefBase::weakref_type*)mIn.readPointer();
+ obj = (BBinder*)mIn.readPointer();
// NOTE: This assertion is not valid, because the object may no
// longer exist (thus the (BBinder*)cast above resulting in a different
// memory address).
@@ -1000,8 +1007,8 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
break;
case BR_ATTEMPT_ACQUIRE:
- refs = (RefBase::weakref_type*)mIn.readInt32();
- obj = (BBinder*)mIn.readInt32();
+ refs = (RefBase::weakref_type*)mIn.readPointer();
+ obj = (BBinder*)mIn.readPointer();
{
const bool success = refs->attemptIncStrong(mProcess.get());
@@ -1026,8 +1033,8 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
buffer.ipcSetDataReference(
reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
tr.data_size,
- reinterpret_cast<const size_t*>(tr.data.ptr.offsets),
- tr.offsets_size/sizeof(size_t), freeBuffer, this);
+ reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
+ tr.offsets_size/sizeof(binder_size_t), freeBuffer, this);
const pid_t origPid = mCallingPid;
const uid_t origUid = mCallingUid;
@@ -1103,15 +1110,15 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
case BR_DEAD_BINDER:
{
- BpBinder *proxy = (BpBinder*)mIn.readInt32();
+ BpBinder *proxy = (BpBinder*)mIn.readPointer();
proxy->sendObituary();
mOut.writeInt32(BC_DEAD_BINDER_DONE);
- mOut.writeInt32((int32_t)proxy);
+ mOut.writePointer((uintptr_t)proxy);
} break;
case BR_CLEAR_DEATH_NOTIFICATION_DONE:
{
- BpBinder *proxy = (BpBinder*)mIn.readInt32();
+ BpBinder *proxy = (BpBinder*)mIn.readPointer();
proxy->getWeakRefs()->decWeak(proxy);
} break;
@@ -1154,9 +1161,10 @@ void IPCThreadState::threadDestructor(void *st)
}
-void IPCThreadState::freeBuffer(Parcel* parcel, const uint8_t* data, size_t dataSize,
- const size_t* objects, size_t objectsSize,
- void* cookie)
+void IPCThreadState::freeBuffer(Parcel* parcel, const uint8_t* data,
+ size_t /*dataSize*/,
+ const binder_size_t* /*objects*/,
+ size_t /*objectsSize*/, void* /*cookie*/)
{
//ALOGI("Freeing parcel %p", &parcel);
IF_LOG_COMMANDS() {
@@ -1166,7 +1174,7 @@ void IPCThreadState::freeBuffer(Parcel* parcel, const uint8_t* data, size_t data
if (parcel != NULL) parcel->closeFileDescriptors();
IPCThreadState* state = self();
state->mOut.writeInt32(BC_FREE_BUFFER);
- state->mOut.writeInt32((int32_t)data);
+ state->mOut.writePointer((uintptr_t)data);
}
}; // namespace android
diff --git a/libs/binder/MemoryDealer.cpp b/libs/binder/MemoryDealer.cpp
index 8d0e0a7..a14c100 100644
--- a/libs/binder/MemoryDealer.cpp
+++ b/libs/binder/MemoryDealer.cpp
@@ -210,7 +210,7 @@ Allocation::~Allocation()
#ifdef MADV_REMOVE
if (size) {
int err = madvise(start_ptr, size, MADV_REMOVE);
- ALOGW_IF(err, "madvise(%p, %u, MADV_REMOVE) returned %s",
+ ALOGW_IF(err, "madvise(%p, %zu, MADV_REMOVE) returned %s",
start_ptr, size, err<0 ? strerror(errno) : "Ok");
}
#endif
@@ -445,8 +445,8 @@ void SimpleBestFitAllocator::dump_l(String8& result,
int np = ((cur->next) && cur->next->prev != cur) ? 1 : 0;
int pn = ((cur->prev) && cur->prev->next != cur) ? 2 : 0;
- snprintf(buffer, SIZE, " %3u: %08x | 0x%08X | 0x%08X | %s %s\n",
- i, int(cur), int(cur->start*kMemoryAlign),
+ snprintf(buffer, SIZE, " %3u: %p | 0x%08X | 0x%08X | %s %s\n",
+ i, cur, int(cur->start*kMemoryAlign),
int(cur->size*kMemoryAlign),
int(cur->free) ? "F" : "A",
errs[np|pn]);
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index db9e0a1..67cb428 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -78,12 +78,12 @@ void acquire_object(const sp<ProcessState>& proc,
case BINDER_TYPE_BINDER:
if (obj.binder) {
LOG_REFS("Parcel %p acquiring reference on local %p", who, obj.cookie);
- static_cast<IBinder*>(obj.cookie)->incStrong(who);
+ reinterpret_cast<IBinder*>(obj.cookie)->incStrong(who);
}
return;
case BINDER_TYPE_WEAK_BINDER:
if (obj.binder)
- static_cast<RefBase::weakref_type*>(obj.binder)->incWeak(who);
+ reinterpret_cast<RefBase::weakref_type*>(obj.binder)->incWeak(who);
return;
case BINDER_TYPE_HANDLE: {
const sp<IBinder> b = proc->getStrongProxyForHandle(obj.handle);
@@ -105,7 +105,7 @@ void acquire_object(const sp<ProcessState>& proc,
}
}
- ALOGD("Invalid object type 0x%08lx", obj.type);
+ ALOGD("Invalid object type 0x%08x", obj.type);
}
void release_object(const sp<ProcessState>& proc,
@@ -115,12 +115,12 @@ void release_object(const sp<ProcessState>& proc,
case BINDER_TYPE_BINDER:
if (obj.binder) {
LOG_REFS("Parcel %p releasing reference on local %p", who, obj.cookie);
- static_cast<IBinder*>(obj.cookie)->decStrong(who);
+ reinterpret_cast<IBinder*>(obj.cookie)->decStrong(who);
}
return;
case BINDER_TYPE_WEAK_BINDER:
if (obj.binder)
- static_cast<RefBase::weakref_type*>(obj.binder)->decWeak(who);
+ reinterpret_cast<RefBase::weakref_type*>(obj.binder)->decWeak(who);
return;
case BINDER_TYPE_HANDLE: {
const sp<IBinder> b = proc->getStrongProxyForHandle(obj.handle);
@@ -136,21 +136,21 @@ void release_object(const sp<ProcessState>& proc,
return;
}
case BINDER_TYPE_FD: {
- if (obj.cookie != (void*)0) close(obj.handle);
+ if (obj.cookie != 0) close(obj.handle);
return;
}
}
- ALOGE("Invalid object type 0x%08lx", obj.type);
+ ALOGE("Invalid object type 0x%08x", obj.type);
}
inline static status_t finish_flatten_binder(
- const sp<IBinder>& binder, const flat_binder_object& flat, Parcel* out)
+ const sp<IBinder>& /*binder*/, const flat_binder_object& flat, Parcel* out)
{
return out->writeObject(flat, false);
}
-status_t flatten_binder(const sp<ProcessState>& proc,
+status_t flatten_binder(const sp<ProcessState>& /*proc*/,
const sp<IBinder>& binder, Parcel* out)
{
flat_binder_object obj;
@@ -165,23 +165,24 @@ status_t flatten_binder(const sp<ProcessState>& proc,
}
const int32_t handle = proxy ? proxy->handle() : 0;
obj.type = BINDER_TYPE_HANDLE;
+ obj.binder = 0; /* Don't pass uninitialized stack data to a remote process */
obj.handle = handle;
- obj.cookie = NULL;
+ obj.cookie = 0;
} else {
obj.type = BINDER_TYPE_BINDER;
- obj.binder = local->getWeakRefs();
- obj.cookie = local;
+ obj.binder = reinterpret_cast<uintptr_t>(local->getWeakRefs());
+ obj.cookie = reinterpret_cast<uintptr_t>(local);
}
} else {
obj.type = BINDER_TYPE_BINDER;
- obj.binder = NULL;
- obj.cookie = NULL;
+ obj.binder = 0;
+ obj.cookie = 0;
}
return finish_flatten_binder(binder, obj, out);
}
-status_t flatten_binder(const sp<ProcessState>& proc,
+status_t flatten_binder(const sp<ProcessState>& /*proc*/,
const wp<IBinder>& binder, Parcel* out)
{
flat_binder_object obj;
@@ -198,12 +199,13 @@ status_t flatten_binder(const sp<ProcessState>& proc,
}
const int32_t handle = proxy ? proxy->handle() : 0;
obj.type = BINDER_TYPE_WEAK_HANDLE;
+ obj.binder = 0; /* Don't pass uninitialized stack data to a remote process */
obj.handle = handle;
- obj.cookie = NULL;
+ obj.cookie = 0;
} else {
obj.type = BINDER_TYPE_WEAK_BINDER;
- obj.binder = binder.get_refs();
- obj.cookie = binder.unsafe_get();
+ obj.binder = reinterpret_cast<uintptr_t>(binder.get_refs());
+ obj.cookie = reinterpret_cast<uintptr_t>(binder.unsafe_get());
}
return finish_flatten_binder(real, obj, out);
}
@@ -217,20 +219,21 @@ status_t flatten_binder(const sp<ProcessState>& proc,
// implementation we are using.
ALOGE("Unable to unflatten Binder weak reference!");
obj.type = BINDER_TYPE_BINDER;
- obj.binder = NULL;
- obj.cookie = NULL;
+ obj.binder = 0;
+ obj.cookie = 0;
return finish_flatten_binder(NULL, obj, out);
} else {
obj.type = BINDER_TYPE_BINDER;
- obj.binder = NULL;
- obj.cookie = NULL;
+ obj.binder = 0;
+ obj.cookie = 0;
return finish_flatten_binder(NULL, obj, out);
}
}
inline static status_t finish_unflatten_binder(
- BpBinder* proxy, const flat_binder_object& flat, const Parcel& in)
+ BpBinder* /*proxy*/, const flat_binder_object& /*flat*/,
+ const Parcel& /*in*/)
{
return NO_ERROR;
}
@@ -243,7 +246,7 @@ status_t unflatten_binder(const sp<ProcessState>& proc,
if (flat) {
switch (flat->type) {
case BINDER_TYPE_BINDER:
- *out = static_cast<IBinder*>(flat->cookie);
+ *out = reinterpret_cast<IBinder*>(flat->cookie);
return finish_unflatten_binder(NULL, *flat, in);
case BINDER_TYPE_HANDLE:
*out = proc->getStrongProxyForHandle(flat->handle);
@@ -262,13 +265,13 @@ status_t unflatten_binder(const sp<ProcessState>& proc,
if (flat) {
switch (flat->type) {
case BINDER_TYPE_BINDER:
- *out = static_cast<IBinder*>(flat->cookie);
+ *out = reinterpret_cast<IBinder*>(flat->cookie);
return finish_unflatten_binder(NULL, *flat, in);
case BINDER_TYPE_WEAK_BINDER:
- if (flat->binder != NULL) {
+ if (flat->binder != 0) {
out->set_object_and_refs(
- static_cast<IBinder*>(flat->cookie),
- static_cast<RefBase::weakref_type*>(flat->binder));
+ reinterpret_cast<IBinder*>(flat->cookie),
+ reinterpret_cast<RefBase::weakref_type*>(flat->binder));
} else {
*out = NULL;
}
@@ -365,7 +368,7 @@ status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len)
const sp<ProcessState> proc(ProcessState::self());
status_t err;
const uint8_t *data = parcel->mData;
- const size_t *objects = parcel->mObjects;
+ const binder_size_t *objects = parcel->mObjects;
size_t size = parcel->mObjectsSize;
int startPos = mDataPos;
int firstIndex = -1, lastIndex = -2;
@@ -412,9 +415,9 @@ status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len)
// grow objects
if (mObjectsCapacity < mObjectsSize + numObjects) {
int newSize = ((mObjectsSize + numObjects)*3)/2;
- size_t *objects =
- (size_t*)realloc(mObjects, newSize*sizeof(size_t));
- if (objects == (size_t*)0) {
+ binder_size_t *objects =
+ (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t));
+ if (objects == (binder_size_t*)0) {
return NO_MEMORY;
}
mObjects = objects;
@@ -437,7 +440,7 @@ status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len)
// new Parcel now owns its own fd, and can declare that we
// officially know we have fds.
flat->handle = dup(flat->handle);
- flat->cookie = (void*)1;
+ flat->cookie = 1;
mHasFds = mFdsKnown = true;
if (!mAllowFds) {
err = FDS_NOT_ALLOWED;
@@ -512,7 +515,7 @@ bool Parcel::enforceInterface(const String16& interface,
}
}
-const size_t* Parcel::objects() const
+const binder_size_t* Parcel::objects() const
{
return mObjects;
}
@@ -644,6 +647,11 @@ status_t Parcel::writeInt64(int64_t val)
return writeAligned(val);
}
+status_t Parcel::writePointer(uintptr_t val)
+{
+ return writeAligned<binder_uintptr_t>(val);
+}
+
status_t Parcel::writeFloat(float val)
{
return writeAligned(val);
@@ -753,8 +761,9 @@ status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership)
flat_binder_object obj;
obj.type = BINDER_TYPE_FD;
obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
+ obj.binder = 0; /* Don't pass uninitialized stack data to a remote process */
obj.handle = fd;
- obj.cookie = (void*) (takeOwnership ? 1 : 0);
+ obj.cookie = takeOwnership ? 1 : 0;
return writeObject(obj, true);
}
@@ -864,7 +873,7 @@ restart_write:
*reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
// Need to write meta-data?
- if (nullMetaData || val.binder != NULL) {
+ if (nullMetaData || val.binder != 0) {
mObjects[mObjectsSize] = mDataPos;
acquire_object(ProcessState::self(), val, this);
mObjectsSize++;
@@ -887,7 +896,7 @@ restart_write:
}
if (!enoughObjects) {
size_t newSize = ((mObjectsSize+2)*3)/2;
- size_t* objects = (size_t*)realloc(mObjects, newSize*sizeof(size_t));
+ binder_size_t* objects = (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t));
if (objects == NULL) return NO_MEMORY;
mObjects = objects;
mObjectsCapacity = newSize;
@@ -901,7 +910,7 @@ status_t Parcel::writeNoException()
return writeInt32(0);
}
-void Parcel::remove(size_t start, size_t amt)
+void Parcel::remove(size_t /*start*/, size_t /*amt*/)
{
LOG_ALWAYS_FATAL("Parcel::remove() not yet implemented!");
}
@@ -991,6 +1000,22 @@ int64_t Parcel::readInt64() const
return readAligned<int64_t>();
}
+status_t Parcel::readPointer(uintptr_t *pArg) const
+{
+ status_t ret;
+ binder_uintptr_t ptr;
+ ret = readAligned(&ptr);
+ if (!ret)
+ *pArg = ptr;
+ return ret;
+}
+
+uintptr_t Parcel::readPointer() const
+{
+ return readAligned<binder_uintptr_t>();
+}
+
+
status_t Parcel::readFloat(float *pArg) const
{
return readAligned(pArg);
@@ -1236,7 +1261,7 @@ const flat_binder_object* Parcel::readObject(bool nullMetaData) const
const flat_binder_object* obj
= reinterpret_cast<const flat_binder_object*>(mData+DPOS);
mDataPos = DPOS + sizeof(flat_binder_object);
- if (!nullMetaData && (obj->cookie == NULL && obj->binder == NULL)) {
+ if (!nullMetaData && (obj->cookie == 0 && obj->binder == 0)) {
// When transferring a NULL object, we don't write it into
// the object list, so we don't want to check for it when
// reading.
@@ -1245,7 +1270,7 @@ const flat_binder_object* Parcel::readObject(bool nullMetaData) const
}
// Ensure that this object is valid...
- size_t* const OBJS = mObjects;
+ binder_size_t* const OBJS = mObjects;
const size_t N = mObjectsSize;
size_t opos = mNextObjectHint;
@@ -1284,7 +1309,7 @@ const flat_binder_object* Parcel::readObject(bool nullMetaData) const
return obj;
}
}
- ALOGW("Attempt to read object from Parcel %p at offset %d that is not in the object list",
+ ALOGW("Attempt to read object from Parcel %p at offset %zu that is not in the object list",
this, DPOS);
}
return NULL;
@@ -1307,9 +1332,9 @@ void Parcel::closeFileDescriptors()
}
}
-const uint8_t* Parcel::ipcData() const
+uintptr_t Parcel::ipcData() const
{
- return mData;
+ return reinterpret_cast<uintptr_t>(mData);
}
size_t Parcel::ipcDataSize() const
@@ -1317,9 +1342,9 @@ size_t Parcel::ipcDataSize() const
return (mDataSize > mDataPos ? mDataSize : mDataPos);
}
-const size_t* Parcel::ipcObjects() const
+uintptr_t Parcel::ipcObjects() const
{
- return mObjects;
+ return reinterpret_cast<uintptr_t>(mObjects);
}
size_t Parcel::ipcObjectsCount() const
@@ -1328,9 +1353,9 @@ size_t Parcel::ipcObjectsCount() const
}
void Parcel::ipcSetDataReference(const uint8_t* data, size_t dataSize,
- const size_t* objects, size_t objectsCount, release_func relFunc, void* relCookie)
+ const binder_size_t* objects, size_t objectsCount, release_func relFunc, void* relCookie)
{
- size_t minOffset = 0;
+ binder_size_t minOffset = 0;
freeDataNoInit();
mError = NO_ERROR;
mData = const_cast<uint8_t*>(data);
@@ -1338,16 +1363,16 @@ void Parcel::ipcSetDataReference(const uint8_t* data, size_t dataSize,
//ALOGI("setDataReference Setting data size of %p to %lu (pid=%d)\n", this, mDataSize, getpid());
mDataPos = 0;
ALOGV("setDataReference Setting data pos of %p to %d\n", this, mDataPos);
- mObjects = const_cast<size_t*>(objects);
+ mObjects = const_cast<binder_size_t*>(objects);
mObjectsSize = mObjectsCapacity = objectsCount;
mNextObjectHint = 0;
mOwner = relFunc;
mOwnerCookie = relCookie;
for (size_t i = 0; i < mObjectsSize; i++) {
- size_t offset = mObjects[i];
+ binder_size_t offset = mObjects[i];
if (offset < minOffset) {
- ALOGE("%s: bad object offset %zu < %zu\n",
- __func__, offset, minOffset);
+ ALOGE("%s: bad object offset %"PRIu64" < %"PRIu64"\n",
+ __func__, (uint64_t)offset, (uint64_t)minOffset);
mObjectsSize = 0;
break;
}
@@ -1356,17 +1381,17 @@ void Parcel::ipcSetDataReference(const uint8_t* data, size_t dataSize,
scanForFds();
}
-void Parcel::print(TextOutput& to, uint32_t flags) const
+void Parcel::print(TextOutput& to, uint32_t /*flags*/) const
{
to << "Parcel(";
if (errorCheck() != NO_ERROR) {
const status_t err = errorCheck();
- to << "Error: " << (void*)err << " \"" << strerror(-err) << "\"";
+ to << "Error: " << (void*)(intptr_t)err << " \"" << strerror(-err) << "\"";
} else if (dataSize() > 0) {
const uint8_t* DATA = data();
to << indent << HexDump(DATA, dataSize()) << dedent;
- const size_t* OBJS = objects();
+ const binder_size_t* OBJS = objects();
const size_t N = objectsCount();
for (size_t i=0; i<N; i++) {
const flat_binder_object* flat
@@ -1387,7 +1412,7 @@ void Parcel::releaseObjects()
const sp<ProcessState> proc(ProcessState::self());
size_t i = mObjectsSize;
uint8_t* const data = mData;
- size_t* const objects = mObjects;
+ binder_size_t* const objects = mObjects;
while (i > 0) {
i--;
const flat_binder_object* flat
@@ -1401,7 +1426,7 @@ void Parcel::acquireObjects()
const sp<ProcessState> proc(ProcessState::self());
size_t i = mObjectsSize;
uint8_t* const data = mData;
- size_t* const objects = mObjects;
+ binder_size_t* const objects = mObjects;
while (i > 0) {
i--;
const flat_binder_object* flat
@@ -1502,10 +1527,10 @@ status_t Parcel::continueWrite(size_t desired)
mError = NO_MEMORY;
return NO_MEMORY;
}
- size_t* objects = NULL;
+ binder_size_t* objects = NULL;
if (objectsSize) {
- objects = (size_t*)malloc(objectsSize*sizeof(size_t));
+ objects = (binder_size_t*)malloc(objectsSize*sizeof(binder_size_t));
if (!objects) {
free(data);
@@ -1525,7 +1550,7 @@ status_t Parcel::continueWrite(size_t desired)
memcpy(data, mData, mDataSize < desired ? mDataSize : desired);
}
if (objects && mObjects) {
- memcpy(objects, mObjects, objectsSize*sizeof(size_t));
+ memcpy(objects, mObjects, objectsSize*sizeof(binder_size_t));
}
//ALOGI("Freeing data ref of %p (pid=%d)\n", this, getpid());
mOwner(this, mData, mDataSize, mObjects, mObjectsSize, mOwnerCookie);
@@ -1552,8 +1577,8 @@ status_t Parcel::continueWrite(size_t desired)
}
release_object(proc, *flat, this);
}
- size_t* objects =
- (size_t*)realloc(mObjects, objectsSize*sizeof(size_t));
+ binder_size_t* objects =
+ (binder_size_t*)realloc(mObjects, objectsSize*sizeof(binder_size_t));
if (objects) {
mObjects = objects;
}
@@ -1592,7 +1617,7 @@ status_t Parcel::continueWrite(size_t desired)
if(!(mDataCapacity == 0 && mObjects == NULL
&& mObjectsCapacity == 0)) {
- ALOGE("continueWrite: %d/%p/%d/%d", mDataCapacity, mObjects, mObjectsCapacity, desired);
+ ALOGE("continueWrite: %zu/%p/%zu/%zu", mDataCapacity, mObjects, mObjectsCapacity, desired);
}
mData = data;
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index c1e49bc..303d6cf 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -48,11 +48,6 @@
namespace android {
-// Global variables
-int mArgC;
-const char* const* mArgV;
-int mArgLen;
-
class PoolThread : public Thread
{
public:
@@ -86,7 +81,7 @@ void ProcessState::setContextObject(const sp<IBinder>& object)
setContextObject(object, String16("default"));
}
-sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& caller)
+sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/)
{
return getStrongProxyForHandle(0);
}
@@ -280,36 +275,6 @@ void ProcessState::expungeHandle(int32_t handle, IBinder* binder)
if (e && e->binder == binder) e->binder = NULL;
}
-void ProcessState::setArgs(int argc, const char* const argv[])
-{
- mArgC = argc;
- mArgV = (const char **)argv;
-
- mArgLen = 0;
- for (int i=0; i<argc; i++) {
- mArgLen += strlen(argv[i]) + 1;
- }
- mArgLen--;
-}
-
-int ProcessState::getArgC() const
-{
- return mArgC;
-}
-
-const char* const* ProcessState::getArgV() const
-{
- return mArgV;
-}
-
-void ProcessState::setArgV0(const char* txt)
-{
- if (mArgV != NULL) {
- strncpy((char*)mArgV[0], txt, mArgLen);
- set_process_name(txt);
- }
-}
-
String8 ProcessState::makeBinderThreadName() {
int32_t s = android_atomic_add(1, &mThreadPoolSeq);
String8 name;
@@ -345,7 +310,7 @@ static int open_driver()
int fd = open("/dev/binder", O_RDWR);
if (fd >= 0) {
fcntl(fd, F_SETFD, FD_CLOEXEC);
- int vers;
+ int vers = 0;
status_t result = ioctl(fd, BINDER_VERSION, &vers);
if (result == -1) {
ALOGE("Binder ioctl to obtain version failed: %s", strerror(errno));