Date: Mon, 03 Aug 2026 21:44:05 +0000 From: Brooks Davis <brooks@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: bbf95a9b8481 - main - exterror(9): split category into multiple sources Message-ID: <6a710ba5.3cf94.105bbf6b@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=bbf95a9b8481e41a99b301e12338e1cda6915a01 commit bbf95a9b8481e41a99b301e12338e1cda6915a01 Author: Brooks Davis <brooks@FreeBSD.org> AuthorDate: 2026-08-03 16:48:27 +0000 Commit: Brooks Davis <brooks@FreeBSD.org> CommitDate: 2026-08-03 21:43:22 +0000 exterror(9): split category into multiple sources The static, global index into an array of strings is simple, cheap, and works for the base kernel, but is unworkable for (potentially third-party) kernel modules or for arbitrary userspace code. Swipe a few of the top bits of category to indicate a source with all-zeros being the current model (EXTERR_CAT_SRC_KERN_STATIC). Add two additional sources EXTERR_CAT_SRC_KERN_DYNAMIC and EXTERR_CAT_SRC_USER with stub implementations. Reviewed by: kib Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D58236 --- lib/libc/gen/uexterr_format.c | 18 +++++++++++++++--- sys/sys/exterr_cat.h | 12 ++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/libc/gen/uexterr_format.c b/lib/libc/gen/uexterr_format.c index 308220adea1f..df93ae1447cd 100644 --- a/lib/libc/gen/uexterr_format.c +++ b/lib/libc/gen/uexterr_format.c @@ -25,10 +25,22 @@ static const char * const cat_to_filenames[] = { static const char * cat_to_filename(int category) { - if (category < 0 || category >= nitems(cat_to_filenames) || - cat_to_filenames[category] == NULL) + switch (EXTERR_CAT_SRC(category)) { + case EXTERR_CAT_SRC_KERN_STATIC: + if (category < 0 || category >= nitems(cat_to_filenames) || + cat_to_filenames[category] == NULL) + return ("unknown:kern"); + return (cat_to_filenames[category]); + + case EXTERR_CAT_SRC_KERN_DYNAMIC: + return ("unknown:kern"); + + case EXTERR_CAT_SRC_USER: + return ("unknown:user"); + + default: return ("unknown"); - return (cat_to_filenames[category]); + } } static const char exterror_verbose_name[] = "EXTERROR_VERBOSE"; diff --git a/sys/sys/exterr_cat.h b/sys/sys/exterr_cat.h index 637cecdcbcd0..1b56e241023b 100644 --- a/sys/sys/exterr_cat.h +++ b/sys/sys/exterr_cat.h @@ -22,6 +22,18 @@ #ifndef _SYS_EXTERR_CAT_H_ #define _SYS_EXTERR_CAT_H_ +#define _EXTERR_CAT_SRC_SHIFT 28 +#define EXTERR_CAT_SRC_MASK (0xf << _EXTERR_CAT_SRC_SHIFT) + +#define EXTERR_CAT_SRC_KERN_STATIC (0 << _EXTERR_CAT_SRC_SHIFT) +#define EXTERR_CAT_SRC_KERN_DYNAMIC (1 << _EXTERR_CAT_SRC_SHIFT) +#define EXTERR_CAT_SRC_USER (2 << _EXTERR_CAT_SRC_SHIFT) + +#define EXTERR_CAT_SRC(c) ((c) & EXTERR_CAT_SRC_MASK) +#define EXTERR_CAT(c) ((c) & ~EXTERR_CAT_SRC_MASK) + +#define EXTERR_CAT_NONE 0 + #define EXTERR_CAT_MMAP 1 #define EXTERR_CAT_FILEDESC 2 #define EXTERR_KTRACE 3 /* To allow inclusion of thishome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a710ba5.3cf94.105bbf6b>
