Ilya Zakharevich on Thu, 12 Dec 2002 15:17:04 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PATCH oldish CVS] os2 stacklimit


The names of the macros would benefit from brushing up, but this would
require changes to Configure.

Enjoy,
Ilya

--- ./src/language/init.c-pre	Thu Oct 31 14:12:10 2002
+++ ./src/language/init.c	Sat Nov 16 14:19:26 2002
@@ -111,9 +112,15 @@ pop_stack(stack **pts)
 /*********************************************************************/
 
 /* adapted from Perl code written by Dominic Dunlop */
-#include <sys/resource.h>
 void *PARI_stack_limit = NULL;
 
+#  ifdef __EMX__				/* Emulate */
+extern void* get_stack(double,int);
+#    define STACK_CHECK_INIT(b)		\
+	((void)b, PARI_stack_limit = get_stack(1./16, 32*1024))
+#  else /* !__EMX__ */
+#include <sys/resource.h>
+
 /* Set PARI_stack_limit to (a little above) the lowest safe address that can
  * be used on the stack. Leave PARI_stack_limit at its initial value (NULL)
  * to show no check should be made [init failed]. Assume stack grows downward.
@@ -128,6 +135,11 @@ pari_init_stackcheck(void *stack_base)
  * PARI_stack_limit = stack_base - ((rip.rlim_cur/16)*15); */
   PARI_stack_limit = (void*)((long)stack_base - (rip.rlim_cur/16)*15);
 }
+#    define STACK_CHECK_INIT(b) pari_init_stackcheck(b)
+#  endif /* !__EMX__ */
+
+#else
+#    define STACK_CHECK_INIT(b)		((void)b)
 #endif /* STACK_CHECK */
 
 /*********************************************************************/
@@ -496,9 +508,7 @@ pari_init(size_t parisize, ulong maxprim
 {
   long i;
 
-#ifdef STACK_CHECK
-  pari_init_stackcheck(&i);
-#endif
+  STACK_CHECK_INIT(&i);
   init_defaults(0);
   if (INIT_JMP && setjmp(environnement))
   {
--- ./src/language/anal.h-pre	Thu Oct 24 02:58:06 2002
+++ ./src/language/anal.h	Fri Nov 15 23:32:10 2002
@@ -140,6 +140,10 @@ enum { NONE, WARN, OLDFUN, OLDALL };
 /* return type for GP functions */
 enum { RET_GEN, RET_INT, RET_VOID };
 
+#ifdef __EMX__
+#  define STACK_CHECK
+#endif
+
 #ifdef STACK_CHECK
 extern void *PARI_stack_limit;
 #endif
--- ./src/systems/os2.c-pre	Fri Nov 15 23:25:30 2002
+++ ./src/systems/os2.c	Sat Nov 16 14:27:26 2002
@@ -3,6 +3,7 @@
 #define INCL_BASE
 #include <os2.h>
 #include <float.h>
+#include <stdlib.h>
 
 static ULONG retcode;
 static char fail[300];
@@ -189,4 +190,26 @@ dlclose(void *handle)
 
 	retcode = rc;
 	return 2;
+}
+
+void*
+get_stack(double fraction, int min)
+{
+  int rc;
+  TIB *tib;
+  PIB *pib;
+  char *s, *e;
+  unsigned long d;
+    
+  if (!(_emx_env & 0x200)) return 0;	/* not OS/2. */
+  rc = DosGetInfoBlocks(&tib, &pib);
+  if (rc) return 0;			/* ignore error */
+  s = (char*)tib->tib_pstack;
+  e = (char*)tib->tib_pstacklimit;
+  d = fraction * (e-s);
+  if (min >= 3*(e-s)/4)
+    min = 3*(e-s)/4;
+  if (d < min)
+    d = min;
+  return (void*)(s + d);
 }