summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2023-07-04 15:06:28 +0000
committerriastradh <riastradh@NetBSD.org>2023-07-04 15:06:28 +0000
commitf9baae5e2b34873478cf545917ec3fa4978cf1cb (patch)
tree8a462b62e98c5981cd4463f0eaa83b6d10e22e8f
parent731af302671ca669d395667672a742de34ef7743 (diff)
jemalloc: Enforce alignment-must-divide-size rule of aligned_alloc.
C11, Sec. 7.22.3.1 The aligned_alloc function, paragraph 2, p. 348: The value of alignment shall be a valid alignment supported by the implementation and the value of size shall be an integral multiple of alignment. posix_memalign does not appear to have any corresponding constraint. XXX pullup-10
-rw-r--r--external/bsd/jemalloc/dist/src/jemalloc.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/external/bsd/jemalloc/dist/src/jemalloc.c b/external/bsd/jemalloc/dist/src/jemalloc.c
index f5800a3fbc9..0007d3fe41a 100644
--- a/external/bsd/jemalloc/dist/src/jemalloc.c
+++ b/external/bsd/jemalloc/dist/src/jemalloc.c
@@ -1635,6 +1635,9 @@ struct static_opts_s {
/* Whether to set errno when we encounter an error condition. */
bool set_errno_on_error;
+ /* Whether the alignment must divide the size. */
+ bool alignment_must_divide_size;
+
/*
* The minimum valid alignment for functions requesting aligned storage.
*/
@@ -1662,6 +1665,7 @@ static_opts_init(static_opts_t *static_opts) {
static_opts->assert_nonempty_alloc = false;
static_opts->null_out_result_on_error = false;
static_opts->set_errno_on_error = false;
+ static_opts->alignment_must_divide_size = false;
static_opts->min_alignment = 0;
static_opts->oom_string = "";
static_opts->invalid_alignment_string = "";
@@ -1857,6 +1861,11 @@ imalloc_body(static_opts_t *sopts, dynamic_opts_t *dopts, tsd_t *tsd) {
|| (dopts->alignment & (dopts->alignment - 1)) != 0)) {
goto label_invalid_alignment;
}
+ if (sopts->alignment_must_divide_size) {
+ if (unlikely(dopts->item_size % dopts->alignment)) {
+ goto label_invalid_alignment;
+ }
+ }
/* This is the beginning of the "core" algorithm. */
@@ -2125,6 +2134,7 @@ je_aligned_alloc(size_t alignment, size_t size) {
sopts.bump_empty_alloc = true;
sopts.null_out_result_on_error = true;
sopts.set_errno_on_error = true;
+ sopts.alignment_must_divide_size = true;
sopts.min_alignment = 1;
sopts.oom_string =
"<jemalloc>: Error allocating aligned memory: out of memory\n";