From 6ea3af57272f5bdfcae73bd41dc48d56c0bdc035 Mon Sep 17 00:00:00 2001 From: vreusch Date: Thu, 18 Dec 2025 13:31:56 +0100 Subject: [PATCH] fixup! Added memory backend --- .../libc/stdlib/malloc-standard/calloc.c | 64 +++---------------- .../libpthread/src/sysdeps/x86_64/tls.h | 6 +- 2 files changed, 13 insertions(+), 57 deletions(-) diff --git a/src/l4/pkg/l4re-core/libc/uclibc-ng/contrib/uclibc/libc/stdlib/malloc-standard/calloc.c b/src/l4/pkg/l4re-core/libc/uclibc-ng/contrib/uclibc/libc/stdlib/malloc-standard/calloc.c index ccf295e8..2a5f541b 100644 --- a/src/l4/pkg/l4re-core/libc/uclibc-ng/contrib/uclibc/libc/stdlib/malloc-standard/calloc.c +++ b/src/l4/pkg/l4re-core/libc/uclibc-ng/contrib/uclibc/libc/stdlib/malloc-standard/calloc.c @@ -18,12 +18,14 @@ /* ------------------------------ calloc ------------------------------ */ +/* + * Our libc_be_mem allocator does not wrap calloc. + * So we need to implement calloc only using the public-facing malloc call without relying on libc + * internals. + */ void* calloc(size_t n_elements, size_t elem_size) { - mchunkptr p; - unsigned long clearsize; - unsigned long nclears; - size_t size, *d; + size_t size; void* mem; @@ -35,59 +37,9 @@ void* calloc(size_t n_elements, size_t elem_size) return NULL; } - __MALLOC_LOCK; mem = malloc(size); - if (mem != 0) { - p = mem2chunk(mem); - - if (!chunk_is_mmapped(p)) - { - /* - Unroll clear of <= 36 bytes (72 if 8byte sizes) - We know that contents have an odd number of - size_t-sized words; minimally 3. - */ - - d = (size_t*)mem; - clearsize = chunksize(p) - (sizeof(size_t)); - nclears = clearsize / sizeof(size_t); - assert(nclears >= 3); - - if (nclears > 9) - memset(d, 0, clearsize); - - else { - *(d+0) = 0; - *(d+1) = 0; - *(d+2) = 0; - if (nclears > 4) { - *(d+3) = 0; - *(d+4) = 0; - if (nclears > 6) { - *(d+5) = 0; - *(d+6) = 0; - if (nclears > 8) { - *(d+7) = 0; - *(d+8) = 0; - } - } - } - } - } -#if 0 - else - { - /* Standard unix mmap using /dev/zero clears memory so calloc - * doesn't need to actually zero anything.... - */ - d = (size_t*)mem; - /* Note the additional (sizeof(size_t)) */ - clearsize = chunksize(p) - 2*(sizeof(size_t)); - memset(d, 0, clearsize); - } -#endif - } - __MALLOC_UNLOCK; + if (mem != 0) + memset(mem, 0, size); return mem; } diff --git a/src/l4/pkg/l4re-core/libc/uclibc-ng/libpthread/src/sysdeps/x86_64/tls.h b/src/l4/pkg/l4re-core/libc/uclibc-ng/libpthread/src/sysdeps/x86_64/tls.h index c3366fa0..b7889bc9 100644 --- a/src/l4/pkg/l4re-core/libc/uclibc-ng/libpthread/src/sysdeps/x86_64/tls.h +++ b/src/l4/pkg/l4re-core/libc/uclibc-ng/libpthread/src/sysdeps/x86_64/tls.h @@ -147,7 +147,11 @@ typedef struct // vector registers in the TCB and we want the storage to be aligned. // unfortunately there isn't yet a type for these values and hence no // 32-byte alignment requirement. Make this explicit, for now. -# define TLS_TCB_ALIGN 32 +// # define TLS_TCB_ALIGN 32 +// The libc_be_mem allocator does not wrap memalign. +// This hack avoids libpthread actually using memalign but is very likely not +// correct and might lead to problems later on. +# define TLS_TCB_ALIGN 4 /* The TCB can have any size and the memory following the address the thread pointer points to is unspecified. Allocate the TCB there. */