Skip to content
Snippets Groups Projects
Commit 50b57d8f authored by chrg's avatar chrg
Browse files

Apperantly sometime dlsym uses calloc (twice)

parent 036f25c1
No related branches found
No related tags found
No related merge requests found
...@@ -48,8 +48,23 @@ calloc(size_t nmemb, size_t size) { ...@@ -48,8 +48,23 @@ calloc(size_t nmemb, size_t size) {
COUNTDOWN_OR_BREAK COUNTDOWN_OR_BREAK
static void *(*fptr)(size_t, size_t) = NULL; static void *(*fptr)(size_t, size_t) = NULL;
fptr = fptr ? fptr if (fptr == NULL) {
: ((void *(*)(size_t, size_t)) dlsym(RTLD_NEXT, "calloc")); // To bootstrap calloc we need to allow dlsym to allocate some memmory.
static uint8_t calloc_is_recusive_call = 0;
if (calloc_is_recusive_call++) {
static uint8_t bootstrap_memory[BUFFER_SIZE];
static uint8_t * bootstrap_pointer = bootstrap_memory;
// Check that we don't bootstrap too much memmory we try to allocate too
// much memory
if (size + (bootstrap_memory - bootstrap_pointer) > BUFFER_SIZE)
abort();
void * ret = bootstrap_pointer;
bootstrap_pointer += size + (size % 8 && 8 - size % 8);
return ret;
}
fptr = ((void *(*)(size_t, size_t)) dlsym(RTLD_NEXT, "calloc"));
calloc_is_recusive_call = 0;
}
if (fptr == NULL) abort(); if (fptr == NULL) abort();
return (*fptr)(nmemb, size); return (*fptr)(nmemb, size);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment