diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2018-04-09 11:18:15 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-07 20:45:54 -0700 |
commit | 6e8cbe40eea777aeaeffe0fa0781a0a5d1763a4d (patch) | |
tree | d229d77bb060be8ba34d4bf94d257ac035c89c26 /include/shared_mem.h | |
parent | c24d480d90699bf6aaf534d66dc48513d867bdd0 (diff) | |
download | chrome-ec-6e8cbe40eea777aeaeffe0fa0781a0a5d1763a4d.tar.gz |
shared_mem: Assert that shared memory size is large enough
We add a configuration option to set the minimum shared memory
size (CONFIG_SHAREDMEM_MINIMUM_SIZE), so that the link will fail
if there is not enough IRAM left.
Also, we add 2 macros around shared_mem_acquire, that check, at
build time, that the shared memory size is sufficient for the
allocation:
- SHARED_MEM_ACQUIRE_CHECK should be used instead of
shared_mem_acquire, when size is known in advance.
- SHARED_MEM_CHECK_SIZE should be used when only a maximum size
is known.
This does not account for "jump tags" that boards often add on
jump from RO to RW. Luckily, RW usually does not do verification,
and does not need as much shared memory.
BRANCH=none
BUG=chromium:739771
TEST=make buildall -j, no error
Change-Id: Ic4c72938affe65fe8f8bc17ee5111c1798fc536f
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1002713
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'include/shared_mem.h')
-rw-r--r-- | include/shared_mem.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/include/shared_mem.h b/include/shared_mem.h index f69730b311..75b295b584 100644 --- a/include/shared_mem.h +++ b/include/shared_mem.h @@ -26,6 +26,9 @@ */ int shared_mem_size(void); +#define SHARED_MEM_CHECK_SIZE(size) \ + BUILD_ASSERT((size) <= CONFIG_SHAREDMEM_MINIMUM_SIZE) + /* * Acquires a shared memory area of the requested size in bytes. * @@ -43,6 +46,12 @@ int shared_mem_size(void); */ int shared_mem_acquire(int size, char **dest_ptr); +#define SHARED_MEM_ACQUIRE_CHECK(size, dest_ptr) \ + ({ \ + SHARED_MEM_CHECK_SIZE(size); \ + shared_mem_acquire((size), (dest_ptr)); \ + }) + /** * Releases a shared memory area previously allocated via shared_mem_acquire(). */ |