/* The function will add a memory region that is only accessible by the calling thread.  */
rt_err_t rt_mprotect_add_exclusive_region(void *start, rt_size_t size)
/* The function will add a memory region that is only accessible by the calling thread.  */
rt_err_t rt_mprotect_add_exclusive_region(void *start, rt_size_t size)
{
    rt_uint8_t i;
    rt_mem_exclusive_region_t region;
    region.owner = rt_thread_self();
    region.region.start = start;
    region.region.size = size;
    region.region.attr = RT_MEM_REGION_P_NA_U_NA;
    if (rt_hw_mpu_add_region(RT_NULL, (rt_mem_region_t *)(&(region.region))) != RT_EOK)
    {
        return RT_ERROR;
    }
    rt_enter_critical();
    for (i = 0; i < NUM_EXCLUSIVE_REGIONS; i++)
    {
        if (exclusive_regions[i].owner == RT_NULL)
        {
            rt_memcpy(&(exclusive_regions[i]), &region, sizeof(rt_mem_exclusive_region_t));
            rt_exit_critical();
            return RT_EOK;
        }
    }
    rt_exit_critical();
    LOG_E("Insufficient regions");
    return RT_ERROR;
}