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

Code before:
        private static unsafe Dictionary<int, List<Token>> Initialize()
        {
            if (!Interop.Sys.InitializeTerminalAndSignalHandling())
            {
                Interop.ThrowIOExceptionForLastError();
            }

            Interop.Sys.SetPosixSignalHandler(&OnPosixSignal);

            return new Dictionary<int, List<Token>>();
        }

        private static PosixSignalRegistration Register(PosixSignal signal, Action<PosixSignalContext> handler)
        {
            int signo = Interop.Sys.GetPlatformSignalNumber(signal);
            if (signo == 0)
            {
                throw new PlatformNotSupportedException();
            }

            // SIGKILL cannot have a signal handler installed on Unix
            if (signo == s_sigkillNumber)
            {
                throw new ArgumentException(SR.Arg_CannotRegisterHandlerForSIGKILL, nameof(signal));
            }

            var token = new Token(signal, signo, handler);
            var registration = new PosixSignalRegistration(token);

            lock (s_registrations)
            {
                if (!s_registrations.TryGetValue(signo, out List<Token>? tokens))
                {
                    s_registrations[signo] = tokens = new List<Token>();
                }

                if (tokens.Count == 0 &&
                    !Interop.Sys.EnablePosixSignalHandling(signo))
                {
                    Interop.ThrowIOExceptionForLastError();
                }

                tokens.Add(token);
            }

            return registration;
        }

        private void Unregister()
        {
            lock (s_registrations)

Review comment (suggestion):
SIGKILL can not be handled on any OS, that is why I believe we should throw in the `Create` method:

https://github.com/dotnet/runtime/blob/73f9225d7e816c2dc1e3a08f30855161c7f42dc7/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.cs#L38-L40

Please move the validation logic there and remove the `s_sigkillNumber` field.

```suggestion
```

Code after:
        {
            if (!Interop.Sys.InitializeTerminalAndSignalHandling())
            {
                Interop.ThrowIOExceptionForLastError();
            }

            Interop.Sys.SetPosixSignalHandler(&OnPosixSignal);

            return new Dictionary<int, List<Token>>();
        }

        private static PosixSignalRegistration Register(PosixSignal signal, Action<PosixSignalContext> handler)
        {
            int signo = Interop.Sys.GetPlatformSignalNumber(signal);
            if (signo == 0)
            {
                throw new PlatformNotSupportedException();
            }

            var token = new Token(signal, signo, handler);
            var registration = new PosixSignalRegistration(token);

            lock (s_registrations)
            {
                if (!s_registrations.TryGetValue(signo, out List<Token>? tokens))
                {
                    s_registrations[signo] = tokens = new List<Token>();
                }

                if (tokens.Count == 0 &&
                    !Interop.Sys.EnablePosixSignalHandling(signo))
                {
                    Interop.ThrowIOExceptionForLastError();
                }

                tokens.Add(token);
            }

            return registration;
        }

        private void Unregister()
        {
            lock (s_registrations)
            {
                if (_token is Token token)
                {
                    _token = null;

                    if (s_registrations.TryGetValue(token.SigNo, out List<Token>? tokens))
                    {