public static UInt64 GetMaxNumberOfOpenFiles() { var limit = new rlimit(); getrlimit((int)RLimit.NoFile, ref limit); return(limit.cur); }
private void TestZero() { rlimit zeroRlimit = rlimit.Zero(); Assert.Equal(0UL, zeroRlimit.rlim_cur); Assert.Equal(0UL, zeroRlimit.rlim_max); }
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); }
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); }
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); }
/// <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; }
/// <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); }
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(); } }
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); } }
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; } } }
internal static extern int setrlimit( RLIMIT_Resources resource, ref rlimit info);
public static extern int setrlimit(int resource, ref rlimit l);
private static extern int setrlimit(rlimit_resource resource, ref rlimit rlim);
internal static extern int setrlimit(int resource, ref rlimit rlim);
internal static extern int getrlimit(int resource, out rlimit rlim);
private static extern int getrlimit( RLIMIT_Resources resource, ref rlimit info);