Wolfgang Thallerfix newlibec13cc97 years agoHistory
175 lines · 5.4 KB · C
RawDownload
/* 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   not compile this code.  */ /* The routines here are simple cover fns to the routines that do the real   work (the reentrant versions).  *//* 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*   thread?  */ #ifdef MALLOC_PROVIDED int _dummy_malloc = 1; #else /*FUNCTION<<malloc>>, <<realloc>>, <<free>>---manage memory INDEX	mallocINDEX	reallocINDEX	reallocfINDEX	freeINDEX	memalignINDEX	malloc_usable_sizeINDEX	_malloc_rINDEX	_realloc_rINDEX	_reallocf_rINDEX	_free_rINDEX	_memalign_rINDEX	_malloc_usable_size_r SYNOPSIS	#include <stdlib.h>	void *malloc(size_t <[nbytes]>);	void *realloc(void *<[aptr]>, size_t <[nbytes]>);	void *reallocf(void *<[aptr]>, size_t <[nbytes]>);	void free(void *<[aptr]>); 	void *memalign(size_t <[align]>, size_t <[nbytes]>); 	size_t malloc_usable_size(void *<[aptr]>); 	void *_malloc_r(void *<[reent]>, size_t <[nbytes]>);	void *_realloc_r(void *<[reent]>,                          void *<[aptr]>, size_t <[nbytes]>);	void *_reallocf_r(void *<[reent]>,                          void *<[aptr]>, size_t <[nbytes]>);	void _free_r(void *<[reent]>, void *<[aptr]>); 	void *_memalign_r(void *<[reent]>,			  size_t <[align]>, size_t <[nbytes]>); 	size_t _malloc_usable_size_r(void *<[reent]>, void *<[aptr]>); DESCRIPTIONThese functions manage a pool of system memory. Use <<malloc>> to request allocation of an object with at least<[nbytes]> bytes of storage available.  If the space is available,<<malloc>> returns a pointer to a newly allocated block as its result. If you already have a block of storage allocated by <<malloc>>, butyou no longer need all the space allocated to it, you can make itsmaller by calling <<realloc>> with both the object pointer and thenew desired size as arguments.  <<realloc>> guarantees that thecontents of the smaller object match the beginning of the original object. Similarly, if you need more space for an object, use <<realloc>> torequest the larger size; again, <<realloc>> guarantees that thebeginning of the new, larger object matches the contents of theoriginal object. When you no longer need an object originally allocated by <<malloc>>or <<realloc>> (or the related function <<calloc>>), return it to thememory storage pool by calling <<free>> with the address of the objectas the argument.  You can also use <<realloc>> for this purpose bycalling it with <<0>> as the <[nbytes]> argument. The <<reallocf>> function behaves just like <<realloc>> except if thefunction is required to allocate new storage and this fails.  In thiscase <<reallocf>> will free the original object passed in whereas<<realloc>> will not. The <<memalign>> function returns a block of size <[nbytes]> alignedto a <[align]> boundary.  The <[align]> argument must be a power oftwo. The <<malloc_usable_size>> function takes a pointer to a blockallocated by <<malloc>>.  It returns the amount of space that isavailable in the block.  This may or may not be more than the sizerequested from <<malloc>>, due to alignment or minimum sizeconstraints. The alternate functions <<_malloc_r>>, <<_realloc_r>>, <<_reallocf_r>>, <<_free_r>>, <<_memalign_r>>, and <<_malloc_usable_size_r>> are reentrantversions.  The extra argument <[reent]> is a pointer to a reentrancy structure. If you have multiple threads of execution which may call any of theseroutines, or if any of these routines may be called reentrantly, thenyou must provide implementations of the <<__malloc_lock>> and<<__malloc_unlock>> functions for your system.  See the documentationfor those functions. These functions operate by calling the function <<_sbrk_r>> or<<sbrk>>, which allocates space.  You may need to provide one of thesefunctions for your system.  <<_sbrk_r>> is called with a positivevalue to allocate more space, and with a negative value to releasepreviously allocated space if it is no longer required.@xref{Stubs}. RETURNS<<malloc>> returns a pointer to the newly allocated space, ifsuccessful; otherwise it returns <<NULL>>.  If your application needsto generate empty objects, you may use <<malloc(0)>> for this purpose. <<realloc>> returns a pointer to the new block of memory, or <<NULL>>if a new block could not be allocated.  <<NULL>> is also the resultwhen you use `<<realloc(<[aptr]>,0)>>' (which has the same effect as`<<free(<[aptr]>)>>').  You should always check the result of<<realloc>>; successful reallocation is not guaranteed even whenyou request a smaller object. <<free>> does not return a result. <<memalign>> returns a pointer to the newly allocated space. <<malloc_usable_size>> returns the usable size. PORTABILITY<<malloc>>, <<realloc>>, and <<free>> are specified by the ANSI Cstandard, but other conforming implementations of <<malloc>> maybehave differently when <[nbytes]> is zero. <<memalign>> is part of SVR4. <<malloc_usable_size>> is not portable. Supporting OS subroutines required: <<sbrk>>.  */ #include <_ansi.h>#include <reent.h>#include <stdlib.h>#include <malloc.h> #ifndef _REENT_ONLY void *malloc (size_t nbytes)		/* get a block */{  return _malloc_r (_REENT, nbytes);} voidfree (void *aptr){  _free_r (_REENT, aptr);} #endif #endif /* ! defined (MALLOC_PROVIDED) */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t