How to overload the system call in the userland program?

Yuri yuri at rawbw.com
Sat Dec 1 00:01:19 UTC 2012


I am looking into one library (google-perftools) that attempts to 
overload sbrk(2).
In Linux libc translates calls, ex. sbrk -> __sbrk (in libc), so one can 
define their own version, call extern __sbrk and it works.
FreeBSD programs connect to the symbol sbrk@@FBSD_1.0

So what is the way to overload the system call like this would be in linux?:

extern "C" void* __sbrk(ptrdiff_t increment);
extern "C" void* sbrk(intptr_t increment) {
   return__sbrk(increment);
}

Yuri



More information about the freebsd-hackers mailing list