Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static partial class PlatformDetection
public static bool IsNativeAot => IsNotMonoRuntime && !IsReflectionEmitSupported;
public static bool IsNotNativeAot => !IsNativeAot;
public static bool IsCoreCLR => IsNotMonoRuntime && IsNotNativeAot;
public static bool IsCoreClrInterpreter => GetIsRunningOnCoreClrInterpreter();
public static bool IsNotCoreClrInterpreter => !IsCoreClrInterpreter;
public static bool IsFreeBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"));
public static bool IsNetBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD"));
public static bool IsAndroid => RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"));
Expand Down Expand Up @@ -209,6 +211,8 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly()
public static bool SupportsSsl3 => GetSsl3Support();
public static bool SupportsSsl2 => IsWindows && !PlatformDetection.IsWindows10Version1607OrGreater;

public static bool SupportsDirtyAccessViolations => !PlatformDetection.IsMonoRuntime && !PlatformDetection.IsCoreClrInterpreter && !PlatformDetection.IsWasm;

#if NET
public static bool IsReflectionEmitSupported => RuntimeFeature.IsDynamicCodeSupported;
public static bool IsNotReflectionEmitSupported => !IsReflectionEmitSupported;
Expand Down Expand Up @@ -727,6 +731,26 @@ private static bool GetIsRunningOnMonoInterpreter()
#endif
}

private static string GetEnvironmentVariableValue(string name, string defaultValue = "0") =>
Environment.GetEnvironmentVariable("DOTNET_" + name) ?? Environment.GetEnvironmentVariable("COMPlus_" + name) ?? defaultValue;

private static bool GetIsRunningOnCoreClrInterpreter()
{
if (IsCoreCLR)
{
#if NET
if (RuntimeFeature.IsDynamicCodeSupported && !RuntimeFeature.IsDynamicCodeCompiled)
return true;
#endif
if (!string.IsNullOrWhiteSpace(GetEnvironmentVariableValue("Interpreter", "")))
return true;
if (int.TryParse(GetEnvironmentVariableValue("InterpMode", "0"), out int mode) && (mode > 0))
return true;
}

return false;
}

private static bool IsEnvironmentVariableTrue(string variableName)
{
if (!IsBrowser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public static bool IsDynamicCodeCompiled
#if MONO
[Intrinsic] // the Mono AOT compiler and Interpreter will change this flag to false for FullAOT and interpreted scenarios, otherwise this code is used
#endif
#if CORECLR && (TARGET_WASM || TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST)
get => false;
#else
get => IsDynamicCodeSupported;
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ public void ReadByte_StructWithReferenceTypes_ReturnsExpected()
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void ReadByte_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadByte(IntPtr.Zero));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadByte(IntPtr.Zero, 2));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadByte(IntPtr.Zero));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadByte(IntPtr.Zero, 2));
}
}

[Fact]
Expand All @@ -157,15 +159,15 @@ public void ReadByte_NotReadable_ThrowsArgumentException()

AssertExtensions.Throws<ArgumentException>(null, () => Marshal.ReadByte(collectibleObject, 0));
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteByte_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteByte(IntPtr.Zero, 0));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteByte(IntPtr.Zero, 2, 0));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteByte(IntPtr.Zero, 0));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteByte(IntPtr.Zero, 2, 0));
}
}

[Fact]
[SkipOnMono("Marshal.WriteByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteByte_NullObject_ThrowsAccessViolationException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ public void ReadInt16_StructWithReferenceTypes_ReturnsExpected()
Assert.Equal(100, Marshal.ReadInt16(structure, pointerOffset));
Assert.Equal(3, Marshal.ReadInt16(structure, arrayOffset + sizeof(short) * 2));
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void ReadInt16_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadInt16(IntPtr.Zero));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadInt16(IntPtr.Zero, 2));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadInt16(IntPtr.Zero));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadInt16(IntPtr.Zero, 2));
}
}

[Fact]
[SkipOnMono("Marshal.ReadInt16 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void ReadInt16_NullObject_ThrowsAccessViolationException()
Expand All @@ -152,15 +152,15 @@ public void ReadInt16_NotReadable_ThrowsArgumentException()

AssertExtensions.Throws<ArgumentException>(null, () => Marshal.ReadInt16(collectibleObject, 0));
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteInt16_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteInt16(IntPtr.Zero, 0));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteInt16(IntPtr.Zero, 2, 0));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteInt16(IntPtr.Zero, 0));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteInt16(IntPtr.Zero, 2, 0));
}
}

[Fact]
[SkipOnMono("Marshal.WriteInt16 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteInt16_NullObject_ThrowsAccessViolationException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ public void ReadInt32_StructWithReferenceTypes_ReturnsExpected()
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void ReadInt32_ZeroPoint_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadInt32(IntPtr.Zero));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadInt32(IntPtr.Zero, 2));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadInt32(IntPtr.Zero));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadInt32(IntPtr.Zero, 2));
}
}

[Fact]
Expand All @@ -154,15 +156,15 @@ public void ReadInt32_NotReadable_ThrowsArgumentException()

AssertExtensions.Throws<ArgumentException>(null, () => Marshal.ReadInt32(collectibleObject, 0));
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteInt32_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteInt32(IntPtr.Zero, 0));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteInt32(IntPtr.Zero, 2, 0));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteInt32(IntPtr.Zero, 0));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteInt32(IntPtr.Zero, 2, 0));
}
}

[Fact]
[SkipOnMono("Marshal.WriteInt32 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteInt32_NullObject_ThrowsAccessViolationException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ public void ReadInt64_StructWithReferenceTypes_ReturnsExpected()
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void ReadInt64_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadInt64(IntPtr.Zero));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadInt64(IntPtr.Zero, 2));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadInt64(IntPtr.Zero));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadInt64(IntPtr.Zero, 2));
}
}

[Fact]
Expand All @@ -166,15 +168,15 @@ public void ReadInt64_NotReadable_ThrowsArgumentException()

AssertExtensions.Throws<ArgumentException>(null, () => Marshal.ReadInt64(collectibleObject, 0));
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteInt64_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteInt64(IntPtr.Zero, 0));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteInt64(IntPtr.Zero, 2, 0));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteInt64(IntPtr.Zero, 0));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteInt64(IntPtr.Zero, 2, 0));
}
}

[Fact]
[SkipOnMono("Marshal.WriteInt64 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteInt64_NullObject_ThrowsAccessViolationException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ public void ReadIntPtr_StructWithReferenceTypes_ReturnsExpected()
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void ReadIntPtr_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadIntPtr(IntPtr.Zero));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.ReadIntPtr(IntPtr.Zero, 2));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadIntPtr(IntPtr.Zero));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.ReadIntPtr(IntPtr.Zero, 2));
}
}

[Fact]
Expand All @@ -163,11 +165,13 @@ public void ReadIntPtr_NotReadable_ThrowsArgumentException()
}

[Fact]
[SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")]
public void WriteIntPtr_ZeroPointer_ThrowsException()
{
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteIntPtr(IntPtr.Zero, (IntPtr)0));
AssertExtensions.ThrowsAny<AccessViolationException, NullReferenceException>(() => Marshal.WriteIntPtr(IntPtr.Zero, 2, (IntPtr)0));
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteIntPtr(IntPtr.Zero, (IntPtr)0));
if (PlatformDetection.SupportsDirtyAccessViolations)
{
AssertExtensions.Throws<AccessViolationException>(() => Marshal.WriteIntPtr(IntPtr.Zero, 2, (IntPtr)0));
}
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void Test()

// Tests that an infinite loop may be aborted, that the ThreadAbortException is automatically rethrown,
// and that it is eventually translated to an OperationCanceledException.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
// [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
public void CancelInTryAndExitCatchNormally()
{
var cts = new CancellationTokenSource();
Expand Down Expand Up @@ -204,7 +204,7 @@ void Test()
}

// Tests cancellation by the action itself
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
// [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
public void CancelItselfOutsideOfTryCatchFinally()
{
var cts = new CancellationTokenSource();
Expand Down
6 changes: 2 additions & 4 deletions src/tests/Common/CoreCLRTestLibrary/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ public static bool IsCoreClrInterpreter
{
get
{
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("DOTNET_Interpreter")))
if (RuntimeFeature.IsDynamicCodeSupported && !RuntimeFeature.IsDynamicCodeCompiled)
return true;
if (int.TryParse(Environment.GetEnvironmentVariable("DOTNET_InterpMode") ?? "", out int mode) && (mode > 0))
return true;
return false;
return CoreClrConfigurationDetection.IsCoreClrInterpreter;
}
}

Expand Down
Loading