Blob Blame History Raw
--- ./o/main.c.orig	2010-11-02 15:56:45.000000000 -0600
+++ ./o/main.c	2012-01-09 20:51:43.097828330 -0700
@@ -51,6 +51,7 @@
 #include <signal.h>
 #endif
 #include "page.h"
+#include "unrandomize.h"
 
 bool saving_system ;
 
@@ -146,11 +147,7 @@
 #endif	
 	*argv=kcl_self;
 
-#ifdef CAN_UNRANDOMIZE_SBRK
-#include <stdio.h>
-#include <stdlib.h>
-#include "unrandomize.h"
-#endif
+	UNRANDOMIZE_SBRK;
 
 #ifdef LD_BIND_NOW
 #include <stdio.h>
--- ./h/unrandomize.h.orig	2010-01-12 07:19:15.000000000 -0700
+++ ./h/unrandomize.h	2012-01-09 20:51:43.101828245 -0700
@@ -1,39 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
 #include <sys/personality.h>
 #include <syscall.h>
 #include <unistd.h>
 #include <alloca.h>
 #include <errno.h>
 
-
-{
-  errno=0;
-
-  {
-
-    long pers = personality(0xffffffffUL);
-    if (pers==-1) {printf("personality failure %d\n",errno);exit(-1);}
-    if (!(pers & ADDR_NO_RANDOMIZE) && !getenv("GCL_UNRANDOMIZE")) {
-      errno=0;
-      if (personality(pers | ADDR_NO_RANDOMIZE) != -1 && personality(0xffffffffUL) & ADDR_NO_RANDOMIZE) {
-	int i;
-	char **n;
-	for (i=0;envp[i];i++);
-	n=alloca((i+2)*sizeof(*n));
-	n[i+1]=0;
-	n[i--]="GCL_UNRANDOMIZE=t";
-	for (;i>=0;i--)
-	  n[i]=envp[i];
-#ifdef GCL_GPROF
-	gprof_cleanup();
+#ifdef CAN_UNRANDOMIZE_SBRK
+# ifdef GCL_GPROF
+#  define GPROF_CLEANUP gprof_cleanup()
+# else
+#  define GPROF_CLEANUP
+# endif
+# define UNRANDOMIZE_SBRK do {						\
+    errno=0;								\
+    {									\
+      long pers = personality(0xffffffffUL);				\
+      if (pers==-1) {printf("personality failure %d\n",errno);exit(-1);} \
+      if (!(pers & ADDR_NO_RANDOMIZE) && !getenv("GCL_UNRANDOMIZE")) {	\
+	errno=0;							\
+	if (personality(pers | ADDR_NO_RANDOMIZE) != -1 && personality(0xffffffffUL) & ADDR_NO_RANDOMIZE) { \
+	  int i;							\
+	  char **n;							\
+	  for (i=0;envp[i];i++);					\
+	  n=alloca((i+2)*sizeof(*n));					\
+	  n[i+1]=0;							\
+	  n[i--]="GCL_UNRANDOMIZE=t";					\
+	  for (;i>=0;i--)						\
+	    n[i]=envp[i];						\
+	  GPROF_CLEANUP;						\
+	  errno=0;							\
+	  execve(*argv,argv,n);						\
+	  printf("execve failure %d\n",errno);				\
+	  exit(-1);							\
+	} else {							\
+	  printf("personality change failure %d\n",errno);		\
+	  exit(-1);							\
+	}								\
+      }									\
+    }									\
+  } while (0)
+#else
+# define UNRANDOMIZE_SBRK
 #endif
-	errno=0;
-	execve(*argv,argv,n);
-	printf("execve failure %d\n",errno);
-	exit(-1);
-      } else {
-	printf("personality change failure %d\n",errno);
-	exit(-1);
-      }
-    }
-  }
-}
--- ./configure.in.orig	2012-01-09 20:49:21.949801255 -0700
+++ ./configure.in	2012-01-09 20:51:43.102828225 -0700
@@ -1167,9 +1167,11 @@
 
 	AC_MSG_CHECKING([for personality(ADDR_NO_RANDOMIZE) support])
 	AC_RUN_IFELSE([AC_LANG_SOURCE([[
+		    #define CAN_UNRANDOMIZE_SBRK 1
+		    #include "h/unrandomize.h"
 		    void gprof_cleanup() {}
 		    int main(int argc,char *argv[],char *envp[]) {
-	            #include "h/unrandomize.h"
+		    UNRANDOMIZE_SBRK;
 		    return 0;}]])],CAN_UNRANDOMIZE_SBRK=1,CAN_UNRANDOMIZE_SBRK=0,CAN_UNRANDOMIZE_SBRK=0)
 
 	if test "$CAN_UNRANDOMIZE_SBRK" != 0 ; then
@@ -1182,12 +1184,11 @@
 	AC_MSG_CHECKING([that sbrk is (now) non-random])
 	AC_RUN_IFELSE([AC_LANG_SOURCE([[
 		    #include <stdio.h>
+		    #include "h/unrandomize.h"
 	            void gprof_cleanup() {}
 		    int main(int argc,char * argv[],char * envp[]) {
 			FILE *f;
-			#ifdef CAN_UNRANDOMIZE_SBRK
-			#include "h/unrandomize.h"
-			#endif
+			UNRANDOMIZE_SBRK;
 			if (!(f=fopen("conftest1","w"))) return -1;
 			fprintf(f,"%u",sbrk(0));
 			return 0;}]])],SBRK=`cat conftest1`,SBRK=0,SBRK=0)
@@ -1196,12 +1197,11 @@
 	fi
 	AC_RUN_IFELSE([AC_LANG_SOURCE([[
 		    #include <stdio.h>
+		    #include "h/unrandomize.h"
                     void gprof_cleanup() {}
 		    int main(int argc,char * argv[],char * envp[]) {
 			FILE *f;
-			#ifdef CAN_UNRANDOMIZE_SBRK
-			#include "h/unrandomize.h"
-			#endif
+			UNRANDOMIZE_SBRK;
 			if (!(f=fopen("conftest1","w"))) return -1;
 			fprintf(f,"%u",sbrk(0));
 			return 0;}]])],SBRK1=`cat conftest1`,SBRK1=0,SBRK1=0)
@@ -1243,6 +1243,7 @@
 AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #include <stdio.h>
 #include <stdlib.h>
+#include "h/unrandomize.h"
 
 void gprof_cleanup() {}
 int
@@ -1251,9 +1252,7 @@
   char *b,*b1;
   FILE *fp;
 
-#ifdef CAN_UNRANDOMIZE_SBRK
-#include "h/unrandomize.h"
-#endif
+  UNRANDOMIZE_SBRK;
   b = (void *) malloc(1000);
   fp = fopen("conftest1","w");
 
--- ./configure.orig	2012-01-09 20:49:33.805551545 -0700
+++ ./configure	2012-01-09 20:51:54.679584389 -0700
@@ -6946,9 +6946,11 @@
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
+		    #define CAN_UNRANDOMIZE_SBRK 1
+		    #include "h/unrandomize.h"
 		    void gprof_cleanup() {}
 		    int main(int argc,char *argv[],char *envp[]) {
-	            #include "h/unrandomize.h"
+		    UNRANDOMIZE_SBRK;
 		    return 0;}
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
@@ -6980,12 +6982,11 @@
 /* end confdefs.h.  */
 
 		    #include <stdio.h>
+		    #include "h/unrandomize.h"
 	            void gprof_cleanup() {}
 		    int main(int argc,char * argv[],char * envp[]) {
 			FILE *f;
-			#ifdef CAN_UNRANDOMIZE_SBRK
-			#include "h/unrandomize.h"
-			#endif
+			UNRANDOMIZE_SBRK;
 			if (!(f=fopen("conftest1","w"))) return -1;
 			fprintf(f,"%u",sbrk(0));
 			return 0;}
@@ -7009,12 +7010,11 @@
 /* end confdefs.h.  */
 
 		    #include <stdio.h>
+		    #include "h/unrandomize.h"
                     void gprof_cleanup() {}
 		    int main(int argc,char * argv[],char * envp[]) {
 			FILE *f;
-			#ifdef CAN_UNRANDOMIZE_SBRK
-			#include "h/unrandomize.h"
-			#endif
+			UNRANDOMIZE_SBRK;
 			if (!(f=fopen("conftest1","w"))) return -1;
 			fprintf(f,"%u",sbrk(0));
 			return 0;}
@@ -7101,6 +7101,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include "h/unrandomize.h"
 
 void gprof_cleanup() {}
 int
@@ -7109,9 +7110,7 @@
   char *b,*b1;
   FILE *fp;
 
-#ifdef CAN_UNRANDOMIZE_SBRK
-#include "h/unrandomize.h"
-#endif
+  UNRANDOMIZE_SBRK;
   b = (void *) malloc(1000);
   fp = fopen("conftest1","w");