Skip to content

Commit

Permalink
Leap Seconds Support
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh committed Dec 6, 2018
1 parent 43840e0 commit f79f7c8
Show file tree
Hide file tree
Showing 15 changed files with 572 additions and 40 deletions.
13 changes: 7 additions & 6 deletions src/BuildIntegration/Microsoft.NETCore.Native.Windows.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ See the LICENSE file in the project root for more information.
<FullRuntimeName>Runtime</FullRuntimeName>
<FullRuntimeName Condition="'$(ServerGarbageCollection)' != ''">Runtime.ServerGC</FullRuntimeName>
</PropertyGroup>

<!-- Part of workaround for lack of secondary build artifact import - https://github.com/Microsoft/msbuild/issues/2807 -->
<!-- Ensure that runtime-specific paths have already been set -->
<!-- Ensure that runtime-specific paths have already been set -->
<Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">
<ItemGroup>
<CppCompilerAndLinkerArg Include="/I$(IlcPath)\inc" />
Expand All @@ -47,9 +47,10 @@ See the LICENSE file in the project root for more information.
<NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)\sdk\PortableRuntime.lib" />
<NativeLibrary Condition="'$(IlcMultiModule)' == 'true' and $(NativeCodeGen) == ''" Include="$(SharedLibrary)" />
</ItemGroup>

<ItemGroup>
<NativeLibrary Include="kernel32.lib" />
<NativeLibrary Include="ntdll.lib" />

This comment has been minimized.

Copy link
@jkotas

jkotas Dec 6, 2018

Does this actually work?

The docs for https://docs.microsoft.com/en-us/windows/desktop/api/winternl/nf-winternl-ntquerysysteminformation say "This function has no associated import library.".

This comment has been minimized.

Copy link
@tarekgh

tarekgh Dec 6, 2018

Author Owner

This only needed because of the pinvoke test was failing on that repo. using that make it work fine.

1>F:\OSS\corert\src\System.Private.CoreLib\shared\System\Diagnostics\Tracing\EventSource.cs(5921): warning C4307: '*': integral constant overflow [F:\OSS\corert\tests\src\Simple\PInvoke\PInvoke.csproj]
PInvokeCompile:
cl @"F:\OSS\corert\tests\src\Simple\PInvoke\obj\Debug\x64\pinvoke_cl.rsp"
PInvokeNative.cpp
LinkNative:
Creating directory "F:\OSS\corert\tests\src\Simple\PInvoke\bin\Debug\x64\native".
link @"F:\OSS\corert\tests\src\Simple\PInvoke\obj\Debug\x64\native\link.rsp"
Creating library F:\OSS\corert\tests\src\Simple\PInvoke\bin\Debug\x64\native\PInvoke.lib and object F:\OSS\corert\tests\src\Simple\PInvoke\bin\Debug\x64\native\PInvoke.exp
1>PInvoke.obj : error LNK2019: unresolved external symbol NtQuerySystemInformation referenced in function "public: static int __cdecl System_Private_CoreLib::Interop_NtDll::_A_rawpinvoke_V_NtQuerySystemInformation(int,void *,int,__int64)" (?_A_rawpinvoke_V_NtQuerySystemInformation@Interop_NtDll@System_Private_CoreLib@@SAHHPEAXH_J@Z) [F:\OSS\corert\tests\src\Simple\PInvoke\PInvoke.csproj]
1>F:\OSS\corert\tests\src\Simple\PInvoke\bin\Debug\x64\native\PInvoke.exe : fatal error LNK1120: 1 unresolved externals [F:\OSS\corert\tests\src\Simple\PInvoke\PInvoke.csproj]
1>F:\OSS\corert\bin\Windows_NT.x64.Debug\build\Microsoft.NETCore.Native.targets(302,5): error MSB3073: The command "link @"F:\OSS\corert\tests\src\Simple\PInvoke\obj\Debug\x64\native\link.rsp"" exited with code 1120. [F:\OSS\corert\tests\src\Simple\PInvoke\PInvoke.csproj]

This comment has been minimized.

Copy link
@jkotas

jkotas Dec 6, 2018

ok

<NativeLibrary Include="user32.lib" />
<NativeLibrary Include="gdi32.lib" />
<NativeLibrary Include="winspool.lib" />
Expand All @@ -62,7 +63,7 @@ See the LICENSE file in the project root for more information.
<NativeLibrary Include="bcrypt.lib" />
<NativeLibrary Include="normaliz.lib" />
</ItemGroup>

<ItemGroup>
<LinkerArg Condition="$(NativeLib) == 'Shared'" Include="/DLL" />
<LinkerArg Include="@(NativeLibrary->'&quot;%(Identity)&quot;')" />
Expand All @@ -71,11 +72,11 @@ See the LICENSE file in the project root for more information.
<LinkerArg Include="/INCREMENTAL:NO" />
<LinkerArg Condition="'$(OutputType)' == 'WinExe'" Include="/SUBSYSTEM:WINDOWS /ENTRY:wmainCRTStartup" />
</ItemGroup>

<ItemGroup>
<!-- TODO <LinkerArg Include="/MACHINE:X64" /> -->
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' != 'Debug'">
<LinkerArg Include="/OPT:REF" />
<LinkerArg Include="/OPT:ICF" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class NtDll
{
[DllImport(Libraries.NtDll, SetLastError = true)]

This comment has been minimized.

Copy link
@jkotas

jkotas Dec 6, 2018

Does this actually set SetLastError? The docs says nothing about it, and you are not checking it after the call either.

This comment has been minimized.

Copy link
@tarekgh

tarekgh Dec 6, 2018

Author Owner

We are not using it in anything. I just copied the same declaration from some other place. I can remove SetLastError

internal static unsafe extern int NtQuerySystemInformation(int SystemInformationClass, void* SystemInformation, int SystemInformationLength, IntPtr ReturnLength);

This comment has been minimized.

Copy link
@jkotas

jkotas Dec 6, 2018

ReturnLength type should better be uint*.

This comment has been minimized.

Copy link
@tarekgh

tarekgh Dec 6, 2018

Author Owner

I can fix that. we are passing null (IntPtr.Zero) anyway.


[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_LEAP_SECOND_INFORMATION
{
public bool Enabled;
public uint Flags;
}

internal const int SystemLeapSecondInformation = 206;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Kernel32
{
[DllImport(Libraries.Kernel32, SetLastError = true)]

This comment has been minimized.

Copy link
@jkotas

jkotas Dec 6, 2018

We do not check the last error, so SetLastError here is just making stuff slower...

This comment has been minimized.

Copy link
@tarekgh

tarekgh Dec 6, 2018

Author Owner

yes, I'll remove it in all newly introduced pinvokes.

internal static unsafe extern bool FileTimeToSystemTime(ref long lpFileTime, ref FullSystemTime lpSystemTime);
}
}
59 changes: 59 additions & 0 deletions src/Common/src/Interop/Windows/kernel32/Interop.FullSystemTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Kernel32
{
// FullSystemTime struct matches Windows SYSTEMTIME struct, except we added the extra nanoSeconds field to store
// more precise time.
[StructLayout(LayoutKind.Sequential)]
internal struct FullSystemTime
{
internal FullSystemTime(int year, int month, DayOfWeek dayOfWeek, int day, int hour, int minute, int second)
{
wYear = (ushort) year;
wMonth = (ushort) month;
wDayOfWeek = (ushort) dayOfWeek;
wDay = (ushort) day;
wHour = (ushort) hour;
wMinute = (ushort) minute;
wSecond = (ushort) second;
wMillisecond = 0;
hundredNanoSecond = 0;
}

internal FullSystemTime(long ticks)
{
DateTime dt = new DateTime(ticks);

int year, month, day;
dt.GetDatePart(out year, out month, out day);

wYear = (ushort) year;
wMonth = (ushort) month;
wDayOfWeek = (ushort) dt.DayOfWeek;
wDay = (ushort) day;
wHour = (ushort) dt.Hour;
wMinute = (ushort) dt.Minute;
wSecond = (ushort) dt.Second;
wMillisecond = (ushort) dt.Millisecond;
hundredNanoSecond = 0;
}

internal ushort wYear;
internal ushort wMonth;
internal ushort wDayOfWeek;
internal ushort wDay;
internal ushort wHour;
internal ushort wMinute;
internal ushort wSecond;
internal ushort wMillisecond;
internal long hundredNanoSecond;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Kernel32
{
internal const int ProcessLeapSecondInfo = 8;

[DllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static extern bool GetProcessInformation(IntPtr hProcess, int ProcessInformationClass, ref long processInformation, int ProcessInformationSize);
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/kernel32/Interop.GetSystemTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Kernel32
{
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static unsafe extern void GetSystemTime(ref FullSystemTime lpSystemTime);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Kernel32
{
// api-ms-win-core-timezone-l1-1-0.dll
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool SystemTimeToFileTime(ref FullSystemTime lpSystemTime, out long lpFileTime);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Kernel32
{
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool TzSpecificLocalTimeToSystemTime(IntPtr lpTimeZoneInformation, ref FullSystemTime lpLocalTime, ref FullSystemTime lpUniversalTime);
}
}
Loading

0 comments on commit f79f7c8

Please sign in to comment.