From patchwork Fri Jan 2 00:50:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1172 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315113; bh=BDk4Ws/ufE56zj90m+kQNWxrzSTvSMCdNh8BVdcdmQw=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=AQptBJRPQb/qE/ym0NofE1zDZZj7EwMGCNdFzY7DK9JShzL48dBJp8onqaBP2GF+W 77DlycDXREe3z8Q9IxrK9n7wlB3yb0UqrVqBowjv6S/D8G9two9oxqZGFFA0t2+J2L kYT1iky+/T9MYq4+HTUY1Hic+yIlsB+ORGic7BtQPLdPOnX9Adqvze/iNp4ki3Xp00 sCgftS4ny9vBPQJtrzUgO1puOFq9J4sRkKrESs4hvvVUKxgIuFdWIXNZwc3WUN8EVT TDjr5BUS8orXXw+GUmyQvyZywRm1Gp0Kd40UUQDOd6Z3loHb2E/fh31e+JPcF7DJsP ZvZb3jYA0YN+g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C4E1A68FFD for ; Thu, 1 Jan 2026 17:51:53 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id EsL3rrjvC_1Z for ; Thu, 1 Jan 2026 17:51:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315112; bh=BDk4Ws/ufE56zj90m+kQNWxrzSTvSMCdNh8BVdcdmQw=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Jpeug1W3PWgMKzGWfCYWMzzGag7KWpdkgg7qgv0Sb+rRnGKOLZepePbr7zlyZVgkr wuI1NYdu6j+c/RgVN5YMZxCFYyYZuyiHVBnQJxlCIFDJWj/6Rx5QJFkVE7XV+ZHefp +fT9MK2TzJ77bjdYt7n6jizu/IWibcghYFyQRXM25lnqx19pXtsnu9BChWrQK1XGjd fJ2KrEzCMofL1X52lhPBHtYSMQ6nuOOHLyUuKUHFtte/NS0zpeynjpZRrzx12k/3zX jBXMoxz8O0OBKJ/ReOAiLWrVtAMj8U+3KO/j4t3MmtCS2FUsx6e7IGMGIEuii97JZZ ZrgsnSWOgBybg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1D87469010 for ; Thu, 1 Jan 2026 17:51:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315109; bh=yiVP8HLA1mkUPVFWrHUYBZkJNerFDUhnA60IakuitXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HkFip4PPnrFnDLmrIwslNhWPxrfRcFJN4DJ4hF5bYxmryZCuo6UQDy/sFNfQLKQuY pB95nvwYbXxJUd34RMuHt+n3Y6fjmmsQ1swW6Mq4iTu+BEbis1TYkF9J8j9xKAo6iy 0sft6+AUozgnxa6dnOogokxHE6UOu+gFveAqPcX1edn7ZX6fkxmcGvdAKJB0QOmJWs 5D7YqTPPlUuxCRfJH4w29s4DExEMM/649yodbkAXwVa19m2zVuKxrR2hEtaJZbI59D /3kHoRkFsH5q0KIylgepojmA6KHYf1b8np9aTw4UW1b+DLpUlF1xZJsKfR4MFCGu28 l73l4jeg7BVpw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E8D1D68313; Thu, 1 Jan 2026 17:51:49 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id iBfBlCROLmQo; Thu, 1 Jan 2026 17:51:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315109; bh=JynQcMwTEbamLUuFEdG7sGoFZhrD8ckN15WkNeAU55Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L0x7Y/ZP1QpLkLM71kKyK6Hx5jXZpy2u5KuwS0enNR39rO59xF9UClTtdp5f5k7qI J02CNRdc0gegwZ5G/QVJL5p/XeZ/5abE4BPqzaAEFH83eSSFdZ5WLzlIRwn96hy+iC sbxCQdCYmT+p9i1jHeB4ubuyF2petdSjOWpDTK88V8/ILBAQTPNNtLp3KW2QjejFhR cUnigr7H6AQwRAWKjGnsEEzCd2lvljlZKE+oij59c0rcrjluNOjbcqHC5iKDUSced8 CswKTH1L2qZXvxzY2ZklLejtEDHfF4tSp5fPGeYqwWIYmS7y6G7xr95SAvbJ/3wN0i mWvOf4gb2wapw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 54DD368F58; Thu, 1 Jan 2026 17:51:49 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Thu, 1 Jan 2026 17:50:38 -0700 Message-ID: <20260102005112.552256-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260102005112.552256-1-sjg@u-boot.org> References: <20260102005112.552256-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: BMA7KV3YFNDEPNJKOVYP4PACYPYQZELT X-Message-ID-Hash: BMA7KV3YFNDEPNJKOVYP4PACYPYQZELT X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 08/30] mcheck: Add Kconfig option for caller string length List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The mcheck heap protection stores a caller string in each allocation header for debugging purposes. The length is hard-coded to 48 bytes in mcheck_core.inc.h Add a CONFIG_MCHECK_CALLER_LEN Kconfig option to make this configurable, allowing users to adjust the trade-off between the amount of debugging context and the memory overhead per allocation. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- (no changes since v1) Kconfig | 11 +++++++++++ common/mcheck_core.inc.h | 5 ++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Kconfig b/Kconfig index c28fddf5016..3b89f2c48dd 100644 --- a/Kconfig +++ b/Kconfig @@ -355,6 +355,17 @@ config MCHECK_HEAP_PROTECTION significantly increases memory overhead and should only be used for debugging. +config MCHECK_CALLER_LEN + int "Length of caller string in mcheck header" + depends on MCHECK_HEAP_PROTECTION + default 48 + help + Sets the maximum length of the caller string stored in each + allocation header. This string records the function/file/line + that allocated the memory, useful for debugging memory leaks. + Larger values provide more context but increase memory overhead + per allocation. + config SPL_SYS_MALLOC_F bool "Enable malloc() pool in SPL" depends on SPL_FRAMEWORK && SYS_MALLOC_F && SPL diff --git a/common/mcheck_core.inc.h b/common/mcheck_core.inc.h index 598a5d018ab..fa152790d45 100644 --- a/common/mcheck_core.inc.h +++ b/common/mcheck_core.inc.h @@ -73,7 +73,6 @@ // Full test suite can exceed 10000 concurrent allocations #define REGISTRY_SZ 12000 #define CANARY_DEPTH 2 -#define MCHECK_CALLER_LEN 48 // avoid problems with BSS at early stage: static char mcheck_pedantic_flag __section(".data") = 0; @@ -89,7 +88,7 @@ struct mcheck_hdr { size_t size; /* Exact size requested by user. */ size_t aln_skip; /* Ignored bytes, before the mcheck_hdr, to fulfill alignment */ mcheck_canary canary; /* Magic number to check header integrity. */ - char caller[MCHECK_CALLER_LEN]; /* caller info for debugging */ + char caller[CONFIG_MCHECK_CALLER_LEN]; /* caller info for debugging */ }; static void mcheck_default_abort(enum mcheck_status status, const void *p) @@ -212,7 +211,7 @@ static void *mcheck_allocated_helper(void *altoghether_ptr, size_t customer_sz, for (i = 0; i < CANARY_DEPTH; ++i) hdr->canary.elems[i] = MAGICWORD; if (caller) - strlcpy(hdr->caller, caller, MCHECK_CALLER_LEN); + strlcpy(hdr->caller, caller, CONFIG_MCHECK_CALLER_LEN); else hdr->caller[0] = '\0';