From nobody Mon Aug 3 21:44:07 2026 X-Original-To: dev-commits-src-main@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 4hDVYh0L1rz6n54y for ; Mon, 03 Aug 2026 21:44:08 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hDVYg5FjDz3Dy9 for ; Mon, 03 Aug 2026 21:44:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785793447; 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=ST8HQTbqropcpdu/W22ZboIF4o9VCI6yUGxmmP+bPIU=; b=Q+Xhao0MoS0tpIrjrIavhk2EOEqZdYEI0DI4C4QWfzfGrq9DMDEg1dZu5UobDelIjlb11e s1rAcqKra4RWM43zUT/M8RCWACtpB/p88kwwSef7t0g/ahIHVZCG1iQWxuVr5AeFhneMhC DfWG1+miFAKjuqSuMMd2vupBzahLemVLhucLjtPCAwuA3O6I7vU0Ly16TYFR73kRPj4Ppv ui6R7WRT6wZJmit2bSZOTyRHeWvtWijwswLoNwEecmPUiyzdwZ6k3py0DBH3p7wEXJZVnL CPldEhx0eEZsQvgK4rXZeQs+cuDqwO/y6tTDi1dtokdJi9DiYpeMrG1e/zwfRQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785793447; a=rsa-sha256; cv=none; b=PqMidD09IOrcxUHAtAL1LtwC4SamLvPjeTrWq9ZulVBeoWcMr4ZjYsE45Ir4W5/d+0zesA kAbczFklVtqhCbhkUEDf+TU0IP6kzEVE9asnOG/nnQgpDokgnwT77CefK6cn9BJD2OprC8 X1KTiPW8FQkD1T/DtufM6m3AvZEdiqcBjebjG15r9q/9faQEMvEE/UPTK4QKbvPbZe4r6R tBP8aJ7fmtulJgId7C7usk8TmKM1KBRCf4FvIsQ/N/1wLtjdz6P03KJog9rT+wq8tAcjrJ uE95OiuEkJ2faoXlpuxpJB566COQTITCkQzIAzVxsUQEzjX4M16Kks7s/SrtZQ== 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=1785793447; 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=ST8HQTbqropcpdu/W22ZboIF4o9VCI6yUGxmmP+bPIU=; b=QFa9CtGEtvMRtYr2MpcD7M9Nj+H8jPxAtU+kwZDm2KnugmhWytHtlOcN5nr+sGIo2/u2eX 4ZcaFZJ7GR3ew5vBPYtSOfYh/+o3fxCRp1GvkceOsXyf3FzlZ/+05xmqeghRrDWKtIk0et f3Ac0Ql+iJuI5A+EWmG0QhoB1zEAV4kMFfMvJoK4x/3h9VvYo0/+XvOGIfYqcwKN6/gO04 ePfoRUP+SblkUEpDofJxdTEZavahRrJnT1aspVRNaYcyYicAC+eCtD5zEBF28ROgMQycV9 bjWVC30YgRs5olUPHs4ivPvd/p5eZIeMaoANlHU29pH68h+U/ZjDz2w6XNeQ8Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDVYg47lGz3h5 for ; Mon, 03 Aug 2026 21:44:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3cbc0 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 03 Aug 2026 21:44:07 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: 5dff273d680a - main - uexterr_gettext(3): support dynamic kernel categories List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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: 5dff273d680ab848c62ca50efacb19f199217ab7 Auto-Submitted: auto-generated Date: Mon, 03 Aug 2026 21:44:07 +0000 Message-Id: <6a710ba7.3cbc0.79d9e807@gitrepo.freebsd.org> The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=5dff273d680ab848c62ca50efacb19f199217ab7 commit 5dff273d680ab848c62ca50efacb19f199217ab7 Author: Brooks Davis AuthorDate: 2026-08-03 16:50:26 +0000 Commit: Brooks Davis CommitDate: 2026-08-03 21:43:23 +0000 uexterr_gettext(3): support dynamic kernel categories Add an uncached sysctl based implementation which retrieves individual categories. A cache would be an obvious extension should this optional feature that can only be enabled by an environmental varible have a noticable performance impact in a case that matters. Reviewed by: kib Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D58238 --- lib/libc/gen/uexterr_format.c | 68 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/lib/libc/gen/uexterr_format.c b/lib/libc/gen/uexterr_format.c index df93ae1447cd..99ae85715f43 100644 --- a/lib/libc/gen/uexterr_format.c +++ b/lib/libc/gen/uexterr_format.c @@ -11,20 +11,75 @@ #include #include #include +#include #include +#include #include #include #include #include #include +#include "libc_private.h" + static const char * const cat_to_filenames[] = { #include "exterr_cat_filenames.h" }; +_Thread_local char filename_buf[128]; + +#define MIB_SIZE 4 +static int mib_template[MIB_SIZE]; +pthread_once_t mib_template_once_control = PTHREAD_ONCE_INIT; + +static void +mib_template_init(void) +{ + size_t len; + + len = nitems(mib_template); + (void)sysctlnametomib("kern.exterr.categories", mib_template, &len); + /* failure handled in kern_dynamic_cat_to_filename() */ +} + +static const char * +kern_dynamic_cat_to_filename(int category) +{ + int mib[MIB_SIZE]; + size_t len; + + if (_once(&mib_template_once_control, mib_template_init) != 0) + return (NULL); + if (__predict_false(mib_template[0] != CTL_KERN)) { + filename_buf[0] = '\0'; + return (filename_buf); + } + + memcpy(mib, mib_template, MIB_SIZE); + mib[MIB_SIZE - 1] = category; + len = sizeof(filename_buf); + if (sysctl(mib, nitems(mib), filename_buf, &len, NULL, 0) != 0) + return (NULL); + return (filename_buf); +} + +static const char * +cat_to_file_prefix(int category) +{ + switch (EXTERR_CAT_SRC(category)) { + case EXTERR_CAT_SRC_KERN_STATIC: + case EXTERR_CAT_SRC_KERN_DYNAMIC: + return ("sys/"); + default: + return (""); + } +} + static const char * cat_to_filename(int category) { + const char *path; + switch (EXTERR_CAT_SRC(category)) { case EXTERR_CAT_SRC_KERN_STATIC: if (category < 0 || category >= nitems(cat_to_filenames) || @@ -33,7 +88,10 @@ cat_to_filename(int category) return (cat_to_filenames[category]); case EXTERR_CAT_SRC_KERN_DYNAMIC: - return ("unknown:kern"); + path = kern_dynamic_cat_to_filename(EXTERR_CAT(category)); + if (path == NULL) + return ("unknown:kern"); + return (path); case EXTERR_CAT_SRC_USER: return ("unknown:user"); @@ -97,16 +155,18 @@ __uexterr_format(const struct uexterror *ue, char *buf, size_t bufsz) if (exterror_verbose > EXTERR_VERBOSE_DEFAULT || !has_msg) { char lbuf[128]; -#define SRC_FMT "(src sys/%s:%u)" +#define SRC_FMT "(src %s%s:%u)" if (exterror_verbose == EXTERR_VERBOSE_ALLOW_BRIEF) { snprintf(lbuf, sizeof(lbuf), SRC_FMT, + cat_to_file_prefix(ue->cat), cat_to_filename(ue->cat), ue->src_line); } else if (!has_msg || exterror_verbose == EXTERR_VERBOSE_ALLOW_FULL) { snprintf(lbuf, sizeof(lbuf), "errno %d category %u " SRC_FMT " p1 %#jx p2 %#jx", - ue->error, ue->cat, cat_to_filename(ue->cat), - ue->src_line, (uintmax_t)ue->p1, (uintmax_t)ue->p2); + ue->error, ue->cat, cat_to_file_prefix(ue->cat), + cat_to_filename(ue->cat), ue->src_line, + (uintmax_t)ue->p1, (uintmax_t)ue->p2); } #undef SRC_FMT if (has_msg)