Path: blob/main/contrib/llvm-project/compiler-rt/lib/interception/interception_aix.cpp
213765 views
//===-- interception_aix.cpp ------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of AddressSanitizer, an address sanity checker.9//10// AIX-specific interception methods.11//===----------------------------------------------------------------------===//1213#include "interception.h"14#include "sanitizer_common/sanitizer_common.h"1516#if SANITIZER_AIX1718# include <dlfcn.h> // for dlsym()1920namespace __interception {2122static void *GetFuncAddr(const char *name, uptr wrapper_addr) {23// AIX dlsym can only defect the functions that are exported, so24// on AIX, we can not intercept some basic functions like memcpy.25// FIXME: if we are going to ship dynamic asan library, we may need to search26// all the loaded modules with RTLD_DEFAULT if RTLD_NEXT failed.27void *addr = dlsym(RTLD_NEXT, name);2829// In case `name' is not loaded, dlsym ends up finding the actual wrapper.30// We don't want to intercept the wrapper and have it point to itself.31if ((uptr)addr == wrapper_addr)32addr = nullptr;33return addr;34}3536bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,37uptr wrapper) {38void *addr = GetFuncAddr(name, wrapper);39*ptr_to_real = (uptr)addr;40return addr && (func == wrapper);41}4243} // namespace __interception44#endif // SANITIZER_AIX454647