diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs index 901cfcfa78a024..be23483549c60d 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs @@ -93,6 +93,10 @@ public static IEnumerable SignalTestData() { foreach (PosixSignal signal in Enum.GetValues()) { + if (signal == PosixSignal.SIGKILL) + { + continue; // SIGKILL cannot be caught or ignored + } yield return new object[] { signal }; } // Test a few raw signals. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignal.cs index e1f278fbd6f557..cc047934908651 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignal.cs @@ -42,6 +42,10 @@ public enum PosixSignal /// Stop typed at terminal [UnsupportedOSPlatform("windows")] - SIGTSTP = -10 + SIGTSTP = -10, + + /// Kill (cannot be caught or ignored) + [UnsupportedOSPlatform("windows")] + SIGKILL = -11 } } diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index d4923a544cc3a0..07ef66f0e6a62d 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -1581,6 +1581,8 @@ public OptionalAttribute() { } } public enum PosixSignal { + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("windows")] + SIGKILL = -11, [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("windows")] SIGTSTP = -10, [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("windows")] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs index 9a4b9f37a8b3d0..95c728174adf03 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs @@ -16,13 +16,19 @@ public partial class PosixSignalRegistrationTests { public static IEnumerable UninstallableSignals() { + yield return new object[] { PosixSignal.SIGKILL }; yield return new object[] { (PosixSignal)9 }; } public static IEnumerable SupportedSignals() { foreach (PosixSignal value in Enum.GetValues(typeof(PosixSignal))) - yield return new object[] { value }; + { + if (value != PosixSignal.SIGKILL) + { + yield return new object[] { value }; + } + } } public static IEnumerable UnsupportedSignals() @@ -252,7 +258,12 @@ public static TheoryData PosixSignalAsRawValues var data = new TheoryData(); foreach (var value in Enum.GetValues(typeof(PosixSignal))) { - int signo = GetPlatformSignalNumber((PosixSignal)value); + PosixSignal signal = (PosixSignal)value; + if (signal == PosixSignal.SIGKILL) + { + continue; // SIGKILL cannot be registered + } + int signo = GetPlatformSignalNumber(signal); Assert.True(signo > 0, "Expected raw signal number to be greater than 0."); data.Add((PosixSignal)signo); } diff --git a/src/native/libs/System.Native/pal_signal.c b/src/native/libs/System.Native/pal_signal.c index 352458c8719f08..33be19b7faf37d 100644 --- a/src/native/libs/System.Native/pal_signal.c +++ b/src/native/libs/System.Native/pal_signal.c @@ -129,6 +129,10 @@ static bool TryConvertSignalCodeToPosixSignal(int signalCode, PosixSignal* posix *posixSignal = PosixSignalSIGTSTP; return true; + case SIGKILL: + *posixSignal = PosixSignalSIGKILL; + return true; + default: *posixSignal = (PosixSignal)signalCode; return false; @@ -169,6 +173,9 @@ int32_t SystemNative_GetPlatformSignalNumber(PosixSignal signal) case PosixSignalSIGTSTP: return SIGTSTP; + case PosixSignalSIGKILL: + return SIGKILL; + case PosixSignalInvalid: break; } diff --git a/src/native/libs/System.Native/pal_signal.h b/src/native/libs/System.Native/pal_signal.h index c3c21009dc836c..d462b611ccb5de 100644 --- a/src/native/libs/System.Native/pal_signal.h +++ b/src/native/libs/System.Native/pal_signal.h @@ -44,7 +44,8 @@ typedef enum PosixSignalSIGWINCH = -7, PosixSignalSIGTTIN = -8, PosixSignalSIGTTOU = -9, - PosixSignalSIGTSTP = -10 + PosixSignalSIGTSTP = -10, + PosixSignalSIGKILL = -11 } PosixSignal; typedef int32_t (*PosixSignalHandler)(int32_t signalCode, PosixSignal signal);