Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2021-01-08 03:06:20 +0300
committerGitHub <noreply@github.com>2021-01-08 03:06:20 +0300
commit2c7ae5c034695ae1255d58aecf38b868e6a0fa93 (patch)
tree96b215e3bc909f11e7d380027952a86253d110d4 /src/coreclr/classlibnative
parent5175f6d13922748f483a42dedfdeb092d28400ce (diff)
Delete DateTime FCalls and switch to fully managed implementation (#46690)
Diffstat (limited to 'src/coreclr/classlibnative')
-rw-r--r--src/coreclr/classlibnative/bcltype/system.cpp150
-rw-r--r--src/coreclr/classlibnative/bcltype/system.h7
2 files changed, 0 insertions, 157 deletions
diff --git a/src/coreclr/classlibnative/bcltype/system.cpp b/src/coreclr/classlibnative/bcltype/system.cpp
index 3660c14963d..91a39ef9d08 100644
--- a/src/coreclr/classlibnative/bcltype/system.cpp
+++ b/src/coreclr/classlibnative/bcltype/system.cpp
@@ -30,157 +30,7 @@
#include "array.h"
#include "eepolicy.h"
-#ifndef TARGET_UNIX
-typedef void(WINAPI *pfnGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);
-extern pfnGetSystemTimeAsFileTime g_pfnGetSystemTimeAsFileTime;
-
-void WINAPI InitializeGetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
-{
- pfnGetSystemTimeAsFileTime func = NULL;
-
- HMODULE hKernel32 = WszLoadLibrary(W("kernel32.dll"));
- if (hKernel32 != NULL)
- {
- func = (pfnGetSystemTimeAsFileTime)GetProcAddress(hKernel32, "GetSystemTimePreciseAsFileTime");
- if (func != NULL)
- {
- // GetSystemTimePreciseAsFileTime exists and we'd like to use it. However, on
- // misconfigured systems, it's possible for the "precise" time to be inaccurate:
- // https://github.com/dotnet/runtime/issues/9014
- // If it's inaccurate, though, we expect it to be wildly inaccurate, so as a
- // workaround/heuristic, we get both the "normal" and "precise" times, and as
- // long as they're close, we use the precise one. This workaround can be removed
- // when we better understand what's causing the drift and the issue is no longer
- // a problem or can be better worked around on all targeted OSes.
-
- FILETIME systemTimeResult;
- ::GetSystemTimeAsFileTime(&systemTimeResult);
-
- FILETIME preciseSystemTimeResult;
- func(&preciseSystemTimeResult);
-
- LONG64 systemTimeLong100ns = (LONG64)((((ULONG64)systemTimeResult.dwHighDateTime) << 32) | (ULONG64)systemTimeResult.dwLowDateTime);
- LONG64 preciseSystemTimeLong100ns = (LONG64)((((ULONG64)preciseSystemTimeResult.dwHighDateTime) << 32) | (ULONG64)preciseSystemTimeResult.dwLowDateTime);
-
- const INT32 THRESHOLD_100NS = 1000000; // 100ms
- if (abs(preciseSystemTimeLong100ns - systemTimeLong100ns) > THRESHOLD_100NS)
- {
- // Too much difference. Don't use GetSystemTimePreciseAsFileTime.
- func = NULL;
- }
- }
- }
- if (func == NULL)
- {
- func = &::GetSystemTimeAsFileTime;
- }
-
- InterlockedCompareExchangeT(&g_pfnGetSystemTimeAsFileTime, func, &InitializeGetSystemTimeAsFileTime);
-
- g_pfnGetSystemTimeAsFileTime(lpSystemTimeAsFileTime);
-}
-
-pfnGetSystemTimeAsFileTime g_pfnGetSystemTimeAsFileTime = &InitializeGetSystemTimeAsFileTime;
-#endif // TARGET_UNIX
-
-FCIMPL0(INT64, SystemNative::__GetSystemTimeAsFileTime)
-{
- FCALL_CONTRACT;
-
- INT64 timestamp;
-#ifndef TARGET_UNIX
- g_pfnGetSystemTimeAsFileTime((FILETIME*)&timestamp);
-#else
- GetSystemTimeAsFileTime((FILETIME*)&timestamp);
-#endif
-
-#if BIGENDIAN
- timestamp = (INT64)(((UINT64)timestamp >> 32) | ((UINT64)timestamp << 32));
-#endif
-
- return timestamp;
-}
-FCIMPLEND;
-
-
-#ifndef TARGET_UNIX
-
-FCIMPL1(VOID, SystemNative::GetSystemTimeWithLeapSecondsHandling, FullSystemTime *time)
-{
- FCALL_CONTRACT;
- INT64 timestamp;
-
- g_pfnGetSystemTimeAsFileTime((FILETIME*)&timestamp);
-
- if (::FileTimeToSystemTime((FILETIME*)&timestamp, &(time->systemTime)))
- {
- // to keep the time precision
- time->hundredNanoSecond = timestamp % 10000; // 10000 is the number of 100-nano seconds per Millisecond
- }
- else
- {
- ::GetSystemTime(&(time->systemTime));
- time->hundredNanoSecond = 0;
- }
-
- if (time->systemTime.wSecond > 59)
- {
- // we have a leap second, force it to last second in the minute as DateTime doesn't account for leap seconds in its calculation.
- // we use the maxvalue from the milliseconds and the 100-nano seconds to avoid reporting two out of order 59 seconds
- time->systemTime.wSecond = 59;
- time->systemTime.wMilliseconds = 999;
- time->hundredNanoSecond = 9999;
- }
-}
-FCIMPLEND;
-FCIMPL2(FC_BOOL_RET, SystemNative::FileTimeToSystemTime, INT64 fileTime, FullSystemTime *time)
-{
- FCALL_CONTRACT;
- if (::FileTimeToSystemTime((FILETIME*)&fileTime, (LPSYSTEMTIME) time))
- {
- // to keep the time precision
- time->hundredNanoSecond = fileTime % 10000; // 10000 is the number of 100-nano seconds per Millisecond
- if (time->systemTime.wSecond > 59)
- {
- // we have a leap second, force it to last second in the minute as DateTime doesn't account for leap seconds in its calculation.
- // we use the maxvalue from the milliseconds and the 100-nano seconds to avoid reporting two out of order 59 seconds
- time->systemTime.wSecond = 59;
- time->systemTime.wMilliseconds = 999;
- time->hundredNanoSecond = 9999;
- }
- FC_RETURN_BOOL(TRUE);
- }
- FC_RETURN_BOOL(FALSE);
-}
-FCIMPLEND;
-
-FCIMPL2(FC_BOOL_RET, SystemNative::ValidateSystemTime, SYSTEMTIME *time, CLR_BOOL localTime)
-{
- FCALL_CONTRACT;
-
- if (localTime)
- {
- SYSTEMTIME st;
- FC_RETURN_BOOL(::TzSpecificLocalTimeToSystemTime(NULL, time, &st));
- }
- else
- {
- FILETIME timestamp;
- FC_RETURN_BOOL(::SystemTimeToFileTime(time, &timestamp));
- }
-}
-FCIMPLEND;
-
-FCIMPL2(FC_BOOL_RET, SystemNative::SystemTimeToFileTime, SYSTEMTIME *time, INT64 *pFileTime)
-{
- FCALL_CONTRACT;
-
- BOOL ret = ::SystemTimeToFileTime(time, (LPFILETIME) pFileTime);
- FC_RETURN_BOOL(ret);
-}
-FCIMPLEND;
-#endif // TARGET_UNIX
FCIMPL0(UINT32, SystemNative::GetTickCount)
diff --git a/src/coreclr/classlibnative/bcltype/system.h b/src/coreclr/classlibnative/bcltype/system.h
index 5bbf73d4a10..fe8b1e476a1 100644
--- a/src/coreclr/classlibnative/bcltype/system.h
+++ b/src/coreclr/classlibnative/bcltype/system.h
@@ -43,13 +43,6 @@ private:
public:
// Functions on the System.Environment class
-#ifndef TARGET_UNIX
- static FCDECL1(VOID, GetSystemTimeWithLeapSecondsHandling, FullSystemTime *time);
- static FCDECL2(FC_BOOL_RET, ValidateSystemTime, SYSTEMTIME *time, CLR_BOOL localTime);
- static FCDECL2(FC_BOOL_RET, FileTimeToSystemTime, INT64 fileTime, FullSystemTime *time);
- static FCDECL2(FC_BOOL_RET, SystemTimeToFileTime, SYSTEMTIME *time, INT64 *pFileTime);
-#endif // TARGET_UNIX
- static FCDECL0(INT64, __GetSystemTimeAsFileTime);
static FCDECL0(UINT32, GetTickCount);
static FCDECL0(UINT64, GetTickCount64);