Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 gcl (2.6.7+dfsga-27) unstable; urgency=high
 .
   * workaround for ia64 and hurd brk issues
Author: Camm Maguire <camm@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- gcl-2.6.7+dfsga.orig/h/ia64-linux.h
+++ gcl-2.6.7+dfsga/h/ia64-linux.h
@@ -26,3 +26,4 @@
 #define SGC
 
 #define STATIC_FUNCTION_POINTERS
+#define BRK_DOES_NOT_GUARANTEE_ALLOCATION
--- gcl-2.6.7+dfsga.orig/h/386-gnu.h
+++ gcl-2.6.7+dfsga/h/386-gnu.h
@@ -69,5 +69,6 @@
 #endif
 #define PATH_MAX 4096 /*fixme dynamic*/
 #define MAXPATHLEN 4096 /*fixme dynamic*/
+#define MAX_BRK 0x70000000 /*GNU Hurd fragmentation bug*/
 
 #define RELOC_H "elf32_i386_reloc.h"
--- gcl-2.6.7+dfsga.orig/o/main.c
+++ gcl-2.6.7+dfsga/o/main.c
@@ -124,10 +124,16 @@ cstack_dir(fixnum j) {
 }
 
 fixnum log_maxpage_bound=sizeof(fixnum)*8-1;
+
 inline int
 mbrk(void *v) {
   ufixnum uv=(ufixnum)v,uc=(ufixnum)sbrk(0),ux,um;
   fixnum m=((1UL<<(sizeof(fixnum)*8-1))-1);
+
+#ifdef MAX_BRK /*GNU Hurd fragmentation bug*/
+  if ((ufixnum)v>MAX_BRK) return -1;
+#endif
+
   if (uv<uc) {
     um=uv;
     ux=uc;
@@ -166,7 +172,7 @@ update_real_maxpage(void) {
 #ifdef HAVE_SYSCONF_PHYS_PAGES
   phys_pages=sysconf(_SC_PHYS_PAGES);
 #ifdef BRK_DOES_NOT_GUARANTEE_ALLOCATION
-  if (real_maxpage>phys_pages) for (real_maxpage=1;real_maxpage<phys_pages;real_maxpage<<=1);
+  if (phys_pages>0 && real_maxpage>phys_pages+first_data_page) real_maxpage=phys_pages+first_data_page;
 #endif
 #endif
 
