Skip to content
Advertisement

Is malloc/free a syscall or a library routine provided by libc?

If malloc/free is implemented as a library routine in libc, then is it implemented on top of the sbrk syscall or the mmap syscall, or something else?

And to be general, does the function declared in sys/syscall.h contains ALL the system calls in the target machine?

Advertisement

Answer

malloc and free are standard C library functions which are to be implemented by each C implementation.

The C standard only defines the way in which these functions behave and the behavior expected from them. How they are to be implemented in left to each implementation.

In short they are implementation detail of the implementation you use.

(An “implementation” consists of the compiler, the linker, the runtime library, and probably a few other things.)

Advertisement