diff options
| author | mlelstv <mlelstv@NetBSD.org> | 2019-03-23 09:33:16 +0000 |
|---|---|---|
| committer | mlelstv <mlelstv@NetBSD.org> | 2019-03-23 09:33:16 +0000 |
| commit | 4d638bd54e3ec6a319aa6cdc2c82db9f8eea138b (patch) | |
| tree | 3413a415c572c3619ced060ca6ef3888ec5df732 /bin | |
| parent | dac8ad71f389f3dc3a4ba8e372abf6d45653ea5e (diff) | |
When buffers are at least page sized, explicitely request page alignment.
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/dd/dd.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/bin/dd/dd.c b/bin/dd/dd.c index c4fb1e87b9f..9c1720d2369 100644 --- a/bin/dd/dd.c +++ b/bin/dd/dd.c @@ -1,4 +1,4 @@ -/* $NetBSD: dd.c,v 1.51 2016/09/05 01:00:07 sevan Exp $ */ +/* $NetBSD: dd.c,v 1.52 2019/03/23 09:33:16 mlelstv Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\ #if 0 static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94"; #else -__RCSID("$NetBSD: dd.c,v 1.51 2016/09/05 01:00:07 sevan Exp $"); +__RCSID("$NetBSD: dd.c,v 1.52 2019/03/23 09:33:16 mlelstv Exp $"); #endif #endif /* not lint */ @@ -72,6 +72,7 @@ static void dd_in(void); static void getfdtype(IO *); static void redup_clean_fd(IO *); static void setup(void); +static void *buffer_alloc(size_t); IO in, out; /* input/output state */ STAT st; /* statistics */ @@ -150,6 +151,20 @@ main(int argc, char *argv[]) /* NOTREACHED */ } +static void * +buffer_alloc(size_t sz) +{ + size_t align = getpagesize(); + void *res; + + if (sz < align) + res = malloc(sz); + else if (posix_memalign(&res, align, sz) != 0) + res = NULL; + + return res; +} + static void setup(void) { @@ -233,14 +248,14 @@ setup(void) size_t dbsz = out.dbsz; if (!(ddflags & C_BS)) dbsz += in.dbsz - 1; - if ((in.db = malloc(dbsz)) == NULL) { + if ((in.db = buffer_alloc(dbsz)) == NULL) { err(EXIT_FAILURE, NULL); /* NOTREACHED */ } out.db = in.db; } else if ((in.db = - malloc((u_int)(MAX(in.dbsz, cbsz) + cbsz))) == NULL || - (out.db = malloc((u_int)(out.dbsz + cbsz))) == NULL) { + buffer_alloc((u_int)(MAX(in.dbsz, cbsz) + cbsz))) == NULL || + (out.db = buffer_alloc((u_int)(out.dbsz + cbsz))) == NULL) { err(EXIT_FAILURE, NULL); /* NOTREACHED */ } |
