From nobody Fri Jan 17 12:26:58 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YZJrh1ZT3z5kvXb; Fri, 17 Jan 2025 12:27:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YZJrg0VVkz3T7K; Fri, 17 Jan 2025 12:26:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737116819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TRIEomBm023vyiZB33Vj/CZtDMubiu95e10P7pv2ons=; b=ysX4Dn3jUKtOSejME4sWXZM0l3Vaf4QVW7Op6XfL1mpMXmyqw800+cO5/SClwSPuBlT/oj T7WZQkXKrjzOjwdNUP5BzMb40SJWEq7oL0tyyf0VC/LluHFSkU95v4NtjWGtu+YO7NGGlp 1DAJR6S44pyKl4HfNeM9E/lX/YRcb0RwVf7xKXheqNWHmQ0V/yEnBRr/LQHyt0DovI7SHT K6A1yTG8NUgxoRYD6IELzqYg5bfL4DaFK7wKWTUkYESg/eyBNrHyrKbzMfCq6p4vUTNTRK CX0HPIeotJ6cGYL3ZyG7J8IdXsiZg7VeSlP/cTCABmshvyy/07vTa/humxgDqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737116819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TRIEomBm023vyiZB33Vj/CZtDMubiu95e10P7pv2ons=; b=U82Rk4iIH4LZBccUJbgeuWTpoTk5+x4+JubRfVklgnWzuA7627qXLcxUhobPilv283jNKg O/MNw7+o1gv//tG3sucbLKE0634Uc5QNkJ5UBkHFRNAnUlko/WJFYBUmK7sYImuAJiRPcz Io4dVIMskPAzPkzlAhCZ9fsUkwRaslLO2zqNGhtZB8MQBRzIw8rIP+o53sPiQzDShjX2Ba 9iZOx0nIGeeDVTSn0gt6DIZahRzSOevjgiTNpZQuXaRhsYv+BxET7CwmNFA6PrzsFhcF7x +kN+yvAnRMuTPYM5Kb/YFtlToqh2r8E88sXNn86N97Vu6t8UD0QnPPsTksUmlA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737116819; a=rsa-sha256; cv=none; b=NsfMIasyzFdd0LWqkPbRmIkWEFWFZvbL6J2mDA2aTizqywHxNsadkjxmhwRkEs4GcRaenN AKIuG9t9hB6ljiRETdlAZl6D0O+qXlEed6SQG37PXpyH+5AECN08oRBhemV1LminW7K2wO vESchFTueb4U4ZV79Oqh+01v8aqXDHwC4NELsUALu5F4zl8ppa4l3VPwAd41z65B62VywF UCyHe9B4yhU+ryPWCiMtApMCa+sNlA+2ykXqLtRqTy+7vhhx8UcVEvTK8vEt9ZXGvjxfkY 5exXAkZRZERtKtyvwVUiNuhDe0u5FU/BMgatsEiKwL0yPWei6n20Wi2sZyHfvA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YZJrg04D7z33L; Fri, 17 Jan 2025 12:26:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50HCQwvj051836; Fri, 17 Jan 2025 12:26:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50HCQw1i051833; Fri, 17 Jan 2025 12:26:58 GMT (envelope-from git) Date: Fri, 17 Jan 2025 12:26:58 GMT Message-Id: <202501171226.50HCQw1i051833@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 229e81dd12fd - stable/13 - queue: New debug macros for STAILQ List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 229e81dd12fd7dca2077c143ff50742e8600bf36 Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=229e81dd12fd7dca2077c143ff50742e8600bf36 commit 229e81dd12fd7dca2077c143ff50742e8600bf36 Author: Olivier Certner AuthorDate: 2024-07-08 16:15:49 +0000 Commit: Olivier Certner CommitDate: 2025-01-17 12:24:49 +0000 queue: New debug macros for STAILQ The new STAILQ_ASSERT_EMPTY() macro allows callers to assert that some STAILQ is empty. It leverages the new QMD_STAILQ_CHECK_EMPTY() internal macro. QMD_STAILQ_CHECK_EMPTY() is a check for empty STAILQ, where heads's 'stqh_last' field must point to the 'stqh_first' one. Use it in STAILQ_ASSERT_EMPTY(). QMD_STAILQ_CHECK_TAIL() checks that the tail pointed by 'head' does not have a next element. It is similar to the already existing QMD_TAILQ_CHECK_TAIL(), but without the superfluous 'field' argument and clearer documentation. Use it in STAILQ_INSERT_TAIL(). Approved by: markj (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46889 (cherry picked from commit 34740937f7a46c7475bb57e804701ba8830bf6ed) --- sys/sys/queue.h | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/sys/sys/queue.h b/sys/sys/queue.h index 8e91ebf7949d..4e0ba068c520 100644 --- a/sys/sys/queue.h +++ b/sys/sys/queue.h @@ -340,6 +340,40 @@ struct { \ /* * Singly-linked Tail queue functions. */ +#if (defined(_KERNEL) && defined(INVARIANTS)) +/* + * QMD_STAILQ_CHECK_EMPTY(STAILQ_HEAD *head) + * + * Validates that the stailq head's pointer to the last element's next pointer + * actually points to the head's first element pointer field. + */ +#define QMD_STAILQ_CHECK_EMPTY(head) do { \ + if ((head)->stqh_last != &(head)->stqh_first) \ + panic("Empty stailq %p->stqh_last is %p, not head's " \ + "first field address", (head), (head)->stqh_last); \ +} while (0) + +#define STAILQ_ASSERT_EMPTY(head) do { \ + if (!STAILQ_EMPTY((head))) \ + panic("stailq %p is not empty", (head)); \ +} + +/* + * QMD_STAILQ_CHECK_TAIL(STAILQ_HEAD *head) + * + * Validates that the stailq's last element's next pointer is NULL. + */ +#define QMD_STAILQ_CHECK_TAIL(head) do { \ + if (*(head)->stqh_last != NULL) \ + panic("Stailq %p last element's next pointer is %p, " \ + "not NULL", (head), *(head)->stqh_last); \ +} while (0) +#else +#define QMD_STAILQ_CHECK_EMPTY(head) +#define STAILQ_ASSERT_EMPTY(head) +#define QMD_STAILQ_CHECK_TAIL(head) +#endif /* (_KERNEL && INVARIANTS) */ + #define STAILQ_CONCAT(head1, head2) do { \ if (!STAILQ_EMPTY((head2))) { \ *(head1)->stqh_last = (head2)->stqh_first; \ @@ -348,7 +382,11 @@ struct { \ } \ } while (0) -#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) +#define STAILQ_EMPTY(head) ({ \ + if (STAILQ_FIRST(head) == NULL) \ + QMD_STAILQ_CHECK_EMPTY(head); \ + STAILQ_FIRST(head) == NULL; \ +}) #define STAILQ_FIRST(head) ((head)->stqh_first) @@ -390,6 +428,7 @@ struct { \ } while (0) #define STAILQ_INSERT_TAIL(head, elm, field) do { \ + QMD_STAILQ_CHECK_TAIL(head); \ STAILQ_NEXT((elm), field) = NULL; \ *(head)->stqh_last = (elm); \ (head)->stqh_last = &STAILQ_NEXT((elm), field); \