示例#1
0
        public static UInt64 GetMaxNumberOfOpenFiles()
        {
            var limit = new rlimit();

            getrlimit((int)RLimit.NoFile, ref limit);
            return(limit.cur);
        }
示例#2
0
        private void TestZero()
        {
            rlimit zeroRlimit = rlimit.Zero();

            Assert.Equal(0UL, zeroRlimit.rlim_cur);
            Assert.Equal(0UL, zeroRlimit.rlim_max);
        }
示例#3
0
        private void TestDisableCoreDumpGlobally()
        {
            Skip.If(libc == null);

            Debug.WriteLine("LibcProtectedMemoryAllocatorTest.TestDisableCoreDumpGlobally");

            // Mac allocator has global core dumps disabled on init
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.False(libcProtectedMemoryAllocator.AreCoreDumpsGloballyDisabled());
                libc.getrlimit(libcProtectedMemoryAllocator.GetRlimitCoreResource(), out var rlim);

                // Initial values here system dependent, assumes docker container spun up w/ unlimited
                Assert.Equal(rlimit.UNLIMITED, rlim.rlim_max);
                Assert.Equal(rlimit.UNLIMITED, rlim.rlim_cur);
            }

            libcProtectedMemoryAllocator.DisableCoreDumpGlobally();
            Assert.True(libcProtectedMemoryAllocator.AreCoreDumpsGloballyDisabled());
            rlimit zeroRlimit = rlimit.Zero();

            libc.getrlimit(libcProtectedMemoryAllocator.GetRlimitCoreResource(), out var newRlimit);
            Assert.Equal(zeroRlimit.rlim_cur, newRlimit.rlim_cur);
            Assert.Equal(zeroRlimit.rlim_max, newRlimit.rlim_max);
        }
示例#4
0
        private void TestDisableCoreDumpGlobally()
        {
            // Don't run libc tests on platforms that don't match libc/posix behaviors
            if (libc == null)
            {
                return;
            }

            // Mac allocator has global core dumps disabled on init
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.False(libcProtectedMemoryAllocator.AreCoreDumpsGloballyDisabled());
                libc.getrlimit(libcProtectedMemoryAllocator.GetRlimitCoreResource(), out var rlim);

                // Initial values here system dependent, assumes docker container spun up w/ unlimited
                Assert.Equal(rlimit.UNLIMITED, rlim.rlim_max);
                Assert.Equal(rlimit.UNLIMITED, rlim.rlim_cur);
            }

            libcProtectedMemoryAllocator.DisableCoreDumpGlobally();
            Assert.True(libcProtectedMemoryAllocator.AreCoreDumpsGloballyDisabled());
            rlimit zeroRlimit = rlimit.Zero();

            libc.getrlimit(libcProtectedMemoryAllocator.GetRlimitCoreResource(), out var newRlimit);
            Assert.Equal(zeroRlimit.rlim_cur, newRlimit.rlim_cur);
            Assert.Equal(zeroRlimit.rlim_max, newRlimit.rlim_max);
        }
示例#5
0
        public static bool SetMaxNumberOfOpenFiles(UInt64 value)
        {
            var limit = new rlimit();

            getrlimit((int)RLimit.NoFile, ref limit);
            limit.cur = value;
            return(0 != setrlimit((int)RLimit.NoFile, ref limit));
        }
        private void TestZero()
        {
            Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX));

            rlimit zeroRlimit = rlimit.Zero();

            Assert.Equal(0UL, zeroRlimit.rlim_cur);
            Assert.Equal(0UL, zeroRlimit.rlim_max);
        }
示例#7
0
        /// <summary>
        /// Gets the resource limits for the current process
        /// </summary>
        /// <param name="resource">The type of resource limit to query for</param>
        /// <returns>Returns the rlimit values for the specific resource</returns>
        internal static rlimit getrlimit(RLIMIT_Resources resource)
        {
            rlimit info = new rlimit();
            int result = getrlimit(resource, ref info);
            if (result < 0)
            {
                throw new System.ComponentModel.Win32Exception(SR.ResourceLimitQueryFailure);
            }

            return info;
        }
示例#8
0
        /// <summary>
        /// Gets the resource limits for the current process
        /// </summary>
        /// <param name="resource">The type of resource limit to query for</param>
        /// <returns>Returns the rlimit values for the specific resource</returns>
        internal static rlimit getrlimit(RLIMIT_Resources resource)
        {
            rlimit info   = new rlimit();
            int    result = getrlimit(resource, ref info);

            if (result < 0)
            {
                throw new System.ComponentModel.Win32Exception(SR.ResourceLimitQueryFailure);
            }

            return(info);
        }
示例#9
0
        public static unsafe void SetToMax(Resource resource)
        {
            rlimit rlp = default;

            if (getrlimit((int)resource, &rlp) != 0)
            {
                ThrowHelper.ThrowNewErrnoException();
            }
            rlp.rlim_cur = rlp.rlim_max;
            if (setrlimit((int)resource, &rlp) != 0)
            {
                ThrowHelper.ThrowNewErrnoException();
            }
        }
示例#10
0
        private static void UlimitUnlimited()
        {
            rlimit rlim = new rlimit();

            if (0 != getrlimit(rlimit_resource.RLIMIT_CORE, ref rlim))
            {
                int            err = Marshal.GetLastWin32Error();
                Win32Exception ex  = new Win32Exception(err);
                throw new PeachException("Error, LinuxCrashHandler could not query the core size resource limit.  " + ex.Message, ex);
            }

            rlim.rlim_curr = rlim.rlim_max;

            if (0 != setrlimit(rlimit_resource.RLIMIT_CORE, ref rlim))
            {
                int            err = Marshal.GetLastWin32Error();
                Win32Exception ex  = new Win32Exception(err);
                throw new PeachException("Error, LinuxCrashHandler could not set the core size resource limit.  " + ex.Message, ex);
            }
        }
示例#11
0
        public static void SetMaxNumberOfOpenFilesClosestTo(UInt64 value)
        {
            var limit = new rlimit();

            getrlimit((int)RLimit.NoFile, ref limit);

            UInt64 min = limit.cur, max = value, mid = 0;

            while (min <= max)
            {
                mid       = (min + max) / 2;
                limit.cur = mid;
                if (0 == setrlimit((int)RLimit.NoFile, ref limit))
                {
                    min = 1 + mid;
                }
                else
                {
                    max = mid - 1;
                }
            }
        }
示例#12
0
 internal static extern int setrlimit(
     RLIMIT_Resources    resource,
     ref rlimit          info);
示例#13
0
 public static extern int setrlimit(int resource, ref rlimit l);
示例#14
0
 private static extern int setrlimit(rlimit_resource resource, ref rlimit rlim);
示例#15
0
 internal static extern int setrlimit(int resource, ref rlimit rlim);
示例#16
0
 internal static extern int getrlimit(int resource, out rlimit rlim);
示例#17
0
 private static extern int getrlimit(
     RLIMIT_Resources resource,
     ref rlimit info);
示例#18
0
 private static extern int getrlimit(
     RLIMIT_Resources    resource, 
     ref rlimit          info);
示例#19
0
 internal static extern int setrlimit(
     RLIMIT_Resources resource,
     ref rlimit info);