Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.cs (C#)

Code before:
        private Token? _token;

        /// <summary>Registers a <paramref name="handler"/> that is invoked when the <paramref name="signal"/> occurs.</summary>
        /// <param name="signal">The signal to register for.</param>
        /// <param name="handler">The handler that gets invoked.</param>
        /// <returns>A <see cref="PosixSignalRegistration"/> instance that can be disposed to unregister the handler.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="handler"/> is <see langword="null"/>.</exception>
        /// <exception cref="PlatformNotSupportedException"><paramref name="signal"/> is not supported by the platform.</exception>
        /// <exception cref="IOException">An error occurred while setting up the signal handling or while installing the handler for the specified signal.</exception>
        /// <remarks>
        /// The handlers are executed in reverse order of their registration.
        /// Raw values can be provided for <paramref name="signal"/> on Unix by casting them to <see cref="PosixSignal"/>.
        /// Default handling of the signal can be canceled through <see cref="PosixSignalContext.Cancel"/>.
        /// <see cref="PosixSignal.SIGINT"/> and <see cref="PosixSignal.SIGQUIT"/> can be canceled on both
        /// Windows and on Unix platforms; <see cref="PosixSignal.SIGTERM"/> can only be canceled on Unix.
        /// On Unix, terminal configuration can be canceled for <see cref="PosixSignal.SIGCHLD"/> and <see cref="PosixSignal.SIGCONT"/>.
        /// </remarks>
        [UnsupportedOSPlatform("android")]
        [UnsupportedOSPlatform("browser")]
        [UnsupportedOSPlatform("ios")]
        [UnsupportedOSPlatform("tvos")]
        public static PosixSignalRegistration Create(PosixSignal signal, Action<PosixSignalContext> handler)
        {
            ArgumentNullException.ThrowIfNull(handler);

            // SIGKILL cannot be caught or ignored on any OS.
            if (signal == PosixSignal.SIGKILL)
            {
                throw new IOException(SR.Arg_CannotRegisterHandlerForSIGKILL);
            }

            return Register(signal, handler);
        }

        /// <summary>Initializes the registration to wrap the specified token.</summary>
        private PosixSignalRegistration(Token token) => _token = token;

        /// <summary>Unregister the handler.</summary>
        public void Dispose()
        {
            Unregister();
            GC.SuppressFinalize(this);
        }

        /// <summary>Unregister the handler.</summary>
        ~PosixSignalRegistration() => Unregister();

        /// <summary>The state associated with a registration.</summary>
        private sealed class Token
        {
            public Token(PosixSignal signal, Action<PosixSignalContext> handler)

Review comment (refactor):
This is adding extra check on Windows that has no value.

SIGKILL is `UnsupportedOSPlatform("windows")`. I think throwing `UnsupportedOSPlatform("windows")` like we throw for all other signals not supported on Windows would make more sense. I would move this check to the Unix specific file where it was originally, or drop it completely. Signal handlers are advanced unsafe API with by-design sharp edges. I think the error from the OS is just fine.

Code after:
        private Token? _token;

        /// <summary>Registers a <paramref name="handler"/> that is invoked when the <paramref name="signal"/> occurs.</summary>
        /// <param name="signal">The signal to register for.</param>
        /// <param name="handler">The handler that gets invoked.</param>
        /// <returns>A <see cref="PosixSignalRegistration"/> instance that can be disposed to unregister the handler.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="handler"/> is <see langword="null"/>.</exception>
        /// <exception cref="PlatformNotSupportedException"><paramref name="signal"/> is not supported by the platform.</exception>
        /// <exception cref="IOException">An error occurred while setting up the signal handling or while installing the handler for the specified signal.</exception>
        /// <remarks>
        /// The handlers are executed in reverse order of their registration.
        /// Raw values can be provided for <paramref name="signal"/> on Unix by casting them to <see cref="PosixSignal"/>.
        /// Default handling of the signal can be canceled through <see cref="PosixSignalContext.Cancel"/>.
        /// <see cref="PosixSignal.SIGINT"/> and <see cref="PosixSignal.SIGQUIT"/> can be canceled on both
        /// Windows and on Unix platforms; <see cref="PosixSignal.SIGTERM"/> can only be canceled on Unix.
        /// On Unix, terminal configuration can be canceled for <see cref="PosixSignal.SIGCHLD"/> and <see cref="PosixSignal.SIGCONT"/>.
        /// </remarks>
        [UnsupportedOSPlatform("android")]
        [UnsupportedOSPlatform("browser")]
        [UnsupportedOSPlatform("ios")]
        [UnsupportedOSPlatform("tvos")]
        public static PosixSignalRegistration Create(PosixSignal signal, Action<PosixSignalContext> handler)
        {
            ArgumentNullException.ThrowIfNull(handler);

            return Register(signal, handler);
        }

        /// <summary>Initializes the registration to wrap the specified token.</summary>
        private PosixSignalRegistration(Token token) => _token = token;

        /// <summary>Unregister the handler.</summary>
        public void Dispose()
        {
            Unregister();
            GC.SuppressFinalize(this);
        }

        /// <summary>Unregister the handler.</summary>
        ~PosixSignalRegistration() => Unregister();

        /// <summary>The state associated with a registration.</summary>
        private sealed class Token
        {
            public Token(PosixSignal signal, Action<PosixSignalContext> handler)
            {
                Signal = signal;
                Handler = handler;
            }

            public Token(PosixSignal signal, int sigNo, Action<PosixSignalContext> handler)