diff options
author | Bill Richardson <wfrichar@chromium.org> | 2015-01-26 12:18:25 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-01-28 01:55:58 +0000 |
commit | 73e5eb38821d693244f841ce4f0a14546e5b6361 (patch) | |
tree | 88f27661515c24c23a02eddca856433189f4b6f8 /firmware/2lib/include | |
parent | 9a8dfd00ecf042b7619f0fbbcb8308fce5cfd5c8 (diff) | |
download | vboot-73e5eb38821d693244f841ce4f0a14546e5b6361.tar.gz |
vboot2: fix alignment issues on 32-bit architectures
We were assuming 8-byte alignment for buffers. That's not true on
32-bit architectures. We should make the alignment requirements
explicit (and correct) for all architectures.
BUG=chromium:452179
BRANCH=ToT
CQ-DEPEND=CL:243380
TEST=manual
USE=vboot2 FEATURES=test emerge-x86-alex vboot_reference
Change-Id: I120f23e9c5312d7c21ff9ebb6eea2bac1e430e37
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243362
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'firmware/2lib/include')
-rw-r--r-- | firmware/2lib/include/2api.h | 1 | ||||
-rw-r--r-- | firmware/2lib/include/2common.h | 18 |
2 files changed, 17 insertions, 2 deletions
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h index 0c5792d8..9db5019f 100644 --- a/firmware/2lib/include/2api.h +++ b/firmware/2lib/include/2api.h @@ -21,6 +21,7 @@ #define VBOOT_2_API_H_ #include <stdint.h> +#include "2common.h" #include "2crypto.h" #include "2fw_hash_tags.h" #include "2guid.h" diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h index 9b4a1eb9..69a238c1 100644 --- a/firmware/2lib/include/2common.h +++ b/firmware/2lib/include/2common.h @@ -39,8 +39,22 @@ struct vb2_public_key; # define VB2_DEBUG(format, args...) #endif -/* Alignment for work buffer pointers/allocations */ -#define VB2_WORKBUF_ALIGN 8 +/* + * Alignment for work buffer pointers/allocations should be useful for any + * data type. When declaring workbuf buffers on the stack, the caller should + * use explicit alignment to avoid run-time errors. For example: + * + * int foo(void) + * { + * struct vb2_workbuf wb; + * uint8_t buf[NUM] __attribute__ ((aligned (VB2_WORKBUF_ALIGN))); + * wb.buf = buf; + * wb.size = sizeof(buf); + */ + +/* We might get away with using __alignof__(void *), but since GCC defines a + * macro for us we'll be safe and use that. */ +#define VB2_WORKBUF_ALIGN __BIGGEST_ALIGNMENT__ /* Work buffer */ struct vb2_workbuf { |