-
Notifications
You must be signed in to change notification settings - Fork 937
Detect if calloc calls malloc #1500
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
Conversation
|
While thinking about this issue, the solution that made most sense to me was something along the lines of what is implented here However I have some doubts On a similar note, do we want to support other patterns the user might introduce via an LD_PRELOAD? (For example a user might change malloc to call calloc) |
|
@Baraa-Hasheesh Checking only one type of relation (calloc calling malloc) was a conscious choice. This relation is a distinctive characteristic of musl's own memory allocator. Other popular allocators (glibc's malloc, jemalloc, tcmalloc, mimalloc) do not do cross-calls via PLT. Checking relation between posix_memalign and aligned_alloc would require writing more code in vain (with no effect for the above allocators). At the same time, it would not be a complete solution for a custom user-provided allocator anyway. Support for custom allocators that hook arbitrary |
src/mallocTracer.cpp
Outdated
| static bool _recursive_malloc = false; | ||
|
|
||
| // Test if calloc() implementation calls malloc() | ||
| static void* recursive_malloc_hook(size_t size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if "recursive" is the right naming, as function is not calling itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I had doubts about that too, but decided it's still recursive in the sense the malloc algorithm (as the whole) calls to itself via PLT. Do you have a suggestion how to name it better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to nested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Nested" sounds good, as we are calling all malloc-family functions malloc here.
Description
Use temporary malloc hook to detect if
callocimplementation callsmallocunder the hood. This is required for propernativememprofiling.Related issues
#1466
Motivation and context
Various malloc implementations may or may not do cross-calls. For example, default
callocin musl libc callsmallocinternally. Async-profiler handles this case specially to prevent double-counting of native memory alocations. Previously, it simply checkedOS::isMusl, but this was inaccurate, since musl libc could be built with different malloc libraries. For example, in Alpaquita Linux, musl is linked with mimalloc, wherecallocdoes not callsmalloc.How has this been tested?
nativememtests now pass on Alpaquita Linux as well as on vanilla Alpine.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.