Different internal allocators (memory blocks, linpools, and slabs) used
different way to compute alignment. Unify it to use alignment based on
standard max_align_t type.
On x86_64, this does not change alignment of memory blocks and linpools
(both old and new is 16), but it increases alignment of slabs from 8 to
16.
#define _BIRD_BIRDLIB_H_
#include "lib/alloca.h"
+#include <stddef.h>
#include <stdarg.h>
#include <stdalign.h>
/* Ugly structure offset handling macros */
-struct align_probe { char x; long int y; };
-
#define OFFSETOF(s, i) ((size_t) &((s *)0)->i)
#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
#define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1))
-#define CPU_STRUCT_ALIGN (sizeof(struct align_probe))
+#define CPU_STRUCT_ALIGN (alignof(max_align_t))
/* Utility macros */
struct lp_chunk {
struct lp_chunk *next;
- uintptr_t data_align[0];
+ max_align_t data_align[0];
byte data[0];
};
struct mblock {
resource r;
unsigned size;
- uintptr_t data_align[0];
+ max_align_t data_align[0];
byte data[0];
};
struct sl_obj {
node n;
- uintptr_t data_align[0];
+ max_align_t data_align[0];
byte data[0];
};
u32 used_bits[0];
};
-struct sl_alignment { /* Magic structure for testing of alignment */
- byte data;
- int x[0];
-};
-
#define TLIST_PREFIX sl_head
#define TLIST_TYPE struct sl_head
#define TLIST_ITEM n
sl_new(pool *p, uint size)
{
slab *s = ralloc(p, &sl_class);
- uint align = sizeof(struct sl_alignment);
- if (align < sizeof(void *))
- align = sizeof(void *);
+ uint align = CPU_STRUCT_ALIGN;
s->data_size = size;
size = (size + align - 1) / align * align;
s->obj_size = size;