diff --git a/kotlin-native/runtime/src/mimalloc/c/stats.c b/kotlin-native/runtime/src/mimalloc/c/stats.c index 5848333f2c5..bddfc81f5ad 100644 --- a/kotlin-native/runtime/src/mimalloc/c/stats.c +++ b/kotlin-native/runtime/src/mimalloc/c/stats.c @@ -410,6 +410,19 @@ mi_msecs_t _mi_clock_now(void) { QueryPerformanceCounter(&t); return mi_to_msecs(t); } +#elif defined(KONAN_MI_MALLOC) && (defined(KONAN_MACOSX) || defined(KONAN_OSX) || defined(KONAN_IOS) || defined(KONAN_TVOS) || defined(KONAN_WATCHOS)) +/** + * clock_gettime man said, that CLOCK_REALTIME returns the same value as gettimeofday, but has better precision + * Unfortunately, this function is available only from Mac OSX 10.12, and relevant ios versions. + * So building against newer sdk, while running on old one can lead to runtime crash as in https://youtrack.jetbrains.com/issue/KT-52430 + * To avoid this we use gettimeofday function, which gives enough precision while existing since 4.2BSD, which seems to be a reasonably long time ago + **/ +#include +mi_msecs_t _mi_clock_now(void) { + struct timeval t; + gettimeofday(&t, NULL); + return ((mi_msecs_t)t.tv_sec * 1000) + ((mi_msecs_t)t.tv_usec / 1000); +} #else #include #ifdef CLOCK_REALTIME diff --git a/kotlin-native/runtime/src/mm/cpp/CallsChecker.cpp b/kotlin-native/runtime/src/mm/cpp/CallsChecker.cpp index f72037cb88e..ccbea97a9b4 100644 --- a/kotlin-native/runtime/src/mm/cpp/CallsChecker.cpp +++ b/kotlin-native/runtime/src/mm/cpp/CallsChecker.cpp @@ -100,6 +100,7 @@ extern "C" const char* Kotlin_callsCheckerGoodFunctionNames[] = { "__exp10f", "free", "getrusage", + "gettimeofday", "hypot", "hypotf", "isinf",