From nobody Sun Jan 4 09:56:21 2026 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 4dkXrP57m5z6MnL1 for ; Sun, 04 Jan 2026 09:56:21 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dkXrP3vM3z4Cxj for ; Sun, 04 Jan 2026 09:56:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767520581; 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=3vfhuD6Wm6hC+yl6YyVYfRKKTOPaIB4VB3997h8J3RM=; b=t58S07FNuxLT3DLEOTXHJDRtcyMZe24zXtLzdXvRs2gaOx0PX5OWU5v7j36xdjtrAY2Ocj UAnwaD+tBc1o4TJq4iZ7GEVeIzoN5MloCSeqhGHOyCboXylUBk86EdzQR7ek1gyWht4vdz 0vOxsgJvb5d8LQ0sEJiuNpsSqpVrYH01QsTZmRJOUbuBpxXL5X03isHA2WXLVzcWUJwyu3 +GUVj9omJ+xVisgmXDGNP9EhCdtwOFoUoKUKjD4BqRJkbeSwbFU6l0TBmmzeDRHU0w/17D FcDJjr8mrIB5i9xR9iZBzX8CStTO9mEm17w9dY0risDM/7NGpVC5418jb0XIhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767520581; 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=3vfhuD6Wm6hC+yl6YyVYfRKKTOPaIB4VB3997h8J3RM=; b=rDLx3qK+6WXcj+BJTW7eTrDNDN+dyB4vQM4kn/D6M6vlDEh/O8iMVPpIANcyUXD8DnSWM4 QlNrDcQ0J0LWU6gEqhAcDDXhPk4Ag2GC1gP8jqJDC4vSEj1GQcr2pclhNxud+AAU5OoCuu C0N125gSe4MVq+RXPlXSjpSSpZ4oCy8vBhGnkBS3Mw/gnnCrJ+mlhdZldeEqoM2EWn8mJU TD8eMusuIu0UvCbKBT8ydbpLYr/MdqIhR0dUX/mwz+Sr2gUGsKcNKdorCn0NV0HiA+iTXm eYnaAgCPMqA8F32D44Zhdor9H92BZ8mQ3+sXC6MfBSc1CqThU0Fuojl3jnQ6UQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1767520581; a=rsa-sha256; cv=none; b=p1o+ho73vKKHGBHZpiuroPuj6bkRakRk5ndYshPnsszWybeYp4XTJkom65aXOxvI8CuCHy yxm0gHeQwIWUrnvqj5OjtmRHeJRR7KVps3ZAcZ6nCkskhizxoIvu6JVlFWQnaBusjdgSup WOEvBfgQbo/8/xgb9JeX4pPF4VG8GYexL+SPc9aU85sTMjiBMqrcOl9CO3FcsadhwtDgqk SxbS4+DBZd5fd4SzXu2IpNjwlit/BGjEsifxnZq4mIbjefSI4CjcxB6CdbqY0+US36FY1Y nYo2o/0lnkQk7vDmS5RD9zr49Ny8rYpqCMWABcU41G2bIS06CLP82tIjgZkY7Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dkXrP3SLLzTZG for ; Sun, 04 Jan 2026 09:56:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id bffa by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 04 Jan 2026 09:56:21 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron Subject: git: b1bef9f7e0e1 - main - linuxkpi: Add hex_dump_to_buffer() 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: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b1bef9f7e0e182a9eee222639ffc8af4883ec0fa Auto-Submitted: auto-generated Date: Sun, 04 Jan 2026 09:56:21 +0000 Message-Id: <695a3945.bffa.623ca786@gitrepo.freebsd.org> The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=b1bef9f7e0e182a9eee222639ffc8af4883ec0fa commit b1bef9f7e0e182a9eee222639ffc8af4883ec0fa Author: Jean-Sébastien Pédron AuthorDate: 2025-07-10 23:03:51 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2026-01-04 09:45:36 +0000 linuxkpi: Add hex_dump_to_buffer() This function prints a single line of hex dump to the given line buffer. The implementation relies on `lkpi_hex_dump()` to format the string. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51559 --- sys/compat/linuxkpi/common/include/linux/printk.h | 6 ++ sys/compat/linuxkpi/common/src/linux_compat.c | 70 +++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/printk.h b/sys/compat/linuxkpi/common/include/linux/printk.h index e10656c8a1d0..066ec900f04e 100644 --- a/sys/compat/linuxkpi/common/include/linux/printk.h +++ b/sys/compat/linuxkpi/common/include/linux/printk.h @@ -50,6 +50,12 @@ void lkpi_hex_dump(int(*)(void *, const char *, ...), void *arg1, const char *, const char *, const int, const int, const int, const void *, size_t, const bool, const bool); +#define hex_dump_to_buffer(buf, len, rowsize, groupsize, linebuf, linebuflen, ascii) \ + lkpi_hex_dump_to_buffer((buf), (len), (rowsize), (groupsize), (linebuf), (linebuflen), (ascii)) + +int lkpi_hex_dump_to_buffer(const void *buf, size_t len, int rowsize, + int groupsize, char *linebuf, size_t linebuflen, bool ascii); + static inline void print_hex_dump(const char *level, const char *prefix_str, const int prefix_type, const int rowsize, const int groupsize, diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index c2bad1f28eaf..8fc644241d79 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -1986,6 +1986,76 @@ lkpi_hex_dump(int(*_fpf)(void *, const char *, ...), void *arg1, } } +struct hdtb_context { + char *linebuf; + size_t linebuflen; + int written; +}; + +static int +hdtb_cb(void *arg, const char *format, ...) +{ + struct hdtb_context *context; + int written; + va_list args; + + context = arg; + + va_start(args, format); + written = vsnprintf( + context->linebuf, context->linebuflen, format, args); + va_end(args); + + if (written < 0) + return (written); + + /* + * Linux' hex_dump_to_buffer() function has the same behaviour as + * snprintf() basically. Therefore, it returns the number of bytes it + * would have written if the destination buffer was large enough. + * + * If the destination buffer was exhausted, lkpi_hex_dump() will + * continue to call this callback but it will only compute the bytes it + * would have written but write nothing to that buffer. + */ + context->written += written; + + if (written < context->linebuflen) { + context->linebuf += written; + context->linebuflen -= written; + } else { + context->linebuf += context->linebuflen; + context->linebuflen = 0; + } + + return (written); +} + +int +lkpi_hex_dump_to_buffer(const void *buf, size_t len, int rowsize, + int groupsize, char *linebuf, size_t linebuflen, bool ascii) +{ + int written; + struct hdtb_context context; + + context.linebuf = linebuf; + context.linebuflen = linebuflen; + context.written = 0; + + if (rowsize != 16 && rowsize != 32) + rowsize = 16; + + len = min(len, rowsize); + + lkpi_hex_dump( + hdtb_cb, &context, NULL, NULL, DUMP_PREFIX_NONE, + rowsize, groupsize, buf, len, ascii, false); + + written = context.written; + + return (written); +} + static void linux_timer_callback_wrapper(void *context) {