Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Snippets Groups Projects
Commit b362f59e authored by Steven Moreland's avatar Steven Moreland Committed by syphyr
Browse files

FlattenableUtils::align memsets


Bug: 141890807
Test: boot, check data is zero'd

[basilgello: Back-ported to 14.1:
 libutils/include/utils/Flattenable.h -> include/utils/Flattenable.h]

Signed-off-by: default avatarVasyl Gello <vasek.gello@gmail.com>

Change-Id: I45aaeac369f4c5cf3eb44f61c233e00f870a5c79
(cherry picked from commit bf824f8f)
(cherry picked from commit e62a9d76)
parent fb927076
Branches
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <utils/Errors.h> #include <utils/Errors.h>
#include <utils/Debug.h> #include <utils/Debug.h>
...@@ -44,7 +45,12 @@ public: ...@@ -44,7 +45,12 @@ public:
template<int N> template<int N>
static size_t align(void*& buffer) { static size_t align(void*& buffer) {
return align<N>( const_cast<void const*&>(buffer) ); static_assert(!(N & (N - 1)), "Can only align to a power of 2.");
void* b = buffer;
buffer = reinterpret_cast<void*>((uintptr_t(buffer) + (N-1)) & ~(N-1));
size_t delta = size_t(uintptr_t(buffer) - uintptr_t(b));
memset(b, 0, delta);
return delta;
} }
static void advance(void*& buffer, size_t& size, size_t offset) { static void advance(void*& buffer, size_t& size, size_t offset) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment