summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2016-02-15 15:00:22 +0000
committerSimon McVittie <smcv@debian.org>2016-03-02 18:16:26 +0000
commit38a5c3028ed27c4ceeffc32ddb17d1a8fe4fd0dd (patch)
tree44b3fa51b51b5e6a444a6038d8ab9e354bfe2fd1
parent338cfa15992b73d2cd43a50c84bf5ebc4eeda04f (diff)
downloaddbus-38a5c3028ed27c4ceeffc32ddb17d1a8fe4fd0dd.tar.gz
DBusMessageIter: eliminate padding on 64-bit platforms
Previously, 64-bit (LP64 or LLP64) platforms would have had 32 bits of padding between pad2 and pad3. We want to guarantee that an ISO C compiler will copy the entire struct when assigning between structs, but padding is not guaranteed to be copied, so we want to ensure that the struct is "packed". Statically assert that the old ABI is compatible with the new ABI. Reviewed-by: Thiago Macieira <thiago@kde.org> [smcv: change >= to == as Thiago requested] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=94136
-rw-r--r--dbus/dbus-message.c29
-rw-r--r--dbus/dbus-message.h2
2 files changed, 30 insertions, 1 deletions
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 50e87cae..abdc11f3 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -136,6 +136,29 @@ struct DBusMessageRealIter
} u; /**< the type writer or reader that does all the work */
};
+/**
+ * Layout of a DBusMessageIter on the stack in dbus 1.10.0. This is no
+ * longer used, but for ABI compatibility we need to assert that the
+ * new layout is the same size.
+ */
+typedef struct
+{
+ void *dummy1;
+ void *dummy2;
+ dbus_uint32_t dummy3;
+ int dummy4;
+ int dummy5;
+ int dummy6;
+ int dummy7;
+ int dummy8;
+ int dummy9;
+ int dummy10;
+ int dummy11;
+ int pad1;
+ int pad2;
+ void *pad3;
+} DBusMessageIter_1_10_0;
+
static void
get_const_signature (DBusHeader *header,
const DBusString **type_str_p,
@@ -2029,6 +2052,12 @@ _dbus_message_iter_init_common (DBusMessage *message,
_DBUS_STATIC_ASSERT (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
_DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (DBusMessageRealIter) <=
_DBUS_ALIGNOF (DBusMessageIter));
+ /* A failure of these two assertions would indicate that we've broken
+ * ABI on this platform since 1.10.0. */
+ _DBUS_STATIC_ASSERT (sizeof (DBusMessageIter_1_10_0) ==
+ sizeof (DBusMessageIter));
+ _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (DBusMessageIter_1_10_0) ==
+ _DBUS_ALIGNOF (DBusMessageIter));
/* Since the iterator will read or write who-knows-what from the
* message, we need to get in the right byte order
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index 3e33eb7b..ac3e4087 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -62,7 +62,7 @@ struct DBusMessageIter
int dummy10; /**< Don't use this */
int dummy11; /**< Don't use this */
int pad1; /**< Don't use this */
- int pad2; /**< Don't use this */
+ void *pad2; /**< Don't use this */
void *pad3; /**< Don't use this */
};