@@ -118,6 +118,12 @@ static long max_stack_depth_bytes = 100 * 1024L;
118
118
*/
119
119
char * stack_base_ptr = NULL ;
120
120
121
+ /*
122
+ * On IA64 we also have to remember the register stack base.
123
+ */
124
+ #if defined(__ia64__ )|| defined(__ia64 )
125
+ char * register_stack_base_ptr = NULL ;
126
+ #endif
121
127
122
128
/*
123
129
* Flag to mark SIGHUP. Whenever the main loop comes around it
@@ -2982,6 +2988,35 @@ ProcessInterrupts(void)
2982
2988
}
2983
2989
2984
2990
2991
+ /*
2992
+ * IA64-specific code to fetch the AR.BSP register for stack depth checks.
2993
+ *
2994
+ * We currently support gcc and icc here.
2995
+ */
2996
+ #if defined(__ia64__ )|| defined(__ia64 )
2997
+
2998
+ #include <asm/ia64regs.h>
2999
+
3000
+ static __inline__char *
3001
+ ia64_get_bsp (void )
3002
+ {
3003
+ char * ret ;
3004
+
3005
+ #ifndef __INTEL_COMPILER
3006
+ /* the ;; is a "stop", seems to be required before fetching BSP */
3007
+ __asm__ __volatile__(
3008
+ ";;\n"
3009
+ "mov%0=ar.bsp\n"
3010
+ :"=r" (ret ));
3011
+ #else
3012
+ ret = (char * )__getReg (_IA64_REG_AR_BSP );
3013
+ #endif
3014
+ return ret ;
3015
+ }
3016
+
3017
+ #endif /* IA64 */
3018
+
3019
+
2985
3020
/*
2986
3021
* check_stack_depth: check for excessively deep recursion
2987
3022
*
@@ -3024,6 +3059,28 @@ check_stack_depth(void)
3024
3059
errhint ("Increase the configuration parameter \"max_stack_depth\", "
3025
3060
"after ensuring the platform's stack depth limit is adequate." )));
3026
3061
}
3062
+
3063
+ /*
3064
+ * On IA64 there is a separate "register" stack that requires its own
3065
+ * independent check. For this, we have to measure the change in the
3066
+ * "BSP" pointer from PostgresMain to here. Logic is just as above,
3067
+ * except that we know IA64's register stack grows up.
3068
+ *
3069
+ * Note we assume that the same max_stack_depth applies to both stacks.
3070
+ */
3071
+ #if defined(__ia64__ )|| defined(__ia64 )
3072
+ stack_depth = (long ) (ia64_get_bsp ()- register_stack_base_ptr );
3073
+
3074
+ if (stack_depth > max_stack_depth_bytes &&
3075
+ register_stack_base_ptr != NULL )
3076
+ {
3077
+ ereport (ERROR ,
3078
+ (errcode (ERRCODE_STATEMENT_TOO_COMPLEX ),
3079
+ errmsg ("stack depth limit exceeded" ),
3080
+ errhint ("Increase the configuration parameter \"max_stack_depth\", "
3081
+ "after ensuring the platform's stack depth limit is adequate." )));
3082
+ }
3083
+ #endif /* IA64 */
3027
3084
}
3028
3085
3029
3086
/* GUC assign hook for max_stack_depth */
@@ -3433,6 +3490,9 @@ PostgresMain(int argc, char *argv[], const char *username)
3433
3490
3434
3491
/* Set up reference point for stack depth checking */
3435
3492
stack_base_ptr = & stack_base ;
3493
+ #if defined(__ia64__ )|| defined(__ia64 )
3494
+ register_stack_base_ptr = ia64_get_bsp ();
3495
+ #endif
3436
3496
3437
3497
/* Compute paths, if we didn't inherit them from postmaster */
3438
3498
if (my_exec_path [0 ]== '\0' )