Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba00726

Browse files
committed
Add support for detecting register-stack overrun on IA64.
Per recent investigation, the register stack can grow faster than theregular stack depending on compiler and choice of options. To avoidcrashes we must check both stacks in check_stack_depth().Back-patch to all supported versions.
1 parentfb9042f commitba00726

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

‎src/backend/tcop/postgres.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ static long max_stack_depth_bytes = 100 * 1024L;
118118
*/
119119
char*stack_base_ptr=NULL;
120120

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
121127

122128
/*
123129
* Flag to mark SIGHUP. Whenever the main loop comes around it
@@ -2982,6 +2988,35 @@ ProcessInterrupts(void)
29822988
}
29832989

29842990

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+
returnret;
3015+
}
3016+
3017+
#endif/* IA64 */
3018+
3019+
29853020
/*
29863021
* check_stack_depth: check for excessively deep recursion
29873022
*
@@ -3024,6 +3059,28 @@ check_stack_depth(void)
30243059
errhint("Increase the configuration parameter \"max_stack_depth\", "
30253060
"after ensuring the platform's stack depth limit is adequate.")));
30263061
}
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 */
30273084
}
30283085

30293086
/* GUC assign hook for max_stack_depth */
@@ -3433,6 +3490,9 @@ PostgresMain(int argc, char *argv[], const char *username)
34333490

34343491
/* Set up reference point for stack depth checking */
34353492
stack_base_ptr=&stack_base;
3493+
#if defined(__ia64__)|| defined(__ia64)
3494+
register_stack_base_ptr=ia64_get_bsp();
3495+
#endif
34363496

34373497
/* Compute paths, if we didn't inherit them from postmaster */
34383498
if (my_exec_path[0]=='\0')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp