mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 10:10:06 +00:00
Use proper padding instead of using alignas()
As it was pointed out, the alignas() can't be used on objects larger than `max_align_t` otherwise the compiler might miscompile the code to use auto-vectorization on unaligned memory. As we were only using alignas() as a way to prevent false memory sharing, we can use manual padding in the affected structures.
This commit is contained in:
parent
05e60a0af6
commit
2463e5232d
@ -388,7 +388,7 @@ AC_COMPILE_IFELSE(
|
||||
],
|
||||
[AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])])
|
||||
|
||||
AC_CHECK_HEADERS([stdalign.h stdnoreturn.h],
|
||||
AC_CHECK_HEADERS([stdnoreturn.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([C11 standard headers not found, update your toolchain.])])
|
||||
|
||||
|
@ -4,7 +4,6 @@ lib_LTLIBRARIES = libisc.la
|
||||
|
||||
libisc_ladir = $(includedir)/isc
|
||||
libisc_la_HEADERS = \
|
||||
include/isc/align.h \
|
||||
include/isc/ascii.h \
|
||||
include/isc/assertions.h \
|
||||
include/isc/async.h \
|
||||
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HAVE_STDALIGN_H
|
||||
#include <stdalign.h>
|
||||
#else /* ifdef HAVE_STDALIGN_H */
|
||||
#define alignas(x) __attribute__((__aligned__(x)))
|
||||
#endif /* ifdef HAVE_STDALIGN_H */
|
@ -30,7 +30,6 @@
|
||||
*** Imports.
|
||||
***/
|
||||
|
||||
#include <isc/align.h>
|
||||
#include <isc/atomic.h>
|
||||
#include <isc/job.h>
|
||||
#include <isc/lang.h>
|
||||
@ -57,14 +56,19 @@ ISC_LANG_BEGINDECLS
|
||||
* synchronization between multiple threads (see urcu/wfcqueue.h for
|
||||
* detailed description).
|
||||
*/
|
||||
STATIC_ASSERT(ISC_OS_CACHELINE_SIZE >= sizeof(struct __cds_wfcq_head),
|
||||
"ISC_OS_CACHELINE_SIZE smaller than "
|
||||
"sizeof(struct __cds_wfcq_head)");
|
||||
struct isc_quota {
|
||||
int magic;
|
||||
atomic_uint_fast32_t max;
|
||||
atomic_uint_fast32_t used;
|
||||
atomic_uint_fast32_t soft;
|
||||
struct {
|
||||
alignas(ISC_OS_CACHELINE_SIZE) struct cds_wfcq_head head;
|
||||
alignas(ISC_OS_CACHELINE_SIZE) struct cds_wfcq_tail tail;
|
||||
struct cds_wfcq_head head;
|
||||
uint8_t __padding[ISC_OS_CACHELINE_SIZE -
|
||||
sizeof(struct __cds_wfcq_head)];
|
||||
struct cds_wfcq_tail tail;
|
||||
} jobs;
|
||||
ISC_LINK(isc_quota_t) link;
|
||||
};
|
||||
|
@ -161,15 +161,23 @@ typedef pthread_rwlock_t isc__rwlock_t;
|
||||
|
||||
#else /* USE_PTHREAD_RWLOCK */
|
||||
|
||||
#include <isc/align.h>
|
||||
#include <isc/atomic.h>
|
||||
#include <isc/os.h>
|
||||
|
||||
STATIC_ASSERT(ISC_OS_CACHELINE_SIZE >= sizeof(atomic_uint_fast32_t),
|
||||
"ISC_OS_CACHELINE_SIZE smaller than "
|
||||
"sizeof(atomic_uint_fast32_t)");
|
||||
STATIC_ASSERT(ISC_OS_CACHELINE_SIZE >= sizeof(atomic_int_fast32_t),
|
||||
"ISC_OS_CACHELINE_SIZE smaller than sizeof(atomic_int_fast32_t)");
|
||||
|
||||
struct isc_rwlock {
|
||||
alignas(ISC_OS_CACHELINE_SIZE) atomic_uint_fast32_t readers_ingress;
|
||||
alignas(ISC_OS_CACHELINE_SIZE) atomic_uint_fast32_t readers_egress;
|
||||
alignas(ISC_OS_CACHELINE_SIZE) atomic_int_fast32_t writers_barrier;
|
||||
alignas(ISC_OS_CACHELINE_SIZE) atomic_bool writers_lock;
|
||||
atomic_uint_fast32_t readers_ingress;
|
||||
uint8_t __padding1[ISC_OS_CACHELINE_SIZE - sizeof(atomic_uint_fast32_t)];
|
||||
atomic_uint_fast32_t readers_egress;
|
||||
uint8_t __padding2[ISC_OS_CACHELINE_SIZE - sizeof(atomic_uint_fast32_t)];
|
||||
atomic_int_fast32_t writers_barrier;
|
||||
uint8_t __padding3[ISC_OS_CACHELINE_SIZE - sizeof(atomic_int_fast32_t)];
|
||||
atomic_bool writers_lock;
|
||||
};
|
||||
|
||||
typedef struct isc_rwlock isc_rwlock_t;
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <isc/align.h>
|
||||
#include <isc/job.h>
|
||||
#include <isc/loop.h>
|
||||
#include <isc/os.h>
|
||||
@ -24,9 +23,15 @@
|
||||
* mutex, because we are only using enqueue and splice, and those don't need
|
||||
* any synchronization (see urcu/wfcqueue.h for detailed description).
|
||||
*/
|
||||
STATIC_ASSERT(ISC_OS_CACHELINE_SIZE >= sizeof(struct __cds_wfcq_head),
|
||||
"ISC_OS_CACHELINE_SIZE smaller than "
|
||||
"sizeof(struct __cds_wfcq_head)");
|
||||
|
||||
typedef struct isc_jobqueue {
|
||||
alignas(ISC_OS_CACHELINE_SIZE) struct __cds_wfcq_head head;
|
||||
alignas(ISC_OS_CACHELINE_SIZE) struct cds_wfcq_tail tail;
|
||||
struct __cds_wfcq_head head;
|
||||
uint8_t __padding[ISC_OS_CACHELINE_SIZE -
|
||||
sizeof(struct __cds_wfcq_head)];
|
||||
struct cds_wfcq_tail tail;
|
||||
} isc_jobqueue_t;
|
||||
|
||||
typedef ISC_LIST(isc_job_t) isc_joblist_t;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <isc/align.h>
|
||||
#include <isc/hash.h>
|
||||
#include <isc/magic.h>
|
||||
#include <isc/mem.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user