As Branislav Katreniak wrote:
I want to use a multitasking OS in my project. What is the best way
to encapsulate all calls to malloc() and free() with a
synchronization primitives? I want all calls to these functions
(even from other libc functions) to be reentrant safe and ideally
I'd like to use official libc library without any modifications.
First, if you don't use stdio (or only use sprintf without
floating-point), the library doesn't use malloc() itself, so it would
suffice to wrap malloc() and free() in your own macros.
If you need stdio functions that call malloc, hmm, I think that'll put
something else onto your list of non-reentrant functions ;-), but
still, you could just import the implementations for malloc/free into
your own application, and make them thread-safe.