mm/ file clean-up
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4943 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
9d898f8d7a
commit
745af7084e
|
@ -2994,3 +2994,4 @@
|
|||
* sched/: Stylistic clean-up of all files. Some of these files are pretty old
|
||||
and do not follow current NuttX coding standards in detail.
|
||||
* fs/: More stylistic file clean-up.
|
||||
* mm/: More stylistic file clean-up.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# mm/Makefile
|
||||
#
|
||||
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
|
@ -74,4 +74,3 @@ distclean: clean
|
|||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
############################################################################
|
||||
# Makefile.test
|
||||
# mm/Makefile.test
|
||||
#
|
||||
# Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_addfreechunk.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,35 +31,35 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* mm_addfreechunk
|
||||
/****************************************************************************
|
||||
* Name: mm_addfreechunk
|
||||
*
|
||||
* Description:
|
||||
* Add a free chunk to the node next
|
||||
* It is assumed that the caller holds the mm semaphore
|
||||
* Add a free chunk to the node next. It is assumed that the caller holds
|
||||
* the mm semaphore
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
void mm_addfreechunk(FAR struct mm_freenode_s *node)
|
||||
{
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
* mm_calloc.c
|
||||
/****************************************************************************
|
||||
* mm/mm_calloc.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,29 +31,30 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* calloc
|
||||
/****************************************************************************
|
||||
* Name: calloc
|
||||
*
|
||||
* Descripton:
|
||||
* calloc calculates the size and calls zalloc
|
||||
************************************************************************/
|
||||
* calloc calculates the size of the allocation and calls zalloc
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *calloc(size_t n, size_t elem_size)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* mm/mm_environment.h
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -40,33 +40,32 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* The platform configuratioin file will not be included
|
||||
* when the memory manager is built for the host-based
|
||||
* test harness.
|
||||
/* The platform configuratioin file will not be included when the memory
|
||||
* manager is built for the host-based test harness.
|
||||
*/
|
||||
|
||||
#ifndef MM_TEST
|
||||
# include <nuttx/config.h>
|
||||
# include <nuttx/compiler.h>
|
||||
# include <sys/types.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <debug.h>
|
||||
# include <errno.h>
|
||||
# include <assert.h>
|
||||
# include <nuttx/mm.h>
|
||||
# include <nuttx/config.h>
|
||||
# include <nuttx/compiler.h>
|
||||
# include <sys/types.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <debug.h>
|
||||
# include <errno.h>
|
||||
# include <assert.h>
|
||||
# include <nuttx/mm.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
# include <sys/types.h>
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Special definitions used when the memory mnager is built
|
||||
* for the host-based test harness.
|
||||
/* Special definitions used when the memory mnager is built for the host-
|
||||
* based test harness.
|
||||
*/
|
||||
|
||||
#ifdef MM_TEST
|
||||
|
@ -86,9 +85,8 @@ extern void mm_addregion(FAR void *heapstart, size_t heapsize);
|
|||
|
||||
# define mm_errno errno
|
||||
|
||||
/* When built for the test harness, we change the names of the
|
||||
* exported functions so that they do not collide with the
|
||||
* host libc names.
|
||||
/* When built for the test harness, we change the names of the exported
|
||||
* functions so that they do not collide with the host libc names.
|
||||
*/
|
||||
|
||||
# define malloc mm_malloc
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_free.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,36 +31,37 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* free
|
||||
/****************************************************************************
|
||||
* Name: free
|
||||
*
|
||||
* Description:
|
||||
* Returns a chunk of memory into the list of free nodes,
|
||||
* merging with adjacent free chunks if possible.
|
||||
* Returns a chunk of memory into the list of free nodes, merging with
|
||||
* adjacent free chunks if possible.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
void free(FAR void *mem)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* mm/mm_initialize.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -61,9 +61,9 @@ FAR struct mm_allocnode_s *g_heapend[CONFIG_MM_REGIONS];
|
|||
int g_nregions;
|
||||
#endif
|
||||
|
||||
/* All free nodes are maintained in a doubly linked list. This
|
||||
* array provides some hooks into the list at various points to
|
||||
* speed searches for free nodes.
|
||||
/* All free nodes are maintained in a doubly linked list. This array
|
||||
* provides some hooks into the list at various points to speed searches for
|
||||
* free nodes.
|
||||
*/
|
||||
|
||||
FAR struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
|
@ -73,11 +73,10 @@ FAR struct mm_freenode_s g_nodelist[MM_NNODES];
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: mm_initialize
|
||||
* Name: mm_initialize
|
||||
*
|
||||
* Description:
|
||||
* This is an internal OS function called only at power-up
|
||||
* boot time.
|
||||
* This is an internal OS function called only at power-up boot time.
|
||||
*
|
||||
* Parameters:
|
||||
* heapstart - Start of the initial heap region
|
||||
|
@ -135,11 +134,10 @@ void mm_initialize(FAR void *heapstart, size_t heapsize)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: mm_addregion
|
||||
* Name: mm_addregion
|
||||
*
|
||||
* Description:
|
||||
* This function gives a region of contiguous memory to
|
||||
* the memory manager
|
||||
* This function gives a region of contiguous memory to the memory manager
|
||||
*
|
||||
* Parameters:
|
||||
* heapstart - Start of the heap region
|
||||
|
@ -163,17 +161,17 @@ void mm_addregion(FAR void *heapstart, size_t heapsize)
|
|||
# define IDX 0
|
||||
#endif
|
||||
|
||||
/* If the MCU handles wide addresses but the memory manager
|
||||
* is configured for a small heap, then verify that the caller
|
||||
* not doing something crazy.
|
||||
/* If the MCU handles wide addresses but the memory manager is configured
|
||||
* for a small heap, then verify that the caller is not doing something
|
||||
* crazy.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_MM_SMALL) && !defined(CONFIG_SMALL_MEMORY)
|
||||
DEBUGASSERT(heapsize <= MMSIZE_MAX+1);
|
||||
#endif
|
||||
|
||||
/* Adjust the provide heap start and size so that they are
|
||||
* both aligned with the MM_MIN_CHUNK size.
|
||||
/* Adjust the provide heap start and size so that they are both aligned
|
||||
* with the MM_MIN_CHUNK size.
|
||||
*/
|
||||
|
||||
heapbase = MM_ALIGN_UP((uintptr_t)heapstart);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_internal.h
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,19 +31,19 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MM_MM_INTERNAL_H
|
||||
#define __MM_MM_INTERNAL_H
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************/
|
||||
/* Configuration ********************************************************/
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
/* If the MCU has a small (16-bit) address capability, then we will use
|
||||
* a smaller chunk header that contains 16-bit size/offset information.
|
||||
* We will also use the smaller header on MCUs with wider addresses if
|
||||
|
@ -60,7 +60,7 @@
|
|||
# define CONFIG_MM_SMALL 1
|
||||
#endif
|
||||
|
||||
/* Chunk Header Definitions *********************************************/
|
||||
/* Chunk Header Definitions *************************************************/
|
||||
/* These definitions define the characteristics of allocator
|
||||
*
|
||||
* MM_MIN_SHIFT is used to define MM_MIN_CHUNK.
|
||||
|
@ -79,11 +79,11 @@
|
|||
*/
|
||||
|
||||
#ifdef CONFIG_MM_SMALL
|
||||
# define MM_MIN_SHIFT 4 /* 16 bytes */
|
||||
# define MM_MAX_SHIFT 15 /* 32 Kb */
|
||||
# define MM_MIN_SHIFT 4 /* 16 bytes */
|
||||
# define MM_MAX_SHIFT 15 /* 32 Kb */
|
||||
#else
|
||||
# define MM_MIN_SHIFT 4 /* 16 bytes */
|
||||
# define MM_MAX_SHIFT 22 /* 4 Mb */
|
||||
# define MM_MIN_SHIFT 4 /* 16 bytes */
|
||||
# define MM_MAX_SHIFT 22 /* 4 Mb */
|
||||
#endif
|
||||
|
||||
/* All other definitions derive from these two */
|
||||
|
@ -109,9 +109,9 @@
|
|||
#define MM_IS_ALLOCATED(n) \
|
||||
((int)((struct mm_allocnode_s*)(n)->preceding) < 0))
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Determine the size of the chunk size/offset type */
|
||||
|
||||
|
@ -186,9 +186,9 @@ struct mallinfo
|
|||
};
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Global Variables
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* This is the size of the heap provided to mm */
|
||||
|
||||
|
@ -212,35 +212,32 @@ extern int g_nregions;
|
|||
|
||||
extern FAR struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************************/
|
||||
|
||||
/* Normally defined in malloc.h */
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef MM_TEST
|
||||
extern FAR void *mm_malloc(size_t);
|
||||
extern void mm_free(void*);
|
||||
extern FAR void *mm_realloc(void*, size_t);
|
||||
extern FAR void *mm_memalign(size_t, size_t);
|
||||
extern FAR void *mm_zalloc(size_t);
|
||||
extern FAR void *mm_calloc(size_t, size_t);
|
||||
FAR void *mm_malloc(size_t);
|
||||
void mm_free(void*);
|
||||
FAR void *mm_realloc(void*, size_t);
|
||||
FAR void *mm_memalign(size_t, size_t);
|
||||
FAR void *mm_zalloc(size_t);
|
||||
FAR void *mm_calloc(size_t, size_t);
|
||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
||||
extern struct mallinfo mallinfo(void);
|
||||
struct mallinfo mallinfo(void);
|
||||
#else
|
||||
extern int mallinfo(struct mallinfo *info);
|
||||
int mallinfo(struct mallinfo *info);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern void mm_shrinkchunk(FAR struct mm_allocnode_s *node,
|
||||
size_t size);
|
||||
extern void mm_addfreechunk(FAR struct mm_freenode_s *node);
|
||||
extern int mm_size2ndx(size_t size);
|
||||
extern void mm_seminitialize(void);
|
||||
extern void mm_takesemaphore(void);
|
||||
extern void mm_givesemaphore(void);
|
||||
void mm_shrinkchunk(FAR struct mm_allocnode_s *node, size_t size);
|
||||
void mm_addfreechunk(FAR struct mm_freenode_s *node);
|
||||
int mm_size2ndx(size_t size);
|
||||
void mm_seminitialize(void);
|
||||
void mm_takesemaphore(void);
|
||||
void mm_givesemaphore(void);
|
||||
#ifdef MM_TEST
|
||||
extern int mm_getsemaphore(void);
|
||||
int mm_getsemaphore(void);
|
||||
#endif
|
||||
|
||||
#endif /* __MM_MM_INTERNAL_H */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* mm/mm_mallinfo.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -38,6 +38,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
|
@ -58,7 +59,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* mallinfo
|
||||
* Name: mallinfo
|
||||
*
|
||||
* Description:
|
||||
* mallinfo returns a copy of updated current mallinfo.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_malloc.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,59 +31,59 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Special definitions when we operate in the normal vs. the
|
||||
* host-pc test environement.
|
||||
/* Special definitions when we operate in the normal vs. the host-pc test
|
||||
* environement.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* malloc
|
||||
/****************************************************************************
|
||||
* Name: malloc
|
||||
*
|
||||
* Description:
|
||||
* Find the smallest chunk that satisfies the request.
|
||||
* Take the memory from that chunk, save the remaining,
|
||||
* smaller chunk (if any).
|
||||
* Find the smallest chunk that satisfies the request. Take the memory from
|
||||
* that chunk, save the remaining, smaller chunk (if any).
|
||||
*
|
||||
* 8-byte alignment of the allocated data is assured.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *malloc(size_t size)
|
||||
{
|
||||
|
@ -98,21 +98,18 @@ FAR void *malloc(size_t size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Adjust the size to account for (1) the size of the allocated
|
||||
* node and (2) to make sure that it is an even multiple of
|
||||
* our granule size.
|
||||
/* Adjust the size to account for (1) the size of the allocated node and
|
||||
* (2) to make sure that it is an even multiple of our granule size.
|
||||
*/
|
||||
|
||||
size = MM_ALIGN_UP(size + SIZEOF_MM_ALLOCNODE);
|
||||
|
||||
/* We need to hold the MM semaphore while we muck with the
|
||||
* nodelist.
|
||||
*/
|
||||
/* We need to hold the MM semaphore while we muck with the nodelist. */
|
||||
|
||||
mm_takesemaphore();
|
||||
|
||||
/* Get the location in the node list to start the search.
|
||||
* Special case really big alloctions
|
||||
/* Get the location in the node list to start the search. Special case
|
||||
* really big allocations
|
||||
*/
|
||||
|
||||
if (size >= MM_MAX_CHUNK)
|
||||
|
@ -126,18 +123,18 @@ FAR void *malloc(size_t size)
|
|||
ndx = mm_size2ndx(size);
|
||||
}
|
||||
|
||||
/* Search for a large enough chunk in the list of nodes.
|
||||
* This list is ordered by size, but will have occasional
|
||||
* zero sized nodes as we visit other g_nodelist[] entries.
|
||||
/* Search for a large enough chunk in the list of nodes. This list is
|
||||
* ordered by size, but will have occasional zero sized nodes as we visit
|
||||
* other g_nodelist[] entries.
|
||||
*/
|
||||
|
||||
for (node = g_nodelist[ndx].flink;
|
||||
node && node->size < size;
|
||||
node = node->flink);
|
||||
|
||||
/* If we found a node with non-zero size, then this is one
|
||||
* to use. Since the list is ordered, we know that is must be
|
||||
* best fitting chunk available.
|
||||
/* If we found a node with non-zero size, then this is one to use. Since
|
||||
* the list is ordered, we know that is must be best fitting chunk
|
||||
* available.
|
||||
*/
|
||||
|
||||
if (node)
|
||||
|
@ -146,8 +143,8 @@ FAR void *malloc(size_t size)
|
|||
FAR struct mm_freenode_s *next;
|
||||
size_t remaining;
|
||||
|
||||
/* Remove the node. There must be a predecessor, but there may
|
||||
* not be a successor node.
|
||||
/* Remove the node. There must be a predecessor, but there may not be
|
||||
* a successor node.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(node->blink);
|
||||
|
@ -157,11 +154,11 @@ FAR void *malloc(size_t size)
|
|||
node->flink->blink = node->blink;
|
||||
}
|
||||
|
||||
/* Check if we have to split the free node into one of the
|
||||
* allocated size and another smaller freenode. In some
|
||||
* cases, the remaining bytes can be smaller (they may be
|
||||
* SIZEOF_MM_ALLOCNODE). In that case, we will just carry
|
||||
* the few wasted bytes at the end of the allocation.
|
||||
/* Check if we have to split the free node into one of the allocated
|
||||
* size and another smaller freenode. In some cases, the remaining
|
||||
* bytes can be smaller (they may be SIZEOF_MM_ALLOCNODE). In that
|
||||
* case, we will just carry the few wasted bytes at the end of the
|
||||
* allocation.
|
||||
*/
|
||||
|
||||
remaining = node->size - size;
|
||||
|
@ -181,8 +178,8 @@ FAR void *malloc(size_t size)
|
|||
|
||||
node->size = size;
|
||||
|
||||
/* Adjust the 'preceding' size of the (old) next node,
|
||||
* preserving the allocated flag.
|
||||
/* Adjust the 'preceding' size of the (old) next node, preserving
|
||||
* the allocated flag.
|
||||
*/
|
||||
|
||||
next->preceding = remaining | (next->preceding & MM_ALLOC_BIT);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_memalign.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,37 +31,37 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* memalign
|
||||
/****************************************************************************
|
||||
* Name: memalign
|
||||
*
|
||||
* Description:
|
||||
* memalign requests more than enough space from malloc,
|
||||
* finds a region within that chunk that meets the alignment
|
||||
* request and then frees any leading or trailing space.
|
||||
* memalign requests more than enough space from malloc, finds a region
|
||||
* within that chunk that meets the alignment request and then frees any
|
||||
* leading or trailing space.
|
||||
*
|
||||
* The alignment argument must be a power of two (not
|
||||
* checked). 8-byte alignment is guaranteed by normal
|
||||
* malloc calls.
|
||||
* The alignment argument must be a power of two (not checked). 8-byte
|
||||
* alignment is guaranteed by normal malloc calls.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *memalign(size_t alignment, size_t size)
|
||||
{
|
||||
|
@ -71,9 +71,8 @@ FAR void *memalign(size_t alignment, size_t size)
|
|||
size_t mask = (size_t)(alignment - 1);
|
||||
size_t allocsize;
|
||||
|
||||
/* If this requested alignement less than or equal to the
|
||||
* natural alignment of malloc, then just let malloc do the
|
||||
* work.
|
||||
/* If this requested alignement less than or equal to the natural alignment
|
||||
* of malloc, then just let malloc do the work.
|
||||
*/
|
||||
|
||||
if (alignment <= MM_MIN_CHUNK)
|
||||
|
@ -81,17 +80,16 @@ FAR void *memalign(size_t alignment, size_t size)
|
|||
return malloc(size);
|
||||
}
|
||||
|
||||
/* Adjust the size to account for (1) the size of the allocated
|
||||
* node, (2) to make sure that it is an even multiple of
|
||||
* our granule size, and to include the alignment amount.
|
||||
/* Adjust the size to account for (1) the size of the allocated node, (2)
|
||||
* to make sure that it is an even multiple of our granule size, and to
|
||||
* include the alignment amount.
|
||||
*
|
||||
* Notice that we increase the allocation size by twice the
|
||||
* the requested alignment. We do this so that there will
|
||||
* be at least two valid alignment points within the allocated
|
||||
* memory.
|
||||
* Notice that we increase the allocation size by twice the requested
|
||||
* alignment. We do this so that there will be at least two valid
|
||||
* alignment points within the allocated memory.
|
||||
*
|
||||
* NOTE: These are sizes given to malloc and not chunk sizes.
|
||||
* The do not include SIZEOF_MM_ALLOCNODE.
|
||||
* NOTE: These are sizes given to malloc and not chunk sizes. They do
|
||||
* not include SIZEOF_MM_ALLOCNODE.
|
||||
*/
|
||||
|
||||
size = MM_ALIGN_UP(size); /* Make multiples of our granule size */
|
||||
|
@ -105,14 +103,14 @@ FAR void *memalign(size_t alignment, size_t size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* We need to hold the MM semaphore while we muck with the
|
||||
* chunks and nodelist.
|
||||
/* We need to hold the MM semaphore while we muck with the chunks and
|
||||
* nodelist.
|
||||
*/
|
||||
|
||||
mm_takesemaphore();
|
||||
|
||||
/* Get the node associated with the allocation and the next
|
||||
* node after the allocation.
|
||||
/* Get the node associated with the allocation and the next node after
|
||||
* the allocation.
|
||||
*/
|
||||
|
||||
node = (FAR struct mm_allocnode_s*)(rawchunk - SIZEOF_MM_ALLOCNODE);
|
||||
|
@ -147,12 +145,12 @@ FAR void *memalign(size_t alignment, size_t size)
|
|||
|
||||
precedingsize = (size_t)newnode - (size_t)node;
|
||||
|
||||
/* If we were unlucky, then the alignedchunk can lie in such
|
||||
* a position that precedingsize < SIZEOF_NODE_FREENODE. We
|
||||
* can't let that happen because we are going to cast 'node' to
|
||||
* struct mm_freenode_s below. This is why we allocated memory
|
||||
* large enough to support two alignment points. In this case,
|
||||
* we will simply use the second alignment point.
|
||||
/* If we were unlucky, then the alignedchunk can lie in such a position
|
||||
* that precedingsize < SIZEOF_NODE_FREENODE. We can't let that happen
|
||||
* because we are going to cast 'node' to struct mm_freenode_s below.
|
||||
* This is why we allocated memory large enough to support two
|
||||
* alignment points. In this case, we will simply use the second
|
||||
* alignment point.
|
||||
*/
|
||||
|
||||
if (precedingsize < SIZEOF_MM_FREENODE)
|
||||
|
@ -176,8 +174,8 @@ FAR void *memalign(size_t alignment, size_t size)
|
|||
|
||||
next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT);
|
||||
|
||||
/* Convert the newnode chunk size back into malloc-compatible
|
||||
* size by subtracting the header size SIZEOF_MM_ALLOCNODE.
|
||||
/* Convert the newnode chunk size back into malloc-compatible size by
|
||||
* subtracting the header size SIZEOF_MM_ALLOCNODE.
|
||||
*/
|
||||
|
||||
allocsize = newnode->size - SIZEOF_MM_ALLOCNODE;
|
||||
|
@ -197,9 +195,9 @@ FAR void *memalign(size_t alignment, size_t size)
|
|||
|
||||
if (allocsize > size)
|
||||
{
|
||||
/* Shrink the chunk by that much -- remember, mm_shrinkchunk
|
||||
* wants internal chunk sizes that include SIZEOF_MM_ALLOCNODE,
|
||||
* and not the malloc-compatible sizes that we have.
|
||||
/* Shrink the chunk by that much -- remember, mm_shrinkchunk wants
|
||||
* internal chunk sizes that include SIZEOF_MM_ALLOCNODE, and not the
|
||||
* malloc-compatible sizes that we have.
|
||||
*/
|
||||
|
||||
mm_shrinkchunk(node, size + SIZEOF_MM_ALLOCNODE);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_realloc.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,47 +31,47 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "mm_environment.h"
|
||||
#include <stdio.h> /* For NULL */
|
||||
#include <stdio.h>
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* realloc
|
||||
/****************************************************************************
|
||||
* Name: realloc
|
||||
*
|
||||
* Description:
|
||||
* If the reallocation is for less space, then:
|
||||
* (1) the current allocation is reduced in size
|
||||
* (2) the remainder at the end of the allocation is
|
||||
* returned to the free list.
|
||||
*
|
||||
* If the request is for more space and the current
|
||||
* allocation can be extended, it will be extended by:
|
||||
* (1) Taking the additional space from the following
|
||||
* free chunk, or
|
||||
* (2) Taking the additional space from the preceding
|
||||
* free chunk.
|
||||
* (1) the current allocation is reduced in size
|
||||
* (2) the remainder at the end of the allocation is returned to the
|
||||
* free list.
|
||||
*
|
||||
* If the request is for more space and the current allocation can be
|
||||
* extended, it will be extended by:
|
||||
*
|
||||
* (1) Taking the additional space from the following free chunk, or
|
||||
* (2) Taking the additional space from the preceding free chunk.
|
||||
* (3) Or both
|
||||
*
|
||||
* If the request is for more space but the current chunk
|
||||
* cannot be extended, then malloc a new buffer, copy the
|
||||
* data into the new buffer, and free the old buffer.
|
||||
* If the request is for more space but the current chunk cannot be
|
||||
* extended, then malloc a new buffer, copy the data into the new buffer,
|
||||
* and free the old buffer.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *realloc(FAR void *oldmem, size_t size)
|
||||
{
|
||||
|
@ -98,9 +98,8 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Adjust the size to account for (1) the size of the allocated
|
||||
* node and (2) to make sure that it is an even multiple of
|
||||
* our granule size.
|
||||
/* Adjust the size to account for (1) the size of the allocated node and
|
||||
* (2) to make sure that it is an even multiple of our granule size.
|
||||
*/
|
||||
|
||||
size = MM_ALIGN_UP(size + SIZEOF_MM_ALLOCNODE);
|
||||
|
@ -109,9 +108,7 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
|
||||
oldnode = (FAR struct mm_allocnode_s *)((FAR char*)oldmem - SIZEOF_MM_ALLOCNODE);
|
||||
|
||||
/* We need to hold the MM semaphore while we muck with the
|
||||
* nodelist.
|
||||
*/
|
||||
/* We need to hold the MM semaphore while we muck with the nodelist. */
|
||||
|
||||
mm_takesemaphore();
|
||||
|
||||
|
@ -120,13 +117,14 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
oldsize = oldnode->size;
|
||||
if (size <= oldsize)
|
||||
{
|
||||
/* Handle the special case where we are not going to change the
|
||||
* size of the allocation.
|
||||
/* Handle the special case where we are not going to change the size
|
||||
* of the allocation.
|
||||
*/
|
||||
|
||||
if (size < oldsize)
|
||||
{
|
||||
mm_shrinkchunk(oldnode, size);
|
||||
}
|
||||
}
|
||||
|
||||
/* Then return the original address */
|
||||
|
||||
|
@ -135,8 +133,8 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
}
|
||||
|
||||
/* This is a request to increase the size of the allocation, Get the
|
||||
* available sizes before and after the oldnode so that we can make
|
||||
* the best decision
|
||||
* available sizes before and after the oldnode so that we can make the
|
||||
* best decision
|
||||
*/
|
||||
|
||||
next = (FAR struct mm_freenode_s *)((FAR char*)oldnode + oldnode->size);
|
||||
|
@ -165,52 +163,52 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
|
||||
if (prevsize > 0 && (nextsize >= prevsize || nextsize <= 0))
|
||||
{
|
||||
/* Can we get everything we need from the previous chunk? */
|
||||
/* Can we get everything we need from the previous chunk? */
|
||||
|
||||
if (needed > prevsize)
|
||||
{
|
||||
/* No, take the whole previous chunk and get the
|
||||
* rest that we need from the next chunk.
|
||||
*/
|
||||
if (needed > prevsize)
|
||||
{
|
||||
/* No, take the whole previous chunk and get the
|
||||
* rest that we need from the next chunk.
|
||||
*/
|
||||
|
||||
takeprev = prevsize;
|
||||
takenext = needed - prevsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes, take what we need from the previous chunk */
|
||||
takeprev = prevsize;
|
||||
takenext = needed - prevsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes, take what we need from the previous chunk */
|
||||
|
||||
takeprev = needed;
|
||||
takenext = 0;
|
||||
}
|
||||
takeprev = needed;
|
||||
takenext = 0;
|
||||
}
|
||||
|
||||
needed = 0;
|
||||
}
|
||||
needed = 0;
|
||||
}
|
||||
|
||||
/* Check if we can extend into the next chunk and if we still
|
||||
* need more memory.
|
||||
/* Check if we can extend into the next chunk and if we still need
|
||||
* more memory.
|
||||
*/
|
||||
|
||||
if (nextsize > 0 && needed)
|
||||
{
|
||||
/* Can we get everything we need from the next chunk? */
|
||||
/* Can we get everything we need from the next chunk? */
|
||||
|
||||
if (needed > nextsize)
|
||||
{
|
||||
/* No, take the whole next chunk and get the
|
||||
* rest that we need from the previous chunk.
|
||||
*/
|
||||
if (needed > nextsize)
|
||||
{
|
||||
/* No, take the whole next chunk and get the rest that we
|
||||
* need from the previous chunk.
|
||||
*/
|
||||
|
||||
takeprev = needed - nextsize;
|
||||
takenext = nextsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes, take what we need from the previous chunk */
|
||||
takeprev = needed - nextsize;
|
||||
takenext = nextsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes, take what we need from the previous chunk */
|
||||
|
||||
takeprev = 0;
|
||||
takenext = needed;
|
||||
}
|
||||
takeprev = 0;
|
||||
takenext = needed;
|
||||
}
|
||||
}
|
||||
|
||||
/* Extend into the previous free chunk */
|
||||
|
@ -218,55 +216,55 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
newmem = oldmem;
|
||||
if (takeprev)
|
||||
{
|
||||
FAR struct mm_allocnode_s *newnode;
|
||||
FAR struct mm_allocnode_s *newnode;
|
||||
|
||||
/* Remove the previous node. There must be a predecessor,
|
||||
* but there may not be a successor node.
|
||||
*/
|
||||
/* Remove the previous node. There must be a predecessor, but
|
||||
* there may not be a successor node.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(prev->blink);
|
||||
prev->blink->flink = prev->flink;
|
||||
if (prev->flink)
|
||||
{
|
||||
prev->flink->blink = prev->blink;
|
||||
}
|
||||
DEBUGASSERT(prev->blink);
|
||||
prev->blink->flink = prev->flink;
|
||||
if (prev->flink)
|
||||
{
|
||||
prev->flink->blink = prev->blink;
|
||||
}
|
||||
|
||||
/* Extend the node into the previous free chunk */
|
||||
/* Extend the node into the previous free chunk */
|
||||
|
||||
newnode = (FAR struct mm_allocnode_s *)((FAR char*)oldnode - takeprev);
|
||||
newnode = (FAR struct mm_allocnode_s *)((FAR char*)oldnode - takeprev);
|
||||
|
||||
/* Did we consume the entire preceding chunk? */
|
||||
/* Did we consume the entire preceding chunk? */
|
||||
|
||||
if (takeprev < prevsize)
|
||||
{
|
||||
/* No.. just take what we need from the previous chunk
|
||||
* and put it back into the free list
|
||||
*/
|
||||
if (takeprev < prevsize)
|
||||
{
|
||||
/* No.. just take what we need from the previous chunk and put
|
||||
* it back into the free list
|
||||
*/
|
||||
|
||||
prev->size -= takeprev;
|
||||
newnode->size = oldsize + takeprev;
|
||||
newnode->preceding = prev->size | MM_ALLOC_BIT;
|
||||
next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT);
|
||||
prev->size -= takeprev;
|
||||
newnode->size = oldsize + takeprev;
|
||||
newnode->preceding = prev->size | MM_ALLOC_BIT;
|
||||
next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT);
|
||||
|
||||
/* Return the previous free node to the nodelist (with the new size) */
|
||||
/* Return the previous free node to the nodelist (with the new size) */
|
||||
|
||||
mm_addfreechunk(prev);
|
||||
mm_addfreechunk(prev);
|
||||
|
||||
/* Now we want to return newnode */
|
||||
/* Now we want to return newnode */
|
||||
|
||||
oldnode = newnode;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes.. update its size (newnode->preceding is already set) */
|
||||
oldnode = newnode;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes.. update its size (newnode->preceding is already set) */
|
||||
|
||||
newnode->size += oldsize;
|
||||
newnode->preceding |= MM_ALLOC_BIT;
|
||||
next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT);
|
||||
}
|
||||
newnode->size += oldsize;
|
||||
newnode->preceding |= MM_ALLOC_BIT;
|
||||
next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT);
|
||||
}
|
||||
|
||||
oldnode = newnode;
|
||||
oldsize = newnode->size;
|
||||
oldnode = newnode;
|
||||
oldsize = newnode->size;
|
||||
|
||||
/* Now we have to move the user contents 'down' in memory. memcpy should
|
||||
* should be save for this.
|
||||
|
@ -283,12 +281,14 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
FAR struct mm_freenode_s *newnode;
|
||||
FAR struct mm_allocnode_s *andbeyond;
|
||||
|
||||
/* Get the chunk following the next node (which could be the tail chunk) */
|
||||
/* Get the chunk following the next node (which could be the tail
|
||||
* chunk)
|
||||
*/
|
||||
|
||||
andbeyond = (FAR struct mm_allocnode_s*)((char*)next + nextsize);
|
||||
|
||||
/* Remove the next node. There must be a predecessor,
|
||||
* but there may not be a successor node.
|
||||
/* Remove the next node. There must be a predecessor, but there
|
||||
* may not be a successor node.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(next->blink);
|
||||
|
@ -307,8 +307,8 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
|
||||
if (takenext < nextsize)
|
||||
{
|
||||
/* No, take what we need from the next chunk and return it
|
||||
* to the free nodelist.
|
||||
/* No, take what we need from the next chunk and return it to
|
||||
* the free nodelist.
|
||||
*/
|
||||
|
||||
newnode->size = nextsize - takenext;
|
||||
|
@ -335,20 +335,18 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||
|
||||
else
|
||||
{
|
||||
/* Allocate a new block. On failure, realloc must return NULL but
|
||||
* leave the original memory in place.
|
||||
*/
|
||||
/* Allocate a new block. On failure, realloc must return NULL but
|
||||
* leave the original memory in place.
|
||||
*/
|
||||
|
||||
mm_givesemaphore();
|
||||
newmem = (FAR void*)malloc(size);
|
||||
if (newmem)
|
||||
{
|
||||
memcpy(newmem, oldmem, oldsize);
|
||||
free(oldmem);
|
||||
}
|
||||
mm_givesemaphore();
|
||||
newmem = (FAR void*)malloc(size);
|
||||
if (newmem)
|
||||
{
|
||||
memcpy(newmem, oldmem, oldsize);
|
||||
free(oldmem);
|
||||
}
|
||||
|
||||
return newmem;
|
||||
return newmem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -38,10 +38,12 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "mm_environment.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "mm_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -73,9 +75,9 @@
|
|||
/* Mutually exclusive access to this data set is enforced with
|
||||
* the following (un-named) semaphore. */
|
||||
|
||||
static sem_t g_mm_semaphore;
|
||||
static pid_t g_holder;
|
||||
static int g_counts_held;
|
||||
static sem_t g_mm_semaphore;
|
||||
static pid_t g_holder;
|
||||
static int g_counts_held;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -91,8 +93,8 @@ static int g_counts_held;
|
|||
|
||||
void mm_seminitialize(void)
|
||||
{
|
||||
/* Initialize the MM semaphore to one (to support one-at-
|
||||
* a-time access to private data sets.
|
||||
/* Initialize the MM semaphore to one (to support one-at-a-time access to
|
||||
* private data sets.
|
||||
*/
|
||||
|
||||
(void)sem_init(&g_mm_semaphore, 0, 1);
|
||||
|
@ -105,11 +107,10 @@ void mm_seminitialize(void)
|
|||
* Name: mm_trysemaphore
|
||||
*
|
||||
* Description:
|
||||
* Try to take the MM mutex. This is called only from the
|
||||
* OS in certain conditions when it is necessary to have
|
||||
* exclusive access to the memory manager but it is
|
||||
* impossible to wait on a semaphore (e.g., the idle process
|
||||
* when it performs its background memory cleanup).
|
||||
* Try to take the MM mutex. This is called only from the OS in certain
|
||||
* conditions when it is necessary to have exclusive access to the memory
|
||||
* manager but it is impossible to wait on a semaphore (e.g., the idle
|
||||
* process when it performs its background memory cleanup).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -149,8 +150,8 @@ int mm_trysemaphore(void)
|
|||
* Name: mm_takesemaphore
|
||||
*
|
||||
* Description:
|
||||
* Take the MM mutex. This is the normal action before all
|
||||
* memory management actions.
|
||||
* Take the MM mutex. This is the normal action before all memory
|
||||
* management actions.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -172,13 +173,13 @@ void mm_takesemaphore(void)
|
|||
|
||||
msemdbg("PID=%d taking\n", my_pid);
|
||||
while (sem_wait(&g_mm_semaphore) != 0)
|
||||
{
|
||||
/* The only case that an error should occur here is if
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
{
|
||||
/* The only case that an error should occur here is if
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
|
||||
ASSERT(mm_errno == EINTR);
|
||||
}
|
||||
ASSERT(mm_errno == EINTR);
|
||||
}
|
||||
|
||||
/* We have it. Claim the stake and return */
|
||||
|
||||
|
@ -186,8 +187,7 @@ void mm_takesemaphore(void)
|
|||
g_counts_held = 1;
|
||||
}
|
||||
|
||||
msemdbg("Holder=%d count=%d\n",
|
||||
g_holder, g_counts_held);
|
||||
msemdbg("Holder=%d count=%d\n", g_holder, g_counts_held);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -215,8 +215,7 @@ void mm_givesemaphore(void)
|
|||
/* Yes, just release one count and return */
|
||||
|
||||
g_counts_held--;
|
||||
msemdbg("Holder=%d count=%d\n",
|
||||
g_holder, g_counts_held);
|
||||
msemdbg("Holder=%d count=%d\n", g_holder, g_counts_held);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -233,8 +232,7 @@ void mm_givesemaphore(void)
|
|||
* Name: mm_getsemaphore
|
||||
*
|
||||
* Description:
|
||||
* Return the current value of the MM semaphore (for test
|
||||
* purposes only)
|
||||
* Return the current value of the MM semaphore (for test purposes only)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_shrinkchunk.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,38 +31,37 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* mm_shrinkchunk
|
||||
/****************************************************************************
|
||||
* Name: mm_shrinkchunk
|
||||
*
|
||||
* Description:
|
||||
* Reduce the size of the chunk specified by the node
|
||||
* structure to the specified size. this internal logic
|
||||
* is used both from memalign to dispose of any trailing
|
||||
* memory in the aligned allocation and also by realloc
|
||||
* when there is a request to reduce the size of an allocation.
|
||||
* Reduce the size of the chunk specified by the node structure to the
|
||||
* specified size. this internal logic is used both from memalign to
|
||||
* dispose of any trailing memory in the aligned allocation and also by
|
||||
* realloc when there is a request to reduce the size of an allocation.
|
||||
*
|
||||
* NOTES:
|
||||
* (1) size is the whole chunk size (payload and header)
|
||||
* (2) the caller must hold the MM semaphore.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
void mm_shrinkchunk(FAR struct mm_allocnode_s *node, size_t size)
|
||||
{
|
||||
|
@ -94,8 +93,8 @@ void mm_shrinkchunk(FAR struct mm_allocnode_s *node, size_t size)
|
|||
next->flink->blink = next->blink;
|
||||
}
|
||||
|
||||
/* Create a new chunk that will hold both the next chunk
|
||||
* and the tailing memory from the aligned chunk.
|
||||
/* Create a new chunk that will hold both the next chunk and the
|
||||
* tailing memory from the aligned chunk.
|
||||
*/
|
||||
|
||||
newnode = (FAR struct mm_freenode_s*)((char*)node + size);
|
||||
|
@ -112,16 +111,16 @@ void mm_shrinkchunk(FAR struct mm_allocnode_s *node, size_t size)
|
|||
mm_addfreechunk(newnode);
|
||||
}
|
||||
|
||||
/* The next chunk is allocated. Try to free the end portion
|
||||
* at the end chunk to be shrunk.
|
||||
/* The next chunk is allocated. Try to free the end portion at the end
|
||||
* chunk to be shrunk.
|
||||
*/
|
||||
|
||||
else if (node->size >= size + SIZEOF_MM_FREENODE)
|
||||
{
|
||||
FAR struct mm_freenode_s *newnode;
|
||||
|
||||
/* Create a new chunk that will hold both the next chunk
|
||||
* and the tailing memory from the aligned chunk.
|
||||
/* Create a new chunk that will hold both the next chunk and the
|
||||
* tailing memory from the aligned chunk.
|
||||
*/
|
||||
|
||||
newnode = (FAR struct mm_freenode_s*)((char*)node + size);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_size2ndx.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,24 +31,30 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Convert the size to a nodelist index */
|
||||
/****************************************************************************
|
||||
* Name: mm_size2ndx
|
||||
*
|
||||
* Description:
|
||||
* Convert the size to a nodelist index.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mm_size2ndx(size_t size)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* mm/mm_test.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -33,10 +33,18 @@
|
|||
*
|
||||
************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************/
|
||||
|
||||
/* Fake NuttX dependencies */
|
||||
|
||||
#define FAR
|
||||
|
@ -56,6 +64,10 @@
|
|||
/* #define STOP_ON_ERRORS do{}while(0) */
|
||||
#define STOP_ON_ERRORS exit(1)
|
||||
|
||||
/************************************************************************
|
||||
* Private Data
|
||||
************************************************************************/
|
||||
|
||||
/* Test allocations */
|
||||
|
||||
static const int alloc_sizes[NTEST_ALLOCS] =
|
||||
|
@ -65,6 +77,7 @@ static const int alloc_sizes[NTEST_ALLOCS] =
|
|||
4732, 28, 901, 480, 5011, 1536, 2011, 81647,
|
||||
646, 1646, 69179, 194, 2590, 7, 969, 70
|
||||
};
|
||||
|
||||
static const int realloc_sizes[NTEST_ALLOCS] =
|
||||
{
|
||||
18, 3088, 963, 123, 511, 11666, 3723, 42,
|
||||
|
@ -72,6 +85,7 @@ static const int realloc_sizes[NTEST_ALLOCS] =
|
|||
8663, 91255, 28, 4346, 9172, 168, 229, 4734,
|
||||
59139, 221, 7830, 30421, 1666, 4, 812, 416
|
||||
};
|
||||
|
||||
static const int random1[NTEST_ALLOCS] =
|
||||
{
|
||||
20, 11, 3, 31, 9, 29, 7, 17,
|
||||
|
@ -79,6 +93,7 @@ static const int random1[NTEST_ALLOCS] =
|
|||
27, 19, 22, 28, 8, 30, 12, 15,
|
||||
4, 1, 24, 6, 16, 13, 5, 23
|
||||
};
|
||||
|
||||
static const int random2[NTEST_ALLOCS] =
|
||||
{
|
||||
2, 19, 12, 23, 30, 11, 27, 4,
|
||||
|
@ -86,6 +101,7 @@ static const int random2[NTEST_ALLOCS] =
|
|||
10, 17, 25, 31, 8, 29, 3, 26,
|
||||
9, 18, 22, 13, 1, 21, 14, 6
|
||||
};
|
||||
|
||||
static const int random3[NTEST_ALLOCS] =
|
||||
{
|
||||
8, 17, 3, 18, 26, 23, 30, 11,
|
||||
|
@ -93,18 +109,24 @@ static const int random3[NTEST_ALLOCS] =
|
|||
29, 14, 19, 21, 0, 31, 7, 24,
|
||||
9, 15, 2, 28, 16, 6, 13, 5
|
||||
};
|
||||
|
||||
static const int alignment[NTEST_ALLOCS/2] =
|
||||
{
|
||||
128, 2048, 131072, 8192, 32, 32768, 16384 , 262144,
|
||||
512, 4096, 65536, 8, 64, 1024, 16, 4
|
||||
};
|
||||
|
||||
static void *allocs[NTEST_ALLOCS];
|
||||
static struct mallinfo alloc_info;
|
||||
static unsigned int g_reportedheapsize = 0;
|
||||
static unsigned int g_actualheapsize = 0;
|
||||
|
||||
/************************************************************************
|
||||
* mm_showchunkinfo
|
||||
* Private Functions
|
||||
************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Name: mm_findinfreelist
|
||||
************************************************************************/
|
||||
|
||||
static int mm_findinfreelist(struct mm_freenode_s *node)
|
||||
|
@ -120,9 +142,14 @@ static int mm_findinfreelist(struct mm_freenode_s *node)
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: mm_showchunkinfo
|
||||
************************************************************************/
|
||||
|
||||
static void mm_showchunkinfo(void)
|
||||
{
|
||||
struct mm_allocnode_s *node;
|
||||
|
@ -146,8 +173,8 @@ static void mm_showchunkinfo(void)
|
|||
for (node = g_heapstart[region];
|
||||
node < g_heapend[region];
|
||||
node = (struct mm_allocnode_s *)((char*)node + node->size))
|
||||
{
|
||||
printf(" %p 0x%08x 0x%08x %s",
|
||||
{
|
||||
printf(" %p 0x%08x 0x%08x %s",
|
||||
node, node->size, node->preceding & ~MM_ALLOC_BIT,
|
||||
node->preceding & MM_ALLOC_BIT ? "Allocated" : "Free ");
|
||||
found = mm_findinfreelist((struct mm_freenode_s *)node);
|
||||
|
@ -168,6 +195,10 @@ static void mm_showchunkinfo(void)
|
|||
#undef region
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: mm_showfreelist
|
||||
************************************************************************/
|
||||
|
||||
static void mm_showfreelist(void)
|
||||
{
|
||||
struct mm_freenode_s *prev;
|
||||
|
@ -204,6 +235,10 @@ static void mm_showfreelist(void)
|
|||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: mm_showmallinfo
|
||||
************************************************************************/
|
||||
|
||||
static void mm_showmallinfo(void)
|
||||
{
|
||||
int sval;
|
||||
|
@ -213,15 +248,15 @@ static void mm_showmallinfo(void)
|
|||
alloc_info = mallinfo();
|
||||
printf(" mallinfo:\n");
|
||||
printf(" Total space allocated from system = %ld\n",
|
||||
alloc_info.arena);
|
||||
alloc_info.arena);
|
||||
printf(" Number of non-inuse chunks = %ld\n",
|
||||
alloc_info.ordblks);
|
||||
alloc_info.ordblks);
|
||||
printf(" Largest non-inuse chunk = %ld\n",
|
||||
alloc_info.mxordblk);
|
||||
alloc_info.mxordblk);
|
||||
printf(" Total allocated space = %ld\n",
|
||||
alloc_info.uordblks);
|
||||
alloc_info.uordblks);
|
||||
printf(" Total non-inuse space = %ld\n",
|
||||
alloc_info.fordblks);
|
||||
alloc_info.fordblks);
|
||||
|
||||
sval = mm_getsemaphore();
|
||||
if (sval != 1)
|
||||
|
@ -249,7 +284,12 @@ static void mm_showmallinfo(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void do_mallocs(void **mem, const int *size, const int *rand, int n)
|
||||
/************************************************************************
|
||||
* Name: do_mallocs
|
||||
************************************************************************/
|
||||
|
||||
static void do_mallocs(void **mem, const int *size, const int *rand,
|
||||
int n)
|
||||
{
|
||||
int sval;
|
||||
int i;
|
||||
|
@ -294,7 +334,12 @@ static void do_mallocs(void **mem, const int *size, const int *rand, int n)
|
|||
}
|
||||
}
|
||||
|
||||
static void do_reallocs(void **mem, const int *oldsize, const int *newsize, const int *rand, int n)
|
||||
/************************************************************************
|
||||
* Name: do_reallocs
|
||||
************************************************************************/
|
||||
|
||||
static void do_reallocs(void **mem, const int *oldsize,
|
||||
const int *newsize, const int *rand, int n)
|
||||
{
|
||||
int sval;
|
||||
int i;
|
||||
|
@ -304,11 +349,11 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons
|
|||
{
|
||||
j = rand[i];
|
||||
printf("(%d)Re-allocating at %p from %d to %d bytes\n",
|
||||
i, mem[j], oldsize[j], newsize[j]);
|
||||
i, mem[j], oldsize[j], newsize[j]);
|
||||
mem[j] = mm_realloc(mem[j], newsize[j]);
|
||||
printf("(%d)Memory re-allocated at %p\n", i, mem[j]);
|
||||
if (mem[j] == NULL)
|
||||
{
|
||||
{
|
||||
int allocsize = MM_ALIGN_UP(newsize[j] + SIZEOF_MM_ALLOCNODE);
|
||||
fprintf(stderr, "(%d)realloc failed for allocsize=%d\n", i, allocsize);
|
||||
if (allocsize > alloc_info.mxordblk)
|
||||
|
@ -320,7 +365,7 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons
|
|||
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(mem[j], 0x55, newsize[j]);
|
||||
|
@ -337,7 +382,12 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons
|
|||
}
|
||||
}
|
||||
|
||||
static void do_memaligns(void **mem, const int *size, const int *align, const int *rand, int n)
|
||||
/************************************************************************
|
||||
* Name: do_memaligns
|
||||
************************************************************************/
|
||||
|
||||
static void do_memaligns(void **mem, const int *size, const int *align,
|
||||
const int *rand, int n)
|
||||
{
|
||||
int sval;
|
||||
int i;
|
||||
|
@ -347,11 +397,11 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
|
|||
{
|
||||
j = rand[i];
|
||||
printf("(%d)Allocating %d bytes aligned to 0x%08x\n",
|
||||
i, size[j], align[i]);
|
||||
i, size[j], align[i]);
|
||||
mem[j] = mm_memalign(align[i], size[j]);
|
||||
printf("(%d)Memory allocated at %p\n", i, mem[j]);
|
||||
if (mem[j] == NULL)
|
||||
{
|
||||
{
|
||||
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE) + 2*align[i];
|
||||
fprintf(stderr, "(%d)memalign failed for allocsize=%d\n", i, allocsize);
|
||||
if (allocsize > alloc_info.mxordblk)
|
||||
|
@ -363,7 +413,7 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
|
|||
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(mem[j], 0x33, size[j]);
|
||||
|
@ -380,6 +430,10 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
|
|||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: do_frees
|
||||
************************************************************************/
|
||||
|
||||
static void do_frees(void **mem, const int *size, const int *rand, int n)
|
||||
{
|
||||
int sval;
|
||||
|
@ -390,7 +444,7 @@ static void do_frees(void **mem, const int *size, const int *rand, int n)
|
|||
{
|
||||
j = rand[i];
|
||||
printf("(%d)Releasing memory at %p (size=%d bytes)\n",
|
||||
i, mem[j], size[j]);
|
||||
i, mem[j], size[j]);
|
||||
mm_free(mem[j]);
|
||||
mem[j] = NULL;
|
||||
|
||||
|
@ -405,6 +459,14 @@ static void do_frees(void **mem, const int *size, const int *rand, int n)
|
|||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Name: main
|
||||
************************************************************************/
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
void *heap1_base;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* mm/mm_zalloc.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -31,30 +31,30 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include "mm_environment.h"
|
||||
#include "mm_internal.h"
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Public: Functions
|
||||
************************************************************************/
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: zalloc
|
||||
*
|
||||
* Description:
|
||||
* zalloc calls malloc, then zeroes out the allocated chunk.
|
||||
*
|
||||
************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *zalloc(size_t size)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue