This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

user defined malloc



I originally posted a message to the cygiwn mailing list and it was
suggested that I also post it here.  The original message is included
below.  

Basically, I am trying to find out if it is possible to provide my own
version of malloc?  If so, does this also require _malloc_r to be
overriden (see message below?.  And finally, if someone can provide some
information or a link on what is required to override _malloc_r (if it is
necessary). 


thanks,
ashif harji.

Original message to cygwin mailing list:

To: cygwin@sourceware.cygnus.com
Subject: user defined malloc


It mentions in the faq that it is possible to override the default malloc
routine.  The problem that I am having is that there is at least one
occasion when my malloc routine is not called for memory allocation.
Instead the function _malloc_r is called directly.  This by passes my
malloc which results in already allocated memory being reallocated.

This direct call to _malloc_r occurs in the __sfmoreglue function in the
file findfp.c:

struct _glue *
__sfmoreglue (d, n)
     struct _reent *d;
     register int n;
{
  struct _glue *g;
  FILE *p;

  g = (struct _glue *) _malloc_r (d, sizeof (*g) + n * sizeof (FILE));
  if (g == NULL)
    return NULL;
  p = (FILE *) (g + 1);
  g->_next = NULL;
  g->_niobs = n;
  g->_iobs = p;
  memset (p, 0, n * sizeof (FILE));
  return g;
}

While I am not sure exactly what this function does, it appears to be
related to opening the /etc/passwd file and occurs even with an empty C++
program:

int main(){}


My question is do I have to also override the _malloc_r routine, and if
so, could someone provide some information or a link on what is required? 
It appears to be a reentrant version of malloc. 

thanks,
ashif harji.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]