@@ -119,6 +119,12 @@ static long max_stack_depth_bytes = 100 * 1024L;
119119 */
120120char * stack_base_ptr = NULL ;
121121
122+ /*
123+ * On IA64 we also have to remember the register stack base.
124+ */
125+ #if defined(__ia64__ ) || defined(__ia64 )
126+ char * register_stack_base_ptr = NULL ;
127+ #endif
122128
123129/*
124130 * Flag to mark SIGHUP. Whenever the main loop comes around it
@@ -2983,6 +2989,35 @@ ProcessInterrupts(void)
29832989}
29842990
29852991
2992+ /*
2993+ * IA64-specific code to fetch the AR.BSP register for stack depth checks.
2994+ *
2995+ * We currently support gcc and icc here.
2996+ */
2997+ #if defined(__ia64__ ) || defined(__ia64 )
2998+
2999+ #include <asm/ia64regs.h>
3000+
3001+ static __inline__ char *
3002+ ia64_get_bsp (void )
3003+ {
3004+ char * ret ;
3005+
3006+ #ifndef __INTEL_COMPILER
3007+ /* the ;; is a "stop", seems to be required before fetching BSP */
3008+ __asm__ __volatile__(
3009+ ";;\n"
3010+ " mov %0=ar.bsp \n"
3011+ : "=r" (ret ));
3012+ #else
3013+ ret = (char * ) __getReg (_IA64_REG_AR_BSP );
3014+ #endif
3015+ return ret ;
3016+ }
3017+
3018+ #endif /* IA64 */
3019+
3020+
29863021/*
29873022 * check_stack_depth: check for excessively deep recursion
29883023 *
@@ -3026,6 +3061,29 @@ check_stack_depth(void)
30263061 "after ensuring the platform's stack depth limit is adequate." ,
30273062 max_stack_depth )));
30283063 }
3064+
3065+ /*
3066+ * On IA64 there is a separate "register" stack that requires its own
3067+ * independent check. For this, we have to measure the change in the
3068+ * "BSP" pointer from PostgresMain to here. Logic is just as above,
3069+ * except that we know IA64's register stack grows up.
3070+ *
3071+ * Note we assume that the same max_stack_depth applies to both stacks.
3072+ */
3073+ #if defined(__ia64__ ) || defined(__ia64 )
3074+ stack_depth = (long ) (ia64_get_bsp () - register_stack_base_ptr );
3075+
3076+ if (stack_depth > max_stack_depth_bytes &&
3077+ register_stack_base_ptr != NULL )
3078+ {
3079+ ereport (ERROR ,
3080+ (errcode (ERRCODE_STATEMENT_TOO_COMPLEX ),
3081+ errmsg ("stack depth limit exceeded" ),
3082+ errhint ("Increase the configuration parameter \"max_stack_depth\" (currently %dkB), "
3083+ "after ensuring the platform's stack depth limit is adequate." ,
3084+ max_stack_depth )));
3085+ }
3086+ #endif /* IA64 */
30293087}
30303088
30313089/* GUC assign hook for max_stack_depth */
@@ -3435,6 +3493,9 @@ PostgresMain(int argc, char *argv[], const char *username)
34353493
34363494 /* Set up reference point for stack depth checking */
34373495 stack_base_ptr = & stack_base ;
3496+ #if defined(__ia64__ ) || defined(__ia64 )
3497+ register_stack_base_ptr = ia64_get_bsp ();
3498+ #endif
34383499
34393500 /* Compute paths, if we didn't inherit them from postmaster */
34403501 if (my_exec_path [0 ] == '\0' )
0 commit comments