sandbox: memblock: align allocated pointers to 16-byte boundary

This commit is contained in:
2023-02-02 21:01:22 +00:00
parent 799a23014a
commit d43347436f

View File

@@ -14,7 +14,7 @@
- Redistributions in binary form must reproduce the above copyright - Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
- Neither the name of the copyright holder nor the names of its - Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this contributors may be used to endorse or promote products derived from this
software without specific prior written permission. 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) { if (memblock.reserved.count >= memblock.reserved.max - 2) {
memblock_double_capacity(&memblock.reserved); memblock_double_capacity(&memblock.reserved);
} }
memblock_double_capacity(&memblock.memory); 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) { if (memblock.reserved.count >= memblock.reserved.max - 2) {
memblock_double_capacity(&memblock.reserved); memblock_double_capacity(&memblock.reserved);
} }
return memblock_add_range(&memblock.reserved, base, size, 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; memblock_iter_t it;
for_each_free_mem_range (&it, region_start, region_end) { 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; size_t region_size = it.it_limit - it.it_base + 1;
if (region_size >= size) { if (region_size >= size) {
allocated_base = it.it_base; allocated_base = it.it_base;