It ports around issues that our handwritten code does not.
* gnulib.modules: Add xalignalloc.
* src/misc.c (ptr_align, page_aligned_alloc): Remove.
All page_aligned_alloc callers changed to use xalignalloc.
unlocked-io
utimensat
version-etc-fsf
+xalignalloc
xalloc
xalloc-die
xgetcwd
#include <signal.h>
+#include <alignalloc.h>
#include <c-ctype.h>
#include <closeout.h>
#include <fnmatch.h>
static tarlong prev_written; /* bytes written on previous volumes */
static tarlong bytes_written; /* bytes written on this volume */
static void *record_buffer[2]; /* allocated memory */
-static union block *record_buffer_aligned[2];
static int record_index;
/* FIXME: The following variables should ideally be static to this
static void
init_buffer (void)
{
- if (! record_buffer_aligned[record_index])
- record_buffer_aligned[record_index] =
- page_aligned_alloc (&record_buffer[record_index], record_size);
+ if (! record_buffer[record_index])
+ record_buffer[record_index] = xalignalloc (getpagesize (), record_size);
- record_start = record_buffer_aligned[record_index];
+ record_start = record_buffer[record_index];
current_block = record_start;
record_end = record_start + blocking_factor;
}
sys_wait_for_child (child_pid, hit_eof);
tar_stat_destroy (¤t_stat_info);
- free (record_buffer[0]);
- free (record_buffer[1]);
+ alignfree (record_buffer[0]);
+ alignfree (record_buffer[1]);
bufmap_free (NULL);
}
pid_t xfork (void);
void xpipe (int fd[2]);
-void *page_aligned_alloc (void **ptr, size_t size);
int set_file_atime (int fd, int parentfd, char const *file,
struct timespec atime);
#endif
#include "common.h"
+#include <alignalloc.h>
#include <quotearg.h>
#include <rmt.h>
#include <stdarg.h>
void
diff_init (void)
{
- void *ptr;
- diff_buffer = page_aligned_alloc (&ptr, record_size);
+ diff_buffer = xalignalloc (getpagesize (), record_size);
if (listed_incremental_option)
read_directory_file ();
}
call_arg_fatal ("pipe", _("interprocess channel"));
}
-/* Return PTR, aligned upward to the next multiple of ALIGNMENT.
- ALIGNMENT must be nonzero. The caller must arrange for ((char *)
- PTR) through ((char *) PTR + ALIGNMENT - 1) to be addressable
- locations. */
-
-static void *
-ptr_align (void *ptr, size_t alignment)
-{
- char *p0 = ptr;
- char *p1 = p0 + alignment - 1;
- return p1 - (size_t) p1 % alignment;
-}
-
-/* Return the address of a page-aligned buffer of at least SIZE bytes.
- The caller should free *PTR when done with the buffer. */
-
-void *
-page_aligned_alloc (void **ptr, size_t size)
-{
- size_t alignment = getpagesize ();
- size_t size1;
- if (ckd_add (&size1, size, alignment))
- xalloc_die ();
- *ptr = xmalloc (size1);
- return ptr_align (*ptr, alignment);
-}
-
\f
struct namebuf