Globally override malloc in visual c++

后端 未结 7 800
死守一世寂寞
死守一世寂寞 2020-12-06 01:47

I\'m trying to figure out a way to globally override malloc and related functions in visual c++ (2005). My setup is a dll with statically linked runtime library that consist

7条回答
  •  半阙折子戏
    2020-12-06 02:32

    Unfortunately I don't know enough about the microsoft linker. But ld has '--wrap' which you can use for anything like malloc or free or anything else (I do this).

    all calls to malloc will be redirected to a function called __wrap_malloc which you have implemented, you can then call real malloc with __real_malloc. This has the benefit of capturing any mallocs used in external libraries too. I'm sure the Microsoft linker might have a similar function.

提交回复
热议问题