mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
arch/arm/src/stm32f7/stm32_allocateheap.c: Fix MPU alignments
Change the logic for allocating user heap for PROTECTED_BUILD: - Don't rely on SRAM1_END alignment - Make better use of MPU subregions when allocating the heap - Don't duplicate the calculation of user heap start in kernel heap allocation; use the previous calculation directly Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
This commit is contained in:
committed by
Xiang Xiao
parent
ea36c2c7ea
commit
3f6bb76e01
@@ -677,7 +677,6 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
log2 = (int)mpu_log2regionfloor(usize);
|
log2 = (int)mpu_log2regionfloor(usize);
|
||||||
DEBUGASSERT((SRAM1_END & ((1 << log2) - 1)) == 0);
|
|
||||||
|
|
||||||
usize = (1 << log2);
|
usize = (1 << log2);
|
||||||
ubase = SRAM1_END - usize;
|
ubase = SRAM1_END - usize;
|
||||||
@@ -740,7 +739,6 @@ void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
log2 = (int)mpu_log2regionfloor(usize);
|
log2 = (int)mpu_log2regionfloor(usize);
|
||||||
DEBUGASSERT((SRAM1_END & ((1 << log2) - 1)) == 0);
|
|
||||||
|
|
||||||
usize = (1 << log2);
|
usize = (1 << log2);
|
||||||
ubase = SRAM1_END - usize;
|
ubase = SRAM1_END - usize;
|
||||||
|
|||||||
@@ -273,20 +273,29 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
|
|||||||
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend +
|
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend +
|
||||||
CONFIG_MM_KERNEL_HEAPSIZE;
|
CONFIG_MM_KERNEL_HEAPSIZE;
|
||||||
size_t usize = SRAM1_END - ubase;
|
size_t usize = SRAM1_END - ubase;
|
||||||
|
size_t subreg_mask;
|
||||||
int log2;
|
int log2;
|
||||||
|
|
||||||
DEBUGASSERT(ubase < (uintptr_t)SRAM1_END);
|
|
||||||
|
|
||||||
/* Adjust that size to account for MPU alignment requirements.
|
/* Adjust that size to account for MPU alignment requirements.
|
||||||
* NOTE that there is an implicit assumption that the SRAM1_END
|
* NOTE that there is an implicit assumption that the SRAM1_END
|
||||||
* is aligned to the MPU requirement.
|
* is aligned to the MPU requirement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
log2 = (int)mpu_log2regionfloor(usize);
|
/* align the ubase initially to a suitable mpu subregion start */
|
||||||
DEBUGASSERT((SRAM1_END & ((1 << log2) - 1)) == 0);
|
|
||||||
|
|
||||||
usize = (1 << log2);
|
log2 = (int)mpu_log2regionceil(usize);
|
||||||
ubase = SRAM1_END - usize;
|
subreg_mask = (1 << log2) / 8 - 1;
|
||||||
|
if (ubase & subreg_mask)
|
||||||
|
{
|
||||||
|
ubase = (ubase | subreg_mask) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUGASSERT(ubase < (uintptr_t)SRAM1_END);
|
||||||
|
|
||||||
|
/* reset the size to fit in SRAM and align down to subregion size */
|
||||||
|
|
||||||
|
usize = SRAM1_END - ubase;
|
||||||
|
usize &= ~subreg_mask;
|
||||||
|
|
||||||
/* Return the user-space heap settings */
|
/* Return the user-space heap settings */
|
||||||
|
|
||||||
@@ -328,35 +337,19 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
|
|||||||
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
|
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
|
||||||
void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
|
void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
|
||||||
{
|
{
|
||||||
/* Get the unaligned size and position of the user-space heap.
|
/* User heap was just initialized, with proper MPU alignment, in nx_start,
|
||||||
* This heap begins after the user-space .bss section at an offset
|
* store the user heap start address
|
||||||
* of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend +
|
uintptr_t ubase = (uintptr_t)*heap_start;
|
||||||
CONFIG_MM_KERNEL_HEAPSIZE;
|
|
||||||
size_t usize = SRAM1_END - ubase;
|
|
||||||
int log2;
|
|
||||||
|
|
||||||
DEBUGASSERT(ubase < (uintptr_t)SRAM1_END);
|
DEBUGASSERT(ubase < (uintptr_t)SRAM1_END);
|
||||||
|
|
||||||
/* Adjust that size to account for MPU alignment requirements.
|
|
||||||
* NOTE that there is an implicit assumption that the SRAM1_END
|
|
||||||
* is aligned to the MPU requirement.
|
|
||||||
*/
|
|
||||||
|
|
||||||
log2 = (int)mpu_log2regionfloor(usize);
|
|
||||||
DEBUGASSERT((SRAM1_END & ((1 << log2) - 1)) == 0);
|
|
||||||
|
|
||||||
usize = (1 << log2);
|
|
||||||
ubase = SRAM1_END - usize;
|
|
||||||
|
|
||||||
/* Return the kernel heap settings (i.e., the part of the heap region
|
/* Return the kernel heap settings (i.e., the part of the heap region
|
||||||
* that was not dedicated to the user heap).
|
* that was not dedicated to the user heap).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
*heap_start = (FAR void *)USERSPACE->us_bssend;
|
*heap_start = (FAR void *)USERSPACE->us_bssend;
|
||||||
*heap_size = ubase - (uintptr_t)USERSPACE->us_bssend;
|
*heap_size = ubase - USERSPACE->us_bssend;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user