delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/03/05/12:14:08

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f
Date: Tue, 05 Mar 2002 19:11:34 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp-workers AT delorie DOT com
Message-Id: <7263-Tue05Mar2002191133+0200-eliz@is.elta.co.il>
X-Mailer: emacs 21.2.50 (via feedmail 8 I) and Blat ver 1.8.9
In-reply-to: <3C84C626.7E259569@yahoo.com> (message from CBFalconer on Tue, 05
Mar 2002 08:20:38 -0500)
Subject: Re: Malloc/free DJGPP code
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1020305101637 DOT 18873A AT is> <3C84C626 DOT 7E259569 AT yahoo DOT com>
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> Date: Tue, 05 Mar 2002 08:20:38 -0500
> From: CBFalconer <cbfalconer AT yahoo DOT com>
> > 
> > That was just an example.  A hook is more general than any specific code,
> > because it allows a programmer to implement many features that the
> > original author never had in mind.
> 
> Nothing prevents you implementing a hook.  You have lost nothing
> compared to the present methods, but have gained the ability to
> see inside the system, with a minimum of danger.  In fact existing
> hook implementations that intercept malloc etc. calls and record
> parameters and return values should continue to work unchanged. 
> The only exception is where they make unclean assumptions about
> internal structure, which they can now find automatically and
> correctly.

Sorry, I don't understand: these are very general statements, whereas
I was looking for a specific technical answer.  Could you please
elaborate?

What I had in mind was this: if malloc, realloc, and free call
certain hooks in strategic places, then a programmer can use those
hooks to implement additional features without any modifications to
the source of the library functions.  If there are no such hooks,
what is the alternative method you offer in your implementation for
getting the same functionality?

Here's an example from the version of malloc in CVS:

    void *
    malloc(size_t size)
    {
      int b, chunk_size;
      BLOCK *rv, **prev;
      static BLOCK *expected_sbrk = 0;

      /* Refuse ridiculously large requests right away.  Anything beyond
	 2GB will be treated by sbrk as a negative request, i.e. as a
	 request to _decrease_ the heap size.  */
      if (size > 0x7fffffffU - 0x10000U) /* sbrk rounds up to 64KB */
      {
	if (__libc_malloc_fail_hook)
	  __libc_malloc_fail_hook(size);
	return 0;
      }

Here you see that a programmer could point __libc_malloc_fail_hook to
some function, and that function will then get called when malloc is
about to fail.  That hook could, for example, gather statistics about
failed malloc calls.

How can I do this with your implementation?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019