From patchwork Wed Dec 10 00:07:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 880 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=1765325387; bh=lfarUQHq5lpwJgUNK1aKCMKUp2pbrzKdnPuXmffLxKo=; 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=KPHnocV9d7PymS291I3SwrSPN4glZ9ifGGbC7Nw07TYvsv5SfL2Z3z5CHXfsza5L6 KAWCnPDgxohf1Z/nlKqiX0VQzIIJWtwPezHqaM1Mk0HqgmE2Qh6f1K98ZyIbzVm2M5 cPKYZZMBYFZYY8SUfuOo1MWeNGyy3Yw5uuoLWcCMeknVJHh/FDg1aQPPdpoCt+8soH 4ZCKuja/MkrR56jl9Z5hyhxoxNHkbAWCjnP8sbHtoXBLfPfcuNkUi/BTCGHt9oBP9I TJf4R5QwJmHIy7N1CmXFcDlRDN7J+eQ345m6ZyS173m94JFR1sY8OdP6IH4Cn9oF97 cp5l6OAkt/irw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7D27268973 for ; Tue, 9 Dec 2025 17:09:47 -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 YqHgG5lzBKZc for ; Tue, 9 Dec 2025 17:09:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325385; bh=lfarUQHq5lpwJgUNK1aKCMKUp2pbrzKdnPuXmffLxKo=; 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=mx9epStCqafg7iXfiPhq/V86XToMC3gZD8g8neS6K7RZqfAU/MAUYxkV+N5Ldntgy VYCYWfTJ5dyGvx536t4/TLtnOE1a0ocrLjzJBjoJR2LbQ3HkqkjiYKe0H/H46qhrKI ctBdQG6hjeMuZk3Y4CEcnMswwMWMzDDxzBoDrmPYOhx6nrZmy+g5etPrm52LC/PpdV CEi9qpyYXhBN9TxyVfkIOU1uf9CAkUJBbAZm+D+9edgWnrG7Y4TF+EN3W922Yn4g+y XMAUhhZu86o/kEejX56SVE2S5aPCPzI4H/RIe/2MkccW8P4e/2O8MJwcygxQFz1KZP /FkwFyeGmt4rw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7656268A44 for ; Tue, 9 Dec 2025 17:09:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325382; bh=pE+Cw/xl/FW4lz4jZPkATYX1xFqgh/c3ZVy96Le7oas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k867dXp1XlsgVBUwG9pfN2pCkILYgdHW0IpUKxyDLjLx46Wkrzdh6szkW6xspUdCS yDdPbRLaImbFM/WmwPJh4ilHB8/kOSW7aIQOga7GOJzslTqtfZRbpd3fxMhrBW4/FN wNTw1WCFVTM2uPSEff9tvX5Q2A8M4XuVJp5hB2lNZ3lNmJ7hX7WjxShK/pVZp3WGyV DjhwY13AbVopNw99FCLBCcHQH0OJyyl0T4Z8qevC88MGsakkMiom/pvSyFn0CTmYnJ KbfgmPH/0B8Tui+iQtpehuO5DdQ++BjZJB8QrixOyrVzV3k0ff1dCUfGKCLr3STjxO 1+nMQ763b7O4w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D7FA5689EA; Tue, 9 Dec 2025 17:09:42 -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 sJo9aeuKt10D; Tue, 9 Dec 2025 17:09:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325382; bh=Yb/EqtJ1GB/V9d4PymG+VkQxAJgcRhphLGh1Ster3Ys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d5CRZ7PdqNZ90JZNrMa84QxkqhiikyINmstJDO6jecFEeiq/08xQZbZb3tINPcZ+M AH/VgpZmAbEAhAuRowFW3cKshFbpVpO0/878pohE6KBYyshajxTPXuqRhBahXMUhYz iYYVmkL1t8vc/fT4sjKLg7joF1xU09FxPFGBRwZrnSWbqv6wWXqu/UfDla/GFgx+Fc MqHi112t5JWYrystu1a5tRB49CLUzABURP0zGaSa9jxxuZTDbVZQB5e1X3Nk90nTHN vXdu5NjhGtjNi4RiVVMpAIQs9XOiwmQtsS7cz41j2ltTtj0kW4iURa19ZDNmHeFNCl 1uUXpZGpkHLHQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 037826884F; Tue, 9 Dec 2025 17:09:41 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 9 Dec 2025 17:07:14 -0700 Message-ID: <20251210000737.180797-24-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251210000737.180797-1-sjg@u-boot.org> References: <20251210000737.180797-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 63V5QL37GEPGZEDYEHCBREVRRQOIG4ZK X-Message-ID-Hash: 63V5QL37GEPGZEDYEHCBREVRRQOIG4ZK 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 23/35] malloc: Update the valloc functions to use mcheck wrappers 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 Fix dlposix_memalign(), dlvalloc(), and dlpvalloc() to call dlmemalign() instead of dlmemalign_impl() or internal_memalign() directly. This ensures these functions go through the mcheck wrappers when CONFIG_MCHECK_HEAP_PROTECTION is enabled. Without this fix, internal_memalign is undefined when mcheck is enabled, causing a build error. Co-developed-by: Claude Signed-off-by: Simon Glass --- common/dlmalloc.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index bcdb4d29424..e288d94d433 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -4096,7 +4096,7 @@ static void unlink_large_chunk(mstate M, tchunkptr X) { * When mcheck is enabled, internal calls must use the _impl functions * to avoid going through the mcheck wrappers which expect user pointers. */ -#ifdef CONFIG_MCHECK_HEAP_PROTECTION +#if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) #define internal_malloc(m, b) dlmalloc_impl(b) #define internal_free(m, mem) dlfree_impl(mem) #else @@ -5827,39 +5827,32 @@ void* dlmemalign_impl(size_t alignment, size_t bytes) { int dlposix_memalign(void** pp, size_t alignment, size_t bytes) { void* mem = 0; - if (alignment == MALLOC_ALIGNMENT) - mem = dlmalloc_impl(bytes); - else { - size_t d = alignment / sizeof(void*); - size_t r = alignment % sizeof(void*); - if (r != 0 || d == 0 || (d & (d-SIZE_T_ONE)) != 0) - return EINVAL; - else if (bytes <= MAX_REQUEST - alignment) { - if (alignment < MIN_CHUNK_SIZE) - alignment = MIN_CHUNK_SIZE; - mem = internal_memalign(gm, alignment, bytes); - } - } + size_t d = alignment / sizeof(void*); + size_t r = alignment % sizeof(void*); + + if (r != 0 || d == 0 || (d & (d-SIZE_T_ONE)) != 0) + return EINVAL; + if (bytes > MAX_REQUEST - alignment) + return ENOMEM; + mem = dlmemalign(alignment, bytes); if (mem == 0) return ENOMEM; - else { - *pp = mem; - return 0; - } + *pp = mem; + return 0; } void* dlvalloc(size_t bytes) { size_t pagesz; ensure_initialization(); pagesz = mparams.page_size; - return dlmemalign_impl(pagesz, bytes); + return dlmemalign(pagesz, bytes); } void* dlpvalloc(size_t bytes) { size_t pagesz; ensure_initialization(); pagesz = mparams.page_size; - return dlmemalign_impl(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE)); + return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE)); } void** dlindependent_calloc(size_t n_elements, size_t elem_size,