$OpenBSD: patch-libgc_misc_c,v 1.2 2016/07/13 08:21:38 ajacoutot Exp $

From pkgsrc:
Behave when address space limits are in place:
(1) Default heap limit to 75% of available address space.
(2) Limit GC marker threads to 4MB/8MB (32bit vs 64bit) stack space.
    As Mono tries to create 16 such threads by default, the default
    stack size on AMD64 would eat 2GB VA alone.

--- libgc/misc.c.orig	Thu Jun 23 19:54:33 2016
+++ libgc/misc.c	Thu Jun 23 20:07:51 2016
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <limits.h>
 #ifndef _WIN32_WCE
+#include <sys/resource.h>
 #include <signal.h>
 #endif
 
@@ -766,6 +767,19 @@ void GC_init_inner()
 	  initial_heap_sz = divHBLKSZ(initial_heap_sz);
 	}
     }
+#ifdef RLIMIT_AS
+    {
+        /*
+	 * If there is a VA limit for the process,
+	 * keep the heap under 75% if that limit.
+	 */
+        struct rlimit lim;
+        if (!getrlimit(RLIMIT_AS, &lim)) {
+          if (lim.rlim_cur != RLIM_INFINITY && lim.rlim_cur == (word)lim.rlim_cur)
+            GC_set_max_heap_size(lim.rlim_cur / 2 + lim.rlim_cur / 4);
+	}
+    }
+#endif
     {
 	char * sz_str = GETENV("GC_MAXIMUM_HEAP_SIZE");
 	if (sz_str != NULL) {
