实现MPU抽象层 (#8080)

- 为RT-Thread设计MPU抽象层,支持ARMV7-M,ARMV8-M架构,让用户使用MPU检测栈溢出等内存问题,实现线程内存隔离
- 在components/mp目录下提供通用的API,libcpu目录下提供各处理器架构的具体实现
- 在STM32U575 NUCLEO, STM32H75 NUCLEO开发板测试通过
This commit is contained in:
tangzz98
2023-10-30 08:24:55 -04:00
committed by GitHub
parent 1554888c0b
commit acc66c5479
32 changed files with 1739 additions and 71 deletions
+10
View File
@@ -233,11 +233,21 @@ static void rt_defunct_execute(void)
}
#ifdef RT_USING_HEAP
#ifdef RT_USING_MEM_PROTECTION
if (thread->mem_regions != RT_NULL)
{
RT_KERNEL_FREE(thread->mem_regions);
}
#endif
/* if need free, delete it */
if (object_is_systemobject == RT_FALSE)
{
/* release thread's stack */
#ifdef RT_USING_HW_STACK_GUARD
RT_KERNEL_FREE(thread->stack_buf);
#else
RT_KERNEL_FREE(thread->stack_addr);
#endif
/* delete thread object */
rt_object_delete((rt_object_t)thread);
}
+10
View File
@@ -107,6 +107,7 @@ static void _scheduler_stack_check(struct rt_thread *thread)
#endif /* not defined ARCH_MM_MMU */
#endif /* RT_USING_SMART */
#ifndef RT_USING_HW_STACK_GUARD
#ifdef ARCH_CPU_STACK_GROWS_UPWARD
if (*((rt_uint8_t *)((rt_ubase_t)thread->stack_addr + thread->stack_size - 1)) != '#' ||
#else
@@ -124,14 +125,23 @@ static void _scheduler_stack_check(struct rt_thread *thread)
rt_spin_lock(&_spinlock);
while (level);
}
#endif
#ifdef ARCH_CPU_STACK_GROWS_UPWARD
#ifndef RT_USING_HW_STACK_GUARD
else if ((rt_ubase_t)thread->sp > ((rt_ubase_t)thread->stack_addr + thread->stack_size))
#else
if ((rt_ubase_t)thread->sp > ((rt_ubase_t)thread->stack_addr + thread->stack_size))
#endif
{
rt_kprintf("warning: %s stack is close to the top of stack address.\n",
thread->parent.name);
}
#else
#ifndef RT_USING_HW_STACK_GUARD
else if ((rt_ubase_t)thread->sp <= ((rt_ubase_t)thread->stack_addr + 32))
#else
if ((rt_ubase_t)thread->sp <= ((rt_ubase_t)thread->stack_addr + 32))
#endif
{
rt_kprintf("warning: %s stack is close to end of stack address.\n",
thread->parent.name);
+10
View File
@@ -110,6 +110,7 @@ static void _scheduler_stack_check(struct rt_thread *thread)
#endif /* not defined ARCH_MM_MMU */
#endif /* RT_USING_SMART */
#ifndef RT_USING_HW_STACK_GUARD
#ifdef ARCH_CPU_STACK_GROWS_UPWARD
if (*((rt_uint8_t *)((rt_ubase_t)thread->stack_addr + thread->stack_size - 1)) != '#' ||
#else
@@ -126,14 +127,23 @@ static void _scheduler_stack_check(struct rt_thread *thread)
level = rt_hw_interrupt_disable();
while (level);
}
#endif
#ifdef ARCH_CPU_STACK_GROWS_UPWARD
#ifndef RT_USING_HW_STACK_GUARD
else if ((rt_ubase_t)thread->sp > ((rt_ubase_t)thread->stack_addr + thread->stack_size))
#else
if ((rt_ubase_t)thread->sp > ((rt_ubase_t)thread->stack_addr + thread->stack_size))
#endif
{
rt_kprintf("warning: %s stack is close to the top of stack address.\n",
thread->parent.name);
}
#else
#ifndef RT_USING_HW_STACK_GUARD
else if ((rt_ubase_t)thread->sp <= ((rt_ubase_t)thread->stack_addr + 32))
#else
if ((rt_ubase_t)thread->sp <= ((rt_ubase_t)thread->stack_addr + 32))
#endif
{
rt_kprintf("warning: %s stack is close to end of stack address.\n",
thread->parent.name);
+7
View File
@@ -157,6 +157,10 @@ static rt_err_t _thread_init(struct rt_thread *thread,
rt_list_init(&(thread->tlist));
rt_list_init(&(thread->tlist_schedule));
#ifdef RT_USING_MEM_PROTECTION
thread->mem_regions = RT_NULL;
#endif
#ifdef RT_USING_SMART
thread->wakeup.func = RT_NULL;
#endif
@@ -170,6 +174,9 @@ static rt_err_t _thread_init(struct rt_thread *thread,
/* init thread stack */
rt_memset(thread->stack_addr, '#', thread->stack_size);
#ifdef RT_USING_HW_STACK_GUARD
rt_hw_stack_guard_init(thread);
#endif
#ifdef ARCH_CPU_STACK_GROWS_UPWARD
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
(void *)((char *)thread->stack_addr),