OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdlib/] [malloc.c] - Diff between revs 1010 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 1010 Rev 1765
/* VxWorks provides its own version of malloc, and we can't use this
/* VxWorks provides its own version of malloc, and we can't use this
   one because VxWorks does not provide sbrk.  So we have a hook to
   one because VxWorks does not provide sbrk.  So we have a hook to
   not compile this code.  */
   not compile this code.  */
 
 
/* The routines here are simple cover fns to the routines that do the real
/* The routines here are simple cover fns to the routines that do the real
   work (the reentrant versions).  */
   work (the reentrant versions).  */
/* FIXME: Does the warning below (see WARNINGS) about non-reentrancy still
/* FIXME: Does the warning below (see WARNINGS) about non-reentrancy still
   apply?  A first guess would be "no", but how about reentrancy in the *same*
   apply?  A first guess would be "no", but how about reentrancy in the *same*
   thread?  */
   thread?  */
 
 
#ifdef MALLOC_PROVIDED
#ifdef MALLOC_PROVIDED
 
 
int _dummy_malloc = 1;
int _dummy_malloc = 1;
 
 
#else
#else
 
 
/*
/*
FUNCTION
FUNCTION
<<malloc>>, <<realloc>>, <<free>>---manage memory
<<malloc>>, <<realloc>>, <<free>>---manage memory
 
 
INDEX
INDEX
        malloc
        malloc
INDEX
INDEX
        realloc
        realloc
INDEX
INDEX
        free
        free
INDEX
INDEX
        memalign
        memalign
INDEX
INDEX
        malloc_usable_size
        malloc_usable_size
INDEX
INDEX
        _malloc_r
        _malloc_r
INDEX
INDEX
        _realloc_r
        _realloc_r
INDEX
INDEX
        _free_r
        _free_r
INDEX
INDEX
        _memalign_r
        _memalign_r
INDEX
INDEX
        _malloc_usable_size_r
        _malloc_usable_size_r
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdlib.h>
        #include <stdlib.h>
        void *malloc(size_t <[nbytes]>);
        void *malloc(size_t <[nbytes]>);
        void *realloc(void *<[aptr]>, size_t <[nbytes]>);
        void *realloc(void *<[aptr]>, size_t <[nbytes]>);
        void free(void *<[aptr]>);
        void free(void *<[aptr]>);
 
 
        void *memalign(size_t <[align]>, size_t <[nbytes]>);
        void *memalign(size_t <[align]>, size_t <[nbytes]>);
 
 
        size_t malloc_usable_size(void *<[aptr]>);
        size_t malloc_usable_size(void *<[aptr]>);
 
 
        void *_malloc_r(void *<[reent]>, size_t <[nbytes]>);
        void *_malloc_r(void *<[reent]>, size_t <[nbytes]>);
        void *_realloc_r(void *<[reent]>,
        void *_realloc_r(void *<[reent]>,
                         void *<[aptr]>, size_t <[nbytes]>);
                         void *<[aptr]>, size_t <[nbytes]>);
        void _free_r(void *<[reent]>, void *<[aptr]>);
        void _free_r(void *<[reent]>, void *<[aptr]>);
 
 
        void *_memalign_r(void *<[reent]>,
        void *_memalign_r(void *<[reent]>,
                          size_t <[align]>, size_t <[nbytes]>);
                          size_t <[align]>, size_t <[nbytes]>);
 
 
        size_t _malloc_usable_size_r(void *<[reent]>, void *<[aptr]>);
        size_t _malloc_usable_size_r(void *<[reent]>, void *<[aptr]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <stdlib.h>
        #include <stdlib.h>
        char *malloc(<[nbytes]>)
        char *malloc(<[nbytes]>)
        size_t <[nbytes]>;
        size_t <[nbytes]>;
 
 
        char *realloc(<[aptr]>, <[nbytes]>)
        char *realloc(<[aptr]>, <[nbytes]>)
        char *<[aptr]>;
        char *<[aptr]>;
        size_t <[nbytes]>;
        size_t <[nbytes]>;
 
 
        void free(<[aptr]>)
        void free(<[aptr]>)
        char *<[aptr]>;
        char *<[aptr]>;
 
 
        char *memalign(<[align]>, <[nbytes]>)
        char *memalign(<[align]>, <[nbytes]>)
        size_t <[align]>;
        size_t <[align]>;
        size_t <[nbytes]>;
        size_t <[nbytes]>;
 
 
        size_t malloc_usable_size(<[aptr]>)
        size_t malloc_usable_size(<[aptr]>)
        char *<[aptr]>;
        char *<[aptr]>;
 
 
        char *_malloc_r(<[reent]>,<[nbytes]>)
        char *_malloc_r(<[reent]>,<[nbytes]>)
        char *<[reent]>;
        char *<[reent]>;
        size_t <[nbytes]>;
        size_t <[nbytes]>;
 
 
        char *_realloc_r(<[reent]>, <[aptr]>, <[nbytes]>)
        char *_realloc_r(<[reent]>, <[aptr]>, <[nbytes]>)
        char *<[reent]>;
        char *<[reent]>;
        char *<[aptr]>;
        char *<[aptr]>;
        size_t <[nbytes]>;
        size_t <[nbytes]>;
 
 
        void _free_r(<[reent]>, <[aptr]>)
        void _free_r(<[reent]>, <[aptr]>)
        char *<[reent]>;
        char *<[reent]>;
        char *<[aptr]>;
        char *<[aptr]>;
 
 
        char *_memalign_r(<[reent]>, <[align]>, <[nbytes]>)
        char *_memalign_r(<[reent]>, <[align]>, <[nbytes]>)
        char *<[reent]>;
        char *<[reent]>;
        size_t <[align]>;
        size_t <[align]>;
        size_t <[nbytes]>;
        size_t <[nbytes]>;
 
 
        size_t malloc_usable_size(<[reent]>, <[aptr]>)
        size_t malloc_usable_size(<[reent]>, <[aptr]>)
        char *<[reent]>;
        char *<[reent]>;
        char *<[aptr]>;
        char *<[aptr]>;
 
 
DESCRIPTION
DESCRIPTION
These functions manage a pool of system memory.
These functions manage a pool of system memory.
 
 
Use <<malloc>> to request allocation of an object with at least
Use <<malloc>> to request allocation of an object with at least
<[nbytes]> bytes of storage available.  If the space is available,
<[nbytes]> bytes of storage available.  If the space is available,
<<malloc>> returns a pointer to a newly allocated block as its result.
<<malloc>> returns a pointer to a newly allocated block as its result.
 
 
If you already have a block of storage allocated by <<malloc>>, but
If you already have a block of storage allocated by <<malloc>>, but
you no longer need all the space allocated to it, you can make it
you no longer need all the space allocated to it, you can make it
smaller by calling <<realloc>> with both the object pointer and the
smaller by calling <<realloc>> with both the object pointer and the
new desired size as arguments.  <<realloc>> guarantees that the
new desired size as arguments.  <<realloc>> guarantees that the
contents of the smaller object match the beginning of the original object.
contents of the smaller object match the beginning of the original object.
 
 
Similarly, if you need more space for an object, use <<realloc>> to
Similarly, if you need more space for an object, use <<realloc>> to
request the larger size; again, <<realloc>> guarantees that the
request the larger size; again, <<realloc>> guarantees that the
beginning of the new, larger object matches the contents of the
beginning of the new, larger object matches the contents of the
original object.
original object.
 
 
When you no longer need an object originally allocated by <<malloc>>
When you no longer need an object originally allocated by <<malloc>>
or <<realloc>> (or the related function <<calloc>>), return it to the
or <<realloc>> (or the related function <<calloc>>), return it to the
memory storage pool by calling <<free>> with the address of the object
memory storage pool by calling <<free>> with the address of the object
as the argument.  You can also use <<realloc>> for this purpose by
as the argument.  You can also use <<realloc>> for this purpose by
calling it with <<0>> as the <[nbytes]> argument.
calling it with <<0>> as the <[nbytes]> argument.
 
 
The <<memalign>> function returns a block of size <[nbytes]> aligned
The <<memalign>> function returns a block of size <[nbytes]> aligned
to a <[align]> boundary.  The <[align]> argument must be a power of
to a <[align]> boundary.  The <[align]> argument must be a power of
two.
two.
 
 
The <<malloc_usable_size>> function takes a pointer to a block
The <<malloc_usable_size>> function takes a pointer to a block
allocated by <<malloc>>.  It returns the amount of space that is
allocated by <<malloc>>.  It returns the amount of space that is
available in the block.  This may or may not be more than the size
available in the block.  This may or may not be more than the size
requested from <<malloc>>, due to alignment or minimum size
requested from <<malloc>>, due to alignment or minimum size
constraints.
constraints.
 
 
The alternate functions <<_malloc_r>>, <<_realloc_r>>, <<_free_r>>,
The alternate functions <<_malloc_r>>, <<_realloc_r>>, <<_free_r>>,
<<_memalign_r>>, and <<_malloc_usable_size_r>> are reentrant versions.
<<_memalign_r>>, and <<_malloc_usable_size_r>> are reentrant versions.
The extra argument <[reent]> is a pointer to a reentrancy structure.
The extra argument <[reent]> is a pointer to a reentrancy structure.
 
 
If you have multiple threads of execution which may call any of these
If you have multiple threads of execution which may call any of these
routines, or if any of these routines may be called reentrantly, then
routines, or if any of these routines may be called reentrantly, then
you must provide implementations of the <<__malloc_lock>> and
you must provide implementations of the <<__malloc_lock>> and
<<__malloc_unlock>> functions for your system.  See the documentation
<<__malloc_unlock>> functions for your system.  See the documentation
for those functions.
for those functions.
 
 
These functions operate by calling the function <<_sbrk_r>> or
These functions operate by calling the function <<_sbrk_r>> or
<<sbrk>>, which allocates space.  You may need to provide one of these
<<sbrk>>, which allocates space.  You may need to provide one of these
functions for your system.  <<_sbrk_r>> is called with a positive
functions for your system.  <<_sbrk_r>> is called with a positive
value to allocate more space, and with a negative value to release
value to allocate more space, and with a negative value to release
previously allocated space if it is no longer required.
previously allocated space if it is no longer required.
@xref{Stubs}.
@xref{Stubs}.
 
 
RETURNS
RETURNS
<<malloc>> returns a pointer to the newly allocated space, if
<<malloc>> returns a pointer to the newly allocated space, if
successful; otherwise it returns <<NULL>>.  If your application needs
successful; otherwise it returns <<NULL>>.  If your application needs
to generate empty objects, you may use <<malloc(0)>> for this purpose.
to generate empty objects, you may use <<malloc(0)>> for this purpose.
 
 
<<realloc>> returns a pointer to the new block of memory, or <<NULL>>
<<realloc>> returns a pointer to the new block of memory, or <<NULL>>
if a new block could not be allocated.  <<NULL>> is also the result
if a new block could not be allocated.  <<NULL>> is also the result
when you use `<<realloc(<[aptr]>,0)>>' (which has the same effect as
when you use `<<realloc(<[aptr]>,0)>>' (which has the same effect as
`<<free(<[aptr]>)>>').  You should always check the result of
`<<free(<[aptr]>)>>').  You should always check the result of
<<realloc>>; successful reallocation is not guaranteed even when
<<realloc>>; successful reallocation is not guaranteed even when
you request a smaller object.
you request a smaller object.
 
 
<<free>> does not return a result.
<<free>> does not return a result.
 
 
<<memalign>> returns a pointer to the newly allocated space.
<<memalign>> returns a pointer to the newly allocated space.
 
 
<<malloc_usable_size>> returns the usable size.
<<malloc_usable_size>> returns the usable size.
 
 
PORTABILITY
PORTABILITY
<<malloc>>, <<realloc>>, and <<free>> are specified by the ANSI C
<<malloc>>, <<realloc>>, and <<free>> are specified by the ANSI C
standard, but other conforming implementations of <<malloc>> may
standard, but other conforming implementations of <<malloc>> may
behave differently when <[nbytes]> is zero.
behave differently when <[nbytes]> is zero.
 
 
<<memalign>> is part of SVR4.
<<memalign>> is part of SVR4.
 
 
<<malloc_usable_size>> is not portable.
<<malloc_usable_size>> is not portable.
 
 
Supporting OS subroutines required: <<sbrk>>.  */
Supporting OS subroutines required: <<sbrk>>.  */
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <reent.h>
#include <reent.h>
#include <stdlib.h>
#include <stdlib.h>
#include <malloc.h>
#include <malloc.h>
 
 
#ifndef _REENT_ONLY
#ifndef _REENT_ONLY
 
 
_PTR
_PTR
_DEFUN (malloc, (nbytes),
_DEFUN (malloc, (nbytes),
        size_t nbytes)          /* get a block */
        size_t nbytes)          /* get a block */
{
{
  return _malloc_r (_REENT, nbytes);
  return _malloc_r (_REENT, nbytes);
}
}
 
 
void
void
_DEFUN (free, (aptr),
_DEFUN (free, (aptr),
        _PTR aptr)
        _PTR aptr)
{
{
  _free_r (_REENT, aptr);
  _free_r (_REENT, aptr);
}
}
 
 
#endif
#endif
 
 
#endif /* ! defined (MALLOC_PROVIDED) */
#endif /* ! defined (MALLOC_PROVIDED) */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.