fixup! Added memory backend
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user