mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/6] malloc: define a maximum malloc size
@ 2025-02-20 20:30 Ahmad Fatoum
  2025-02-20 20:30 ` [PATCH 2/6] tlsf: fail allocations exceeding MALLOC_MAX_SIZE Ahmad Fatoum
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-02-20 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Richard Weinberger, Ahmad Fatoum

TLSF and dlmalloc each already enforce a maximum allocation size.

Let's define SZ_1G as common maximum allocation size in preparation
for aligning all allocators to observe it.

The intention is to make code easier to reason about and as extra
hardening against possible, yet undiscovered, allocator bugs.

Suggested-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/malloc.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/malloc.h b/include/malloc.h
index 7bee03dab236..c38726342c08 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,6 +5,9 @@
 #include <linux/compiler.h>
 #include <types.h>
 
+#define MALLOC_SHIFT_MAX	30
+#define MALLOC_MAX_SIZE		(1UL << MALLOC_SHIFT_MAX)
+
 #if IN_PROPER
 void *malloc(size_t) __alloc_size(1);
 size_t malloc_usable_size(void *);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-02-21 12:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-20 20:30 [PATCH 1/6] malloc: define a maximum malloc size Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 2/6] tlsf: fail allocations exceeding MALLOC_MAX_SIZE Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 3/6] dlmalloc: " Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 4/6] sandbox: libc_malloc: " Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 5/6] dummy_malloc: " Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 6/6] test: self: malloc: adapt to addition of MALLOC_MAX_SIZE Ahmad Fatoum
2025-02-21 12:20 ` [PATCH 1/6] malloc: define a maximum malloc size Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox