From 2aa70fff760911533eee75a263780c057ed80b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 28 Feb 2025 21:01:29 +0100 Subject: [PATCH 1/5] Remove unused isc_mutexblock and isc_condition units The isc_mutexblock and isc_condition units were no longer in use and were removed. --- bin/dig/nslookup.c | 1 - bin/named/fuzz.c | 1 - lib/dns/openssl_link.c | 1 - lib/isc/Makefile.am | 4 -- lib/isc/async.c | 1 - lib/isc/condition.c | 65 --------------------- lib/isc/helper.c | 1 - lib/isc/include/isc/condition.h | 97 -------------------------------- lib/isc/include/isc/mutexblock.h | 49 ---------------- lib/isc/job.c | 1 - lib/isc/loop.c | 1 - lib/isc/mutexblock.c | 35 ------------ lib/isc/netmgr/netmgr-int.h | 1 - lib/isc/netmgr/netmgr.c | 1 - lib/isc/netmgr/tcp.c | 1 - lib/isc/netmgr/tlsstream.c | 1 - lib/isc/netmgr/udp.c | 1 - lib/isc/timer.c | 1 - lib/isc/tls.c | 1 - tests/isc/doh_test.c | 1 - tests/isc/timer_test.c | 1 - 21 files changed, 266 deletions(-) delete mode 100644 lib/isc/condition.c delete mode 100644 lib/isc/include/isc/condition.h delete mode 100644 lib/isc/include/isc/mutexblock.h delete mode 100644 lib/isc/mutexblock.c diff --git a/bin/dig/nslookup.c b/bin/dig/nslookup.c index ca36291881..68116749dd 100644 --- a/bin/dig/nslookup.c +++ b/bin/dig/nslookup.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/bin/named/fuzz.c b/bin/named/fuzz.c index 25804892eb..9742590919 100644 --- a/bin/named/fuzz.c +++ b/bin/named/fuzz.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include diff --git a/lib/dns/openssl_link.c b/lib/dns/openssl_link.c index b693bc3789..9f06b54553 100644 --- a/lib/dns/openssl_link.c +++ b/lib/dns/openssl_link.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 4978ab4ed1..3ccee9a520 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -15,7 +15,6 @@ libisc_la_HEADERS = \ include/isc/base64.h \ include/isc/buffer.h \ include/isc/commandline.h \ - include/isc/condition.h \ include/isc/counter.h \ include/isc/crypto.h \ include/isc/dir.h \ @@ -51,7 +50,6 @@ libisc_la_HEADERS = \ include/isc/mem.h \ include/isc/meminfo.h \ include/isc/mutex.h \ - include/isc/mutexblock.h \ include/isc/net.h \ include/isc/netaddr.h \ include/isc/netmgr.h \ @@ -122,7 +120,6 @@ libisc_la_SOURCES = \ base32.c \ base64.c \ commandline.c \ - condition.c \ counter.c \ crypto.c \ dir.c \ @@ -159,7 +156,6 @@ libisc_la_SOURCES = \ meminfo.c \ mutex.c \ mutex_p.h \ - mutexblock.c \ net.c \ netaddr.c \ netscope.c \ diff --git a/lib/isc/async.c b/lib/isc/async.c index 351b213a14..acb5585e09 100644 --- a/lib/isc/async.c +++ b/lib/isc/async.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/condition.c b/lib/isc/condition.c deleted file mode 100644 index 722a599491..0000000000 --- a/lib/isc/condition.c +++ /dev/null @@ -1,65 +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. - */ - -/*! \file */ - -#include - -#include -#include -#include -#include -#include - -isc_result_t -isc__condition_waituntil(pthread_cond_t *c, pthread_mutex_t *m, isc_time_t *t) { - int presult; - isc_result_t result; - struct timespec ts; - - REQUIRE(c != NULL && m != NULL && t != NULL); - - /* - * POSIX defines a timespec's tv_sec as time_t. - */ - result = isc_time_secondsastimet(t, &ts.tv_sec); - - /* - * If we have a range error ts.tv_sec is most probably a signed - * 32 bit value. Set ts.tv_sec to INT_MAX. This is a kludge. - */ - if (result == ISC_R_RANGE) { - ts.tv_sec = INT_MAX; - } else if (result != ISC_R_SUCCESS) { - return result; - } - - /*! - * POSIX defines a timespec's tv_nsec as long. isc_time_nanoseconds - * ensures its return value is < 1 billion, which will fit in a long. - */ - ts.tv_nsec = (long)isc_time_nanoseconds(t); - - do { - presult = pthread_cond_timedwait(c, m, &ts); - if (presult == 0) { - return ISC_R_SUCCESS; - } - if (presult == ETIMEDOUT) { - return ISC_R_TIMEDOUT; - } - } while (presult == EINTR); - - UNEXPECTED_SYSERROR(presult, "pthread_cond_timedwait()"); - return ISC_R_UNEXPECTED; -} diff --git a/lib/isc/helper.c b/lib/isc/helper.c index f5a83cc833..1644c244ef 100644 --- a/lib/isc/helper.c +++ b/lib/isc/helper.c @@ -17,7 +17,6 @@ #include #include -#include #include #include #include diff --git a/lib/isc/include/isc/condition.h b/lib/isc/include/isc/condition.h deleted file mode 100644 index 27f2b80c73..0000000000 --- a/lib/isc/include/isc/condition.h +++ /dev/null @@ -1,97 +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 - -/*! \file */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -/* - * We use macros instead of static inline functions so that the exact code - * location can be reported when PTHREADS_RUNTIME_CHECK() fails or when mutrace - * reports lock contention. - */ - -#ifdef ISC_TRACK_PTHREADS_OBJECTS - -typedef pthread_cond_t *isc_condition_t; - -#define isc_condition_init(cp) \ - { \ - *cp = malloc(sizeof(**cp)); \ - isc__condition_init(*cp); \ - } -#define isc_condition_wait(cp, mp) isc__condition_wait(*cp, *mp) -#define isc_condition_waituntil(cp, mp, t) isc__condition_waituntil(*cp, *mp, t) -#define isc_condition_signal(cp) isc__condition_signal(*cp) -#define isc_condition_broadcast(cp) isc__condition_broadcast(*cp) -#define isc_condition_destroy(cp) \ - { \ - isc__condition_destroy(*cp); \ - free(*cp); \ - } - -#else /* ISC_TRACK_PTHREADS_OBJECTS */ - -typedef pthread_cond_t isc_condition_t; - -#define isc_condition_init(cond) isc__condition_init(cond) -#define isc_condition_wait(cp, mp) isc__condition_wait(cp, mp) -#define isc_condition_waituntil(cp, mp, t) isc__condition_waituntil(cp, mp, t) -#define isc_condition_signal(cp) isc__condition_signal(cp) -#define isc_condition_broadcast(cp) isc__condition_broadcast(cp) -#define isc_condition_destroy(cp) isc__condition_destroy(cp) - -#endif /* ISC_TRACK_PTHREADS_OBJECTS */ - -#define isc__condition_init(cond) \ - { \ - int _ret = pthread_cond_init(cond, NULL); \ - PTHREADS_RUNTIME_CHECK(pthread_cond_init, _ret); \ - } - -#define isc__condition_wait(cp, mp) \ - { \ - int _ret = pthread_cond_wait(cp, mp); \ - PTHREADS_RUNTIME_CHECK(pthread_cond_wait, _ret); \ - } - -#define isc__condition_signal(cp) \ - { \ - int _ret = pthread_cond_signal(cp); \ - PTHREADS_RUNTIME_CHECK(pthread_cond_signal, _ret); \ - } - -#define isc__condition_broadcast(cp) \ - { \ - int _ret = pthread_cond_broadcast(cp); \ - PTHREADS_RUNTIME_CHECK(pthread_cond_broadcast, _ret); \ - } - -#define isc__condition_destroy(cp) \ - { \ - int _ret = pthread_cond_destroy(cp); \ - PTHREADS_RUNTIME_CHECK(pthread_cond_destroy, _ret); \ - } - -isc_result_t -isc__condition_waituntil(pthread_cond_t *, pthread_mutex_t *, isc_time_t *); diff --git a/lib/isc/include/isc/mutexblock.h b/lib/isc/include/isc/mutexblock.h deleted file mode 100644 index 7251efe0e5..0000000000 --- a/lib/isc/include/isc/mutexblock.h +++ /dev/null @@ -1,49 +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 - -/*! \file isc/mutexblock.h */ - -#include -#include - -void -isc_mutexblock_init(isc_mutex_t *block, unsigned int count); -/*%< - * Initialize a block of locks. If an error occurs all initialized locks - * will be destroyed, if possible. - * - * Requires: - * - *\li block != NULL - * - *\li count > 0 - * - */ - -void -isc_mutexblock_destroy(isc_mutex_t *block, unsigned int count); -/*%< - * Destroy a block of locks. - * - * Requires: - * - *\li block != NULL - * - *\li count > 0 - * - *\li Each lock in the block be initialized via isc_mutex_init() or - * the whole block was initialized via isc_mutex_initblock(). - * - */ diff --git a/lib/isc/job.c b/lib/isc/job.c index 78bbb03d09..d715861ca4 100644 --- a/lib/isc/job.c +++ b/lib/isc/job.c @@ -17,7 +17,6 @@ #include #include -#include #include #include #include diff --git a/lib/isc/loop.c b/lib/isc/loop.c index d04c4cc4ad..c1f2b540b5 100644 --- a/lib/isc/loop.c +++ b/lib/isc/loop.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/mutexblock.c b/lib/isc/mutexblock.c deleted file mode 100644 index 56a29858ce..0000000000 --- a/lib/isc/mutexblock.c +++ /dev/null @@ -1,35 +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. - */ - -/*! \file */ - -#include -#include - -void -isc_mutexblock_init(isc_mutex_t *block, unsigned int count) { - unsigned int i; - - for (i = 0; i < count; i++) { - isc_mutex_init(&block[i]); - } -} - -void -isc_mutexblock_destroy(isc_mutex_t *block, unsigned int count) { - unsigned int i; - - for (i = 0; i < count; i++) { - isc_mutex_destroy(&block[i]); - } -} diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index e6c6e82830..c42348fcce 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index b88f2d9fb7..55aaa011c0 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index 4f98b50862..76dd0c8a78 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/netmgr/tlsstream.c b/lib/isc/netmgr/tlsstream.c index 8d5fe1fd37..b928842e29 100644 --- a/lib/isc/netmgr/tlsstream.c +++ b/lib/isc/netmgr/tlsstream.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index ae2fea4ae1..e8106c1b13 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/timer.c b/lib/isc/timer.c index bfd3377f4c..504e49a166 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -17,7 +17,6 @@ #include #include -#include #include #include #include diff --git a/lib/isc/tls.c b/lib/isc/tls.c index 0a646837bb..a52863e23a 100644 --- a/lib/isc/tls.c +++ b/lib/isc/tls.c @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/isc/doh_test.c b/tests/isc/doh_test.c index 9ccc11f777..5b98989bef 100644 --- a/tests/isc/doh_test.c +++ b/tests/isc/doh_test.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/isc/timer_test.c b/tests/isc/timer_test.c index 4a6ee8045c..0a5c8d01ac 100644 --- a/tests/isc/timer_test.c +++ b/tests/isc/timer_test.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include From c5075a9a616d4f4c3959c22b48df0d575ebf26b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 28 Feb 2025 21:04:21 +0100 Subject: [PATCH 2/5] Remove convenience list macros from isc/util.h The short convenience list macros were used very sparingly and inconsistenly in the code base. As the consistency is prefered over the convenience, all shortened list macro were removed in favor of their ISC_LIST API targets. --- lib/dns/dyndb.c | 16 ++++++------ lib/dns/qpzone.c | 49 ++++++++++++++++++++----------------- lib/isc/include/isc/util.h | 18 -------------- lib/isc/lex.c | 24 +++++++++--------- lib/isc/netmgr/http.c | 2 +- lib/isc/netmgr/netmgr-int.h | 10 ++++---- lib/isc/ratelimiter.c | 4 +-- lib/ns/hooks.c | 2 +- 8 files changed, 55 insertions(+), 70 deletions(-) diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c index b4ead8dcfa..fd327bef9f 100644 --- a/lib/dns/dyndb.c +++ b/lib/dns/dyndb.c @@ -43,7 +43,7 @@ struct dyndb_implementation { dns_dyndb_destroy_t *destroy_func; char *name; void *inst; - LINK(dyndb_implementation_t) link; + ISC_LINK(dyndb_implementation_t) link; }; /* @@ -52,7 +52,7 @@ struct dyndb_implementation { * These are stored here so they can be cleaned up on shutdown. * (The order in which they are stored is not important.) */ -static LIST(dyndb_implementation_t) dyndb_implementations; +static ISC_LIST(dyndb_implementation_t) dyndb_implementations; /* Locks dyndb_implementations. */ static isc_mutex_t dyndb_lock; @@ -60,7 +60,7 @@ static isc_mutex_t dyndb_lock; void dns__dyndb_initialize(void) { isc_mutex_init(&dyndb_lock); - INIT_LIST(dyndb_implementations); + ISC_LIST_INIT(dyndb_implementations); } void @@ -135,7 +135,7 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname, isc_mem_attach(mctx, &imp->mctx); - INIT_LINK(imp, link); + ISC_LINK_INIT(imp, link); r = uv_dlopen(filename, &imp->handle); if (r != 0) { @@ -225,7 +225,7 @@ dns_dyndb_load(const char *libname, const char *name, const char *parameters, CHECK(implementation->register_func(mctx, name, parameters, file, line, dctx, &implementation->inst)); - APPEND(dyndb_implementations, implementation, link); + ISC_LIST_APPEND(dyndb_implementations, implementation, link); result = ISC_R_SUCCESS; cleanup: @@ -245,10 +245,10 @@ dns_dyndb_cleanup(void) { dyndb_implementation_t *prev; LOCK(&dyndb_lock); - elem = TAIL(dyndb_implementations); + elem = ISC_LIST_TAIL(dyndb_implementations); while (elem != NULL) { - prev = PREV(elem, link); - UNLINK(dyndb_implementations, elem, link); + prev = ISC_LIST_PREV(elem, link); + ISC_LIST_UNLINK(dyndb_implementations, elem, link); isc_log_write(DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB, ISC_LOG_INFO, "unloading DynDB instance '%s'", elem->name); diff --git a/lib/dns/qpzone.c b/lib/dns/qpzone.c index 766d25fe8a..72050bf96b 100644 --- a/lib/dns/qpzone.c +++ b/lib/dns/qpzone.c @@ -544,7 +544,7 @@ qpzone_destroy(qpzonedb_t *qpdb) { isc_refcount_decrementz(&qpdb->current_version->references); isc_refcount_destroy(&qpdb->current_version->references); - UNLINK(qpdb->open_versions, qpdb->current_version, link); + ISC_LIST_UNLINK(qpdb->open_versions, qpdb->current_version, link); cds_wfs_destroy(&qpdb->current_version->glue_stack); isc_rwlock_destroy(&qpdb->current_version->rwlock); isc_mem_put(qpdb->common.mctx, qpdb->current_version, @@ -723,7 +723,7 @@ dns__qpzone_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, * Keep the current version in the open list so that list operation * won't happen in normal lookup operations. */ - PREPEND(qpdb->open_versions, qpdb->current_version, link); + ISC_LIST_PREPEND(qpdb->open_versions, qpdb->current_version, link); qpdb->common.magic = DNS_DB_MAGIC; qpdb->common.impmagic = QPZONE_DB_MAGIC; @@ -1125,13 +1125,13 @@ cleanup_nondirty(qpz_version_t *version, qpz_changedlist_t *cleanup_list) { * * The caller must be holding the database lock. */ - for (changed = HEAD(version->changed_list); changed != NULL; + for (changed = ISC_LIST_HEAD(version->changed_list); changed != NULL; changed = next_changed) { - next_changed = NEXT(changed, link); + next_changed = ISC_LIST_NEXT(changed, link); if (!changed->dirty) { - UNLINK(version->changed_list, changed, link); - APPEND(*cleanup_list, changed, link); + ISC_LIST_UNLINK(version->changed_list, changed, link); + ISC_LIST_APPEND(*cleanup_list, changed, link); } } } @@ -1378,12 +1378,13 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, (void)isc_refcount_current( &cur_version->references); if (cur_version->serial == qpdb->least_serial) { - INSIST(EMPTY( + INSIST(ISC_LIST_EMPTY( cur_version->changed_list)); } - UNLINK(qpdb->open_versions, cur_version, link); + ISC_LIST_UNLINK(qpdb->open_versions, + cur_version, link); } - if (EMPTY(qpdb->open_versions)) { + if (ISC_LIST_EMPTY(qpdb->open_versions)) { /* * We're going to become the least open * version. @@ -1413,8 +1414,9 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, */ if (cur_ref == 1) { cleanup_version = cur_version; - APPENDLIST(version->changed_list, - cleanup_version->changed_list, link); + ISC_LIST_APPENDLIST( + version->changed_list, + cleanup_version->changed_list, link); } /* * Become the current version. @@ -1433,8 +1435,8 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, */ INSIST(isc_refcount_increment0(&version->references) == 0); - PREPEND(qpdb->open_versions, qpdb->current_version, - link); + ISC_LIST_PREPEND(qpdb->open_versions, + qpdb->current_version, link); resigned_list = version->resigned_list; ISC_LIST_INIT(version->resigned_list); } else { @@ -1461,7 +1463,7 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, * Find the version with the least serial * number greater than ours. */ - least_greater = PREV(version, link); + least_greater = ISC_LIST_PREV(version, link); if (least_greater == NULL) { least_greater = qpdb->current_version; } @@ -1482,20 +1484,21 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, * Add any unexecuted cleanups to * those of the least greater version. */ - APPENDLIST(least_greater->changed_list, - version->changed_list, link); + ISC_LIST_APPENDLIST(least_greater->changed_list, + version->changed_list, + link); } } else if (version->serial == qpdb->least_serial) { - INSIST(EMPTY(version->changed_list)); + INSIST(ISC_LIST_EMPTY(version->changed_list)); } - UNLINK(qpdb->open_versions, version, link); + ISC_LIST_UNLINK(qpdb->open_versions, version, link); } least_serial = qpdb->least_serial; RWUNLOCK(&qpdb->lock, isc_rwlocktype_write); if (cleanup_version != NULL) { isc_refcount_destroy(&cleanup_version->references); - INSIST(EMPTY(cleanup_version->changed_list)); + INSIST(ISC_LIST_EMPTY(cleanup_version->changed_list)); cleanup_gluelists(&cleanup_version->glue_stack); cds_wfs_destroy(&cleanup_version->glue_stack); isc_rwlock_destroy(&cleanup_version->rwlock); @@ -1506,8 +1509,8 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, /* * Commit/rollback re-signed headers. */ - for (header = HEAD(resigned_list); header != NULL; - header = HEAD(resigned_list)) + for (header = ISC_LIST_HEAD(resigned_list); header != NULL; + header = ISC_LIST_HEAD(resigned_list)) { isc_rwlock_t *nlock = NULL; isc_rwlocktype_t nlocktype = isc_rwlocktype_none; @@ -1527,13 +1530,13 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, dns_qp_t *tree = NULL, *nsec = NULL, *nsec3 = NULL; bool need_tree = false, need_nsec = false, need_nsec3 = false; - for (changed = HEAD(cleanup_list); changed != NULL; + for (changed = ISC_LIST_HEAD(cleanup_list); changed != NULL; changed = next_changed) { isc_rwlock_t *nlock = NULL; isc_rwlocktype_t nlocktype = isc_rwlocktype_none; - next_changed = NEXT(changed, link); + next_changed = ISC_LIST_NEXT(changed, link); node = changed->node; nlock = &qpdb->buckets[node->locknum].lock; diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 6d0b537c0e..bcfe3ad2ae 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -223,24 +223,6 @@ */ #include /* Contractual promise. */ -#define LIST(type) ISC_LIST(type) -#define INIT_LIST(type) ISC_LIST_INIT(type) -#define LINK(type) ISC_LINK(type) -#define INIT_LINK(elt, link) ISC_LINK_INIT(elt, link) -#define HEAD(list) ISC_LIST_HEAD(list) -#define TAIL(list) ISC_LIST_TAIL(list) -#define EMPTY(list) ISC_LIST_EMPTY(list) -#define PREV(elt, link) ISC_LIST_PREV(elt, link) -#define NEXT(elt, link) ISC_LIST_NEXT(elt, link) -#define APPEND(list, elt, link) ISC_LIST_APPEND(list, elt, link) -#define PREPEND(list, elt, link) ISC_LIST_PREPEND(list, elt, link) -#define UNLINK(list, elt, link) ISC_LIST_UNLINK(list, elt, link) -#define ENQUEUE(list, elt, link) ISC_LIST_APPEND(list, elt, link) -#define DEQUEUE(list, elt, link) ISC_LIST_UNLINK(list, elt, link) -#define INSERTBEFORE(li, b, e, ln) ISC_LIST_INSERTBEFORE(li, b, e, ln) -#define INSERTAFTER(li, a, e, ln) ISC_LIST_INSERTAFTER(li, a, e, ln) -#define APPENDLIST(list1, list2, link) ISC_LIST_APPENDLIST(list1, list2, link) - /*% * Performance */ diff --git a/lib/isc/lex.c b/lib/isc/lex.c index b1ac9b2cbd..e38947cbdd 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -61,7 +61,7 @@ struct isc_lex { unsigned int paren_count; unsigned int saved_paren_count; isc_lexspecials_t specials; - LIST(struct inputsource) sources; + ISC_LIST(struct inputsource) sources; }; static void @@ -104,7 +104,7 @@ isc_lex_create(isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp) { lex->paren_count = 0; lex->saved_paren_count = 0; memset(lex->specials, 0, 256); - INIT_LIST(lex->sources); + ISC_LIST_INIT(lex->sources); lex->magic = LEX_MAGIC; *lexp = lex; @@ -123,7 +123,7 @@ isc_lex_destroy(isc_lex_t **lexp) { *lexp = NULL; REQUIRE(VALID_LEX(lex)); - while (!EMPTY(lex->sources)) { + while (!ISC_LIST_EMPTY(lex->sources)) { RUNTIME_CHECK(isc_lex_close(lex) == ISC_R_SUCCESS); } if (lex->data != NULL) { @@ -259,7 +259,7 @@ isc_lex_close(isc_lex_t *lex) { REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return ISC_R_NOMORE; } @@ -352,7 +352,7 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { */ REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); REQUIRE(tokenp != NULL); if (source == NULL) { @@ -999,7 +999,7 @@ isc_lex_ungettoken(isc_lex_t *lex, isc_token_t *tokenp) { */ REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); REQUIRE(source != NULL); REQUIRE(tokenp != NULL); REQUIRE(isc_buffer_consumedlength(source->pushback) != 0 || @@ -1018,7 +1018,7 @@ isc_lex_getlasttokentext(isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r) { inputsource *source; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); REQUIRE(source != NULL); REQUIRE(tokenp != NULL); REQUIRE(isc_buffer_consumedlength(source->pushback) != 0 || @@ -1038,7 +1038,7 @@ isc_lex_getsourcename(isc_lex_t *lex) { inputsource *source; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return NULL; @@ -1052,7 +1052,7 @@ isc_lex_getsourceline(isc_lex_t *lex) { inputsource *source; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return 0; @@ -1067,7 +1067,7 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name) { char *newname; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return ISC_R_NOTFOUND; @@ -1083,7 +1083,7 @@ isc_lex_setsourceline(isc_lex_t *lex, unsigned long line) { inputsource *source; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return ISC_R_NOTFOUND; @@ -1099,7 +1099,7 @@ isc_lex_isfile(isc_lex_t *lex) { REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return false; diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index 39beec0487..cb8a77197f 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -150,7 +150,7 @@ typedef struct http_cstream { isc_nm_http_response_status_t response_status; isc_nmsocket_t *httpsock; - LINK(struct http_cstream) link; + ISC_LINK(struct http_cstream) link; } http_cstream_t; #define HTTP2_SESSION_MAGIC ISC_MAGIC('H', '2', 'S', 'S') diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index c42348fcce..fb49de7879 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -270,8 +270,8 @@ struct isc_nmhandle { void *backtrace[TRACE_SIZE]; int backtrace_size; #endif - LINK(isc_nmhandle_t) active_link; - LINK(isc_nmhandle_t) inactive_link; + ISC_LINK(isc_nmhandle_t) active_link; + ISC_LINK(isc_nmhandle_t) inactive_link; void *opaque; @@ -422,7 +422,7 @@ typedef struct isc_nm_httphandler { char *path; isc_nm_recv_cb_t cb; void *cbarg; - LINK(struct isc_nm_httphandler) link; + ISC_LINK(struct isc_nm_httphandler) link; } isc_nm_httphandler_t; struct isc_nm_http_endpoints { @@ -466,7 +466,7 @@ typedef struct isc_nmsocket_h2 { isc_nm_recv_cb_t cb; void *cbarg; - LINK(struct isc_nmsocket_h2) link; + ISC_LINK(struct isc_nmsocket_h2) link; isc_nm_http_endpoints_t **listener_endpoints; size_t n_listener_endpoints; @@ -712,7 +712,7 @@ struct isc_nmsocket { void *backtrace[TRACE_SIZE]; int backtrace_size; #endif - LINK(isc_nmsocket_t) active_link; + ISC_LINK(isc_nmsocket_t) active_link; isc_job_t job; }; diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c index 5cb83f273c..c66cebc4f7 100644 --- a/lib/isc/ratelimiter.c +++ b/lib/isc/ratelimiter.c @@ -231,7 +231,7 @@ isc__ratelimiter_tick(void *arg) { REQUIRE(rl->timer != NULL); if (rl->state == isc_ratelimiter_shuttingdown) { - INSIST(EMPTY(rl->pending)); + INSIST(ISC_LIST_EMPTY(rl->pending)); goto unlock; } @@ -277,7 +277,7 @@ isc__ratelimiter_doshutdown(void *arg) { LOCK(&rl->lock); INSIST(rl->state == isc_ratelimiter_shuttingdown); - INSIST(EMPTY(rl->pending)); + INSIST(ISC_LIST_EMPTY(rl->pending)); isc_timer_stop(rl->timer); isc_timer_destroy(&rl->timer); diff --git a/lib/ns/hooks.c b/lib/ns/hooks.c index 915f476c3b..33be5cd206 100644 --- a/lib/ns/hooks.c +++ b/lib/ns/hooks.c @@ -48,7 +48,7 @@ struct ns_plugin { ns_plugin_check_t *check_func; ns_plugin_register_t *register_func; ns_plugin_destroy_t *destroy_func; - LINK(ns_plugin_t) link; + ISC_LINK(ns_plugin_t) link; }; static ns_hooklist_t default_hooktable[NS_HOOKPOINTS_COUNT]; From 901637c25c0b4d3075dd33b0aff59209d39a7886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 28 Feb 2025 21:40:50 +0100 Subject: [PATCH 3/5] Remove superflous header includes from isc/util.h header Formerly, isc/util.h would pull a few extra headers (isc/list.h, isc/attributes.h, isc/result.h and errno.h). These includes were removed in favor of including them directly when used. --- lib/isc/include/isc/rwlock.h | 4 +++- lib/isc/include/isc/util.h | 11 ----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/isc/include/isc/rwlock.h b/lib/isc/include/isc/rwlock.h index 16cbe536d8..b636fbc37c 100644 --- a/lib/isc/include/isc/rwlock.h +++ b/lib/isc/include/isc/rwlock.h @@ -14,7 +14,6 @@ #pragma once #include -#include /*! \file isc/rwlock.h */ @@ -28,6 +27,7 @@ typedef enum { } isc_rwlocktype_t; #if USE_PTHREAD_RWLOCK +#include #include /* @@ -38,6 +38,8 @@ typedef enum { #if ISC_TRACK_PTHREADS_OBJECTS +#include + typedef pthread_rwlock_t *isc_rwlock_t; typedef pthread_rwlock_t isc__rwlock_t; diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index bcfe3ad2ae..a392714e18 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -27,8 +27,6 @@ * ISC_ or isc_ to the name. */ -#include - /*** *** Clang Compatibility Macros ***/ @@ -122,8 +120,6 @@ #define ISC_UTIL_TRACE(a) #endif /* ifdef ISC_UTIL_TRACEON */ -#include /* Contractual promise. */ - #define SPINLOCK(sp) \ { \ ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKING %p %s %d\n", (sp), \ @@ -218,11 +214,6 @@ INSIST(locktype == isc_rwlocktype_write); \ } -/* - * List Macros. - */ -#include /* Contractual promise. */ - /*% * Performance */ @@ -318,8 +309,6 @@ mock_assert(const int result, const char *const expression, /* * Errors */ -#include /* for errno */ - #include /* Contractual promise. */ #include /* for ISC_STRERRORSIZE */ From 534069e048bddcad6738a4f7f79a39981a618fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 28 Feb 2025 21:49:48 +0100 Subject: [PATCH 4/5] Move locking macros into individual headers Previously, the LOCK()/UNLOCK() and friends macros were defined in the isc/util.h header. Those macros were moved to their respective headers as those would have to be included anyway if that particular lock was in use. --- lib/isc/include/isc/mutex.h | 15 ++++++ lib/isc/include/isc/rwlock.h | 34 ++++++++++++ lib/isc/include/isc/spinlock.h | 15 ++++++ lib/isc/include/isc/util.h | 99 ---------------------------------- 4 files changed, 64 insertions(+), 99 deletions(-) diff --git a/lib/isc/include/isc/mutex.h b/lib/isc/include/isc/mutex.h index a975b0d065..19612dd99b 100644 --- a/lib/isc/include/isc/mutex.h +++ b/lib/isc/include/isc/mutex.h @@ -22,6 +22,21 @@ #include /* for ISC_R_ codes */ #include +#define LOCK(lp) \ + { \ + ISC_UTIL_TRACE(fprintf(stderr, "LOCKING %p %s %d\n", (lp), \ + __FILE__, __LINE__)); \ + isc_mutex_lock((lp)); \ + ISC_UTIL_TRACE(fprintf(stderr, "LOCKED %p %s %d\n", (lp), \ + __FILE__, __LINE__)); \ + } +#define UNLOCK(lp) \ + { \ + isc_mutex_unlock((lp)); \ + ISC_UTIL_TRACE(fprintf(stderr, "UNLOCKED %p %s %d\n", (lp), \ + __FILE__, __LINE__)); \ + } + /* * We use macros instead of static inline functions so that the exact code * location can be reported when PTHREADS_RUNTIME_CHECK() fails or when mutrace diff --git a/lib/isc/include/isc/rwlock.h b/lib/isc/include/isc/rwlock.h index b636fbc37c..67be70e2e0 100644 --- a/lib/isc/include/isc/rwlock.h +++ b/lib/isc/include/isc/rwlock.h @@ -26,6 +26,40 @@ typedef enum { isc_rwlocktype_write } isc_rwlocktype_t; +#define RWLOCK(lp, t) \ + { \ + ISC_UTIL_TRACE(fprintf(stderr, "RWLOCK %p, %d %s %d\n", (lp), \ + (t), __FILE__, __LINE__)); \ + isc_rwlock_lock((lp), (t)); \ + ISC_UTIL_TRACE(fprintf(stderr, "RWLOCKED %p, %d %s %d\n", \ + (lp), (t), __FILE__, __LINE__)); \ + } +#define RWUNLOCK(lp, t) \ + { \ + ISC_UTIL_TRACE(fprintf(stderr, "RWUNLOCK %p, %d %s %d\n", \ + (lp), (t), __FILE__, __LINE__)); \ + isc_rwlock_unlock((lp), (t)); \ + } + +#define RDLOCK(lp) RWLOCK(lp, isc_rwlocktype_read) +#define RDUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_read) +#define WRLOCK(lp) RWLOCK(lp, isc_rwlocktype_write) +#define WRUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_write) + +#define UPGRADELOCK(lock, locktype) \ + { \ + if (locktype == isc_rwlocktype_read) { \ + if (isc_rwlock_tryupgrade(lock) == ISC_R_SUCCESS) { \ + locktype = isc_rwlocktype_write; \ + } else { \ + RWUNLOCK(lock, locktype); \ + locktype = isc_rwlocktype_write; \ + RWLOCK(lock, locktype); \ + } \ + } \ + INSIST(locktype == isc_rwlocktype_write); \ + } + #if USE_PTHREAD_RWLOCK #include #include diff --git a/lib/isc/include/isc/spinlock.h b/lib/isc/include/isc/spinlock.h index 3333836af5..f8c1e487c1 100644 --- a/lib/isc/include/isc/spinlock.h +++ b/lib/isc/include/isc/spinlock.h @@ -21,6 +21,21 @@ #include #include +#define SPINLOCK(sp) \ + { \ + ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKING %p %s %d\n", (sp), \ + __FILE__, __LINE__)); \ + isc_spinlock_lock((sp)); \ + ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKED %p %s %d\n", (sp), \ + __FILE__, __LINE__)); \ + } +#define SPINUNLOCK(sp) \ + { \ + isc_spinlock_unlock((sp)); \ + ISC_UTIL_TRACE(fprintf(stderr, "SPINUNLOCKED %p %s %d\n", \ + (sp), __FILE__, __LINE__)); \ + } + /* * We use macros instead of static inline functions so that the exact code * location can be reported when PTHREADS_RUNTIME_CHECK() fails or when mutrace diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index a392714e18..805e518afc 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -108,11 +108,6 @@ */ #define EMPTY_TRANSLATION_UNIT extern int isc__empty; -/*% - * We use macros instead of calling the routines directly because - * the capital letters make the locking stand out. - */ - #ifdef ISC_UTIL_TRACEON #define ISC_UTIL_TRACE(a) a #include /* Required for fprintf/stderr when tracing. */ @@ -120,100 +115,6 @@ #define ISC_UTIL_TRACE(a) #endif /* ifdef ISC_UTIL_TRACEON */ -#define SPINLOCK(sp) \ - { \ - ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKING %p %s %d\n", (sp), \ - __FILE__, __LINE__)); \ - isc_spinlock_lock((sp)); \ - ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKED %p %s %d\n", (sp), \ - __FILE__, __LINE__)); \ - } -#define SPINUNLOCK(sp) \ - { \ - isc_spinlock_unlock((sp)); \ - ISC_UTIL_TRACE(fprintf(stderr, "SPINUNLOCKED %p %s %d\n", \ - (sp), __FILE__, __LINE__)); \ - } - -#define LOCK(lp) \ - { \ - ISC_UTIL_TRACE(fprintf(stderr, "LOCKING %p %s %d\n", (lp), \ - __FILE__, __LINE__)); \ - isc_mutex_lock((lp)); \ - ISC_UTIL_TRACE(fprintf(stderr, "LOCKED %p %s %d\n", (lp), \ - __FILE__, __LINE__)); \ - } -#define UNLOCK(lp) \ - { \ - isc_mutex_unlock((lp)); \ - ISC_UTIL_TRACE(fprintf(stderr, "UNLOCKED %p %s %d\n", (lp), \ - __FILE__, __LINE__)); \ - } - -#define BROADCAST(cvp) \ - { \ - ISC_UTIL_TRACE(fprintf(stderr, "BROADCAST %p %s %d\n", (cvp), \ - __FILE__, __LINE__)); \ - isc_condition_broadcast((cvp)); \ - } -#define SIGNAL(cvp) \ - { \ - ISC_UTIL_TRACE(fprintf(stderr, "SIGNAL %p %s %d\n", (cvp), \ - __FILE__, __LINE__)); \ - isc_condition_signal((cvp)); \ - } -#define WAIT(cvp, lp) \ - { \ - ISC_UTIL_TRACE(fprintf(stderr, "WAIT %p LOCK %p %s %d\n", \ - (cvp), (lp), __FILE__, __LINE__)); \ - isc_condition_wait((cvp), (lp)); \ - ISC_UTIL_TRACE(fprintf(stderr, "WAITED %p LOCKED %p %s %d\n", \ - (cvp), (lp), __FILE__, __LINE__)); \ - } - -/* - * isc_condition_waituntil can return ISC_R_TIMEDOUT, so we - * don't RUNTIME_CHECK the result. - * - * XXX Also, can't really debug this then... - */ - -#define WAITUNTIL(cvp, lp, tp) isc_condition_waituntil((cvp), (lp), (tp)) - -#define RWLOCK(lp, t) \ - { \ - ISC_UTIL_TRACE(fprintf(stderr, "RWLOCK %p, %d %s %d\n", (lp), \ - (t), __FILE__, __LINE__)); \ - isc_rwlock_lock((lp), (t)); \ - ISC_UTIL_TRACE(fprintf(stderr, "RWLOCKED %p, %d %s %d\n", \ - (lp), (t), __FILE__, __LINE__)); \ - } -#define RWUNLOCK(lp, t) \ - { \ - ISC_UTIL_TRACE(fprintf(stderr, "RWUNLOCK %p, %d %s %d\n", \ - (lp), (t), __FILE__, __LINE__)); \ - isc_rwlock_unlock((lp), (t)); \ - } - -#define RDLOCK(lp) RWLOCK(lp, isc_rwlocktype_read) -#define RDUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_read) -#define WRLOCK(lp) RWLOCK(lp, isc_rwlocktype_write) -#define WRUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_write) - -#define UPGRADELOCK(lock, locktype) \ - { \ - if (locktype == isc_rwlocktype_read) { \ - if (isc_rwlock_tryupgrade(lock) == ISC_R_SUCCESS) { \ - locktype = isc_rwlocktype_write; \ - } else { \ - RWUNLOCK(lock, locktype); \ - locktype = isc_rwlocktype_write; \ - RWLOCK(lock, locktype); \ - } \ - } \ - INSIST(locktype == isc_rwlocktype_write); \ - } - /*% * Performance */ From ce7879c924a6f0fb50029831dad107c52a7d6281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 28 Feb 2025 21:51:18 +0100 Subject: [PATCH 5/5] Remove STATIC_ASSERT variants in favor of the C11 variant Previously, a gcc < 4.6 shim for _Static_assert() was included. Such an old compiler is not supported now anyway, so the macro variant has been removed in favor of a single definition using _Static_assert(). --- lib/isc/include/isc/util.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 805e518afc..9fed22df60 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -140,18 +140,7 @@ #define ISC_NO_SANITIZE_THREAD #endif /* if __SANITIZE_THREAD__ */ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 6) #define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) -#elif __has_feature(c_static_assert) -#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) -#else /* if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 6) */ - -/* Courtesy of Joseph Quinsey: https://godbolt.org/z/K9RvWS */ -#define TOKENPASTE(a, b) a##b /* "##" is the "Token Pasting Operator" */ -#define EXPAND_THEN_PASTE(a, b) TOKENPASTE(a, b) /* expand then paste */ -#define STATIC_ASSERT(x, msg) \ - enum { EXPAND_THEN_PASTE(ASSERT_line_, __LINE__) = 1 / ((msg) && (x)) } -#endif /* if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 6) */ #ifdef UNIT_TESTING extern void