summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2017-11-02 18:54:40 +0000
committerMartijn Coenen <maco@google.com>2017-11-02 18:54:40 +0000
commitea0090a0392db2f3b7b047647d48b01885722cda (patch)
tree03dadce41c2ea8c844324fabd000f4389bccae75
parent0494d6ab6f4b85eb28eeb71737398ba0b862a822 (diff)
downloadnative-ea0090a0392db2f3b7b047647d48b01885722cda.tar.gz
Revert "binder: send BC_REPLY and BC_FREE_BUFFER together"
This reverts commit 0494d6ab6f4b85eb28eeb71737398ba0b862a822. Change-Id: I115dd7cd3e11bb573e17b3859133e0cad1afef49
-rw-r--r--libs/binder/IPCThreadState.cpp124
-rw-r--r--libs/binder/include/binder/IPCThreadState.h1
2 files changed, 63 insertions, 62 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index 50974ef74f..ba9bf61f8c 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -718,6 +718,16 @@ IPCThreadState::~IPCThreadState()
{
}
+status_t IPCThreadState::sendReply(const Parcel& reply, uint32_t flags)
+{
+ status_t err;
+ status_t statusBuffer;
+ err = writeTransactionData(BC_REPLY, flags, -1, 0, reply, &statusBuffer);
+ if (err < NO_ERROR) return err;
+
+ return waitForResponse(NULL, NULL);
+}
+
status_t IPCThreadState::waitForResponse(Parcel *reply, status_t *acquireResult)
{
uint32_t cmd;
@@ -1040,78 +1050,68 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
"Not enough command data for brTRANSACTION");
if (result != NO_ERROR) break;
- Parcel reply;
- {
- Parcel buffer;
- const pid_t origPid = mCallingPid;
- const uid_t origUid = mCallingUid;
- const int32_t origStrictModePolicy = mStrictModePolicy;
- const int32_t origTransactionBinderFlags = mLastTransactionBinderFlags;
-
- buffer.ipcSetDataReference(
- reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
- tr.data_size,
- reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
- tr.offsets_size/sizeof(binder_size_t), freeBuffer, this);
-
- mCallingPid = tr.sender_pid;
- mCallingUid = tr.sender_euid;
- mLastTransactionBinderFlags = tr.flags;
-
- //ALOGI(">>>> TRANSACT from pid %d uid %d\n", mCallingPid, mCallingUid);
-
- status_t error;
- IF_LOG_TRANSACTIONS() {
- TextOutput::Bundle _b(alog);
- alog << "BR_TRANSACTION thr " << (void*)pthread_self()
- << " / obj " << tr.target.ptr << " / code "
- << TypeCode(tr.code) << ": " << indent << buffer
- << dedent << endl
- << "Data addr = "
- << reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer)
- << ", offsets addr="
- << reinterpret_cast<const size_t*>(tr.data.ptr.offsets) << endl;
- }
- if (tr.target.ptr) {
- // We only have a weak reference on the target object, so we must first try to
- // safely acquire a strong reference before doing anything else with it.
- if (reinterpret_cast<RefBase::weakref_type*>(
- tr.target.ptr)->attemptIncStrong(this)) {
- error = reinterpret_cast<BBinder*>(tr.cookie)->transact(tr.code, buffer,
- &reply, tr.flags);
- reinterpret_cast<BBinder*>(tr.cookie)->decStrong(this);
- } else {
- error = UNKNOWN_TRANSACTION;
- }
+ Parcel buffer;
+ buffer.ipcSetDataReference(
+ reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
+ tr.data_size,
+ reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
+ tr.offsets_size/sizeof(binder_size_t), freeBuffer, this);
- } else {
- error = the_context_object->transact(tr.code, buffer, &reply, tr.flags);
- }
+ const pid_t origPid = mCallingPid;
+ const uid_t origUid = mCallingUid;
+ const int32_t origStrictModePolicy = mStrictModePolicy;
+ const int32_t origTransactionBinderFlags = mLastTransactionBinderFlags;
- //ALOGI("<<<< TRANSACT from pid %d restore pid %d uid %d\n",
- // mCallingPid, origPid, origUid);
+ mCallingPid = tr.sender_pid;
+ mCallingUid = tr.sender_euid;
+ mLastTransactionBinderFlags = tr.flags;
- if ((tr.flags & TF_ONE_WAY) == 0) {
- LOG_ONEWAY("Sending reply to %d!", mCallingPid);
- if (error < NO_ERROR) reply.setError(error);
+ //ALOGI(">>>> TRANSACT from pid %d uid %d\n", mCallingPid, mCallingUid);
- status_t statusBuffer;
- result = writeTransactionData(BC_REPLY, 0, -1, 0, reply, &statusBuffer);
+ Parcel reply;
+ status_t error;
+ IF_LOG_TRANSACTIONS() {
+ TextOutput::Bundle _b(alog);
+ alog << "BR_TRANSACTION thr " << (void*)pthread_self()
+ << " / obj " << tr.target.ptr << " / code "
+ << TypeCode(tr.code) << ": " << indent << buffer
+ << dedent << endl
+ << "Data addr = "
+ << reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer)
+ << ", offsets addr="
+ << reinterpret_cast<const size_t*>(tr.data.ptr.offsets) << endl;
+ }
+ if (tr.target.ptr) {
+ // We only have a weak reference on the target object, so we must first try to
+ // safely acquire a strong reference before doing anything else with it.
+ if (reinterpret_cast<RefBase::weakref_type*>(
+ tr.target.ptr)->attemptIncStrong(this)) {
+ error = reinterpret_cast<BBinder*>(tr.cookie)->transact(tr.code, buffer,
+ &reply, tr.flags);
+ reinterpret_cast<BBinder*>(tr.cookie)->decStrong(this);
} else {
- LOG_ONEWAY("NOT sending reply to %d!", mCallingPid);
+ error = UNKNOWN_TRANSACTION;
}
- mCallingPid = origPid;
- mCallingUid = origUid;
- mStrictModePolicy = origStrictModePolicy;
- mLastTransactionBinderFlags = origTransactionBinderFlags;
+ } else {
+ error = the_context_object->transact(tr.code, buffer, &reply, tr.flags);
}
- if (result != NO_ERROR)
- break;
+ //ALOGI("<<<< TRANSACT from pid %d restore pid %d uid %d\n",
+ // mCallingPid, origPid, origUid);
+
+ if ((tr.flags & TF_ONE_WAY) == 0) {
+ LOG_ONEWAY("Sending reply to %d!", mCallingPid);
+ if (error < NO_ERROR) reply.setError(error);
+ sendReply(reply, 0);
+ } else {
+ LOG_ONEWAY("NOT sending reply to %d!", mCallingPid);
+ }
- if ((tr.flags & TF_ONE_WAY) == 0)
- waitForResponse(NULL, NULL);
+ mCallingPid = origPid;
+ mCallingUid = origUid;
+ mStrictModePolicy = origStrictModePolicy;
+ mLastTransactionBinderFlags = origTransactionBinderFlags;
IF_LOG_TRANSACTIONS() {
TextOutput::Bundle _b(alog);
diff --git a/libs/binder/include/binder/IPCThreadState.h b/libs/binder/include/binder/IPCThreadState.h
index 9fb13bbe95..245607e74e 100644
--- a/libs/binder/include/binder/IPCThreadState.h
+++ b/libs/binder/include/binder/IPCThreadState.h
@@ -93,6 +93,7 @@ private:
IPCThreadState();
~IPCThreadState();
+ status_t sendReply(const Parcel& reply, uint32_t flags);
status_t waitForResponse(Parcel *reply,
status_t *acquireResult=NULL);
status_t talkWithDriver(bool doReceive=true);