1 //===-- interception_aix.cpp ------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is a part of AddressSanitizer, an address sanity checker. 10 // 11 // AIX-specific interception methods. 12 //===----------------------------------------------------------------------===// 13 14 #include "interception.h" 15 #include "sanitizer_common/sanitizer_common.h" 16 17 #if SANITIZER_AIX 18 19 # include <dlfcn.h> // for dlsym() 20 21 namespace __interception { 22 23 static void *GetFuncAddr(const char *name, uptr wrapper_addr) { 24 // AIX dlsym can only defect the functions that are exported, so 25 // on AIX, we can not intercept some basic functions like memcpy. 26 // FIXME: if we are going to ship dynamic asan library, we may need to search 27 // all the loaded modules with RTLD_DEFAULT if RTLD_NEXT failed. 28 void *addr = dlsym(RTLD_NEXT, name); 29 30 // In case `name' is not loaded, dlsym ends up finding the actual wrapper. 31 // We don't want to intercept the wrapper and have it point to itself. 32 if ((uptr)addr == wrapper_addr) 33 addr = nullptr; 34 return addr; 35 } 36 37 bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func, 38 uptr wrapper) { 39 void *addr = GetFuncAddr(name, wrapper); 40 *ptr_to_real = (uptr)addr; 41 return addr && (func == wrapper); 42 } 43 44 } // namespace __interception 45 #endif // SANITIZER_AIX 46