1 /* 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * All rights reserved. 4 * 5 * This source code is licensed under the BSD-style license found in the 6 * LICENSE file in the root directory of this source tree. 7 */ 8 9 /** 10 * @file 11 * Platform abstraction layer to allow individual host OS to override 12 * symbols in ExecuTorch. PAL functions are defined as C functions so an 13 * implementer can use C in lieu of C++. 14 */ 15 #pragma once 16 17 /** 18 * To enable dynamic linking debugging capability on UNIX-like OS. If enabled 19 * and see an error like: `undefined symbol: dladdr`, install `libdl` to fix. 20 */ 21 #if defined(ET_USE_LIBDL) 22 #include <dlfcn.h> 23 #endif 24 25 static constexpr const char* DYNAMIC_LIBRARY_NOT_SUPPORTED = "NOT_SUPPORTED"; 26 static constexpr const char* DYNAMIC_LIBRARY_NOT_FOUND = "NOT_FOUND"; 27 28 extern "C" { 29 30 /** 31 * Return shared library . 32 * 33 * @param[in] addr Address to the symbol we are looking for in shared libraries. 34 * @retval The path to the shared library containing the symbol. 35 */ et_pal_get_shared_library_name(const void * addr)36inline const char* et_pal_get_shared_library_name(const void* addr) { 37 #if defined(ET_USE_LIBDL) 38 Dl_info info; 39 if (dladdr(addr, &info) && info.dli_fname) { 40 return info.dli_fname; 41 } else { 42 return DYNAMIC_LIBRARY_NOT_FOUND; 43 } 44 #endif 45 (void)addr; 46 return DYNAMIC_LIBRARY_NOT_SUPPORTED; 47 } 48 49 } // extern "C" 50