This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] tst-rec-dlopen: Use custom malloc instead of hooks
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Fri, 20 May 2016 15:53:47 -0300
- Subject: Re: [PATCH] tst-rec-dlopen: Use custom malloc instead of hooks
- Authentication-results: sourceware.org; auth=none
- References: <20160510143805 dot 6AA4141C38D19 at oldenburg dot str dot redhat dot com>
LGTM with some comments:
On 10/05/2016 11:38, Florian Weimer wrote:
> +size_t
> +malloc_usable_size (void *ptr)
> +{
> + struct chunk_header *chunk = ptr - sizeof (struct chunk_header);
> + return chunk->chunk_size;
> +}
> +
> +void *
> +realloc (void *ptr, size_t size)
> +{
> + size_t old_size = malloc_usable_size (ptr);
> + size_t to_copy;
> + if (old_size < size)
> + to_copy = old_size;
> + else
> + to_copy = size;
> + void *newptr = malloc_internal (size);
> + if (newptr == NULL)
> + return NULL;
> + memcpy (newptr, ptr, to_copy);
> + return newptr;
> +}
> +
> +void *
> +memalign (size_t alignment, size_t size)
> +{
> + if (alignment > __alignof__ (struct chunk_header))
> + {
> + if (size < size + __alignof__ (struct chunk_header))
> + return NULL;
> + void *result = malloc_internal
> + (size + __alignof__ (struct chunk_header));
> + if (result == NULL)
> + return NULL;
> + uintptr_t bits = (uintptr_t) result;
> + /* Round up to the next multiple of he alignment. */
> + bits += __alignof__ (struct chunk_header) - 1;
> + bits &= ~(__alignof__ (struct chunk_header) - 1);
> + result = (void *) bits;
> + struct chunk_header *chunk = result - sizeof (struct chunk_header);
> + chunk->chunk_size = size;
> + return result;
> + }
> + return malloc_internal (size);
> +}
>
Since the idea is simulate the hooks for malloc/free, do we still need to add
all this code to be used on this single test?