From nobody Sun Jun 02 18:43:09 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 4Vsm2Q0ylVz5Jl8y; Sun, 02 Jun 2024 18:43:10 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vsm2Q0136z4Vkw; Sun, 2 Jun 2024 18:43:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717353790; 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=aMGQHYmNoEG67nwhGUBIMa4zVNfqr8ebN4F8OZ65sXo=; b=Ns2dp+A8rdlWxS4f4tPzyPi1mAijKc9h4N5DjI5Mz+EmF9NZRHm6RnVz11Abe69gUxe+dg EBntqx+cz4X3daoqHXuZJ0FuJdo862rVu0c8HIoTRLJkaPnBds23FsRHp1bZJwOXdR9ARe ml4C845bxLHVwPyWtleY+PgkQYbBJ7kjrzCqKZh2KT+JFgvFkoqdfIFYuEHhORA37+1f3q DznOiRi/qnFxIdZnV/R67Yb0WRztj6S8WisUYmZk9BMGU/6FF6bLp1FclBs9pVFr6caMQ6 CWZ9/E60U1NiReElLopVil6C11AOmj2iZmN1eqhbBNBXDNQ513LzK+eDc30vDQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717353790; a=rsa-sha256; cv=none; b=cDO+gEnp61EB0XiuFkPVCOm1HhmEu4k34oGxIiUYwy9Hz3idQaRTQRyuZjY/KQ8+3SHpP+ TGs6aEBv0Td8vkXMRqlN6UZdy7rkhy1CzhQgmcjg4IfLEIVucFaHZEKSdPFSPxQlP1f5PW vFZVPrTi9TkEZyReP4nLpyCvmKWlwlJYtiQPplcZ9s2eCXZuke4x4FUFRR+p+tRAYeSpyv FXrkbLBK2sCHOxyUqERDB1QvQEy4quXl9pkTY9dCzZ/inSQhnwpqtTCXcgG9J3LWkOGkKM MdulIq1EvuPRBkcWPjnBOd9YE8x+M463kjRxlihfuxWLduujk/kg5DV6srMZww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717353790; 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=aMGQHYmNoEG67nwhGUBIMa4zVNfqr8ebN4F8OZ65sXo=; b=Rp0M30h5QED1zhaf7mzYMI2KzPrU9eztTomESnJbOWAwvkIksN32wR3NVQyDrx87hL9zQI s0+H7U+M2H/ZpFQr5X1l8f2IkoQjRs5xrzh8nk9Wf014PzmMz5/GXVaWjQ+tQhk559U0rb 5jb5ZFljzarpJBIij6vpLTLMQdCZNdKJZYXUl0cn0qHsP9qdpGKfFE+B4vaGZzmHifgYdP V/OjcTe5tTSY8zI/0d4CHrbldNNkSZcjOaqFZWS8HMKDoy0o9Oku1QDEhNCogOMV7cGInc s0orAoX6tf6ap6jmq4m2urJvXgbW4Cc5O7eJ4d2oDBL4P/5rNcOVoHCkz6kCwg== 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 4Vsm2P6k4sz137L; Sun, 2 Jun 2024 18:43:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 452Ih9AK047108; Sun, 2 Jun 2024 18:43:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 452Ih9Us047105; Sun, 2 Jun 2024 18:43:09 GMT (envelope-from git) Date: Sun, 2 Jun 2024 18:43:09 GMT Message-Id: <202406021843.452Ih9Us047105@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: af8cafb2a380 - main - iovec: macros to manipulate len and base together 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: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: af8cafb2a38070907ed5c4d872599617ce9d6d48 Auto-Submitted: auto-generated The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=af8cafb2a38070907ed5c4d872599617ce9d6d48 commit af8cafb2a38070907ed5c4d872599617ce9d6d48 Author: Brooks Davis AuthorDate: 2024-06-02 18:36:55 +0000 Commit: Brooks Davis CommitDate: 2024-06-02 18:41:22 +0000 iovec: macros to manipulate len and base together A set of convenience macros to initialize struct iovec's and increment the base and length together. IOVEC_INIT - sets iov_base and iov_len IOVEC_INIT_CSTR - takes a string and sets iov_len to strlen + 1 IOVEC_INIT_OBJ - takes an object and sets iov_len to sizeof obj IOVEC_ADVANCE - increments iov_base and decrements iov_len On CheriBSD these present the opportunity to insert more precise bounds on some objects and hide differences in casts in hybrid kernels (where some, but not all pointers are capabilities and require annotation). Here in FreeBSD the resulting code is tidier, particularly in the IOVEC_ADVANCE case where the need to cast iov_base to (char *) is avoided. Reviewed by: kib Feedback from: des, jrtc27 MFC after: 1 week Sponsored by: AFRL, DARPA Differential Revision: https://reviews.freebsd.org/D45422 --- sys/sys/_iovec.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sys/sys/_iovec.h b/sys/sys/_iovec.h index 72642e5227c5..9a4eedc80b4f 100644 --- a/sys/sys/_iovec.h +++ b/sys/sys/_iovec.h @@ -44,4 +44,28 @@ struct iovec { size_t iov_len; /* Length. */ }; +#ifdef _KERNEL +#define IOVEC_INIT(iovp, base, len) \ + *(iovp) = (struct iovec){ .iov_base = (base), .iov_len = (len) } + +/* String with length including NUL terminator */ +#define IOVEC_INIT_CSTR(iovp, str) do { \ + void *__str = (str); \ + IOVEC_INIT(iovp, __str, strlen(__str) + 1); \ +} while(0) + +/* Object with size from sizeof() */ +#define IOVEC_INIT_OBJ(iovp, obj) \ + IOVEC_INIT(iovp, &(obj), sizeof(obj)) + +#define IOVEC_ADVANCE(iovp, amt) do { \ + struct iovec *__iovp = (iovp); \ + size_t __amt = (amt); \ + KASSERT(__amt <= __iovp->iov_len, ("%s: amount %zu > iov_len \ + %zu", __func__, __amt, __iovp->iov_len)); \ + __iovp->iov_len -= __amt; \ + __iovp->iov_base = (char *)__iovp->iov_base + __amt; \ +} while(0) +#endif /* _KERNEL */ + #endif /* !_SYS__IOVEC_H_ */