Skip to content

Commit 9cde7c0

Browse files
marcinszkudlinskikv2019i
authored andcommitted
mem: add check if region being mapped fits into virtual mem region
Add a _safe check, verify if virtual memory being mapped for virtual heap fits into the region it belongs Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
1 parent 59ec929 commit 9cde7c0

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

zephyr/lib/regions_mm.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ static void vmh_get_mapped_size(void *addr, size_t *size)
327327
*
328328
* @retval 0 on success, error code otherwise.
329329
*/
330-
static int vmh_map_region(struct sys_mem_blocks *region, void *ptr, size_t size)
330+
static int vmh_map_region(const struct sys_mm_drv_region *virtual_region,
331+
struct sys_mem_blocks *region, void *ptr, size_t size)
331332
{
332333
const size_t block_size = 1 << region->info.blk_sz_shift;
333334
uintptr_t begin;
@@ -340,8 +341,8 @@ static int vmh_map_region(struct sys_mem_blocks *region, void *ptr, size_t size)
340341
if (!vmh_get_map_region_boundaries(region, ptr, size, &begin, &size))
341342
return 0;
342343
}
343-
344-
ret = sys_mm_drv_map_region(UINT_TO_POINTER(begin), 0, size, SYS_MM_MEM_PERM_RW);
344+
ret = sys_mm_drv_map_region_safe(virtual_region, UINT_TO_POINTER(begin), 0, size,
345+
SYS_MM_MEM_PERM_RW);
345346

346347
/* In case of an error, the pages that were successfully mapped must be manually released */
347348
if (ret)
@@ -495,7 +496,8 @@ static void *_vmh_alloc(struct vmh_heap *heap, uint32_t alloc_size)
495496
if (!ptr)
496497
return NULL;
497498

498-
allocation_error_code = vmh_map_region(heap->physical_blocks_allocators[mem_block_iterator],
499+
allocation_error_code = vmh_map_region(heap->virtual_region,
500+
heap->physical_blocks_allocators[mem_block_iterator],
499501
ptr, alloc_size);
500502
if (allocation_error_code) {
501503
sys_mem_blocks_free_contiguous(heap->physical_blocks_allocators[mem_block_iterator],

0 commit comments

Comments
 (0)