Merge "Fix mips build for libbinder."
diff --git a/include/input/Input.h b/include/input/Input.h
index a4fa317..bba8f1e 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -189,7 +189,7 @@
enum { MAX_AXES = 14 }; // 14 so that sizeof(PointerCoords) == 64
// Bitfield of axes that are present in this structure.
- uint64_t bits;
+ uint64_t bits __attribute__((aligned(8)));
// Values of axes that are stored in this structure packed in order by axis id
// for each axis that is present in the structure according to 'bits'.
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h
index 8ffdfca..e7e383b 100644
--- a/include/input/InputTransport.h
+++ b/include/input/InputTransport.h
@@ -39,6 +39,9 @@
/*
* Intermediate representation used to send input events and related signals.
+ *
+ * Note that this structure is used for IPCs so its layout must be identical
+ * on 64 and 32 bit processes. This is tested in StructLayout_test.cpp.
*/
struct InputMessage {
enum {
@@ -49,13 +52,17 @@
struct Header {
uint32_t type;
- uint32_t padding; // 8 byte alignment for the body that follows
+ // We don't need this field in order to align the body below but we
+ // leave it here because InputMessage::size() and other functions
+ // compute the size of this structure as sizeof(Header) + sizeof(Body).
+ uint32_t padding;
} header;
+ // Body *must* be 8 byte aligned.
union Body {
struct Key {
uint32_t seq;
- nsecs_t eventTime;
+ nsecs_t eventTime __attribute__((aligned(8)));
int32_t deviceId;
int32_t source;
int32_t action;
@@ -64,7 +71,7 @@
int32_t scanCode;
int32_t metaState;
int32_t repeatCount;
- nsecs_t downTime;
+ nsecs_t downTime __attribute__((aligned(8)));
inline size_t size() const {
return sizeof(Key);
@@ -73,7 +80,7 @@
struct Motion {
uint32_t seq;
- nsecs_t eventTime;
+ nsecs_t eventTime __attribute__((aligned(8)));
int32_t deviceId;
int32_t source;
int32_t action;
@@ -81,13 +88,14 @@
int32_t metaState;
int32_t buttonState;
int32_t edgeFlags;
- nsecs_t downTime;
+ nsecs_t downTime __attribute__((aligned(8)));
float xOffset;
float yOffset;
float xPrecision;
float yPrecision;
uint32_t pointerCount;
- struct Pointer {
+ // Note that PointerCoords requires 8 byte alignment.
+ struct Pointer{
PointerProperties properties;
PointerCoords coords;
} pointers[MAX_POINTERS];
@@ -112,7 +120,7 @@
return sizeof(Finished);
}
} finished;
- } body;
+ } __attribute__((aligned(8))) body;
bool isValid(size_t actualSize) const;
size_t size() const;
diff --git a/libs/binder/Android.mk b/libs/binder/Android.mk
index c8a1e35..79decfe 100644
--- a/libs/binder/Android.mk
+++ b/libs/binder/Android.mk
@@ -47,6 +47,7 @@
LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1
endif
endif
+LOCAL_CFLAGS += -Werror
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
@@ -58,4 +59,5 @@
LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1
endif
endif
+LOCAL_CFLAGS += -Werror
include $(BUILD_STATIC_LIBRARY)
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 1bad67a..101de7e 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -73,7 +73,7 @@
void BpBinder::ObjectManager::kill()
{
const size_t N = mObjects.size();
- ALOGV("Killing %d objects in manager %p", N, this);
+ ALOGV("Killing %zu objects in manager %p", N, this);
for (size_t i=0; i<N; i++) {
const entry_t& e = mObjects.valueAt(i);
if (e.func != NULL) {
@@ -119,11 +119,11 @@
mDescriptorCache = res;
}
}
-
+
// we're returning a reference to a non-static object here. Usually this
- // is not something smart to do, however, with binder objects it is
+ // is not something smart to do, however, with binder objects it is
// (usually) safe because they are reference-counted.
-
+
return mDescriptorCache;
}
@@ -260,8 +260,8 @@
mObitsSent = 1;
mLock.unlock();
- ALOGV("Reporting death of proxy %p for %d recipients\n",
- this, obits ? obits->size() : 0);
+ ALOGV("Reporting death of proxy %p for %zu recipients\n",
+ this, obits ? obits->size() : 0U);
if (obits != NULL) {
const size_t N = obits->size();
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 66823de..f0d8732 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -155,7 +155,7 @@
const sp<IBinder>& binder, Parcel* out)
{
flat_binder_object obj;
-
+
obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
if (binder != NULL) {
IBinder *local = binder->localBinder();
@@ -179,7 +179,7 @@
obj.binder = 0;
obj.cookie = 0;
}
-
+
return finish_flatten_binder(binder, obj, out);
}
@@ -187,7 +187,7 @@
const wp<IBinder>& binder, Parcel* out)
{
flat_binder_object obj;
-
+
obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
if (binder != NULL) {
sp<IBinder> real = binder.promote();
@@ -210,7 +210,7 @@
}
return finish_flatten_binder(real, obj, out);
}
-
+
// XXX How to deal? In order to flatten the given binder,
// we need to probe it for information, which requires a primary
// reference... but we don't have one.
@@ -223,7 +223,7 @@
obj.binder = 0;
obj.cookie = 0;
return finish_flatten_binder(NULL, obj, out);
-
+
} else {
obj.type = BINDER_TYPE_BINDER;
obj.binder = 0;
@@ -238,12 +238,12 @@
{
return NO_ERROR;
}
-
+
status_t unflatten_binder(const sp<ProcessState>& proc,
const Parcel& in, sp<IBinder>* out)
{
const flat_binder_object* flat = in.readObject(false);
-
+
if (flat) {
switch (flat->type) {
case BINDER_TYPE_BINDER:
@@ -253,7 +253,7 @@
*out = proc->getStrongProxyForHandle(flat->handle);
return finish_unflatten_binder(
static_cast<BpBinder*>(out->get()), *flat, in);
- }
+ }
}
return BAD_TYPE;
}
@@ -262,7 +262,7 @@
const Parcel& in, wp<IBinder>* out)
{
const flat_binder_object* flat = in.readObject(false);
-
+
if (flat) {
switch (flat->type) {
case BINDER_TYPE_BINDER:
@@ -336,7 +336,7 @@
err = continueWrite(size);
if (err == NO_ERROR) {
mDataSize = size;
- ALOGV("setDataSize Setting data size of %p to %d\n", this, mDataSize);
+ ALOGV("setDataSize Setting data size of %p to %zu", this, mDataSize);
}
return err;
}
@@ -424,7 +424,7 @@
mObjects = objects;
mObjectsCapacity = newSize;
}
-
+
// append and acquire objects
int idx = mObjectsSize;
for (int i = firstIndex; i <= lastIndex; i++) {
@@ -510,7 +510,7 @@
if (str == interface) {
return true;
} else {
- ALOGW("**** enforceInterface() expected '%s' but read '%s'\n",
+ ALOGW("**** enforceInterface() expected '%s' but read '%s'",
String8(interface).string(), String8(str).string());
return false;
}
@@ -540,10 +540,10 @@
{
//printf("Finish write of %d\n", len);
mDataPos += len;
- ALOGV("finishWrite Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("finishWrite Setting data pos of %p to %zu", this, mDataPos);
if (mDataPos > mDataSize) {
mDataSize = mDataPos;
- ALOGV("finishWrite Setting data size of %p to %d\n", this, mDataSize);
+ ALOGV("finishWrite Setting data size of %p to %zu", this, mDataSize);
}
//printf("New pos=%d, size=%d\n", mDataPos, mDataSize);
return NO_ERROR;
@@ -709,7 +709,7 @@
status_t Parcel::writeString16(const char16_t* str, size_t len)
{
if (str == NULL) return writeInt32(-1);
-
+
status_t err = writeInt32(len);
if (err == NO_ERROR) {
len *= sizeof(char16_t);
@@ -898,14 +898,14 @@
if (enoughData && enoughObjects) {
restart_write:
*reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
-
+
// Need to write meta-data?
if (nullMetaData || val.binder != 0) {
mObjects[mObjectsSize] = mDataPos;
acquire_object(ProcessState::self(), val, this);
mObjectsSize++;
}
-
+
// remember if it's a file descriptor
if (val.type == BINDER_TYPE_FD) {
if (!mAllowFds) {
@@ -928,7 +928,7 @@
mObjects = objects;
mObjectsCapacity = newSize;
}
-
+
goto restart_write;
}
@@ -948,7 +948,7 @@
&& len <= PAD_SIZE(len)) {
memcpy(outData, mData+mDataPos, len);
mDataPos += PAD_SIZE(len);
- ALOGV("read Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("read Setting data pos of %p to %zu", this, mDataPos);
return NO_ERROR;
}
return NOT_ENOUGH_DATA;
@@ -960,7 +960,7 @@
&& len <= PAD_SIZE(len)) {
const void* data = mData+mDataPos;
mDataPos += PAD_SIZE(len);
- ALOGV("readInplace Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("readInplace Setting data pos of %p to %zu", this, mDataPos);
return data;
}
return NULL;
@@ -1115,7 +1115,7 @@
if (eos) {
const size_t len = eos - str;
mDataPos += PAD_SIZE(len+1);
- ALOGV("readCString Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("readCString Setting data pos of %p to %zu", this, mDataPos);
return str;
}
}
@@ -1217,9 +1217,9 @@
if (flat) {
switch (flat->type) {
case BINDER_TYPE_FD:
- //ALOGI("Returning file descriptor %ld from parcel %p\n", flat->handle, this);
+ //ALOGI("Returning file descriptor %ld from parcel %p", flat->handle, this);
return flat->handle;
- }
+ }
}
return BAD_TYPE;
}
@@ -1288,7 +1288,7 @@
fds[i] = dup(this->readFileDescriptor());
if (fds[i] < 0) {
err = BAD_VALUE;
- ALOGE("dup() failed in Parcel::read, i is %d, fds[i] is %d, fd_count is %d, error: %s",
+ ALOGE("dup() failed in Parcel::read, i is %zu, fds[i] is %d, fd_count is %zu, error: %s",
i, fds[i], fd_count, strerror(errno));
}
}
@@ -1314,19 +1314,19 @@
// 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.
- ALOGV("readObject Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("readObject Setting data pos of %p to %zu", this, mDataPos);
return obj;
}
-
+
// Ensure that this object is valid...
binder_size_t* const OBJS = mObjects;
const size_t N = mObjectsSize;
size_t opos = mNextObjectHint;
-
+
if (N > 0) {
- ALOGV("Parcel %p looking for obj at %d, hint=%d\n",
+ ALOGV("Parcel %p looking for obj at %zu, hint=%zu",
this, DPOS, opos);
-
+
// Start at the current hint position, looking for an object at
// the current data position.
if (opos < N) {
@@ -1338,23 +1338,23 @@
}
if (OBJS[opos] == DPOS) {
// Found it!
- ALOGV("Parcel found obj %d at index %d with forward search",
+ ALOGV("Parcel %p found obj %zu at index %zu with forward search",
this, DPOS, opos);
mNextObjectHint = opos+1;
- ALOGV("readObject Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("readObject Setting data pos of %p to %zu", this, mDataPos);
return obj;
}
-
+
// Look backwards for it...
while (opos > 0 && OBJS[opos] > DPOS) {
opos--;
}
if (OBJS[opos] == DPOS) {
// Found it!
- ALOGV("Parcel found obj %d at index %d with backward search",
+ ALOGV("Parcel %p found obj %zu at index %zu with backward search",
this, DPOS, opos);
mNextObjectHint = opos+1;
- ALOGV("readObject Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("readObject Setting data pos of %p to %zu", this, mDataPos);
return obj;
}
}
@@ -1368,14 +1368,14 @@
{
size_t i = mObjectsSize;
if (i > 0) {
- //ALOGI("Closing file descriptors for %d objects...", mObjectsSize);
+ //ALOGI("Closing file descriptors for %zu objects...", i);
}
while (i > 0) {
i--;
const flat_binder_object* flat
= reinterpret_cast<flat_binder_object*>(mData+mObjects[i]);
if (flat->type == BINDER_TYPE_FD) {
- //ALOGI("Closing fd: %ld\n", flat->handle);
+ //ALOGI("Closing fd: %ld", flat->handle);
close(flat->handle);
}
}
@@ -1409,9 +1409,9 @@
mError = NO_ERROR;
mData = const_cast<uint8_t*>(data);
mDataSize = mDataCapacity = dataSize;
- //ALOGI("setDataReference Setting data size of %p to %lu (pid=%d)\n", this, mDataSize, getpid());
+ //ALOGI("setDataReference Setting data size of %p to %lu (pid=%d)", this, mDataSize, getpid());
mDataPos = 0;
- ALOGV("setDataReference Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("setDataReference Setting data pos of %p to %zu", this, mDataPos);
mObjects = const_cast<binder_size_t*>(objects);
mObjectsSize = mObjectsCapacity = objectsCount;
mNextObjectHint = 0;
@@ -1433,7 +1433,7 @@
void Parcel::print(TextOutput& to, uint32_t /*flags*/) const
{
to << "Parcel(";
-
+
if (errorCheck() != NO_ERROR) {
const status_t err = errorCheck();
to << "Error: " << (void*)(intptr_t)err << " \"" << strerror(-err) << "\"";
@@ -1452,7 +1452,7 @@
} else {
to << "NULL";
}
-
+
to << ")";
}
@@ -1493,7 +1493,7 @@
void Parcel::freeDataNoInit()
{
if (mOwner) {
- //ALOGI("Freeing data ref of %p (pid=%d)\n", this, getpid());
+ //ALOGI("Freeing data ref of %p (pid=%d)", this, getpid());
mOwner(this, mData, mDataSize, mObjects, mObjectsSize, mOwnerCookie);
} else {
releaseObjects();
@@ -1516,24 +1516,24 @@
freeData();
return continueWrite(desired);
}
-
+
uint8_t* data = (uint8_t*)realloc(mData, desired);
if (!data && desired > mDataCapacity) {
mError = NO_MEMORY;
return NO_MEMORY;
}
-
+
releaseObjects();
-
+
if (data) {
mData = data;
mDataCapacity = desired;
}
-
+
mDataSize = mDataPos = 0;
- ALOGV("restartWrite Setting data size of %p to %d\n", this, mDataSize);
- ALOGV("restartWrite Setting data pos of %p to %d\n", this, mDataPos);
-
+ ALOGV("restartWrite Setting data size of %p to %zu", this, mDataSize);
+ ALOGV("restartWrite Setting data pos of %p to %zu", this, mDataPos);
+
free(mObjects);
mObjects = NULL;
mObjectsSize = mObjectsCapacity = 0;
@@ -1541,7 +1541,7 @@
mHasFds = false;
mFdsKnown = true;
mAllowFds = true;
-
+
return NO_ERROR;
}
@@ -1561,7 +1561,7 @@
}
}
}
-
+
if (mOwner) {
// If the size is going to zero, just release the owner's data.
if (desired == 0) {
@@ -1577,7 +1577,7 @@
return NO_MEMORY;
}
binder_size_t* objects = NULL;
-
+
if (objectsSize) {
objects = (binder_size_t*)malloc(objectsSize*sizeof(binder_size_t));
if (!objects) {
@@ -1594,21 +1594,21 @@
acquireObjects();
mObjectsSize = oldObjectsSize;
}
-
+
if (mData) {
memcpy(data, mData, mDataSize < desired ? mDataSize : desired);
}
if (objects && mObjects) {
memcpy(objects, mObjects, objectsSize*sizeof(binder_size_t));
}
- //ALOGI("Freeing data ref of %p (pid=%d)\n", this, getpid());
+ //ALOGI("Freeing data ref of %p (pid=%d)", this, getpid());
mOwner(this, mData, mDataSize, mObjects, mObjectsSize, mOwnerCookie);
mOwner = NULL;
mData = data;
mObjects = objects;
mDataSize = (mDataSize < desired) ? mDataSize : desired;
- ALOGV("continueWrite Setting data size of %p to %d\n", this, mDataSize);
+ ALOGV("continueWrite Setting data size of %p to %zu", this, mDataSize);
mDataCapacity = desired;
mObjectsSize = mObjectsCapacity = objectsSize;
mNextObjectHint = 0;
@@ -1648,14 +1648,14 @@
} else {
if (mDataSize > desired) {
mDataSize = desired;
- ALOGV("continueWrite Setting data size of %p to %d\n", this, mDataSize);
+ ALOGV("continueWrite Setting data size of %p to %zu", this, mDataSize);
}
if (mDataPos > desired) {
mDataPos = desired;
- ALOGV("continueWrite Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("continueWrite Setting data pos of %p to %zu", this, mDataPos);
}
}
-
+
} else {
// This is the first data. Easy!
uint8_t* data = (uint8_t*)malloc(desired);
@@ -1668,11 +1668,11 @@
&& mObjectsCapacity == 0)) {
ALOGE("continueWrite: %zu/%p/%zu/%zu", mDataCapacity, mObjects, mObjectsCapacity, desired);
}
-
+
mData = data;
mDataSize = mDataPos = 0;
- ALOGV("continueWrite Setting data size of %p to %d\n", this, mDataSize);
- ALOGV("continueWrite Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("continueWrite Setting data size of %p to %zu", this, mDataSize);
+ ALOGV("continueWrite Setting data pos of %p to %zu", this, mDataPos);
mDataCapacity = desired;
}
@@ -1686,8 +1686,8 @@
mDataSize = 0;
mDataCapacity = 0;
mDataPos = 0;
- ALOGV("initState Setting data size of %p to %d\n", this, mDataSize);
- ALOGV("initState Setting data pos of %p to %d\n", this, mDataPos);
+ ALOGV("initState Setting data size of %p to %zu", this, mDataSize);
+ ALOGV("initState Setting data pos of %p to %zu", this, mDataPos);
mObjects = NULL;
mObjectsSize = 0;
mObjectsCapacity = 0;
diff --git a/libs/input/tests/Android.mk b/libs/input/tests/Android.mk
index c62dff1..9612a65 100644
--- a/libs/input/tests/Android.mk
+++ b/libs/input/tests/Android.mk
@@ -29,5 +29,16 @@
$(eval include $(BUILD_NATIVE_TEST)) \
)
+# NOTE: This is a compile time test, and does not need to be
+# run. All assertions are static_asserts and will fail during
+# buildtime if something's wrong.
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := StructLayout_test.cpp
+LOCAL_MODULE := StructLayout_test
+LOCAL_CFLAGS := -std=c++11 -O0
+LOCAL_MULTILIB := both
+include $(BUILD_STATIC_LIBRARY)
+
+
# Build the manual test programs.
include $(call all-makefiles-under, $(LOCAL_PATH))
diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp
new file mode 100644
index 0000000..83bc6ae
--- /dev/null
+++ b/libs/input/tests/StructLayout_test.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <input/InputTransport.h>
+#include <input/Input.h>
+
+namespace android {
+
+#define CHECK_OFFSET(type, member, expected_offset) \
+ static_assert((offsetof(type, member) == expected_offset), "")
+
+struct Foo {
+ uint32_t dummy;
+ PointerCoords coords;
+};
+
+void TestPointerCoordsAlignment() {
+ CHECK_OFFSET(Foo, coords, 8);
+}
+
+void TestInputMessageAlignment() {
+ CHECK_OFFSET(InputMessage, body, 8);
+
+ CHECK_OFFSET(InputMessage::Body::Key, seq, 0);
+ CHECK_OFFSET(InputMessage::Body::Key, eventTime, 8);
+ CHECK_OFFSET(InputMessage::Body::Key, deviceId, 16);
+ CHECK_OFFSET(InputMessage::Body::Key, source, 20);
+ CHECK_OFFSET(InputMessage::Body::Key, action, 24);
+ CHECK_OFFSET(InputMessage::Body::Key, flags, 28);
+ CHECK_OFFSET(InputMessage::Body::Key, keyCode, 32);
+ CHECK_OFFSET(InputMessage::Body::Key, scanCode, 36);
+ CHECK_OFFSET(InputMessage::Body::Key, metaState, 40);
+ CHECK_OFFSET(InputMessage::Body::Key, repeatCount, 44);
+ CHECK_OFFSET(InputMessage::Body::Key, downTime, 48);
+
+ CHECK_OFFSET(InputMessage::Body::Motion, seq, 0);
+ CHECK_OFFSET(InputMessage::Body::Motion, eventTime, 8);
+ CHECK_OFFSET(InputMessage::Body::Motion, deviceId, 16);
+ CHECK_OFFSET(InputMessage::Body::Motion, source, 20);
+ CHECK_OFFSET(InputMessage::Body::Motion, action, 24);
+ CHECK_OFFSET(InputMessage::Body::Motion, flags, 28);
+ CHECK_OFFSET(InputMessage::Body::Motion, metaState, 32);
+ CHECK_OFFSET(InputMessage::Body::Motion, buttonState, 36);
+ CHECK_OFFSET(InputMessage::Body::Motion, edgeFlags, 40);
+ CHECK_OFFSET(InputMessage::Body::Motion, downTime, 48);
+ CHECK_OFFSET(InputMessage::Body::Motion, xOffset, 56);
+ CHECK_OFFSET(InputMessage::Body::Motion, yOffset, 60);
+ CHECK_OFFSET(InputMessage::Body::Motion, xPrecision, 64);
+ CHECK_OFFSET(InputMessage::Body::Motion, yPrecision, 68);
+ CHECK_OFFSET(InputMessage::Body::Motion, pointerCount, 72);
+ CHECK_OFFSET(InputMessage::Body::Motion, pointers, 80);
+}
+
+} // namespace android