Warning, file /sdk/heaptrack/src/track/heaptrack_env.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2022 Milian Wolff <mail@milianw.de> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include <cstdio> 0008 #include <cstdlib> 0009 #include <cstring> 0010 0011 #include <dlfcn.h> 0012 0013 extern "C" { 0014 __attribute__((weak)) void* __libc_dlopen_mode(const char* filename, int flag); 0015 } 0016 0017 namespace { 0018 void dlopenLine(const char* lib) 0019 { 0020 #ifdef __FreeBSD__ 0021 0022 fprintf(stdout, "'dlopen@plt'(\"%s\", 0x%x)\n", lib, RTLD_NOW); 0023 0024 #else 0025 0026 if (&__libc_dlopen_mode) { 0027 // __libc_dlopen_mode was available directly in glibc before libdl got merged into it 0028 fprintf(stdout, "__libc_dlopen_mode(\"%s\", 0x80000000 | 0x002)\n", lib); 0029 return; 0030 } 0031 0032 #ifdef __USE_GNU 0033 fprintf(stdout, "dlmopen(0x%x, \"%s\", 0x%x)\n", LM_ID_BASE, lib, RTLD_NOW); 0034 #else 0035 fprintf(stdout, "dlopen(\"%s\", 0x%x)\n", lib, RTLD_NOW); 0036 #endif 0037 0038 #endif 0039 } 0040 } 0041 0042 int main(int argc, char** argv) 0043 { 0044 if (argc < 2) { 0045 fprintf(stderr, "missing check\n"); 0046 return EXIT_FAILURE; 0047 } 0048 0049 const auto check = argv[1]; 0050 if (strcmp(check, "dlopen") == 0) { 0051 if (argc != 3) { 0052 fprintf(stderr, "missing lib arg\n"); 0053 return EXIT_FAILURE; 0054 } 0055 dlopenLine(argv[2]); 0056 return EXIT_SUCCESS; 0057 } 0058 0059 fprintf(stderr, "unsupported check %s\n", check); 0060 return EXIT_FAILURE; 0061 }