Re: custom memory manager..



Hi,

I am developing a user level memory manager for a protocol stack. It
will replace the usual malloc() by something like my_malloc() and free
by my_free(). The basic idea is to minimize the chances of memory non-
avaliabiltiy, minimize system calls at run time thereby minimizing
risk for failure, and use the memeory in an effcient way.

To say somthing stupid: use Malloc and Free. They're really good ;-)

The problem is i donot want to change the prototype of my_malloc which
is currently same as malloc() but I also want to associate debug
information along wth every buffer allocated.

OK, here's a sample solution:
In your Memory manager keep track of things. You can add some data to
each memory block by malloc'ing a few (sizeof int) bytes more, writing
the size of the chunk to those bytes and returning the pointer to the
chunk, increased by the few bytes. In your Free, decrease the pointer,
read the info and release the memory.

See it as a finger exercise ;-)

Ciao...
.



Relevant Pages

  • The Malloc Maleficarum
    ... Glibc Malloc Exploitation Techniques ... the exploitation of overflowed dynamic memory chunks on Linux. ... I have the House of Prime. ... a malloc chunk. ...
    (Bugtraq)
  • [Full-disclosure] The Malloc Maleficarum
    ... Glibc Malloc Exploitation Techniques ... the exploitation of overflowed dynamic memory chunks on Linux. ... I have the House of Prime. ... a malloc chunk. ...
    (Full-Disclosure)
  • Re: sizeof(ptr) = ?
    ... The value returned by malloc() is of type 'void*', ... The memory is typeless until an object has been written ... Since 'void' is defined to be an incomplete ... an lvalue of a complete type, there must be a pointer conversion ...
    (comp.lang.c)
  • Re: memory allocation wrapper
    ... I've written a wrapper for malloc and friends. ... The reason for doing writing this so that newbies ... How do I know how much memory a pointer points to? ...
    (comp.lang.c)
  • Re: 2D array of structures
    ... Don't cast the return value of malloc(), ... you allocate here memory for 7 such structures. ... a pointer to the start of this memory, which is of type 'STRUCTURE *' ...
    (comp.lang.c)