/* The function will add a memory region configuraiton for a thread.  */
rt_err_t rt_mprotect_add_region(rt_thread_t thread, rt_mem_region_t *region)
/* The function will add a memory region configuraiton for a thread.  */
rt_err_t rt_mprotect_add_region(rt_thread_t thread, rt_mem_region_t *region)
{
    if (thread == RT_NULL)
    {
        thread = rt_thread_self();
    }
    if (thread->mem_regions == RT_NULL)
    {
        thread->mem_regions = RT_KERNEL_MALLOC(NUM_DYNAMIC_REGIONS * sizeof(rt_mem_region_t));
        if (thread->mem_regions == RT_NULL)
        {
            return RT_ERROR;
        }
        rt_memset(thread->mem_regions, 0U, sizeof(rt_mem_region_t ) * NUM_DYNAMIC_REGIONS);
    }
    return rt_hw_mpu_add_region(thread, region);
}