From 4f2c3784a3514752897e57c9296aa0c82c5caf85 Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Tue, 23 May 2023 14:11:06 -0400 Subject: [PATCH 1/2] Remove the property disabling optimization - Remove the property group that disabled optimization when building for non-Windows platforms - Set packing size on the `UnixTm` struct to match our native declaration - Add `SetLastError` to our p/invoke as libpsl-native!setdate does set `errno` --- PowerShell.Common.props | 8 -------- .../CoreCLR/CorePsPlatform.cs | 7 ++++--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/PowerShell.Common.props b/PowerShell.Common.props index cf9f792f99c..72fbf3c86a8 100644 --- a/PowerShell.Common.props +++ b/PowerShell.Common.props @@ -185,14 +185,6 @@ full - - - - false - - strict diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 25b1624c6cf..e90616f437c 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -932,8 +932,9 @@ internal static partial class NativeMethods [LibraryImport(psLib)] internal static partial int WaitPid(int pid, [MarshalAs(UnmanagedType.Bool)] bool nohang); - // This is a struct tm from . - [StructLayout(LayoutKind.Sequential)] + // This is the struct `private_tm` from setdate.h in libpsl-native. + // https://github.com/PowerShell/PowerShell-Native/blob/c5575ceb064e60355b9fee33eabae6c6d2708d14/src/libpsl-native/src/setdate.h#L23 + [StructLayout(LayoutKind.Sequential, Pack = 4)] internal unsafe struct UnixTm { /// Seconds (0-60). @@ -980,7 +981,7 @@ internal static UnixTm DateTimeToUnixTm(DateTime date) return tm; } - [LibraryImport(psLib)] + [LibraryImport(psLib, SetLastError = true)] internal static unsafe partial int SetDate(UnixTm* tm); [LibraryImport(psLib, StringMarshalling = StringMarshalling.Utf8)] From 9ad01b8014eb72c066a5617b4baa3ebf5b322ecb Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Tue, 23 May 2023 16:34:01 -0400 Subject: [PATCH 2/2] Update src/System.Management.Automation/CoreCLR/CorePsPlatform.cs --- src/System.Management.Automation/CoreCLR/CorePsPlatform.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index e90616f437c..783afe62915 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -933,6 +933,7 @@ internal static partial class NativeMethods internal static partial int WaitPid(int pid, [MarshalAs(UnmanagedType.Bool)] bool nohang); // This is the struct `private_tm` from setdate.h in libpsl-native. + // Packing is set to 4 to match the unmanaged declaration. // https://github.com/PowerShell/PowerShell-Native/blob/c5575ceb064e60355b9fee33eabae6c6d2708d14/src/libpsl-native/src/setdate.h#L23 [StructLayout(LayoutKind.Sequential, Pack = 4)] internal unsafe struct UnixTm