Skip to content

Commit

Permalink
Merge in 'release/6.0' changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnet-bot committed Jul 13, 2022
2 parents 02f4445 + 78111ad commit f9fbf00
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 27 deletions.
5 changes: 4 additions & 1 deletion src/coreclr/debug/createdump/crashinfomac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "createdump.h"

int g_readProcessMemoryResult = KERN_SUCCESS;

bool
CrashInfo::Initialize()
{
Expand Down Expand Up @@ -127,7 +129,7 @@ CrashInfo::EnumerateMemoryRegions()
}
else
{
if ((info.protection & (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)) != 0)
if (info.share_mode != SM_EMPTY && (info.protection & (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)) != 0)
{
MemoryRegion memoryRegion(ConvertProtectionFlags(info.protection), address, address + size, info.offset);
m_allMemoryRegions.insert(memoryRegion);
Expand Down Expand Up @@ -362,6 +364,7 @@ CrashInfo::ReadProcessMemory(void* address, void* buffer, size_t size, size_t* r
kern_return_t result = ::vm_read_overwrite(Task(), addressAligned, PAGE_SIZE, (vm_address_t)data, &bytesRead);
if (result != KERN_SUCCESS || bytesRead != PAGE_SIZE)
{
g_readProcessMemoryResult = result;
TRACE_VERBOSE("ReadProcessMemory(%p %d): vm_read_overwrite failed bytesLeft %d bytesRead %d from %p: %x %s\n",
address, size, bytesLeft, bytesRead, (void*)addressAligned, result, mach_error_string(result));
break;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/debug/createdump/crashreportwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CrashReportWriter::WriteCrashReport(const std::string& dumpFileName)
}
WriteCrashReport();
CloseWriter();
printf_status("Crash report successfully written\n");
}
catch (const std::exception& e)
{
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/debug/createdump/createdumpunix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ CreateDump(const char* dumpPathTemplate, int pid, const char* dumpType, MINIDUMP
}
result = true;
exit:
if (kill(pid, 0) == 0)
{
printf_status("Target process is alive\n");
}
else
{
int err = errno;
if (err == ESRCH)
{
printf_error("Target process terminated\n");
}
else
{
printf_error("kill(%d, 0) FAILED %s (%d)\n", pid, strerror(err), err);
}
}
crashInfo->CleanupAndResumeProcess();
return result;
}
6 changes: 4 additions & 2 deletions src/coreclr/debug/createdump/dumpwritermacho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "createdump.h"
#include "specialthreadinfo.h"

extern int g_readProcessMemoryResult;

//
// Write the core dump file
//
Expand Down Expand Up @@ -264,13 +266,13 @@ DumpWriter::WriteSegments()
size_t read = 0;

if (!m_crashInfo.ReadProcessMemory((void*)address, m_tempBuffer, bytesToRead, &read)) {
printf_error("ReadProcessMemory(%" PRIA PRIx64 ", %08zx) FAILED\n", address, bytesToRead);
printf_error("ReadProcessMemory(%" PRIA PRIx64 ", %08zx) read %d FAILED %s (%x)\n", address, bytesToRead, read, mach_error_string(g_readProcessMemoryResult), g_readProcessMemoryResult);
return false;
}

// This can happen if the target process dies before createdump is finished
if (read == 0) {
printf_error("ReadProcessMemory(%" PRIA PRIx64 ", %08zx) returned 0 bytes read\n", address, bytesToRead);
printf_error("ReadProcessMemory(%" PRIA PRIx64 ", %08zx) returned 0 bytes read: %s (%x)\n", address, bytesToRead, mach_error_string(g_readProcessMemoryResult), g_readProcessMemoryResult);
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/pal/src/exception/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ static void sigterm_handler(int code, siginfo_t *siginfo, void *context)
{
if (PALIsInitialized())
{
char* enable = getenv("COMPlus_EnableDumpOnSigTerm");
if (enable != nullptr && strcmp(enable, "1") == 0)
{
PROCCreateCrashDumpIfEnabled(code);
}
// g_pSynchronizationManager shouldn't be null if PAL is initialized.
_ASSERTE(g_pSynchronizationManager != nullptr);

Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ void HandleTerminationRequest(int terminationExitCode)
{
SetLatchedExitCode(terminationExitCode);

DWORD enabled = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EnableDumpOnSigTerm);
ForceEEShutdown(enabled == 1 ? SCA_TerminateProcessWhenShutdownComplete : SCA_ExitProcessWhenShutdownComplete);
ForceEEShutdown(SCA_ExitProcessWhenShutdownComplete);
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static bool TryDecrypt(

if (rsaPaddingProcessor != null)
{
return rsaPaddingProcessor.DepadOaep(paddingBuf, destination, out bytesWritten);
return rsaPaddingProcessor.DepadOaep(paddingBuf.AsSpan(0, returnValue), destination, out bytesWritten);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using Test.Cryptography;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;
Expand Down Expand Up @@ -673,6 +674,23 @@ public void UnusualExponentCryptRoundtrip()
Assert.Equal(TestData.HelloBytes, output);
}

[Theory]
[MemberData(nameof(OaepPaddingModes))]
public void NonPowerOfTwoKeySizeOaepRoundtrip(RSAEncryptionPadding oaepPaddingMode)
{
byte[] crypt;
byte[] output;

using (RSA rsa = RSAFactory.Create(3072))
{
crypt = Encrypt(rsa, TestData.HelloBytes, oaepPaddingMode);
output = Decrypt(rsa, crypt, oaepPaddingMode);
}

Assert.NotEqual(crypt, output);
Assert.Equal(TestData.HelloBytes, output);
}

[Fact]
public void NotSupportedValueMethods()
{
Expand All @@ -682,5 +700,20 @@ public void NotSupportedValueMethods()
Assert.Throws<NotSupportedException>(() => rsa.EncryptValue(null));
}
}

public static IEnumerable<object[]> OaepPaddingModes
{
get
{
yield return new object[] { RSAEncryptionPadding.OaepSHA1 };

if (RSAFactory.SupportsSha2Oaep)
{
yield return new object[] { RSAEncryptionPadding.OaepSHA256 };
yield return new object[] { RSAEncryptionPadding.OaepSHA384 };
yield return new object[] { RSAEncryptionPadding.OaepSHA512 };
}
}
}
}
}
42 changes: 26 additions & 16 deletions src/libraries/System.Private.CoreLib/src/System/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,8 @@ public static double Max(double val1, double val2)
// This matches the IEEE 754:2019 `maximum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the larger of the inputs. It
// treats +0 as larger than -0 as per the specification.
// otherwise returns the greater of the inputs. It
// treats +0 as greater than -0 as per the specification.

if (val1 != val2)
{
Expand Down Expand Up @@ -888,8 +888,8 @@ public static float Max(float val1, float val2)
// This matches the IEEE 754:2019 `maximum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the larger of the inputs. It
// treats +0 as larger than -0 as per the specification.
// otherwise returns the greater of the inputs. It
// treats +0 as greater than -0 as per the specification.

if (val1 != val2)
{
Expand Down Expand Up @@ -941,8 +941,8 @@ public static double MaxMagnitude(double x, double y)
// This matches the IEEE 754:2019 `maximumMagnitude` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the input with a larger magnitude.
// It treats +0 as larger than -0 as per the specification.
// otherwise returns the input with a greater magnitude.
// It treats +0 as greater than -0 as per the specification.

double ax = Abs(x);
double ay = Abs(y);
Expand Down Expand Up @@ -978,12 +978,17 @@ public static double Min(double val1, double val2)
// This matches the IEEE 754:2019 `minimum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the larger of the inputs. It
// treats +0 as larger than -0 as per the specification.
// otherwise returns the lesser of the inputs. It
// treats -0 as lesser than +0 as per the specification.

if (val1 != val2 && !double.IsNaN(val1))
if (val1 != val2)
{
return val1 < val2 ? val1 : val2;
if (!double.IsNaN(val1))
{
return val1 < val2 ? val1 : val2;
}

return val1;
}

return double.IsNegative(val1) ? val1 : val2;
Expand Down Expand Up @@ -1030,12 +1035,17 @@ public static float Min(float val1, float val2)
// This matches the IEEE 754:2019 `minimum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the larger of the inputs. It
// treats +0 as larger than -0 as per the specification.
// otherwise returns the lesser of the inputs. It
// treats -0 as lesser than +0 as per the specification.

if (val1 != val2 && !float.IsNaN(val1))
if (val1 != val2)
{
return val1 < val2 ? val1 : val2;
if (!float.IsNaN(val1))
{
return val1 < val2 ? val1 : val2;
}

return val1;
}

return float.IsNegative(val1) ? val1 : val2;
Expand Down Expand Up @@ -1078,8 +1088,8 @@ public static double MinMagnitude(double x, double y)
// This matches the IEEE 754:2019 `minimumMagnitude` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the input with a larger magnitude.
// It treats +0 as larger than -0 as per the specification.
// otherwise returns the input with a lesser magnitude.
// It treats -0 as lesser than +0 as per the specification.

double ax = Abs(x);
double ay = Abs(y);
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/MathF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public static float MaxMagnitude(float x, float y)
// This matches the IEEE 754:2019 `maximumMagnitude` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the input with a larger magnitude.
// It treats +0 as larger than -0 as per the specification.
// otherwise returns the input with a greater magnitude.
// It treats +0 as greater than -0 as per the specification.

float ax = Abs(x);
float ay = Abs(y);
Expand Down Expand Up @@ -246,8 +246,8 @@ public static float MinMagnitude(float x, float y)
// This matches the IEEE 754:2019 `minimumMagnitude` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the input with a larger magnitude.
// It treats +0 as larger than -0 as per the specification.
// otherwise returns the input with a lesser magnitude.
// It treats -0 as lesser than +0 as per the specification.

float ax = Abs(x);
float ay = Abs(y);
Expand Down
Loading

0 comments on commit f9fbf00

Please sign in to comment.