mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
Finally, a clean SDCC compile
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@20 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ $(BIN): $(OBJS)
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
rm -f $(BIN) *.o *~
|
||||
rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
|
||||
|
||||
distclean: clean
|
||||
rm -f Make.dep .depend
|
||||
|
||||
@@ -61,10 +61,10 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void mm_addfreechunk(struct mm_freenode_s *node)
|
||||
void mm_addfreechunk(FAR struct mm_freenode_s *node)
|
||||
{
|
||||
struct mm_freenode_s *next;
|
||||
struct mm_freenode_s *prev;
|
||||
FAR struct mm_freenode_s *next;
|
||||
FAR struct mm_freenode_s *prev;
|
||||
|
||||
/* Convert the size to a nodelist index */
|
||||
|
||||
|
||||
+2
-2
@@ -55,9 +55,9 @@
|
||||
* calloc calculates the size and calls zalloc
|
||||
************************************************************/
|
||||
|
||||
void *calloc(size_t n, size_t elem_size)
|
||||
FAR void *calloc(size_t n, size_t elem_size)
|
||||
{
|
||||
void *ret = NULL;
|
||||
FAR void *ret = NULL;
|
||||
|
||||
if (n > 0 && elem_size > 0)
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#ifndef MM_TEST
|
||||
# include <nuttx/config.h>
|
||||
# include <nuttx/compiler.h>
|
||||
# include <sys/types.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
|
||||
+10
-11
@@ -62,11 +62,11 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void free(void *mem)
|
||||
void free(FAR void *mem)
|
||||
{
|
||||
struct mm_freenode_s *node;
|
||||
struct mm_freenode_s *prev;
|
||||
struct mm_freenode_s *next;
|
||||
FAR struct mm_freenode_s *node;
|
||||
FAR struct mm_freenode_s *prev;
|
||||
FAR struct mm_freenode_s *next;
|
||||
|
||||
/* Protect against attempts to free a NULL reference */
|
||||
|
||||
@@ -83,22 +83,22 @@ void free(void *mem)
|
||||
|
||||
/* Map the memory chunk into a free node */
|
||||
|
||||
node = (struct mm_freenode_s *)((char*)mem - SIZEOF_MM_ALLOCNODE);
|
||||
node = (FAR struct mm_freenode_s *)((char*)mem - SIZEOF_MM_ALLOCNODE);
|
||||
node->preceding &= ~MM_ALLOC_BIT;
|
||||
|
||||
/* Check if the following node is free and, if so, merge it */
|
||||
|
||||
next = (struct mm_freenode_s *)((char*)node + node->size);
|
||||
next = (FAR struct mm_freenode_s *)((char*)node + node->size);
|
||||
if ((next->preceding & MM_ALLOC_BIT) == 0)
|
||||
{
|
||||
struct mm_allocnode_s *andbeyond;
|
||||
FAR struct mm_allocnode_s *andbeyond;
|
||||
|
||||
/* Get the node following the next node (which will
|
||||
* become the new next node). We know that we can never
|
||||
* index past the tail chunk because it is always allocated.
|
||||
*/
|
||||
|
||||
andbeyond = (struct mm_allocnode_s*)((char*)next + next->size);
|
||||
andbeyond = (FAR struct mm_allocnode_s*)((char*)next + next->size);
|
||||
|
||||
/* Remove the next node. There must be a predecessor,
|
||||
* but there may not be a successor node.
|
||||
@@ -115,14 +115,14 @@ void free(void *mem)
|
||||
|
||||
node->size += next->size;
|
||||
andbeyond->preceding = node->size | (andbeyond->preceding & MM_ALLOC_BIT);
|
||||
next = (struct mm_freenode_s *)andbeyond;
|
||||
next = (FAR struct mm_freenode_s *)andbeyond;
|
||||
}
|
||||
|
||||
/* Check if the preceding node is also free and, if so, merge
|
||||
* it with this node
|
||||
*/
|
||||
|
||||
prev = (struct mm_freenode_s *)((char*)node - node->preceding);
|
||||
prev = (FAR struct mm_freenode_s *)((char*)node - node->preceding);
|
||||
if ((prev->preceding & MM_ALLOC_BIT) == 0)
|
||||
{
|
||||
/* Remove the node. There must be a predecessor, but there may
|
||||
@@ -146,6 +146,5 @@ void free(void *mem)
|
||||
/* Add the merged node to the nodelist */
|
||||
|
||||
mm_addfreechunk(node);
|
||||
|
||||
mm_givesemaphore();
|
||||
}
|
||||
|
||||
+13
-11
@@ -50,19 +50,19 @@
|
||||
|
||||
/* This is the size of the heap provided to mm */
|
||||
|
||||
size_t g_heapsize;
|
||||
size_t g_heapsize;
|
||||
|
||||
/* This is the first and last nodes of the heap */
|
||||
|
||||
struct mm_allocnode_s *g_heapstart;
|
||||
struct mm_allocnode_s *g_heapend;
|
||||
FAR struct mm_allocnode_s *g_heapstart;
|
||||
FAR struct mm_allocnode_s *g_heapend;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
FAR struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
@@ -85,9 +85,11 @@ struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void mm_initialize(void *heapstart, size_t heapsize)
|
||||
void mm_initialize(FAR void *heapstart, size_t heapsize)
|
||||
{
|
||||
struct mm_freenode_s *node;
|
||||
FAR struct mm_freenode_s *node;
|
||||
size_t heapbase;
|
||||
size_t heapend;
|
||||
int i;
|
||||
|
||||
CHECK_ALLOCNODE_SIZE;
|
||||
@@ -97,8 +99,8 @@ void mm_initialize(void *heapstart, size_t heapsize)
|
||||
* both aligned with the MM_MIN_CHUNK size.
|
||||
*/
|
||||
|
||||
size_t heapbase = MM_ALIGN_UP((size_t)heapstart);
|
||||
size_t heapend = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
|
||||
heapbase = MM_ALIGN_UP((size_t)heapstart);
|
||||
heapend = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
|
||||
|
||||
/* Save the size of the heap */
|
||||
|
||||
@@ -121,15 +123,15 @@ void mm_initialize(void *heapstart, size_t heapsize)
|
||||
* all available memory.
|
||||
*/
|
||||
|
||||
g_heapstart = (struct mm_allocnode_s *)heapbase;
|
||||
g_heapstart = (FAR struct mm_allocnode_s *)heapbase;
|
||||
g_heapstart->size = SIZEOF_MM_ALLOCNODE;
|
||||
g_heapstart->preceding = MM_ALLOC_BIT;
|
||||
|
||||
node = (struct mm_freenode_s *)(heapbase + SIZEOF_MM_ALLOCNODE);
|
||||
node = (FAR struct mm_freenode_s *)(heapbase + SIZEOF_MM_ALLOCNODE);
|
||||
node->size = g_heapsize - 2*SIZEOF_MM_ALLOCNODE;
|
||||
node->preceding = SIZEOF_MM_ALLOCNODE;
|
||||
|
||||
g_heapend = (struct mm_allocnode_s *)(heapend - SIZEOF_MM_ALLOCNODE);
|
||||
g_heapend = (FAR struct mm_allocnode_s *)(heapend - SIZEOF_MM_ALLOCNODE);
|
||||
g_heapend->size = SIZEOF_MM_ALLOCNODE;
|
||||
g_heapend->preceding = node->size | MM_ALLOC_BIT;
|
||||
|
||||
|
||||
+26
-21
@@ -120,14 +120,14 @@ struct mm_allocnode_s
|
||||
|
||||
struct mm_freenode_s
|
||||
{
|
||||
size_t size; /* Size of this chunk */
|
||||
size_t preceding; /* Size of the preceding chunk */
|
||||
struct mm_freenode_s *flink; /* Supports a doubly linked list */
|
||||
struct mm_freenode_s *blink;
|
||||
size_t size; /* Size of this chunk */
|
||||
size_t preceding; /* Size of the preceding chunk */
|
||||
FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */
|
||||
FAR struct mm_freenode_s *blink;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_SMALL_MEMORY
|
||||
# define SIZEOF_MM_FREENODE 10
|
||||
# define SIZEOF_MM_FREENODE 8
|
||||
#else
|
||||
# define SIZEOF_MM_FREENODE 16
|
||||
#endif
|
||||
@@ -160,15 +160,15 @@ extern size_t g_heapsize;
|
||||
|
||||
/* This is the first and last nodes of the heap */
|
||||
|
||||
extern struct mm_allocnode_s *g_heapstart;
|
||||
extern struct mm_allocnode_s *g_heapend;
|
||||
extern FAR struct mm_allocnode_s *g_heapstart;
|
||||
extern FAR struct mm_allocnode_s *g_heapend;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
extern struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
extern FAR struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
|
||||
/************************************************************
|
||||
* Pulblic Function Prototypes
|
||||
@@ -177,23 +177,28 @@ extern struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
/* Normally defined in malloc.h */
|
||||
|
||||
#ifdef MM_TEST
|
||||
extern void *mm_malloc(size_t);
|
||||
extern void mm_free(void*);
|
||||
extern void *mm_realloc(void*, size_t);
|
||||
extern void *mm_memalign(size_t, size_t);
|
||||
extern void *mm_zalloc(size_t);
|
||||
extern void *mm_calloc(size_t, size_t);
|
||||
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);
|
||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
||||
extern struct mallinfo mallinfo(void);
|
||||
#else
|
||||
extern int mallinfo(struct mallinfo *info);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size);
|
||||
extern void mm_addfreechunk(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);
|
||||
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);
|
||||
#ifdef MM_TEST
|
||||
extern int mm_getsemaphore(void);
|
||||
extern int mm_getsemaphore(void);
|
||||
#endif
|
||||
|
||||
#endif /* __MM_INTERNAL_H */
|
||||
|
||||
+27
-7
@@ -65,15 +65,26 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
||||
struct mallinfo mallinfo(void)
|
||||
#else
|
||||
int mallinfo(struct mallinfo *info)
|
||||
#endif
|
||||
{
|
||||
static struct mallinfo stats;
|
||||
struct mm_allocnode_s *node;
|
||||
size_t mxordblk = 0;
|
||||
int ordblks = 0; /* Number of non-inuse chunks */
|
||||
size_t uordblks = 0; /* Total allocated space */
|
||||
size_t fordblks = 0; /* Total non-inuse space */
|
||||
|
||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
||||
static struct mallinfo info;
|
||||
#else
|
||||
if (!info)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
/* Visit each node in physical memory */
|
||||
|
||||
for (node = g_heapstart;
|
||||
@@ -99,10 +110,19 @@ struct mallinfo mallinfo(void)
|
||||
uordblks += SIZEOF_MM_ALLOCNODE; /* account for the tail node */
|
||||
DEBUGASSERT(uordblks + fordblks == g_heapsize);
|
||||
|
||||
stats.arena = g_heapsize;
|
||||
stats.ordblks = ordblks;
|
||||
stats.mxordblk = mxordblk;
|
||||
stats.uordblks = uordblks;
|
||||
stats.fordblks = fordblks;
|
||||
return stats;
|
||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
||||
info.arena = g_heapsize;
|
||||
info.ordblks = ordblks;
|
||||
info.mxordblk = mxordblk;
|
||||
info.uordblks = uordblks;
|
||||
info.fordblks = fordblks;
|
||||
return info;
|
||||
#else
|
||||
info->arena = g_heapsize;
|
||||
info->ordblks = ordblks;
|
||||
info->mxordblk = mxordblk;
|
||||
info->uordblks = uordblks;
|
||||
info->fordblks = fordblks;
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
+6
-6
@@ -85,9 +85,9 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void *malloc(size_t size)
|
||||
FAR void *malloc(size_t size)
|
||||
{
|
||||
struct mm_freenode_s *node;
|
||||
FAR struct mm_freenode_s *node;
|
||||
void *ret = NULL;
|
||||
int ndx;
|
||||
|
||||
@@ -142,8 +142,8 @@ void *malloc(size_t size)
|
||||
|
||||
if (node)
|
||||
{
|
||||
struct mm_freenode_s *remainder;
|
||||
struct mm_freenode_s *next;
|
||||
FAR struct mm_freenode_s *remainder;
|
||||
FAR struct mm_freenode_s *next;
|
||||
size_t remaining;
|
||||
|
||||
/* Remove the node. There must be a predecessor, but there may
|
||||
@@ -169,11 +169,11 @@ void *malloc(size_t size)
|
||||
{
|
||||
/* Get a pointer to the next node in physical memory */
|
||||
|
||||
next = (struct mm_freenode_s*)(((char*)node) + node->size);
|
||||
next = (FAR struct mm_freenode_s*)(((char*)node) + node->size);
|
||||
|
||||
/* Create the remainder node */
|
||||
|
||||
remainder = (struct mm_freenode_s*)(((char*)node) + size);
|
||||
remainder = (FAR struct mm_freenode_s*)(((char*)node) + size);
|
||||
remainder->size = remaining;
|
||||
remainder->preceding = size;
|
||||
|
||||
|
||||
+10
-10
@@ -63,9 +63,9 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void *memalign(size_t alignment, size_t size)
|
||||
FAR void *memalign(size_t alignment, size_t size)
|
||||
{
|
||||
struct mm_allocnode_s *node;
|
||||
FAR struct mm_allocnode_s *node;
|
||||
size_t rawchunk;
|
||||
size_t alignedchunk;
|
||||
size_t mask = (size_t)(alignment - 1);
|
||||
@@ -115,7 +115,7 @@ void *memalign(size_t alignment, size_t size)
|
||||
* node after the allocation.
|
||||
*/
|
||||
|
||||
node = (struct mm_allocnode_s*)(rawchunk - SIZEOF_MM_ALLOCNODE);
|
||||
node = (FAR struct mm_allocnode_s*)(rawchunk - SIZEOF_MM_ALLOCNODE);
|
||||
|
||||
/* Find the aligned subregion */
|
||||
|
||||
@@ -125,13 +125,13 @@ void *memalign(size_t alignment, size_t size)
|
||||
|
||||
if (alignedchunk != rawchunk)
|
||||
{
|
||||
struct mm_allocnode_s *newnode;
|
||||
struct mm_allocnode_s *next;
|
||||
FAR struct mm_allocnode_s *newnode;
|
||||
FAR struct mm_allocnode_s *next;
|
||||
size_t precedingsize;
|
||||
|
||||
/* Get the node the next node after the allocation. */
|
||||
|
||||
next = (struct mm_allocnode_s*)((char*)node + node->size);
|
||||
next = (FAR struct mm_allocnode_s*)((char*)node + node->size);
|
||||
|
||||
/* Make sure that there is space to convert the preceding mm_allocnode_s
|
||||
* into an mm_freenode_s. I think that this should always be true
|
||||
@@ -139,7 +139,7 @@ void *memalign(size_t alignment, size_t size)
|
||||
|
||||
DEBUGASSERT(alignedchunk >= rawchunk + 8);
|
||||
|
||||
newnode = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
|
||||
newnode = (FAR struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
|
||||
|
||||
/* Preceding size is full size of the new 'node,' including
|
||||
* SIZEOF_MM_ALLOCNODE
|
||||
@@ -158,7 +158,7 @@ void *memalign(size_t alignment, size_t size)
|
||||
if (precedingsize < SIZEOF_MM_FREENODE)
|
||||
{
|
||||
alignedchunk += alignment;
|
||||
newnode = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
|
||||
newnode = (FAR struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
|
||||
precedingsize = (size_t)newnode - (size_t)node;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ void *memalign(size_t alignment, size_t size)
|
||||
|
||||
/* Add the original, newly freed node to the free nodelist */
|
||||
|
||||
mm_addfreechunk((struct mm_freenode_s *)node);
|
||||
mm_addfreechunk((FAR struct mm_freenode_s *)node);
|
||||
|
||||
/* Replace the original node with the newlay realloaced,
|
||||
* aligned node
|
||||
@@ -206,5 +206,5 @@ void *memalign(size_t alignment, size_t size)
|
||||
}
|
||||
|
||||
mm_givesemaphore();
|
||||
return (void*)alignedchunk;
|
||||
return (FAR void*)alignedchunk;
|
||||
}
|
||||
|
||||
+20
-18
@@ -73,11 +73,11 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void *realloc(void *oldmem, size_t size)
|
||||
FAR void *realloc(FAR void *oldmem, size_t size)
|
||||
{
|
||||
struct mm_allocnode_s *oldnode;
|
||||
struct mm_freenode_s *prev;
|
||||
struct mm_freenode_s *next;
|
||||
FAR struct mm_allocnode_s *oldnode;
|
||||
FAR struct mm_freenode_s *prev;
|
||||
FAR struct mm_freenode_s *next;
|
||||
size_t oldsize;
|
||||
size_t prevsize = 0;
|
||||
size_t nextsize = 0;
|
||||
@@ -106,7 +106,7 @@ void *realloc(void *oldmem, size_t size)
|
||||
|
||||
/* Map the memory chunk into an allocated node structure */
|
||||
|
||||
oldnode = (struct mm_allocnode_s *)((char*)oldmem - SIZEOF_MM_ALLOCNODE);
|
||||
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.
|
||||
@@ -129,13 +129,13 @@ void *realloc(void *oldmem, size_t size)
|
||||
* the best decision
|
||||
*/
|
||||
|
||||
next = (struct mm_freenode_s *)((char*)oldnode + oldnode->size);
|
||||
next = (FAR struct mm_freenode_s *)((FAR char*)oldnode + oldnode->size);
|
||||
if ((next->preceding & MM_ALLOC_BIT) == 0)
|
||||
{
|
||||
nextsize = next->size;
|
||||
}
|
||||
|
||||
prev = (struct mm_freenode_s *)((char*)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT));
|
||||
prev = (FAR struct mm_freenode_s *)((FAR char*)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT));
|
||||
if ((prev->preceding & MM_ALLOC_BIT) == 0)
|
||||
{
|
||||
prevsize = prev->size;
|
||||
@@ -145,9 +145,9 @@ void *realloc(void *oldmem, size_t size)
|
||||
|
||||
if (nextsize + prevsize + oldsize >= size)
|
||||
{
|
||||
size_t needed = size - oldsize;
|
||||
size_t takeprev;
|
||||
size_t takenext;
|
||||
size_t needed = size - oldsize;
|
||||
size_t takeprev = 0;
|
||||
size_t takenext = 0;
|
||||
|
||||
/* Check if we can extend into the previous chunk and if the
|
||||
* previous chunk is smaller than the next chunk.
|
||||
@@ -207,7 +207,7 @@ void *realloc(void *oldmem, size_t size)
|
||||
|
||||
if (takeprev)
|
||||
{
|
||||
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.
|
||||
@@ -222,7 +222,7 @@ void *realloc(void *oldmem, size_t size)
|
||||
|
||||
/* Extend the node into the previous free chunk */
|
||||
|
||||
newnode = (struct mm_allocnode_s *)((char*)oldnode - takeprev);
|
||||
newnode = (FAR struct mm_allocnode_s *)((FAR char*)oldnode - takeprev);
|
||||
|
||||
/* Did we consume the entire preceding chunk? */
|
||||
|
||||
@@ -261,12 +261,12 @@ void *realloc(void *oldmem, size_t size)
|
||||
|
||||
if (takenext)
|
||||
{
|
||||
struct mm_freenode_s *newnode;
|
||||
struct mm_allocnode_s *andbeyond;
|
||||
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) */
|
||||
|
||||
andbeyond = (struct mm_allocnode_s*)((char*)next + nextsize);
|
||||
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.
|
||||
@@ -282,7 +282,7 @@ void *realloc(void *oldmem, size_t size)
|
||||
/* Extend the node into the previous next chunk */
|
||||
|
||||
oldnode->size = oldsize + takenext;
|
||||
newnode = (struct mm_freenode_s *)((char*)oldnode + oldnode->size);
|
||||
newnode = (FAR struct mm_freenode_s *)((char*)oldnode + oldnode->size);
|
||||
|
||||
/* Did we consume the entire preceding chunk? */
|
||||
|
||||
@@ -310,19 +310,21 @@ void *realloc(void *oldmem, size_t size)
|
||||
|
||||
|
||||
mm_givesemaphore();
|
||||
return (void*)((char*)oldnode + SIZEOF_MM_ALLOCNODE);
|
||||
return (FAR void*)((FAR char*)oldnode + SIZEOF_MM_ALLOCNODE);
|
||||
}
|
||||
|
||||
/* The current chunk cannot be extended. Just allocate a new chunk and copy */
|
||||
|
||||
else
|
||||
{
|
||||
FAR void *newmem;
|
||||
|
||||
/* Allocate a new block. On failure, realloc must return NULL but
|
||||
* leave the original memory in place.
|
||||
*/
|
||||
|
||||
mm_givesemaphore();
|
||||
char *newmem = (char*)malloc(size);
|
||||
newmem = (FAR void*)malloc(size);
|
||||
if (newmem)
|
||||
{
|
||||
memcpy(newmem, oldmem, oldsize);
|
||||
|
||||
+9
-9
@@ -64,24 +64,24 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
|
||||
void mm_shrinkchunk(FAR struct mm_allocnode_s *node, size_t size)
|
||||
{
|
||||
struct mm_freenode_s *next;
|
||||
FAR struct mm_freenode_s *next;
|
||||
|
||||
/* Get a reference to the next node */
|
||||
|
||||
next = (struct mm_freenode_s*)((char*)node + node->size);
|
||||
next = (FAR struct mm_freenode_s*)((char*)node + node->size);
|
||||
|
||||
/* Check if it is free */
|
||||
|
||||
if ((next->preceding & MM_ALLOC_BIT) == 0)
|
||||
{
|
||||
struct mm_allocnode_s *andbeyond;
|
||||
struct mm_freenode_s *newnode;
|
||||
FAR struct mm_allocnode_s *andbeyond;
|
||||
FAR struct mm_freenode_s *newnode;
|
||||
|
||||
/* Get the chunk next the next node (which could be the tail chunk) */
|
||||
|
||||
andbeyond = (struct mm_allocnode_s*)((char*)next + next->size);
|
||||
andbeyond = (FAR struct mm_allocnode_s*)((char*)next + next->size);
|
||||
|
||||
/* Remove the next node. There must be a predecessor, but there may
|
||||
* not be a successor node.
|
||||
@@ -98,7 +98,7 @@ void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
|
||||
* and the tailing memory from the aligned chunk.
|
||||
*/
|
||||
|
||||
newnode = (struct mm_freenode_s*)((char*)node + size);
|
||||
newnode = (FAR struct mm_freenode_s*)((char*)node + size);
|
||||
|
||||
/* Set up the size of the new node */
|
||||
|
||||
@@ -118,13 +118,13 @@ void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
|
||||
|
||||
else if (node->size >= size + SIZEOF_MM_FREENODE)
|
||||
{
|
||||
struct mm_freenode_s *newnode;
|
||||
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.
|
||||
*/
|
||||
|
||||
newnode = (struct mm_freenode_s*)((char*)node + size);
|
||||
newnode = (FAR struct mm_freenode_s*)((char*)node + size);
|
||||
|
||||
/* Set up the size of the new node */
|
||||
|
||||
|
||||
+2
-2
@@ -56,9 +56,9 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void *zalloc(size_t size)
|
||||
FAR void *zalloc(size_t size)
|
||||
{
|
||||
void *alloc = malloc(size);
|
||||
FAR void *alloc = malloc(size);
|
||||
if (alloc)
|
||||
{
|
||||
memset(alloc, 0, size);
|
||||
|
||||
Reference in New Issue
Block a user