Commit a29b31d8 authored by Andrew Boie's avatar Andrew Boie Committed by Anas Nashif
Browse files

libc: newlib: fix virtual memory arena size



The calculations need to be from the RAM base virtual
address and not the physical address.

Signed-off-by: default avatarAndrew Boie <andrew.p.boie@intel.com>
parent ea6e4ad0
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -61,13 +61,27 @@ MALLOC_BSS static unsigned char __aligned(CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE)
#define HEAP_BASE	USED_RAM_END_ADDR
#endif /* Z_MALLOC_PARTITION_EXISTS */

#ifdef CONFIG_XTENSA
#ifdef CONFIG_MMU
/* Currently a placeholder, we're just setting up all unused RAM pages
 * past the end of the kernel as the heap arena. SRAM_BASE_ADDRESS is
 * a physical address so we can't use that.
 *
 * Later, we should do this much more like other VM-enabled operating systems:
 * - Set up a core kernel ontology of free physical pages
 * - Allow anonymous memoory mappings drawing from the pool of free physical
 *   pages
 * - Have _sbrk() map anonymous pages into the heap arena as needed
 * - See: https://github.com/zephyrproject-rtos/zephyr/issues/29526
 */
#define MAX_HEAP_SIZE	(CONFIG_KERNEL_RAM_SIZE - (HEAP_BASE - \
						   CONFIG_KERNEL_VM_BASE))
#elif defined(CONFIG_XTENSA)
extern void *_heap_sentry;
#define MAX_HEAP_SIZE	(POINTER_TO_UINT(&_heap_sentry) - HEAP_BASE)
#else
#define MAX_HEAP_SIZE	(KB(CONFIG_SRAM_SIZE) - \
			 (HEAP_BASE - CONFIG_SRAM_BASE_ADDRESS))
#endif
#define MAX_HEAP_SIZE	(KB(CONFIG_SRAM_SIZE) - (HEAP_BASE - \
						 CONFIG_SRAM_BASE_ADDRESS))
#endif /* CONFIG_MMU */

#if Z_MALLOC_PARTITION_EXISTS
struct k_mem_partition z_malloc_partition;