+2009-01-16 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+
+ * 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 <sebastian.droege@collabora.co.uk>
* gst-libs/gst/tag/gsttagdemux.c: (gst_tag_demux_srcpad_event):
#include "kiss_fft_f32.h"
#include <limits.h>
+/* 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
#include "kiss_fft_f64.h"
#include <limits.h>
+/* 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
#include "kiss_fft_s16.h"
#include <limits.h>
+/* 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
#include "kiss_fft_s32.h"
#include <limits.h>
+/* 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
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);
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);
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);
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);
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);
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);
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);
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);