[PATCH] tst-rec-dlopen: Use custom malloc instead of hooks
Adhemerval Zanella
adhemerval.zanella@linaro.org
Fri May 20 19:46:00 GMT 2016
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?
More information about the Libc-alpha
mailing list