+2019-03-07 Mark Wielaard <mark@klomp.org>
+
+ * elf32_updatefile.c (updatemmap): Use posix_memalign instead of
+ aligned_alloc.
+
2019-03-06 Mark Wielaard <mark@klomp.org>
* elf32_updatefile.c (updatemmap): Free scns before returning
else
{
/* We have to do the conversion on properly
- aligned memory first. */
+ aligned memory first. align is a power of 2,
+ but posix_memalign only works for alignments
+ which are a multiple of sizeof (void *).
+ So use normal malloc for smaller alignments. */
size_t size = dl->data.d.d_size;
- char *converted = aligned_alloc (align, size);
+ void *converted;
+ if (align < sizeof (void *))
+ converted = malloc (size);
+ else
+ {
+ int res;
+ res = posix_memalign (&converted, align, size);
+ if (res != 0)
+ converted = NULL;
+ }
+
if (converted == NULL)
{
free (scns);
__libelf_seterrno (ELF_E_NOMEM);
return 1;
}
- (*fctp) (converted, dl->data.d.d_buf, size, 1);
+
+ (*fctp) (converted, dl->data.d.d_buf, size, 1);
/* And then write it to the mmapped file. */
memcpy (last_position, converted, size);