2018-08-23 17:38:49 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* mm/mm_heap/mm_heapmember.c
|
|
|
|
*
|
2024-09-12 16:44:55 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-08-23 17:38:49 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2021-03-02 09:03:00 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2018-08-23 17:38:49 +02:00
|
|
|
#include <nuttx/mm/mm.h>
|
2024-03-14 09:40:52 +01:00
|
|
|
#include <nuttx/mm/kasan.h>
|
2018-08-23 17:38:49 +02:00
|
|
|
|
2021-03-02 09:03:00 +01:00
|
|
|
#include "mm_heap/mm.h"
|
|
|
|
|
2018-08-23 17:38:49 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_heapmember
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if an address lies in the heap.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* heap - The heap to check
|
|
|
|
* mem - The address to check
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* true if the address is a member of the heap. false if not
|
|
|
|
* not. If the address is not a member of the heap, then it
|
|
|
|
* must be a member of the user-space heap (unchecked)
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool mm_heapmember(FAR struct mm_heap_s *heap, FAR void *mem)
|
|
|
|
{
|
2024-03-14 09:40:52 +01:00
|
|
|
mem = kasan_reset_tag(mem);
|
2018-08-23 17:38:49 +02:00
|
|
|
#if CONFIG_MM_REGIONS > 1
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* A valid address from the heap for this region would have to lie
|
|
|
|
* between the region's two guard nodes.
|
|
|
|
*/
|
|
|
|
|
2021-07-03 16:16:25 +02:00
|
|
|
for (i = 0; i < heap->mm_nregions; i++)
|
2018-08-23 17:38:49 +02:00
|
|
|
{
|
2021-07-03 16:16:25 +02:00
|
|
|
if (mem > (FAR void *)heap->mm_heapstart[i] &&
|
|
|
|
mem < (FAR void *)heap->mm_heapend[i])
|
2018-08-23 17:38:49 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The address does not like any any region assigned to the heap */
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* A valid address from the heap would have to lie between the
|
|
|
|
* two guard nodes.
|
|
|
|
*/
|
|
|
|
|
2021-07-03 16:16:25 +02:00
|
|
|
if (mem > (FAR void *)heap->mm_heapstart[0] &&
|
|
|
|
mem < (FAR void *)heap->mm_heapend[0])
|
2018-08-23 17:38:49 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, the address does not lie in the heap */
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|