$OpenBSD: patch-libgc_pthread_support_c,v 1.1 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/pthread_support.c.orig	Thu Jun  9 17:01:54 2016
+++ libgc/pthread_support.c	Wed Jul 13 09:18:37 2016
@@ -595,6 +595,20 @@ static void start_mark_threads()
 	}
       }
 #   endif /* HPUX || GC_DGUX386_THREADS */
+#   if defined(__OpenBSD__)
+#     define MAX_STACK_SIZE (1024 * 1024 *sizeof(word))
+      {
+	size_t old_size;
+	int code;
+
+        if (pthread_attr_getstacksize(&attr, &old_size) != 0)
+	  ABORT("pthread_attr_getstacksize failed\n");
+	if (old_size > MAX_STACK_SIZE) {
+	  if (pthread_attr_setstacksize(&attr, MAX_STACK_SIZE) != 0)
+		  ABORT("pthread_attr_setstacksize failed\n");
+	}
+      }
+#   endif
 #   ifdef CONDPRINT
       if (GC_print_stats) {
 	GC_printf1("Starting %ld marker threads\n", GC_markers - 1);
