From 79bd94558c4b7913c93987970e456dfedba2c515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 23 Mar 2008 11:23:30 +0000 Subject: [PATCH] gst/gstregistrybinary.c: Align memory to the pointer size instead of always 32 bit. Fixes unaligned memory accesses o... Original commit message from CVS: * gst/gstregistrybinary.c: (gst_registry_binary_write), (gst_registry_binary_check_magic), (gst_registry_binary_load_pad_template), (gst_registry_binary_load_feature), (gst_registry_binary_load_plugin): Align memory to the pointer size instead of always 32 bit. Fixes unaligned memory accesses on ia64 and friends. * gst/gstregistrybinary.h: Bump binary registry format version for this as it changes the format on those architectures that don't have unaligned access and 64 bit pointers. --- ChangeLog | 15 +++++++++++++++ common | 2 +- gst/gstregistrybinary.c | 32 +++++++++++++++++--------------- gst/gstregistrybinary.h | 2 +- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7670d31ca2..3215a3dea4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-03-23 Sebastian Dröge + + * gst/gstregistrybinary.c: (gst_registry_binary_write), + (gst_registry_binary_check_magic), + (gst_registry_binary_load_pad_template), + (gst_registry_binary_load_feature), + (gst_registry_binary_load_plugin): + Align memory to the pointer size instead of always 32 bit. Fixes + unaligned memory accesses on ia64 and friends. + + * gst/gstregistrybinary.h: + Bump binary registry format version for this as it changes the + format on those architectures that don't have unaligned access + and 64 bit pointers. + 2008-03-22 Sebastian Dröge * docs/pwg/advanced-dparams.xml: diff --git a/common b/common index 9a358e5cc3..4221e9dcb0 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 9a358e5cc3977fd6121f12dd25a358081fd77041 +Subproject commit 4221e9dcb05faa6f6f7ba19bba32fe90da4577dd diff --git a/gst/gstregistrybinary.c b/gst/gstregistrybinary.c index 02b0bd3459..9df54028af 100644 --- a/gst/gstregistrybinary.c +++ b/gst/gstregistrybinary.c @@ -77,7 +77,7 @@ /* macros */ #define unpack_element(_inptr, _outptr, _element) \ - _outptr = (_element *)_inptr; \ + _outptr = (_element *) _inptr; \ _inptr += sizeof (_element) #define unpack_const_string(_inptr, _outptr) \ @@ -89,11 +89,13 @@ _inptr += strlen(_outptr) + 1 #if !GST_HAVE_UNALIGNED_ACCESS -# define alignment32(_address) (gsize)_address%4 -# define align32(_ptr) _ptr += (( alignment32(_ptr) == 0) ? 0 : 4-alignment32(_ptr)) +# define ALIGNMENT (sizeof (void *)) +# define alignment(_address) (gsize)_address%ALIGNMENT +# define align(_ptr) _ptr += (( alignment(_ptr) == 0) ? 0 : ALIGNMENT-alignment(_ptr)) #else -# define alignment32(_address) 0 -# define align32(_ptr) do {} while(0) +# define ALIGNMENT 0 +# define alignment(_address) 0 +# define align(_ptr) do {} while(0) #endif @@ -111,12 +113,12 @@ gst_registry_binary_write (GstRegistry * registry, const void *mem, const gssize size, unsigned long *file_position, gboolean align) { #if !GST_HAVE_UNALIGNED_ACCESS - gchar padder[] = { 0, 0, 0, 0 }; + gchar padder[ALIGN] = { 0, }; int padsize = 0; /* Padding to insert the struct that requiere word alignment */ - if ((align) && (alignment32 (*file_position) != 0)) { - padsize = 4 - alignment32 (*file_position); + if ((align) && (alignment (*file_position) != 0)) { + padsize = ALIGNMENT - alignment (*file_position); if (write (registry->cache_file, padder, padsize) != padsize) { GST_ERROR ("Failed to write binary registry padder"); return FALSE; @@ -606,7 +608,7 @@ gst_registry_binary_check_magic (gchar ** in) { GstBinaryRegistryMagic *m; - align32 (*in); + align (*in); GST_DEBUG ("Reading/casting for GstBinaryRegistryMagic at address %p", *in); unpack_element (*in, m, GstBinaryRegistryMagic); @@ -648,7 +650,7 @@ gst_registry_binary_load_pad_template (GstElementFactory * factory, gchar ** in) GstBinaryPadTemplate *pt; GstStaticPadTemplate *template; - align32 (*in); + align (*in); GST_DEBUG ("Reading/casting for GstBinaryPadTemplate at address %p", *in); unpack_element (*in, pt, GstBinaryPadTemplate); @@ -714,7 +716,7 @@ gst_registry_binary_load_feature (GstRegistry * registry, gchar ** in, GstBinaryElementFactory *ef; GstElementFactory *factory = GST_ELEMENT_FACTORY (feature); - align32 (*in); + align (*in); GST_LOG ("Reading/casting for GstBinaryElementFactory at address %p", *in); unpack_element (*in, ef, GstBinaryElementFactory); pf = (GstBinaryPluginFeature *) ef; @@ -739,7 +741,7 @@ gst_registry_binary_load_feature (GstRegistry * registry, gchar ** in, if (ef->nuriprotocols) { GST_DEBUG ("Reading %d UriTypes at address %p", ef->nuriprotocols, *in); - align32 (*in); + align (*in); factory->uri_type = *((guint *) * in); *in += sizeof (factory->uri_type); //unpack_element(*in, &factory->uri_type, factory->uri_type); @@ -761,7 +763,7 @@ gst_registry_binary_load_feature (GstRegistry * registry, gchar ** in, GstBinaryTypeFindFactory *tff; GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature); - align32 (*in); + align (*in); GST_DEBUG ("Reading/casting for GstBinaryPluginFeature at address %p", *in); unpack_element (*in, tff, GstBinaryTypeFindFactory); pf = (GstBinaryPluginFeature *) tff; @@ -785,7 +787,7 @@ gst_registry_binary_load_feature (GstRegistry * registry, gchar ** in, else if (GST_IS_INDEX_FACTORY (feature)) { GstIndexFactory *factory = GST_INDEX_FACTORY (feature); - align32 (*in); + align (*in); GST_DEBUG ("Reading/casting for GstBinaryPluginFeature at address %p", *in); unpack_element (*in, pf, GstBinaryPluginFeature); @@ -830,7 +832,7 @@ gst_registry_binary_load_plugin (GstRegistry * registry, gchar ** in) GstPlugin *plugin = NULL; guint i; - align32 (*in); + align (*in); GST_LOG ("Reading/casting for GstBinaryPluginElement at address %p", *in); unpack_element (*in, pe, GstBinaryPluginElement); diff --git a/gst/gstregistrybinary.h b/gst/gstregistrybinary.h index c9c7995e75..8193f7c03b 100644 --- a/gst/gstregistrybinary.h +++ b/gst/gstregistrybinary.h @@ -57,7 +57,7 @@ * This _must_ be updated whenever the registry format changes, * we currently use the core version where this change happened. */ -#define GST_MAGIC_BINARY_VERSION_STR ("0.10.18") +#define GST_MAGIC_BINARY_VERSION_STR ("0.10.18.1") /* * GST_MAGIC_BINARY_VERSION_LEN: