diff options
author | Andre Heider <a.heider@gmail.com> | 2013-10-19 14:20:48 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-10-22 15:28:58 +0200 |
commit | 55f6869c33e62f6ba253e4fa6fcb9724288a0deb (patch) | |
tree | 311a6eb4b6f983e0bd92bcdee1a9c76012da50f5 /include/common.h | |
parent | 0fdd91d92b7eac2161dbcec2032d055eb2b90b04 (diff) | |
download | barebox-55f6869c33e62f6ba253e4fa6fcb9724288a0deb.tar.gz barebox-55f6869c33e62f6ba253e4fa6fcb9724288a0deb.tar.xz |
common: add a macro to align an array on the stack
The macro can be used for temporary stack buffers which need to meet
a minimum alignment requirement.
This will be used by bcm2835 mailbox users, where all buffers need to
be aligned.
Signed-off-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/common.h')
-rw-r--r-- | include/common.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h index 0f0ba08c44..00f1642cd5 100644 --- a/include/common.h +++ b/include/common.h @@ -192,6 +192,17 @@ int run_shell(void); #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) #define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x) +/* + * The STACK_ALIGN_ARRAY macro is used to allocate a buffer on the stack that + * meets a minimum alignment requirement. + * + * Note that the size parameter is the number of array elements to allocate, + * not the number of bytes. + */ +#define STACK_ALIGN_ARRAY(type, name, size, align) \ + char __##name[sizeof(type) * (size) + (align) - 1]; \ + type *name = (type *)ALIGN((uintptr_t)__##name, align) + /** * container_of - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. |