From c88cca1c38bb2752a7284590ec70a55caf3e490d Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Thu, 22 Jan 2015 08:53:02 -0600 Subject: [PATCH] libpayload: add xmemalign() Similarly to xzalloc() and xmalloc() provide an xmemalign() function to do the approriate assertions on allocation failure. BUG=None BRANCH=None TEST=Built and booted using xmemalign(). Change-Id: I59579d9ee973af3bb34037b7df5b1024b60e348d Signed-off-by: Patrick Georgi Original-Commit-Id: 3001822656024dbfc34d6b849a0245274b8c0f46 Original-Change-Id: Ie307d4c9c1882bba25745afe38455f2682303e37 Original-Signed-off-by: Aaron Durbin Original-Reviewed-on: https://chromium-review.googlesource.com/242455 Original-Reviewed-by: Patrick Georgi Reviewed-on: http://review.coreboot.org/8728 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Stefan Reinauer --- payloads/libpayload/include/stdlib.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/payloads/libpayload/include/stdlib.h b/payloads/libpayload/include/stdlib.h index 04acec54e1..e571d18f0b 100644 --- a/payloads/libpayload/include/stdlib.h +++ b/payloads/libpayload/include/stdlib.h @@ -174,6 +174,20 @@ static inline void *xzalloc_work(size_t size, const char *file, return ret; } #define xzalloc(size) xzalloc_work((size), __FILE__, __FUNCTION__, __LINE__) + +static inline void *xmemalign_work(size_t align, size_t size, const char *file, + const char *func, int line) +{ + void *ret = memalign(align, size); + if (!ret && size) { + die_work(file, func, line, + "Failed to memalign %zu bytes with %zu alignment.\n", + size, align); + } + return ret; +} +#define xmemalign(align, size) \ + xmemalign_work((align), (size), __FILE__, __func__, __LINE__) /** @} */ /**