Beispiel #1
0
        public AllocatorGenerator()
        {
            var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary <string, string>()
            {
                { "heapSize", "32000" },
                { "minimumAllocationSize", "128" },
            }).Build();

            allocators = new List <object[]>();
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                allocators.Add(new object[] { new MacOSProtectedMemoryAllocatorLP64() });
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                if (LinuxOpenSSL11ProtectedMemoryAllocatorLP64.IsAvailable())
                {
                    allocators.Add(new object[] { new LinuxOpenSSL11ProtectedMemoryAllocatorLP64(configuration) });
                }
                allocators.Add(new object[] { new LinuxProtectedMemoryAllocatorLP64() });
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                allocators.Add(new object[] { new WindowsProtectedMemoryAllocatorVirtualAlloc(configuration) });
            }
        }
        private static IProtectedMemoryAllocator ConfigureForLinux64(IConfiguration configuration)
        {
            if (configuration != null)
            {
                var secureHeapEngine = configuration["secureHeapEngine"];
                if (!string.IsNullOrWhiteSpace(secureHeapEngine))
                {
                    if (string.Compare(secureHeapEngine, "openssl11", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        if (LinuxOpenSSL11ProtectedMemoryAllocatorLP64.IsAvailable())
                        {
                            return(new LinuxOpenSSL11ProtectedMemoryAllocatorLP64(configuration));
                        }

                        throw new PlatformNotSupportedException(
                                  "OpenSSL 1.1 selected for secureHeapEngine but library not found");
                    }

                    if (string.Compare(secureHeapEngine, "mmap", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        return(new LinuxProtectedMemoryAllocatorLP64());
                    }

                    throw new PlatformNotSupportedException("Unknown secureHeapEngine: " + secureHeapEngine);
                }
            }

            return(new LinuxProtectedMemoryAllocatorLP64());
        }