2012-09-11 20:22:27 +02:00
|
|
|
/****************************************************************************
|
2014-09-22 18:33:23 +02:00
|
|
|
* mm/mm_gran/mm_granfree.c
|
2012-09-11 20:22:27 +02:00
|
|
|
*
|
2024-09-12 16:44:55 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2020-03-29 19:57:53 +02: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
|
2012-09-11 20:22:27 +02:00
|
|
|
*
|
2020-03-29 19:57:53 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-09-11 20:22:27 +02:00
|
|
|
*
|
2020-03-29 19:57:53 +02:00
|
|
|
* 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.
|
2012-09-11 20:22:27 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2012-09-11 22:33:58 +02:00
|
|
|
#include <assert.h>
|
2024-04-08 08:48:17 +02:00
|
|
|
#include <debug.h>
|
2012-09-11 22:33:58 +02:00
|
|
|
|
2014-09-24 14:55:26 +02:00
|
|
|
#include <nuttx/mm/gran.h>
|
2012-09-11 20:22:27 +02:00
|
|
|
|
2014-09-22 18:33:23 +02:00
|
|
|
#include "mm_gran/mm_gran.h"
|
2024-04-08 08:48:17 +02:00
|
|
|
#include "mm_gran/mm_grantable.h"
|
2012-09-11 22:33:58 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_GRAN
|
|
|
|
|
2012-09-11 20:22:27 +02:00
|
|
|
/****************************************************************************
|
2017-11-14 18:47:12 +01:00
|
|
|
* Public Functions
|
2012-09-11 20:22:27 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-14 18:47:12 +01:00
|
|
|
void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size)
|
2012-09-11 20:22:27 +02:00
|
|
|
{
|
2024-04-08 08:48:17 +02:00
|
|
|
FAR gran_t *gran = (FAR gran_t *)handle;
|
|
|
|
uint ngran;
|
|
|
|
size_t posi;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(gran && memory && size);
|
|
|
|
DEBUGASSERT(GRAN_PRODUCT(gran, memory));
|
|
|
|
DEBUGASSERT(GRAN_INRANGE(gran, (((uintptr_t)memory) + size - 1)));
|
2012-09-11 22:33:58 +02:00
|
|
|
|
2024-04-08 08:48:17 +02:00
|
|
|
posi = MEM2GRAN(gran, memory);
|
|
|
|
ngran = NGRANULE(gran, size);
|
2012-09-11 20:22:27 +02:00
|
|
|
|
2024-04-08 08:48:17 +02:00
|
|
|
graninfo(" heap=%"PRIxPTR" posi=%zu addr=%zx size=%zu n=%d\n",
|
|
|
|
gran->heapstart, posi, (size_t)memory, size, ngran);
|
2012-09-11 23:39:39 +02:00
|
|
|
|
2020-03-29 21:23:47 +02:00
|
|
|
do
|
2020-03-29 19:57:53 +02:00
|
|
|
{
|
2024-04-08 08:48:17 +02:00
|
|
|
ret = gran_enter_critical(gran);
|
2020-03-29 21:23:47 +02:00
|
|
|
DEBUGASSERT(ret == OK || ret == -ECANCELED);
|
2020-03-29 19:57:53 +02:00
|
|
|
}
|
2024-04-08 08:48:17 +02:00
|
|
|
while (ret < 0); /* Retry upon task cancellation */
|
2012-09-11 20:22:27 +02:00
|
|
|
|
2024-04-08 08:48:17 +02:00
|
|
|
/* check double free */
|
2012-09-11 20:22:27 +02:00
|
|
|
|
2024-04-08 08:48:17 +02:00
|
|
|
DEBUGASSERT(gran_match(gran, posi, ngran, 1, NULL));
|
|
|
|
gran_clear(gran, posi, ngran);
|
|
|
|
gran_leave_critical(gran);
|
2012-09-11 20:22:27 +02:00
|
|
|
}
|
|
|
|
|
2012-09-11 22:33:58 +02:00
|
|
|
#endif /* CONFIG_GRAN */
|