Use xalignalloc
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.
This commit is contained in:
@@ -119,6 +119,7 @@ unlinkdir
|
||||
unlocked-io
|
||||
utimensat
|
||||
version-etc-fsf
|
||||
xalignalloc
|
||||
xalloc
|
||||
xalloc-die
|
||||
xgetcwd
|
||||
|
||||
13
src/buffer.c
13
src/buffer.c
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <alignalloc.h>
|
||||
#include <c-ctype.h>
|
||||
#include <closeout.h>
|
||||
#include <fnmatch.h>
|
||||
@@ -45,7 +46,6 @@
|
||||
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
|
||||
@@ -665,11 +665,10 @@ xclose (int fd)
|
||||
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;
|
||||
}
|
||||
@@ -1139,8 +1138,8 @@ close_archive (void)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -766,7 +766,6 @@ _Noreturn void write_fatal (char const *name);
|
||||
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);
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
#include <alignalloc.h>
|
||||
#include <quotearg.h>
|
||||
#include <rmt.h>
|
||||
#include <stdarg.h>
|
||||
@@ -48,8 +49,7 @@ static char *diff_buffer;
|
||||
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 ();
|
||||
}
|
||||
|
||||
27
src/misc.c
27
src/misc.c
@@ -1216,33 +1216,6 @@ xpipe (int fd[2])
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct namebuf
|
||||
|
||||
Reference in New Issue
Block a user