From nobody Mon Dec 16 14:45:06 2024 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 4YBjQq1xXgz5hWS4; Mon, 16 Dec 2024 14:45:07 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YBjQp6x81z4c6x; Mon, 16 Dec 2024 14:45:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734360307; 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=7V32KNxniWCY2IjQ6esp4cCTjN/tiBFqIjrMktLRG7Q=; b=g8jA7m0LWwYaXpgDVo4oDZaX/nsYJkdGQj+1Y2DxNIIzqtCDI1j1aTZ3pC0kEhGzQFf5rm +rDWlyD/PitW+qL3jFNJh/XYRj72NW9vEcl0CF51PpadnEaZZAFnkjz/b0ROh1HbbOtDDT Eg6jFYlWOLCpQlZ58yZO3PUEezJdZAKMisOwLCHLbZs33ThusXAw36d6omRyj4ebAsIzv+ 1zrM9WnmwAXff0Y0hIDagh3SX9bPULVCtIBW/EFkD6yTcqhv6JESB2y8NatvQg2Ekzg9zh q3N2agJ9H9E6VHx85ECt0fT6QIQYKwHZJeqOokjoxJEo1vE8oG1ux7T2tkx8DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734360307; 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=7V32KNxniWCY2IjQ6esp4cCTjN/tiBFqIjrMktLRG7Q=; b=egjGMUKSh4pFlvBrD345cFiGrkCbbpIvE9Eafe67M/g1lSjV9Hd9wE2aFPhKnYDQk/FgIO sb3SAeMraWXgdMkAeQ0mR6awxqWfSH8zB2oiP5dTa3P1MmOAShu1bN+y/SiT/6KeKhLBVl wPt0DZw/OUlkh1kpOQsmH1djW0kw2bR3NCeycyq3R1jKiT4eF23VFAB1LZp/bQnrzlaO7y 2sW3hzZldXOBRgioQf5D0UQ4fvhYYp1XmUkZPz6isIft6tmW6h9ly8d8ZMiGw+yQETkKBB xytDKlFKa6PFKHLzdx9XbTPZLNxjTEpGkCC0KWUd7rGCaVLA5vSt7iyjq2/TnQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734360307; a=rsa-sha256; cv=none; b=l+bdkWe4QXErAegrCnwIO5YttJnucC1DaFcJRFeXZnWi71vkNKAcGHDqJegtGhUqqrw9ig 5iy6xr+vs4yuxhRlu8uzQDlbJlXdAD5o3OPXX6LAtK6JYk6LHbMP9y1foaiOZP5+AHEr9X 247rFALalYrjgeglLURIBFzisSZbz3rkUZfnzMev+vHn0MnhtoETdtj9WJpKtGJzKy492H 5mUeNGZMArylc4IrrbahkEHHVIsXfGOducyDqjf52zs8cMXph42MUeFxRtsOVr6xuo7AR9 VNIKdiEGqP0zY1YJsoEIGQ04BbSW4AGvCdhUkPCpQB2nBDpxRWEHCkVenb/gMQ== 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 4YBjQp6VQ4zxB6; Mon, 16 Dec 2024 14:45:06 +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 4BGEj6st051064; Mon, 16 Dec 2024 14:45:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BGEj6x3051061; Mon, 16 Dec 2024 14:45:06 GMT (envelope-from git) Date: Mon, 16 Dec 2024 14:45:06 GMT Message-Id: <202412161445.4BGEj6x3051061@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 34740937f7a4 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 34740937f7a46c7475bb57e804701ba8830bf6ed Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=34740937f7a46c7475bb57e804701ba8830bf6ed commit 34740937f7a46c7475bb57e804701ba8830bf6ed Author: Olivier Certner AuthorDate: 2024-07-08 16:15:49 +0000 Commit: Olivier Certner CommitDate: 2024-12-16 14:42:26 +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 --- 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 0479d780fd85..8a1c6cd7afbb 100644 --- a/sys/sys/queue.h +++ b/sys/sys/queue.h @@ -339,6 +339,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; \ @@ -347,7 +381,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) @@ -389,6 +427,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); \