This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Custom malloc/mmap for x86_64


On Saturday 28 April 2012 19:47:19 Daniel wrote:
> Thank you guys for your quick replies. I have a separate library already
> working independently that supports my work. I was asked to migrate
>  it to glibc to provide an actual implementation and deploy it on a
> real system.
> 
> So to answer your questions: my_malloc and malloc, as well as
> my_mmap and mmap all have to be supported and may be called
> at any time. Whenever free() is called, it works perfectly since both
>  malloc and my_malloc operate over the same data structures,
> so I do not have to worry about keeping track of space that way.
> Moreover, malloc and my_malloc can grow the same
> heap/virtual address space for the given process.
> 
> So, basically, we just need to overload the above methods. I do not want
> to overwrite mmap nor malloc. I know how to do that via the -wrap flag
> as you guys mentioned. I also know about LD_PRELOAD variable.

if you want the whole system to use the wrappers and not just one or two apps, 
then you can use /etc/ld.so.preload.  every ELF that runs will first check that 
file and load any libs listed in it.

> But, back to my old question. Out of curiosity because I like to
>  know how things really work. How does glibc exaclty generate
>  wrappers for mmap, munmap, et al.?
> 
> I know the make-syscals.sh script creates syscall wrappers for
>  the methods specified in syscalls.list. But when I looked in there
>  I did not see mmap, munmap, sbrk, etc.

maybe you looked in the wrong syscalls.list file ?  these files stack, so you 
have to look at all the ones that come into play for your target.
$ find -name syscalls.list -exec grep mmap {} +
sysdeps/unix/sysv/linux/syscalls.list:
mmap	-	mmap	b:aniiii	__mmap	mmap
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


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