xref: /aosp_15_r20/external/compiler-rt/lib/interception/interception_linux.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- interception_linux.cc -----------------------------------*- C++ -*-===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file is a part of AddressSanitizer, an address sanity checker.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot // Linux-specific interception methods.
13*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
14*7c3d14c8STreehugger Robot 
15*7c3d14c8STreehugger Robot #if defined(__linux__) || defined(__FreeBSD__)
16*7c3d14c8STreehugger Robot #include "interception.h"
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot #include <dlfcn.h>   // for dlsym() and dlvsym()
19*7c3d14c8STreehugger Robot 
20*7c3d14c8STreehugger Robot namespace __interception {
GetRealFunctionAddress(const char * func_name,uptr * func_addr,uptr real,uptr wrapper)21*7c3d14c8STreehugger Robot bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
22*7c3d14c8STreehugger Robot     uptr real, uptr wrapper) {
23*7c3d14c8STreehugger Robot   *func_addr = (uptr)dlsym(RTLD_NEXT, func_name);
24*7c3d14c8STreehugger Robot   return real == wrapper;
25*7c3d14c8STreehugger Robot }
26*7c3d14c8STreehugger Robot 
27*7c3d14c8STreehugger Robot #if !defined(__ANDROID__)  // android does not have dlvsym
GetFuncAddrVer(const char * func_name,const char * ver)28*7c3d14c8STreehugger Robot void *GetFuncAddrVer(const char *func_name, const char *ver) {
29*7c3d14c8STreehugger Robot   return dlvsym(RTLD_NEXT, func_name, ver);
30*7c3d14c8STreehugger Robot }
31*7c3d14c8STreehugger Robot #endif  // !defined(__ANDROID__)
32*7c3d14c8STreehugger Robot 
33*7c3d14c8STreehugger Robot }  // namespace __interception
34*7c3d14c8STreehugger Robot 
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot #endif  // __linux__ || __FreeBSD__
37