From: Sebastian Dröge Date: Fri, 16 Jan 2009 11:44:04 +0000 (+0000) Subject: gst-libs/gst/fft/: Use correct struct alignment everywhere to prevent unaligned memor... X-Git-Tag: GIT_CONVERSION~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d3ff205be797c61cfdef49330d255b1822a3288;p=platform%2Fupstream%2Fgst-plugins-base.git gst-libs/gst/fft/: Use correct struct alignment everywhere to prevent unaligned memory accesses, resulting in SIGBUS ... Original commit message from CVS: * gst-libs/gst/fft/_kiss_fft_guts_f32.h: * gst-libs/gst/fft/_kiss_fft_guts_f64.h: * gst-libs/gst/fft/_kiss_fft_guts_s16.h: * gst-libs/gst/fft/_kiss_fft_guts_s32.h: * gst-libs/gst/fft/kiss_fftr_f32.c: (kiss_fftr_f32_alloc): * gst-libs/gst/fft/kiss_fftr_f64.c: (kiss_fftr_f64_alloc): * gst-libs/gst/fft/kiss_fftr_s16.c: (kiss_fftr_s16_alloc): * gst-libs/gst/fft/kiss_fftr_s32.c: (kiss_fftr_s32_alloc): Use correct struct alignment everywhere to prevent unaligned memory accesses, resulting in SIGBUS on sparc and probably others. Fixes bug #500833. --- diff --git a/ChangeLog b/ChangeLog index 073c06152..b6b58ab6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-01-16 Sebastian Dröge + + * gst-libs/gst/fft/_kiss_fft_guts_f32.h: + * gst-libs/gst/fft/_kiss_fft_guts_f64.h: + * gst-libs/gst/fft/_kiss_fft_guts_s16.h: + * gst-libs/gst/fft/_kiss_fft_guts_s32.h: + * gst-libs/gst/fft/kiss_fftr_f32.c: (kiss_fftr_f32_alloc): + * gst-libs/gst/fft/kiss_fftr_f64.c: (kiss_fftr_f64_alloc): + * gst-libs/gst/fft/kiss_fftr_s16.c: (kiss_fftr_s16_alloc): + * gst-libs/gst/fft/kiss_fftr_s32.c: (kiss_fftr_s32_alloc): + Use correct struct alignment everywhere to prevent unaligned + memory accesses, resulting in SIGBUS on sparc and probably others. + Fixes bug #500833. + 2009-01-16 Sebastian Dröge * gst-libs/gst/tag/gsttagdemux.c: (gst_tag_demux_srcpad_event): diff --git a/gst-libs/gst/fft/_kiss_fft_guts_f32.h b/gst-libs/gst/fft/_kiss_fft_guts_f32.h index 15dc06b41..78d2e2e81 100644 --- a/gst-libs/gst/fft/_kiss_fft_guts_f32.h +++ b/gst-libs/gst/fft/_kiss_fft_guts_f32.h @@ -19,6 +19,20 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "kiss_fft_f32.h" #include +/* The 2*sizeof(size_t) alignment here is borrowed from + * GNU libc, so it should be good most everywhere. + * It is more conservative than is needed on some 64-bit + * platforms, but ia64 does require a 16-byte alignment. + * The SIMD extensions for x86 and ppc32 would want a + * larger alignment than this, but we don't need to + * do better than malloc. + * + * Borrowed from GLib's gobject/gtype.c + */ +#define STRUCT_ALIGNMENT (2 * sizeof (size_t)) +#define ALIGN_STRUCT(offset) \ + ((offset + (STRUCT_ALIGNMENT - 1)) & -STRUCT_ALIGNMENT) + #define MAXFACTORS 32 /* e.g. an fft of length 128 has 4 factors as far as kissfft is concerned diff --git a/gst-libs/gst/fft/_kiss_fft_guts_f64.h b/gst-libs/gst/fft/_kiss_fft_guts_f64.h index 276f65eab..4202716d8 100644 --- a/gst-libs/gst/fft/_kiss_fft_guts_f64.h +++ b/gst-libs/gst/fft/_kiss_fft_guts_f64.h @@ -19,6 +19,20 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "kiss_fft_f64.h" #include +/* The 2*sizeof(size_t) alignment here is borrowed from + * GNU libc, so it should be good most everywhere. + * It is more conservative than is needed on some 64-bit + * platforms, but ia64 does require a 16-byte alignment. + * The SIMD extensions for x86 and ppc32 would want a + * larger alignment than this, but we don't need to + * do better than malloc. + * + * Borrowed from GLib's gobject/gtype.c + */ +#define STRUCT_ALIGNMENT (2 * sizeof (size_t)) +#define ALIGN_STRUCT(offset) \ + ((offset + (STRUCT_ALIGNMENT - 1)) & -STRUCT_ALIGNMENT) + #define MAXFACTORS 32 /* e.g. an fft of length 128 has 4 factors as far as kissfft is concerned diff --git a/gst-libs/gst/fft/_kiss_fft_guts_s16.h b/gst-libs/gst/fft/_kiss_fft_guts_s16.h index 110ed7b4d..2d8256e09 100644 --- a/gst-libs/gst/fft/_kiss_fft_guts_s16.h +++ b/gst-libs/gst/fft/_kiss_fft_guts_s16.h @@ -19,6 +19,20 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "kiss_fft_s16.h" #include +/* The 2*sizeof(size_t) alignment here is borrowed from + * GNU libc, so it should be good most everywhere. + * It is more conservative than is needed on some 64-bit + * platforms, but ia64 does require a 16-byte alignment. + * The SIMD extensions for x86 and ppc32 would want a + * larger alignment than this, but we don't need to + * do better than malloc. + * + * Borrowed from GLib's gobject/gtype.c + */ +#define STRUCT_ALIGNMENT (2 * sizeof (size_t)) +#define ALIGN_STRUCT(offset) \ + ((offset + (STRUCT_ALIGNMENT - 1)) & -STRUCT_ALIGNMENT) + #define MAXFACTORS 32 /* e.g. an fft of length 128 has 4 factors as far as kissfft is concerned diff --git a/gst-libs/gst/fft/_kiss_fft_guts_s32.h b/gst-libs/gst/fft/_kiss_fft_guts_s32.h index 5da7ec396..f0ec9c0f4 100644 --- a/gst-libs/gst/fft/_kiss_fft_guts_s32.h +++ b/gst-libs/gst/fft/_kiss_fft_guts_s32.h @@ -19,6 +19,20 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "kiss_fft_s32.h" #include +/* The 2*sizeof(size_t) alignment here is borrowed from + * GNU libc, so it should be good most everywhere. + * It is more conservative than is needed on some 64-bit + * platforms, but ia64 does require a 16-byte alignment. + * The SIMD extensions for x86 and ppc32 would want a + * larger alignment than this, but we don't need to + * do better than malloc. + * + * Borrowed from GLib's gobject/gtype.c + */ +#define STRUCT_ALIGNMENT (2 * sizeof (size_t)) +#define ALIGN_STRUCT(offset) \ + ((offset + (STRUCT_ALIGNMENT - 1)) & -STRUCT_ALIGNMENT) + #define MAXFACTORS 32 /* e.g. an fft of length 128 has 4 factors as far as kissfft is concerned diff --git a/gst-libs/gst/fft/kiss_fftr_f32.c b/gst-libs/gst/fft/kiss_fftr_f32.c index 1f9fdb21a..ea45206eb 100644 --- a/gst-libs/gst/fft/kiss_fftr_f32.c +++ b/gst-libs/gst/fft/kiss_fftr_f32.c @@ -39,9 +39,8 @@ kiss_fftr_f32_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem) nfft >>= 1; kiss_fft_f32_alloc (nfft, inverse_fft, NULL, &subsize); - memneeded = - sizeof (struct kiss_fftr_f32_state) + subsize + - sizeof (kiss_fft_f32_cpx) * (nfft * 2); + memneeded = ALIGN_STRUCT (sizeof (struct kiss_fftr_f32_state)) + + ALIGN_STRUCT (subsize) + sizeof (kiss_fft_f32_cpx) * (nfft * 2); if (lenmem == NULL) { st = (kiss_fftr_f32_cfg) KISS_FFT_F32_MALLOC (memneeded); @@ -53,8 +52,9 @@ kiss_fftr_f32_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem) if (!st) return NULL; - st->substate = (kiss_fft_f32_cfg) (st + 1); /*just beyond kiss_fftr_f32_state struct */ - st->tmpbuf = (kiss_fft_f32_cpx *) (((char *) st->substate) + subsize); + st->substate = (kiss_fft_f32_cfg) (((char *) st) + ALIGN_STRUCT (sizeof (struct kiss_fftr_f32_state))); /*just beyond kiss_fftr_f32_state struct */ + st->tmpbuf = + (kiss_fft_f32_cpx *) (((char *) st->substate) + ALIGN_STRUCT (subsize)); st->super_twiddles = st->tmpbuf + nfft; kiss_fft_f32_alloc (nfft, inverse_fft, st->substate, &subsize); diff --git a/gst-libs/gst/fft/kiss_fftr_f64.c b/gst-libs/gst/fft/kiss_fftr_f64.c index d566336d3..59587147b 100644 --- a/gst-libs/gst/fft/kiss_fftr_f64.c +++ b/gst-libs/gst/fft/kiss_fftr_f64.c @@ -39,9 +39,9 @@ kiss_fftr_f64_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem) nfft >>= 1; kiss_fft_f64_alloc (nfft, inverse_fft, NULL, &subsize); - memneeded = - sizeof (struct kiss_fftr_f64_state) + subsize + - sizeof (kiss_fft_f64_cpx) * (nfft * 2); + memneeded = ALIGN_STRUCT (sizeof (struct kiss_fftr_f64_state)) + + ALIGN_STRUCT (subsize) + + sizeof (kiss_fft_f64_cpx) * (nfft * 2); if (lenmem == NULL) { st = (kiss_fftr_f64_cfg) KISS_FFT_F64_MALLOC (memneeded); @@ -53,8 +53,9 @@ kiss_fftr_f64_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem) if (!st) return NULL; - st->substate = (kiss_fft_f64_cfg) (st + 1); /*just beyond kiss_fftr_f64_state struct */ - st->tmpbuf = (kiss_fft_f64_cpx *) (((char *) st->substate) + subsize); + st->substate = (kiss_fft_f64_cfg) (((char *) st) + ALIGN_STRUCT (sizeof (struct kiss_fftr_f64_state))); /*just beyond kiss_fftr_f64_state struct */ + st->tmpbuf = + (kiss_fft_f64_cpx *) (((char *) st->substate) + ALIGN_STRUCT (subsize)); st->super_twiddles = st->tmpbuf + nfft; kiss_fft_f64_alloc (nfft, inverse_fft, st->substate, &subsize); diff --git a/gst-libs/gst/fft/kiss_fftr_s16.c b/gst-libs/gst/fft/kiss_fftr_s16.c index 2df51557a..803fa6338 100644 --- a/gst-libs/gst/fft/kiss_fftr_s16.c +++ b/gst-libs/gst/fft/kiss_fftr_s16.c @@ -39,9 +39,9 @@ kiss_fftr_s16_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem) nfft >>= 1; kiss_fft_s16_alloc (nfft, inverse_fft, NULL, &subsize); - memneeded = - sizeof (struct kiss_fftr_s16_state) + subsize + - sizeof (kiss_fft_s16_cpx) * (nfft * 2); + memneeded = ALIGN_STRUCT (sizeof (struct kiss_fftr_s16_state)) + + ALIGN_STRUCT (subsize) + + sizeof (kiss_fft_s16_cpx) * (nfft * 2); if (lenmem == NULL) { st = (kiss_fftr_s16_cfg) KISS_FFT_S16_MALLOC (memneeded); @@ -53,8 +53,9 @@ kiss_fftr_s16_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem) if (!st) return NULL; - st->substate = (kiss_fft_s16_cfg) (st + 1); /*just beyond kiss_fftr_s16_state struct */ - st->tmpbuf = (kiss_fft_s16_cpx *) (((char *) st->substate) + subsize); + st->substate = (kiss_fft_s16_cfg) (((char *) st) + ALIGN_STRUCT (sizeof (struct kiss_fftr_s16_state))); /*just beyond kiss_fftr_s16_state struct */ + st->tmpbuf = + (kiss_fft_s16_cpx *) (((char *) st->substate) + ALIGN_STRUCT (subsize)); st->super_twiddles = st->tmpbuf + nfft; kiss_fft_s16_alloc (nfft, inverse_fft, st->substate, &subsize); diff --git a/gst-libs/gst/fft/kiss_fftr_s32.c b/gst-libs/gst/fft/kiss_fftr_s32.c index 47dc18703..e2a8541a5 100644 --- a/gst-libs/gst/fft/kiss_fftr_s32.c +++ b/gst-libs/gst/fft/kiss_fftr_s32.c @@ -39,9 +39,9 @@ kiss_fftr_s32_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem) nfft >>= 1; kiss_fft_s32_alloc (nfft, inverse_fft, NULL, &subsize); - memneeded = - sizeof (struct kiss_fftr_s32_state) + subsize + - sizeof (kiss_fft_s32_cpx) * (nfft * 2); + memneeded = ALIGN_STRUCT (sizeof (struct kiss_fftr_s32_state)) + + ALIGN_STRUCT (subsize) + + sizeof (kiss_fft_s32_cpx) * (nfft * 2); if (lenmem == NULL) { st = (kiss_fftr_s32_cfg) KISS_FFT_S32_MALLOC (memneeded); @@ -53,8 +53,9 @@ kiss_fftr_s32_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem) if (!st) return NULL; - st->substate = (kiss_fft_s32_cfg) (st + 1); /*just beyond kiss_fftr_s32_state struct */ - st->tmpbuf = (kiss_fft_s32_cpx *) (((char *) st->substate) + subsize); + st->substate = (kiss_fft_s32_cfg) (((char *) st) + ALIGN_STRUCT (sizeof (struct kiss_fftr_s32_state))); /*just beyond kiss_fftr_s32_state struct */ + st->tmpbuf = + (kiss_fft_s32_cpx *) (((char *) st->substate) + ALIGN_STRUCT (subsize)); st->super_twiddles = st->tmpbuf + nfft; kiss_fft_s32_alloc (nfft, inverse_fft, st->substate, &subsize);