69 if (symbol_inside_runtime_binary ==
nullptr)
71 static const char symbol_inside_this_runtime_binary{};
72 symbol_inside_runtime_binary = &symbol_inside_this_runtime_binary;
78 if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
79 (LPCSTR)symbol_inside_runtime_binary,
81 || GetModuleFileName(hm, path,
sizeof(path)) <= 0)
83 throw std::runtime_error(
"cbeam::platform::get_path_to_runtime_binary: Could not get path to current runtime binary: " +
get_last_windows_error_message());
87 return std::filesystem::absolute(std::filesystem::path(path));
91 if (!dladdr(symbol_inside_runtime_binary, &dl_info))
93 throw std::runtime_error(
"cbeam::platform::get_path_to_runtime_binary: Could not resolve symbol");
96 if (dl_info.dli_fname)
98 char resolved_path[PATH_MAX];
99 if (realpath(dl_info.dli_fname, resolved_path) !=
nullptr)
101 return std::filesystem::path(resolved_path);
105 throw std::runtime_error(
"cbeam::platform::get_path_to_runtime_binary: Could not resolve symbolic link '" + std::string{dl_info.dli_fname} +
"'");
110 throw std::runtime_error(
"cbeam::platform::get_path_to_runtime_binary: Symbol is not associated with a shared library or executable");
113 #error Unsupported platform
115 throw std::runtime_error(
"cbeam::platform::get_path_to_runtime_binary: Could not get path to current runtime binary");