From patchwork Mon Dec 1 17:04:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 784 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=1764608899; bh=UkJn/vEl5xnKbYeCBuKeKvloFCIvMZd1WwQIqkl6MCM=; 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=JCfp0VeVJeelTdDJOwbUxarjVFZEqx88E0xpxYOoUsvHQfjvphfIJZ8rKe+Kz2Wzp s4JzCj4kM5m7lL+Wa1ELJEtStyUkvrBK0F84A7WJE+1oiVFiH4iOVuuesqD+woEd1C mkew+wZjHEsTmWsTv7+1tksZgBRB5x5eEdf1nUi4L514omZ815FhKbZmevAQeihyXH 7Uv3cYZTP/TwllvfxFf128Htch6GgcklL/BugdYPwAsFXTj9pucuS4JqYhFrijU8NU N/VG9UiPeriXA5E4TabEXC6Z/OLk7GSN6PKF/LMZiT/sl00Fs5xemiPHbSomGYp4DL 1hBor4TO6xZbA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 46A0F688CF for ; Mon, 1 Dec 2025 10:08:19 -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 yHa7jXljEeQi for ; Mon, 1 Dec 2025 10:08:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608899; bh=UkJn/vEl5xnKbYeCBuKeKvloFCIvMZd1WwQIqkl6MCM=; 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=JCfp0VeVJeelTdDJOwbUxarjVFZEqx88E0xpxYOoUsvHQfjvphfIJZ8rKe+Kz2Wzp s4JzCj4kM5m7lL+Wa1ELJEtStyUkvrBK0F84A7WJE+1oiVFiH4iOVuuesqD+woEd1C mkew+wZjHEsTmWsTv7+1tksZgBRB5x5eEdf1nUi4L514omZ815FhKbZmevAQeihyXH 7Uv3cYZTP/TwllvfxFf128Htch6GgcklL/BugdYPwAsFXTj9pucuS4JqYhFrijU8NU N/VG9UiPeriXA5E4TabEXC6Z/OLk7GSN6PKF/LMZiT/sl00Fs5xemiPHbSomGYp4DL 1hBor4TO6xZbA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 29462688D2 for ; Mon, 1 Dec 2025 10:08:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608895; bh=PPotmIdGx5wy3GVBOIb2IidldP9/OXNqdp/IMU27iU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pS3jeluyN4Xs4UgP0hR165dqCY4m1K0PXNmX2UFgTcERDsne4iOozoVHOyVoiIca+ wLD7VnSjR+9JK392948Jg347/1DE6RxHMnqgqifFA21jUj7yh49VZ+EhJo31s/djdo KrOINyRk/eNVcIHyyIpqg2N/1XgKp/WeydFMcunfXc/XbDW+41ztfj4ZtRl5Lx5ZNf r6oS+lUunxE1lAK3Itb3/Iu51WMVOtwBAwh1WyOftTFXrIR/RxEP9lfZb00UVJsshN +2beHholPyq/64LpLgKztIlztFEe/OTNum2yp2GwIF/Xof/9N6qjYGWfoPherZ108F jcMRlCXuai8gQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E5974688A7; Mon, 1 Dec 2025 10:08:15 -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 sb5_0GsMBU8i; Mon, 1 Dec 2025 10:08:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608895; bh=66bklsFfLpH4VhV0yyBxRurV1U6H2OQMBdH+4uQRMi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=srjgr43GHOaoOm/QUyvIZbCaABKj9Tk8iie00hwJF3qKCBM+BuCkai0SQ/hfiTWp0 TfTSEGLQfJ44JmmdcpO+HCg2jmph8oMhDeY90s1UsNAnBHaYyD+FZ+iK9pla+EhLVE 7KtMhLIWHYXC0mnqnDnSs6JiGY7kh10Eg9Bp+u4K+IauLBUItgZtAPUz3M1dG+NfXl ak4LgRnnnYJxi/sjEmuF/EvxVWnwtsyZaid0nJnkswirxhH/qcfahVS8rp0WSiM02c u9EJrmIwMkO11I+jFOqlNVv1bDcLy5RWOdQSCZW2a+VnKBGdDdfEgNd+meC2O4kmZG NO93Kc0hmbwvA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1E3266881A; Mon, 1 Dec 2025 10:08:15 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 1 Dec 2025 10:04:48 -0700 Message-ID: <20251201170529.3237986-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251201170529.3237986-1-sjg@u-boot.org> References: <20251201170529.3237986-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: UZCVTAHQD6JMTTSS6Z4KSXXWROVS5ITB X-Message-ID-Hash: UZCVTAHQD6JMTTSS6Z4KSXXWROVS5ITB 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 09/37] malloc: Add U-Boot configuration for dlmalloc 2.8.6 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 Add an #ifdef __UBOOT__ section to configure dlmalloc for U-Boot's embedded environment: - Disable mmap, set LACKS_* for unavailable headers - Include string.h and errno.h - Add ABORT definition using infinite loop - Define DEBUG 0 to avoid assert redefinition issues - Fix dlmalloc_footprint_limit() prototype (add void) - Fix dlmalloc_usable_size() to use const void * - Use MFAIL instead of MORECORE_FAILURE in sbrk() Co-developed-by: Claude Signed-off-by: Simon Glass --- common/dlmalloc.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 2be2262ebeb..480dd46c0cf 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -543,6 +543,26 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP #endif #ifdef __UBOOT__ + +#define LACKS_FCNTL_H +#define LACKS_UNISTD_H +#define LACKS_SYS_PARAM_H +#define LACKS_SYS_MMAN_H +#define LACKS_SYS_TYPES_H +#define LACKS_SCHED_H +#define LACKS_TIME_H +#define HAVE_MMAP 0 +#define HAVE_MREMAP 0 +#define MORECORE_CONTIGUOUS 1 +#define MORECORE_CANNOT_TRIM 1 +#define MORECORE_CLEARS 1 +#define NO_MALLOC_STATS 1 +#define USE_LOCKS 0 +#define USE_SPIN_LOCKS 0 +#define MALLOC_FAILURE_ACTION +#define ABORT do {} while (1) + +#include #include #include @@ -1020,7 +1040,7 @@ DLMALLOC_EXPORT size_t dlmalloc_max_footprint(void); guarantee that this number of bytes can actually be obtained from the system. */ -DLMALLOC_EXPORT size_t dlmalloc_footprint_limit(); +DLMALLOC_EXPORT size_t dlmalloc_footprint_limit(void); /* malloc_set_footprint_limit(); @@ -1281,7 +1301,7 @@ DLMALLOC_EXPORT void dlmalloc_stats(void); p = malloc(n); assert(malloc_usable_size(p) >= 256); */ -size_t dlmalloc_usable_size(void*); +size_t dlmalloc_usable_size(const void*); #endif /* ONLY_MSPACES */ @@ -5400,9 +5420,9 @@ int dlmallopt(int param_number, int value) { return change_mparam(param_number, value); } -size_t dlmalloc_usable_size(void* mem) { +size_t dlmalloc_usable_size(const void* mem) { if (mem != 0) { - mchunkptr p = mem2chunk(mem); + mchunkptr p = mem2chunk((void*)mem); if (is_inuse(p)) return chunksize(p) - overhead_for(p); } @@ -6314,7 +6334,7 @@ void *sbrk(ptrdiff_t increment) /* mem_malloc_end points one byte past the end, so >= is correct */ if ((new < mem_malloc_start) || (new >= mem_malloc_end)) - return (void *)MORECORE_FAILURE; + return MFAIL; /* * if we are giving memory back make sure we clear it out since