diff --git a/src/native/clr/host/host-shared.cc b/src/native/clr/host/host-shared.cc index 5015a7a7a34..9b6da9345b6 100644 --- a/src/native/clr/host/host-shared.cc +++ b/src/native/clr/host/host-shared.cc @@ -12,13 +12,13 @@ auto HostCommon::get_java_class_name_for_TypeManager (jclass klass) noexcept -> JNIEnv *env = OSBridge::ensure_jnienv (); jstring name = reinterpret_cast (env->CallObjectMethod (klass, Class_getName)); if (name == nullptr) { - log_error (LOG_DEFAULT, "Failed to obtain Java class name for object at {:p}", reinterpret_cast(klass)); + log_errorf (LOG_DEFAULT, "Failed to obtain Java class name for object at %p", reinterpret_cast(klass)); return nullptr; } const char *mutf8 = env->GetStringUTFChars (name, nullptr); if (mutf8 == nullptr) { - log_error (LOG_DEFAULT, "Failed to convert Java class name to UTF8 (out of memory?)"sv); + log_errorf (LOG_DEFAULT, "Failed to convert Java class name to UTF8 (out of memory?)"); env->DeleteLocalRef (name); return nullptr; } diff --git a/src/native/clr/include/runtime-base/util.hh b/src/native/clr/include/runtime-base/util.hh index c20ff0c7328..f3dd0b22e28 100644 --- a/src/native/clr/include/runtime-base/util.hh +++ b/src/native/clr/include/runtime-base/util.hh @@ -139,7 +139,7 @@ namespace xamarin::android { { struct stat sbuf; if (fstatat (dirfd, file_name, &sbuf, 0) == -1) { - log_warn (LOG_ASSEMBLY, "Failed to stat file '{}': {}", file_name, std::strerror (errno)); + log_warnf (LOG_ASSEMBLY, "Failed to stat file '%s': %s", optional_string (file_name), std::strerror (errno)); return std::nullopt; } @@ -154,18 +154,30 @@ namespace xamarin::android { [[gnu::flatten, gnu::always_inline]] static void set_environment_variable (const char *name, const char *value) noexcept { - log_debug (LOG_DEFAULT, "Setting environment variable {} = '{}'", optional_string (name), optional_string (value)); + log_debugf (LOG_DEFAULT, "Setting environment variable %s = '%s'", optional_string (name), optional_string (value)); if (::setenv (name, value, 1) < 0) { - log_warn (LOG_DEFAULT, "Failed to set environment variable '{}': {}", name, ::strerror (errno)); + log_warnf (LOG_DEFAULT, "Failed to set environment variable '%s': %s", optional_string (name), ::strerror (errno)); } } [[gnu::flatten, gnu::always_inline]] static void set_environment_variable_if_unset (std::string_view const& name, jstring_wrapper& value) noexcept { - log_debug (LOG_DEFAULT, "Setting environment variable {} = '{}' if unset", name, value.get_string_view ()); + log_debugf ( + LOG_DEFAULT, + "Setting environment variable %.*s = '%s' if unset", + static_cast(name.length ()), + name.data (), + optional_string (value.get_cstr ()) + ); if (::setenv (name.data (), value.get_cstr (), 0) < 0) { - log_warn (LOG_DEFAULT, "Failed to set environment variable '{}': {}", name, ::strerror (errno)); + log_warnf ( + LOG_DEFAULT, + "Failed to set environment variable '%.*s': %s", + static_cast(name.length ()), + name.data (), + ::strerror (errno) + ); } } @@ -187,7 +199,14 @@ namespace xamarin::android { if (createDirectory) { int rv = create_directory (value.get_cstr (), mode); if (rv < 0 && errno != EEXIST) { - log_warn (LOG_DEFAULT, "Failed to create directory '{}' for environment variable '{}'. {}", value.get_string_view (), name, strerror (errno)); + log_warnf ( + LOG_DEFAULT, + "Failed to create directory '%s' for environment variable '%.*s'. %s", + optional_string (value.get_cstr ()), + static_cast(name.length ()), + name.data (), + strerror (errno) + ); } } set_environment_variable (name, value); @@ -217,14 +236,14 @@ namespace xamarin::android { mmap_info.area = mmap (nullptr, offsetSize, PROT_READ, MAP_PRIVATE, fd, static_cast(offsetPage)); if (mmap_info.area == MAP_FAILED) { - Helpers::abort_application ( + Helpers::abort_applicationf ( LOG_ASSEMBLY, - std::format ( - "Could not mmap APK fd {}: {}; File={}", - fd, - strerror (errno), - filename - ) + std::source_location::current (), + "Could not mmap APK fd %d: %s; File=%.*s", + fd, + strerror (errno), + static_cast(filename.length ()), + filename.data () ); } @@ -232,9 +251,9 @@ namespace xamarin::android { file_info.area = pointer_add (mmap_info.area, offsetFromPage); file_info.size = size; - log_info ( + log_infof ( LOG_ASSEMBLY, - " mmap_start: {:<8p}; mmap_end: {:<8p} mmap_len: {:<12} file_start: {:<8p} file_end: {:<8p} file_len: {:<12} apk descriptor: {} file: {}", + " mmap_start: %-8p; mmap_end: %-8p\t mmap_len: %-12zu file_start: %-8p file_end: %-8p\t file_len: %-12zu\t apk descriptor: %d file: %.*s", mmap_info.area, pointer_add (mmap_info.area, mmap_info.size), mmap_info.size, @@ -242,7 +261,8 @@ namespace xamarin::android { pointer_add (file_info.area, file_info.size), file_info.size, fd, - filename + static_cast(filename.length ()), + filename.data () ); return file_info; @@ -265,7 +285,12 @@ namespace xamarin::android { elf_header->e_ident[EI_MAG1] != ELFMAG1 || elf_header->e_ident[EI_MAG2] != ELFMAG2 || elf_header->e_ident[EI_MAG3] != ELFMAG3) { - log_debug (LOG_ASSEMBLY, "Not an ELF image: {}", file_name); + log_debugf ( + LOG_ASSEMBLY, + "Not an ELF image: %.*s", + static_cast(file_name.length ()), + file_name.data () + ); // Not an ELF image, just return what we mmapped before return { map_info.area, map_info.size }; } diff --git a/src/native/clr/runtime-base/android-system-shared.cc b/src/native/clr/runtime-base/android-system-shared.cc index 2aa1d54b001..7eeaa4fc7c6 100644 --- a/src/native/clr/runtime-base/android-system-shared.cc +++ b/src/native/clr/runtime-base/android-system-shared.cc @@ -36,7 +36,7 @@ AndroidSystem::monodroid__system_property_get (std::string_view const& name, cha char *buf = nullptr; if (sp_value_len < Constants::PROPERTY_VALUE_BUFFER_LEN) { size_t alloc_size = Helpers::add_with_overflow_check (Constants::PROPERTY_VALUE_BUFFER_LEN, 1uz); - log_warn (LOG_DEFAULT, "Buffer to store system property may be too small, will copy only {} bytes", sp_value_len); + log_warnf (LOG_DEFAULT, "Buffer to store system property may be too small, will copy only %zu bytes", sp_value_len); buf = new char [alloc_size]; } @@ -81,10 +81,16 @@ AndroidSystem::get_max_gref_count_from_system () noexcept -> long } if (*e) { - log_warn (LOG_GC, "Unsupported '{}' value '{}'.", Constants::DEBUG_MONO_MAX_GREFC.data (), override.get ()); + log_warnf ( + LOG_GC, + "Unsupported '%.*s' value '%s'.", + static_cast(Constants::DEBUG_MONO_MAX_GREFC.length ()), + Constants::DEBUG_MONO_MAX_GREFC.data (), + override.get () + ); } - log_warn (LOG_GC, "Overriding max JNI Global Reference count to {}", max); + log_warnf (LOG_GC, "Overriding max JNI Global Reference count to %ld", max); } return max; diff --git a/src/native/clr/runtime-base/util.cc b/src/native/clr/runtime-base/util.cc index 8f59681a55f..afb034eaba5 100644 --- a/src/native/clr/runtime-base/util.cc +++ b/src/native/clr/runtime-base/util.cc @@ -58,7 +58,13 @@ Util::create_public_directory (std::string_view const& dir) // Try to change the mode, just in case chmod (dir.data (), 0777); } else { - log_warn (LOG_DEFAULT, "Failed to create directory '{}'. {}"sv, dir, std::strerror (errno)); + log_warnf ( + LOG_DEFAULT, + "Failed to create directory '%.*s'. %s", + static_cast(dir.length ()), + dir.data (), + std::strerror (errno) + ); } } umask (m); @@ -72,7 +78,13 @@ Util::monodroid_fopen (std::string_view const& filename, std::string_view const& */ FILE *ret = fopen (filename.data (), mode.data ()); if (ret == nullptr) { - log_error (LOG_DEFAULT, "fopen failed for file {}: {}", filename, strerror (errno)); + log_errorf ( + LOG_DEFAULT, + "fopen failed for file %.*s: %s", + static_cast(filename.length ()), + filename.data (), + strerror (errno) + ); return nullptr; } @@ -87,7 +99,13 @@ void Util::set_world_accessable (std::string_view const& path) } while (r == -1 && errno == EINTR); if (r == -1) { - log_error (LOG_DEFAULT, "chmod(\"{}\", 0664) failed: {}", path, strerror (errno)); + log_errorf ( + LOG_DEFAULT, + "chmod(\"%.*s\", 0664) failed: %s", + static_cast(path.length ()), + path.data (), + strerror (errno) + ); } } @@ -99,7 +117,7 @@ auto Util::set_world_accessible (int fd) noexcept -> bool } while (r == -1 && errno == EINTR); if (r == -1) { - log_error (LOG_DEFAULT, "fchmod() failed: {}"sv, strerror (errno)); + log_errorf (LOG_DEFAULT, "fchmod() failed: %s", strerror (errno)); return false; }