Skip to content

Commit

Permalink
Merge pull request RIOT-OS#4043 from LudwigOrtmann/pr/native-gpp520
Browse files Browse the repository at this point in the history
native: dynamically load malloc
  • Loading branch information
OlegHahm committed Oct 4, 2015
2 parents 3a77e96 + dd3229a commit 76e5126
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cpu/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,25 @@ void _native_syscall_leave(void)
}
}

int _native_in_malloc = 0;
void *malloc(size_t size)
{
/* dynamically load malloc when it's needed - this is necessary to
* support g++ 5.2.0 as it uses malloc before startup runs */
if (!real_malloc) {
if (_native_in_malloc) {
/* XXX: This is a dirty hack for behaviour that came along
* with g++ 5.2.0.
* Throw it out when whatever made it necessary it is fixed. */
return NULL;
}
else {
_native_in_malloc = 1;
*(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc");
_native_in_malloc = 0;
}
}

void *r;
_native_syscall_enter();
r = real_malloc(size);
Expand Down

0 comments on commit 76e5126

Please sign in to comment.