Overriding malloc
Will Newton
will.newton@linaro.org
Tue Jul 1 08:56:00 GMT 2014
On 1 July 2014 09:28, Florian Weimer <fweimer@redhat.com> wrote:
> We need to support overriding malloc through LD_PRELOAD and other forms of
> symbol interposition. Once you override malloc, you also have to override
> free, realloc and calloc at least.
>
> If the application (or one of its libraries) uses posix_memalign etc., these
> have to be overridden as well. Same for the malloc_usable_size.
>
> The question is if overriding those should is required even if the
> application does not call those fringe malloc-related functions, i.e. if
> glibc should behave as if it never calls them if malloc has been overridden.
>
> If yes, we should likely remove the remaining call to malloc_usable_size
> from the code base.
Are you referring to the assert in nis/nss_nis/nis-netgrp.c?
Those asserts look rather dubious to me anyway, is there some reason
why we should expect yp_match to be broken in that way?
IMO malloc_usable_size should not be called from within glibc because
it is almost always a sign of bad code. A good subset of the allocator
functions to require to be overridden would be the union of C90, C11
and POSIX:
ISO C90
void *malloc(size_t size);
void free(void *ptr);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
ISO C11
void *aligned_alloc(size_t alignment, size_t size);
POSIX
int posix_memalign(void **memptr, size_t alignment, size_t size);
--
Will Newton
Toolchain Working Group, Linaro
More information about the Libc-alpha
mailing list