system/core
Revisión | cb0dfbf14ee08f904dcce47a2b4e06965eb0d88b (tree) |
---|---|
Tiempo | 2019-11-08 09:20:18 |
Autor | Steven Moreland <smoreland@goog...> |
Commiter | Kyriakos Ispoglou |
FlattenableUtils::align memsets
Bug: 141890807
Test: boot, check data is zero'd
Change-Id: I45aaeac369f4c5cf3eb44f61c233e00f870a5c79
(cherry picked from commit bf824f8fa50d9f7390057278fefb58e83323a644)
(cherry picked from commit e62a9d7669ac85844d4424474f5c88c096f7160b)
@@ -47,7 +47,12 @@ public: | ||
47 | 47 | |
48 | 48 | template<size_t N> |
49 | 49 | static size_t align(void*& buffer) { |
50 | - return align<N>( const_cast<void const*&>(buffer) ); | |
50 | + static_assert(!(N & (N - 1)), "Can only align to a power of 2."); | |
51 | + void* b = buffer; | |
52 | + buffer = reinterpret_cast<void*>((uintptr_t(buffer) + (N-1)) & ~(N-1)); | |
53 | + size_t delta = size_t(uintptr_t(buffer) - uintptr_t(b)); | |
54 | + memset(b, 0, delta); | |
55 | + return delta; | |
51 | 56 | } |
52 | 57 | |
53 | 58 | static void advance(void*& buffer, size_t& size, size_t offset) { |