From d43347436f82801c5795a8eac47355249caf9407 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 2 Feb 2023 21:01:22 +0000 Subject: [PATCH] sandbox: memblock: align allocated pointers to 16-byte boundary --- sandbox/memblock/memblock.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sandbox/memblock/memblock.c b/sandbox/memblock/memblock.c index 4cc7256..ac3178b 100644 --- a/sandbox/memblock/memblock.c +++ b/sandbox/memblock/memblock.c @@ -14,7 +14,7 @@ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -214,7 +214,7 @@ int memblock_add(uintptr_t base, size_t size) if (memblock.reserved.count >= memblock.reserved.max - 2) { memblock_double_capacity(&memblock.reserved); } - + memblock_double_capacity(&memblock.memory); } @@ -226,7 +226,7 @@ int memblock_reserve(uintptr_t base, size_t size) if (memblock.reserved.count >= memblock.reserved.max - 2) { memblock_double_capacity(&memblock.reserved); } - + return memblock_add_range(&memblock.reserved, base, size, MEMBLOCK_RESERVED); } @@ -239,6 +239,11 @@ static phys_addr_t do_alloc(size_t size) memblock_iter_t it; for_each_free_mem_range (&it, region_start, region_end) { + if (it.it_base & 0xF) { + it.it_base &= ~0xF; + it.it_base += 0x10; + } + size_t region_size = it.it_limit - it.it_base + 1; if (region_size >= size) { allocated_base = it.it_base;