How do I reimplement (or wrap) a syscall function on Linux?

前端 未结 2 1392
我在风中等你
我在风中等你 2020-11-30 23:41

Suppose I want to completely take over the open() system call, maybe to wrap the actual syscall and perform some logging. One way to do this is to use LD_PRELOAD to load a (

2条回答
  •  北海茫月
    2020-12-01 00:11

    Symbols are resolved by the linker in the order you list them on the command line so if you listed your library before the standard library you'd have precidence. For gcc you'd need to specify

    gcc  -nodefaultlibs  -lYOUR_LIB 
    

    This way your libraries would be searched and found first.

提交回复
热议问题