Skip to content

Commit 9bea982

Browse files
authored
Merge pull request #92484 from dotnet-maestro-bot/merge/release/8.0-rc2-to-release/8.0
[automated] Merge branch 'release/8.0-rc2' => 'release/8.0'
2 parents 4f51a33 + 6cc5257 commit 9bea982

File tree

16 files changed

+612
-165
lines changed

16 files changed

+612
-165
lines changed

src/coreclr/jit/lowerxarch.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8202,18 +8202,20 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre
82028202
case NI_AVX2_BroadcastScalarToVector256:
82038203
case NI_AVX512F_BroadcastScalarToVector512:
82048204
{
8205-
var_types baseType = hwintrinsic->GetSimdBaseType();
8206-
if (varTypeIsSmall(baseType))
8205+
var_types parentBaseType = parentNode->GetSimdBaseType();
8206+
var_types childBaseType = hwintrinsic->GetSimdBaseType();
8207+
8208+
if (varTypeIsSmall(parentBaseType) || (genTypeSize(parentBaseType) != genTypeSize(childBaseType)))
82078209
{
8208-
// early return if the base type is not embedded broadcast compatible.
8210+
// early return if either base type is not embedded broadcast compatible.
82098211
return false;
82108212
}
82118213

82128214
// make the broadcast node containable when embedded broadcast can be enabled.
82138215
if (intrinsicId == NI_SSE3_MoveAndDuplicate)
82148216
{
82158217
// NI_SSE3_MoveAndDuplicate is for Vector128<double> only.
8216-
assert(baseType == TYP_DOUBLE);
8218+
assert(childBaseType == TYP_DOUBLE);
82178219
}
82188220

82198221
if (comp->compOpportunisticallyDependsOn(InstructionSet_AVX512F_VL) &&
@@ -8246,6 +8248,15 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre
82468248
case NI_AVX_BroadcastScalarToVector128:
82478249
case NI_AVX_BroadcastScalarToVector256:
82488250
{
8251+
var_types parentBaseType = parentNode->GetSimdBaseType();
8252+
var_types childBaseType = hwintrinsic->GetSimdBaseType();
8253+
8254+
if (varTypeIsSmall(parentBaseType) || (genTypeSize(parentBaseType) != genTypeSize(childBaseType)))
8255+
{
8256+
// early return if either base type is not embedded broadcast compatible.
8257+
return false;
8258+
}
8259+
82498260
return parentNode->OperIsEmbBroadcastCompatible();
82508261
}
82518262

Lines changed: 39 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
5+
using System.Buffers.Binary;
46
using System.IO;
57
using System.IO.MemoryMappedFiles;
8+
using System.Reflection.PortableExecutable;
69

710
namespace Microsoft.NET.HostModel.AppHost
811
{
@@ -15,29 +18,13 @@ public static class PEUtils
1518
/// <returns>true if the accessor represents a PE image, false otherwise.</returns>
1619
internal static unsafe bool IsPEImage(MemoryMappedViewAccessor accessor)
1720
{
18-
byte* pointer = null;
21+
if (accessor.Capacity < PEOffsets.DosStub.PESignatureOffset + sizeof(uint))
22+
return false;
1923

20-
try
21-
{
22-
accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);
23-
byte* bytes = pointer + accessor.PointerOffset;
24-
25-
// https://en.wikipedia.org/wiki/Portable_Executable
26-
// Validate that we're looking at Windows PE file
27-
if (((ushort*)bytes)[0] != PEOffsets.DosImageSignature
28-
|| accessor.Capacity < PEOffsets.DosStub.PESignatureOffset + sizeof(uint))
29-
{
30-
return false;
31-
}
32-
return true;
33-
}
34-
finally
35-
{
36-
if (pointer != null)
37-
{
38-
accessor.SafeMemoryMappedViewHandle.ReleasePointer();
39-
}
40-
}
24+
// https://en.wikipedia.org/wiki/Portable_Executable
25+
// Validate that we're looking at Windows PE file
26+
ushort signature = AsLittleEndian(accessor.ReadUInt16(0));
27+
return signature == PEOffsets.DosImageSignature;
4128
}
4229

4330
public static bool IsPEImage(string filePath)
@@ -60,40 +47,15 @@ public static bool IsPEImage(string filePath)
6047
/// <param name="accessor">The memory accessor which has the apphost file opened.</param>
6148
internal static unsafe void SetWindowsGraphicalUserInterfaceBit(MemoryMappedViewAccessor accessor)
6249
{
63-
byte* pointer = null;
64-
65-
try
66-
{
67-
accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);
68-
byte* bytes = pointer + accessor.PointerOffset;
69-
70-
// https://en.wikipedia.org/wiki/Portable_Executable
71-
uint peHeaderOffset = ((uint*)(bytes + PEOffsets.DosStub.PESignatureOffset))[0];
72-
73-
if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
74-
{
75-
throw new AppHostNotPEFileException("Subsystem offset out of file range.");
76-
}
77-
78-
ushort* subsystem = ((ushort*)(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem));
79-
80-
// https://docs.microsoft.com/en-us/windows/desktop/Debug/pe-format#windows-subsystem
81-
// The subsystem of the prebuilt apphost should be set to CUI
82-
if (subsystem[0] != (ushort)PEOffsets.Subsystem.WindowsCui)
83-
{
84-
throw new AppHostNotCUIException(subsystem[0]);
85-
}
86-
87-
// Set the subsystem to GUI
88-
subsystem[0] = (ushort)PEOffsets.Subsystem.WindowsGui;
89-
}
90-
finally
91-
{
92-
if (pointer != null)
93-
{
94-
accessor.SafeMemoryMappedViewHandle.ReleasePointer();
95-
}
96-
}
50+
// https://learn.microsoft.com/windows/win32/debug/pe-format#windows-subsystem
51+
// The subsystem of the prebuilt apphost should be set to CUI
52+
uint peHeaderOffset;
53+
ushort subsystem = GetWindowsSubsystem(accessor, out peHeaderOffset);
54+
if (subsystem != (ushort)Subsystem.WindowsCui)
55+
throw new AppHostNotCUIException(subsystem);
56+
57+
// Set the subsystem to GUI
58+
accessor.Write(peHeaderOffset + PEOffsets.PEHeader.Subsystem, AsLittleEndian((ushort)Subsystem.WindowsGui));
9759
}
9860

9961
public static unsafe void SetWindowsGraphicalUserInterfaceBit(string filePath)
@@ -113,32 +75,7 @@ public static unsafe void SetWindowsGraphicalUserInterfaceBit(string filePath)
11375
/// <param name="accessor">The memory accessor which has the apphost file opened.</param>
11476
internal static unsafe ushort GetWindowsGraphicalUserInterfaceBit(MemoryMappedViewAccessor accessor)
11577
{
116-
byte* pointer = null;
117-
118-
try
119-
{
120-
accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);
121-
byte* bytes = pointer + accessor.PointerOffset;
122-
123-
// https://en.wikipedia.org/wiki/Portable_Executable
124-
uint peHeaderOffset = ((uint*)(bytes + PEOffsets.DosStub.PESignatureOffset))[0];
125-
126-
if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
127-
{
128-
throw new AppHostNotPEFileException("Subsystem offset out of file range.");
129-
}
130-
131-
ushort* subsystem = ((ushort*)(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem));
132-
133-
return subsystem[0];
134-
}
135-
finally
136-
{
137-
if (pointer != null)
138-
{
139-
accessor.SafeMemoryMappedViewHandle.ReleasePointer();
140-
}
141-
}
78+
return GetWindowsSubsystem(accessor, out _);
14279
}
14380

14481
public static unsafe ushort GetWindowsGraphicalUserInterfaceBit(string filePath)
@@ -151,5 +88,25 @@ public static unsafe ushort GetWindowsGraphicalUserInterfaceBit(string filePath)
15188
}
15289
}
15390
}
91+
92+
private static ushort GetWindowsSubsystem(MemoryMappedViewAccessor accessor, out uint peHeaderOffset)
93+
{
94+
// https://en.wikipedia.org/wiki/Portable_Executable
95+
if (accessor.Capacity < PEOffsets.DosStub.PESignatureOffset + sizeof(uint))
96+
throw new AppHostNotPEFileException("PESignature offset out of file range.");
97+
98+
peHeaderOffset = AsLittleEndian(accessor.ReadUInt32(PEOffsets.DosStub.PESignatureOffset));
99+
if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
100+
throw new AppHostNotPEFileException("Subsystem offset out of file range.");
101+
102+
// https://learn.microsoft.com/windows/win32/debug/pe-format#windows-subsystem
103+
return AsLittleEndian(accessor.ReadUInt16(peHeaderOffset + PEOffsets.PEHeader.Subsystem));
104+
}
105+
106+
private static ushort AsLittleEndian(ushort value)
107+
=> BitConverter.IsLittleEndian ? value : BinaryPrimitives.ReverseEndianness(value);
108+
109+
private static uint AsLittleEndian(uint value)
110+
=> BitConverter.IsLittleEndian ? value : BinaryPrimitives.ReverseEndianness(value);
154111
}
155112
}

src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.NET.HostModel.AppHost;
1212
using Microsoft.DotNet.CoreSetup.Test;
1313
using System.Diagnostics;
14+
using System.Reflection.PortableExecutable;
1415

1516
namespace Microsoft.NET.HostModel.Tests
1617
{
@@ -111,7 +112,9 @@ public void ItCanSetWindowsGUISubsystem()
111112
BitConverter
112113
.ToUInt16(File.ReadAllBytes(destinationFilePath), SubsystemOffset)
113114
.Should()
114-
.Be(2);
115+
.Be((ushort)Subsystem.WindowsGui);
116+
117+
Assert.Equal((ushort)Subsystem.WindowsGui, PEUtils.GetWindowsGraphicalUserInterfaceBit(destinationFilePath));
115118
}
116119
}
117120

@@ -153,6 +156,7 @@ public void ItFailsToSetGUISubsystemWithWrongDefault()
153156
string destinationFilePath = Path.Combine(testDirectory.Path, "DestinationAppHost.exe.mock");
154157
string appBinaryFilePath = "Test/App/Binary/Path.dll";
155158

159+
Assert.Equal(42, PEUtils.GetWindowsGraphicalUserInterfaceBit(sourceAppHostMock));
156160
Assert.Throws<AppHostNotCUIException>(() =>
157161
HostWriter.CreateAppHost(
158162
sourceAppHostMock,

src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ private static void BindInstance(
298298
return;
299299
}
300300

301+
if (config is null)
302+
{
303+
return;
304+
}
305+
301306
var section = config as IConfigurationSection;
302307
string? configValue = section?.Value;
303308
if (configValue != null && TryConvertValue(type, configValue, section?.Path, out object? convertedValue, out Exception? error))

src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.TestClasses.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,5 +888,11 @@ public int MyIntProperty
888888
}
889889
}
890890

891+
public class SimplePoco
892+
{
893+
public string A { get; set; }
894+
public string B { get; set; }
895+
}
896+
891897
}
892898
}

src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#if BUILDING_SOURCE_GENERATOR_TESTS
1212
using Microsoft.Extensions.Configuration;
1313
#endif
14+
using Microsoft.Extensions.Configuration.Memory;
1415
using Microsoft.Extensions.Configuration.Test;
1516
using Xunit;
1617

@@ -1767,7 +1768,7 @@ public void EnsureCallingThePropertySetter()
17671768
Assert.Equal(0, options.OtherCodeNullable);
17681769
Assert.Equal("default", options.OtherCodeString);
17691770
Assert.Null(options.OtherCodeNull);
1770-
Assert.Null(options.OtherCodeUri);
1771+
Assert.Null(options.OtherCodeUri);
17711772
}
17721773

17731774
[Fact]
@@ -2238,7 +2239,7 @@ void TestUntypedOverloads(IConfiguration? configuration, string? key)
22382239
Assert.Throws<ArgumentNullException>(() => configuration.GetValue(typeof(GeolocationClass), key, new GeolocationClass()));
22392240
Assert.Throws<ArgumentNullException>(() => configuration.GetValue(typeof(Geolocation), key));
22402241
Assert.Throws<ArgumentNullException>(() => configuration.GetValue(typeof(Geolocation), key, defaultValue: null));
2241-
Assert.Throws<ArgumentNullException>(() => configuration.GetValue(typeof(Geolocation), key, default(Geolocation)));
2242+
Assert.Throws<ArgumentNullException>(() => configuration.GetValue(typeof(Geolocation), key, default(Geolocation)));
22422243
}
22432244
}
22442245

@@ -2404,5 +2405,38 @@ public void SharedChildInstance()
24042405
config.GetSection("A").Bind(instance);
24052406
Assert.Equal("localhost", instance.ConnectionString);
24062407
}
2408+
2409+
[Fact]
2410+
public void CanBindToMockConfigurationSection()
2411+
{
2412+
const string expectedA = "hello";
2413+
2414+
var configSource = new MemoryConfigurationSource()
2415+
{
2416+
InitialData = new Dictionary<string, string?>()
2417+
{
2418+
[$":{nameof(SimplePoco.A)}"] = expectedA,
2419+
}
2420+
};
2421+
var configRoot = new MockConfigurationRoot(new[] { configSource.Build(null) });
2422+
var configSection = new ConfigurationSection(configRoot, string.Empty);
2423+
2424+
SimplePoco result = new();
2425+
configSection.Bind(result);
2426+
2427+
Assert.Equal(expectedA, result.A);
2428+
Assert.Equal(default(string), result.B);
2429+
}
2430+
2431+
// a mock configuration root that will return null for undefined Sections,
2432+
// as is common when Configuration interfaces are mocked
2433+
class MockConfigurationRoot : ConfigurationRoot, IConfigurationRoot
2434+
{
2435+
public MockConfigurationRoot(IList<IConfigurationProvider> providers) : base(providers)
2436+
{ }
2437+
2438+
IConfigurationSection IConfiguration.GetSection(string key) =>
2439+
this[key] is null ? null : new ConfigurationSection(this, key);
2440+
}
24072441
}
24082442
}

src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace System.Numerics.Tensors
88
{
99
public static partial class TensorPrimitives
1010
{
11+
public static void Abs(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
1112
public static void Add(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
1213
public static void Add(System.ReadOnlySpan<float> x, float y, System.Span<float> destination) { }
1314
public static void AddMultiply(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.ReadOnlySpan<float> multiplier, System.Span<float> destination) { }
@@ -24,12 +25,17 @@ public static void Exp(System.ReadOnlySpan<float> x, System.Span<float> destinat
2425
public static int IndexOfMaxMagnitude(System.ReadOnlySpan<float> x) { throw null; }
2526
public static int IndexOfMin(System.ReadOnlySpan<float> x) { throw null; }
2627
public static int IndexOfMinMagnitude(System.ReadOnlySpan<float> x) { throw null; }
27-
public static float L2Normalize(System.ReadOnlySpan<float> x) { throw null; }
28+
public static float Norm(System.ReadOnlySpan<float> x) { throw null; }
2829
public static void Log(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
30+
public static void Log2(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
2931
public static float Max(System.ReadOnlySpan<float> x) { throw null; }
32+
public static void Max(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { throw null; }
3033
public static float MaxMagnitude(System.ReadOnlySpan<float> x) { throw null; }
34+
public static void MaxMagnitude(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { throw null; }
3135
public static float Min(System.ReadOnlySpan<float> x) { throw null; }
36+
public static void Min(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { throw null; }
3237
public static float MinMagnitude(System.ReadOnlySpan<float> x) { throw null; }
38+
public static void MinMagnitude(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { throw null; }
3339
public static void Multiply(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
3440
public static void Multiply(System.ReadOnlySpan<float> x, float y, System.Span<float> destination) { }
3541
public static void MultiplyAdd(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.ReadOnlySpan<float> addend, System.Span<float> destination) { }

0 commit comments

Comments
 (0)