2021-02-18 11:19:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* mm/mm_heap/mm_checkcorruption.c
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sched.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/mm/mm.h>
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
|
2021-03-29 21:36:46 +08:00
|
|
|
#include "mm_heap/mm.h"
|
|
|
|
|
2022-01-24 20:15:20 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void checkcorruption_handler(FAR struct mm_allocnode_s *node,
|
|
|
|
FAR void *arg)
|
|
|
|
{
|
2023-09-06 11:48:30 +08:00
|
|
|
size_t nodesize = MM_SIZEOF_NODE(node);
|
2022-12-15 19:55:16 +08:00
|
|
|
|
2023-09-06 12:30:24 +08:00
|
|
|
if (MM_NODE_IS_ALLOC(node))
|
2022-01-24 20:15:20 +08:00
|
|
|
{
|
2023-09-06 11:48:30 +08:00
|
|
|
assert(nodesize >= MM_SIZEOF_ALLOCNODE);
|
2022-01-24 20:15:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FAR struct mm_freenode_s *fnode = (FAR void *)node;
|
|
|
|
|
2022-12-30 16:30:55 +08:00
|
|
|
assert(nodesize >= MM_MIN_CHUNK);
|
2022-01-24 20:15:20 +08:00
|
|
|
assert(fnode->blink->flink == fnode);
|
2023-09-06 11:48:30 +08:00
|
|
|
assert(MM_SIZEOF_NODE(fnode->blink) <= nodesize);
|
2022-01-24 20:15:20 +08:00
|
|
|
assert(fnode->flink == NULL ||
|
|
|
|
fnode->flink->blink == fnode);
|
|
|
|
assert(fnode->flink == NULL ||
|
2023-09-06 11:48:30 +08:00
|
|
|
MM_SIZEOF_NODE(fnode->flink) == 0 ||
|
|
|
|
MM_SIZEOF_NODE(fnode->flink) >= nodesize);
|
2022-01-24 20:15:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 11:19:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_checkcorruption
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* mm_checkcorruption is used to check whether memory heap is normal.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void mm_checkcorruption(FAR struct mm_heap_s *heap)
|
|
|
|
{
|
2022-01-24 20:15:20 +08:00
|
|
|
mm_foreach(heap, checkcorruption_handler, NULL);
|
2021-02-18 11:19:32 +08:00
|
|
|
}
|