Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native: dynamically load malloc #4044

Merged
merged 1 commit into from
Oct 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cpu/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,29 @@ void _native_syscall_leave(void)
}
}

#ifdef NATIVE_IN_MALLOC
int _native_in_malloc = 1;
#else
int _native_in_malloc = 0;
#endif
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